cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
243 lines (242 loc) • 9 kB
JavaScript
import { __extends } from "../../../../tslib/tslib.es6.mjs";
import { createSymbol, normalizeSymbolOffset, normalizeSymbolSize } from "../../util/symbol.mjs";
import { getECData } from "../../util/innerStore.mjs";
import { enterEmphasis, leaveEmphasis, toggleHoverEmphasis } from "../../util/states.mjs";
import { getDefaultLabel } from "./labelHelper.mjs";
import { extend } from "../../../../zrender/lib/core/util.mjs";
import { getLabelStatesModels, setLabelStyle } from "../../label/labelStyle.mjs";
import ZRImage from "../../../../zrender/lib/graphic/Image.mjs";
import { updateProps, saveOldStyle, initProps, removeElement } from "../../animation/basicTransition.mjs";
import Group from "../../../../zrender/lib/graphic/Group.mjs";
var Symbol$1 = function(_super) {
__extends(Symbol, _super);
function Symbol(data, idx, seriesScope, opts) {
var _this = _super.call(this) || this;
_this.updateData(data, idx, seriesScope, opts);
return _this;
}
Symbol.prototype._createSymbol = function(symbolType, data, idx, symbolSize, keepAspect) {
this.removeAll();
var symbolPath = createSymbol(symbolType, -1, -1, 2, 2, null, keepAspect);
symbolPath.attr({
z2: 100,
culling: true,
scaleX: symbolSize[0] / 2,
scaleY: symbolSize[1] / 2
});
symbolPath.drift = driftSymbol;
this._symbolType = symbolType;
this.add(symbolPath);
};
Symbol.prototype.stopSymbolAnimation = function(toLastFrame) {
this.childAt(0).stopAnimation(null, toLastFrame);
};
Symbol.prototype.getSymbolType = function() {
return this._symbolType;
};
Symbol.prototype.getSymbolPath = function() {
return this.childAt(0);
};
Symbol.prototype.highlight = function() {
enterEmphasis(this.childAt(0));
};
Symbol.prototype.downplay = function() {
leaveEmphasis(this.childAt(0));
};
Symbol.prototype.setZ = function(zlevel, z) {
var symbolPath = this.childAt(0);
symbolPath.zlevel = zlevel;
symbolPath.z = z;
};
Symbol.prototype.setDraggable = function(draggable, hasCursorOption) {
var symbolPath = this.childAt(0);
symbolPath.draggable = draggable;
symbolPath.cursor = !hasCursorOption && draggable ? "move" : symbolPath.cursor;
};
Symbol.prototype.updateData = function(data, idx, seriesScope, opts) {
this.silent = false;
var symbolType = data.getItemVisual(idx, "symbol") || "circle";
var seriesModel = data.hostModel;
var symbolSize = Symbol.getSymbolSize(data, idx);
var isInit = symbolType !== this._symbolType;
var disableAnimation = opts && opts.disableAnimation;
if (isInit) {
var keepAspect = data.getItemVisual(idx, "symbolKeepAspect");
this._createSymbol(symbolType, data, idx, symbolSize, keepAspect);
} else {
var symbolPath = this.childAt(0);
symbolPath.silent = false;
var target = {
scaleX: symbolSize[0] / 2,
scaleY: symbolSize[1] / 2
};
disableAnimation ? symbolPath.attr(target) : updateProps(symbolPath, target, seriesModel, idx);
saveOldStyle(symbolPath);
}
this._updateCommon(data, idx, symbolSize, seriesScope, opts);
if (isInit) {
var symbolPath = this.childAt(0);
if (!disableAnimation) {
var target = {
scaleX: this._sizeX,
scaleY: this._sizeY,
style: {
opacity: symbolPath.style.opacity
}
};
symbolPath.scaleX = symbolPath.scaleY = 0;
symbolPath.style.opacity = 0;
initProps(symbolPath, target, seriesModel, idx);
}
}
if (disableAnimation) {
this.childAt(0).stopAnimation("leave");
}
};
Symbol.prototype._updateCommon = function(data, idx, symbolSize, seriesScope, opts) {
var symbolPath = this.childAt(0);
var seriesModel = data.hostModel;
var emphasisItemStyle;
var blurItemStyle;
var selectItemStyle;
var focus;
var blurScope;
var emphasisDisabled;
var labelStatesModels;
var hoverScale;
var cursorStyle;
if (seriesScope) {
emphasisItemStyle = seriesScope.emphasisItemStyle;
blurItemStyle = seriesScope.blurItemStyle;
selectItemStyle = seriesScope.selectItemStyle;
focus = seriesScope.focus;
blurScope = seriesScope.blurScope;
labelStatesModels = seriesScope.labelStatesModels;
hoverScale = seriesScope.hoverScale;
cursorStyle = seriesScope.cursorStyle;
emphasisDisabled = seriesScope.emphasisDisabled;
}
if (!seriesScope || data.hasItemOption) {
var itemModel = seriesScope && seriesScope.itemModel ? seriesScope.itemModel : data.getItemModel(idx);
var emphasisModel = itemModel.getModel("emphasis");
emphasisItemStyle = emphasisModel.getModel("itemStyle").getItemStyle();
selectItemStyle = itemModel.getModel(["select", "itemStyle"]).getItemStyle();
blurItemStyle = itemModel.getModel(["blur", "itemStyle"]).getItemStyle();
focus = emphasisModel.get("focus");
blurScope = emphasisModel.get("blurScope");
emphasisDisabled = emphasisModel.get("disabled");
labelStatesModels = getLabelStatesModels(itemModel);
hoverScale = emphasisModel.getShallow("scale");
cursorStyle = itemModel.getShallow("cursor");
}
var symbolRotate = data.getItemVisual(idx, "symbolRotate");
symbolPath.attr("rotation", (symbolRotate || 0) * Math.PI / 180 || 0);
var symbolOffset = normalizeSymbolOffset(data.getItemVisual(idx, "symbolOffset"), symbolSize);
if (symbolOffset) {
symbolPath.x = symbolOffset[0];
symbolPath.y = symbolOffset[1];
}
cursorStyle && symbolPath.attr("cursor", cursorStyle);
var symbolStyle = data.getItemVisual(idx, "style");
var visualColor = symbolStyle.fill;
if (symbolPath instanceof ZRImage) {
var pathStyle = symbolPath.style;
symbolPath.useStyle(extend({
image: pathStyle.image,
x: pathStyle.x,
y: pathStyle.y,
width: pathStyle.width,
height: pathStyle.height
}, symbolStyle));
} else {
if (symbolPath.__isEmptyBrush) {
symbolPath.useStyle(extend({}, symbolStyle));
} else {
symbolPath.useStyle(symbolStyle);
}
symbolPath.style.decal = null;
symbolPath.setColor(visualColor, opts && opts.symbolInnerColor);
symbolPath.style.strokeNoScale = true;
}
var liftZ = data.getItemVisual(idx, "liftZ");
var z2Origin = this._z2;
if (liftZ != null) {
if (z2Origin == null) {
this._z2 = symbolPath.z2;
symbolPath.z2 += liftZ;
}
} else if (z2Origin != null) {
symbolPath.z2 = z2Origin;
this._z2 = null;
}
var useNameLabel = opts && opts.useNameLabel;
setLabelStyle(symbolPath, labelStatesModels, {
labelFetcher: seriesModel,
labelDataIndex: idx,
defaultText: getLabelDefaultText,
inheritColor: visualColor,
defaultOpacity: symbolStyle.opacity
});
function getLabelDefaultText(idx2) {
return useNameLabel ? data.getName(idx2) : getDefaultLabel(data, idx2);
}
this._sizeX = symbolSize[0] / 2;
this._sizeY = symbolSize[1] / 2;
var emphasisState = symbolPath.ensureState("emphasis");
emphasisState.style = emphasisItemStyle;
symbolPath.ensureState("select").style = selectItemStyle;
symbolPath.ensureState("blur").style = blurItemStyle;
var scaleRatio = hoverScale == null || hoverScale === true ? Math.max(1.1, 3 / this._sizeY) : isFinite(hoverScale) && hoverScale > 0 ? +hoverScale : 1;
emphasisState.scaleX = this._sizeX * scaleRatio;
emphasisState.scaleY = this._sizeY * scaleRatio;
this.setSymbolScale(1);
toggleHoverEmphasis(this, focus, blurScope, emphasisDisabled);
};
Symbol.prototype.setSymbolScale = function(scale) {
this.scaleX = this.scaleY = scale;
};
Symbol.prototype.fadeOut = function(cb, seriesModel, opt) {
var symbolPath = this.childAt(0);
var dataIndex = getECData(this).dataIndex;
var animationOpt = opt && opt.animation;
this.silent = symbolPath.silent = true;
if (opt && opt.fadeLabel) {
var textContent = symbolPath.getTextContent();
if (textContent) {
removeElement(textContent, {
style: {
opacity: 0
}
}, seriesModel, {
dataIndex,
removeOpt: animationOpt,
cb: function() {
symbolPath.removeTextContent();
}
});
}
} else {
symbolPath.removeTextContent();
}
removeElement(symbolPath, {
style: {
opacity: 0
},
scaleX: 0,
scaleY: 0
}, seriesModel, {
dataIndex,
cb,
removeOpt: animationOpt
});
};
Symbol.getSymbolSize = function(data, idx) {
return normalizeSymbolSize(data.getItemVisual(idx, "symbolSize"));
};
return Symbol;
}(Group);
function driftSymbol(dx, dy) {
this.parent.drift(dx, dy);
}
var SymbolClz = Symbol$1;
export { SymbolClz as default };