123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925 |
- import { __extends } from "tslib";
- import { hasOwn, assert, isString, retrieve2, retrieve3, defaults, each, indexOf } from 'zrender/lib/core/util.js';
- import * as graphicUtil from '../../util/graphic.js';
- import { setDefaultStateProxy, toggleHoverEmphasis } from '../../util/states.js';
- import * as labelStyleHelper from '../../label/labelStyle.js';
- import { getDefaultLabel } from '../helper/labelHelper.js';
- import { getLayoutOnAxis } from '../../layout/barGrid.js';
- import DataDiffer from '../../data/DataDiffer.js';
- import ChartView from '../../view/Chart.js';
- import { createClipPath } from '../helper/createClipPathFromCoordSys.js';
- import prepareCartesian2d from '../../coord/cartesian/prepareCustom.js';
- import prepareGeo from '../../coord/geo/prepareCustom.js';
- import prepareSingleAxis from '../../coord/single/prepareCustom.js';
- import preparePolar from '../../coord/polar/prepareCustom.js';
- import prepareCalendar from '../../coord/calendar/prepareCustom.js';
- import Displayable from 'zrender/lib/graphic/Displayable.js';
- import { convertToEC4StyleForCustomSerise, isEC4CompatibleStyle, convertFromEC4CompatibleStyle, warnDeprecated } from '../../util/styleCompat.js';
- import { throwError } from '../../util/log.js';
- import { createOrUpdatePatternFromDecal } from '../../util/decal.js';
- import { STYLE_VISUAL_TYPE, NON_STYLE_VISUAL_PROPS, customInnerStore } from './CustomSeries.js';
- import { applyLeaveTransition, applyUpdateTransition } from '../../animation/customGraphicTransition.js';
- import { applyKeyframeAnimation, stopPreviousKeyframeAnimationAndRestore } from '../../animation/customGraphicKeyframeAnimation.js';
- var EMPHASIS = 'emphasis';
- var NORMAL = 'normal';
- var BLUR = 'blur';
- var SELECT = 'select';
- var STATES = [NORMAL, EMPHASIS, BLUR, SELECT];
- var PATH_ITEM_STYLE = {
- normal: ['itemStyle'],
- emphasis: [EMPHASIS, 'itemStyle'],
- blur: [BLUR, 'itemStyle'],
- select: [SELECT, 'itemStyle']
- };
- var PATH_LABEL = {
- normal: ['label'],
- emphasis: [EMPHASIS, 'label'],
- blur: [BLUR, 'label'],
- select: [SELECT, 'label']
- };
- var DEFAULT_TRANSITION = ['x', 'y'];
- var GROUP_DIFF_PREFIX = 'e\0\0';
- var attachedTxInfoTmp = {
- normal: {},
- emphasis: {},
- blur: {},
- select: {}
- };
- var prepareCustoms = {
- cartesian2d: prepareCartesian2d,
- geo: prepareGeo,
- single: prepareSingleAxis,
- polar: preparePolar,
- calendar: prepareCalendar
- };
- function isPath(el) {
- return el instanceof graphicUtil.Path;
- }
- function isDisplayable(el) {
- return el instanceof Displayable;
- }
- function copyElement(sourceEl, targetEl) {
- targetEl.copyTransform(sourceEl);
- if (isDisplayable(targetEl) && isDisplayable(sourceEl)) {
- targetEl.setStyle(sourceEl.style);
- targetEl.z = sourceEl.z;
- targetEl.z2 = sourceEl.z2;
- targetEl.zlevel = sourceEl.zlevel;
- targetEl.invisible = sourceEl.invisible;
- targetEl.ignore = sourceEl.ignore;
- if (isPath(targetEl) && isPath(sourceEl)) {
- targetEl.setShape(sourceEl.shape);
- }
- }
- }
- var CustomChartView = function (_super) {
- __extends(CustomChartView, _super);
- function CustomChartView() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.type = CustomChartView.type;
- return _this;
- }
- CustomChartView.prototype.render = function (customSeries, ecModel, api, payload) {
-
- this._progressiveEls = null;
- var oldData = this._data;
- var data = customSeries.getData();
- var group = this.group;
- var renderItem = makeRenderItem(customSeries, data, ecModel, api);
- if (!oldData) {
-
-
- group.removeAll();
- }
- data.diff(oldData).add(function (newIdx) {
- createOrUpdateItem(api, null, newIdx, renderItem(newIdx, payload), customSeries, group, data);
- }).remove(function (oldIdx) {
- var el = oldData.getItemGraphicEl(oldIdx);
- el && applyLeaveTransition(el, customInnerStore(el).option, customSeries);
- }).update(function (newIdx, oldIdx) {
- var oldEl = oldData.getItemGraphicEl(oldIdx);
- createOrUpdateItem(api, oldEl, newIdx, renderItem(newIdx, payload), customSeries, group, data);
- }).execute();
-
- var clipPath = customSeries.get('clip', true) ? createClipPath(customSeries.coordinateSystem, false, customSeries) : null;
- if (clipPath) {
- group.setClipPath(clipPath);
- } else {
- group.removeClipPath();
- }
- this._data = data;
- };
- CustomChartView.prototype.incrementalPrepareRender = function (customSeries, ecModel, api) {
- this.group.removeAll();
- this._data = null;
- };
- CustomChartView.prototype.incrementalRender = function (params, customSeries, ecModel, api, payload) {
- var data = customSeries.getData();
- var renderItem = makeRenderItem(customSeries, data, ecModel, api);
- var progressiveEls = this._progressiveEls = [];
- function setIncrementalAndHoverLayer(el) {
- if (!el.isGroup) {
- el.incremental = true;
- el.ensureState('emphasis').hoverLayer = true;
- }
- }
- for (var idx = params.start; idx < params.end; idx++) {
- var el = createOrUpdateItem(null, null, idx, renderItem(idx, payload), customSeries, this.group, data);
- if (el) {
- el.traverse(setIncrementalAndHoverLayer);
- progressiveEls.push(el);
- }
- }
- };
- CustomChartView.prototype.eachRendered = function (cb) {
- graphicUtil.traverseElements(this._progressiveEls || this.group, cb);
- };
- CustomChartView.prototype.filterForExposedEvent = function (eventType, query, targetEl, packedEvent) {
- var elementName = query.element;
- if (elementName == null || targetEl.name === elementName) {
- return true;
- }
-
-
- while ((targetEl = targetEl.__hostTarget || targetEl.parent) && targetEl !== this.group) {
- if (targetEl.name === elementName) {
- return true;
- }
- }
- return false;
- };
- CustomChartView.type = 'custom';
- return CustomChartView;
- }(ChartView);
- export default CustomChartView;
- function createEl(elOption) {
- var graphicType = elOption.type;
- var el;
-
-
- if (graphicType === 'path') {
- var shape = elOption.shape;
-
- var pathRect = shape.width != null && shape.height != null ? {
- x: shape.x || 0,
- y: shape.y || 0,
- width: shape.width,
- height: shape.height
- } : null;
- var pathData = getPathData(shape);
-
- el = graphicUtil.makePath(pathData, null, pathRect, shape.layout || 'center');
- customInnerStore(el).customPathData = pathData;
- } else if (graphicType === 'image') {
- el = new graphicUtil.Image({});
- customInnerStore(el).customImagePath = elOption.style.image;
- } else if (graphicType === 'text') {
- el = new graphicUtil.Text({});
-
- } else if (graphicType === 'group') {
- el = new graphicUtil.Group();
- } else if (graphicType === 'compoundPath') {
- throw new Error('"compoundPath" is not supported yet.');
- } else {
- var Clz = graphicUtil.getShapeClass(graphicType);
- if (!Clz) {
- var errMsg = '';
- if (process.env.NODE_ENV !== 'production') {
- errMsg = 'graphic type "' + graphicType + '" can not be found.';
- }
- throwError(errMsg);
- }
- el = new Clz();
- }
- customInnerStore(el).customGraphicType = graphicType;
- el.name = elOption.name;
-
-
-
- el.z2EmphasisLift = 1;
- el.z2SelectLift = 1;
- return el;
- }
- function updateElNormal(
- // Can be null/undefined
- api, el, dataIndex, elOption, attachedTxInfo, seriesModel, isInit) {
- // Stop and restore before update any other attributes.
- stopPreviousKeyframeAnimationAndRestore(el);
- var txCfgOpt = attachedTxInfo && attachedTxInfo.normal.cfg;
- if (txCfgOpt) {
- // PENDING: whether use user object directly rather than clone?
- // TODO:5.0 textConfig transition animation?
- el.setTextConfig(txCfgOpt);
- }
- // Default transition ['x', 'y']
- if (elOption && elOption.transition == null) {
- elOption.transition = DEFAULT_TRANSITION;
- }
- // Do some normalization on style.
- var styleOpt = elOption && elOption.style;
- if (styleOpt) {
- if (el.type === 'text') {
- var textOptionStyle = styleOpt;
- // Compatible with ec4: if `textFill` or `textStroke` exists use them.
- hasOwn(textOptionStyle, 'textFill') && (textOptionStyle.fill = textOptionStyle.textFill);
- hasOwn(textOptionStyle, 'textStroke') && (textOptionStyle.stroke = textOptionStyle.textStroke);
- }
- var decalPattern = void 0;
- var decalObj = isPath(el) ? styleOpt.decal : null;
- if (api && decalObj) {
- decalObj.dirty = true;
- decalPattern = createOrUpdatePatternFromDecal(decalObj, api);
- }
- // Always overwrite in case user specify this prop.
- styleOpt.__decalPattern = decalPattern;
- }
- if (isDisplayable(el)) {
- if (styleOpt) {
- var decalPattern = styleOpt.__decalPattern;
- if (decalPattern) {
- styleOpt.decal = decalPattern;
- }
- }
- }
- applyUpdateTransition(el, elOption, seriesModel, {
- dataIndex: dataIndex,
- isInit: isInit,
- clearStyle: true
- });
- applyKeyframeAnimation(el, elOption.keyframeAnimation, seriesModel);
- }
- function updateElOnState(state, el, elStateOpt, styleOpt, attachedTxInfo) {
- var elDisplayable = el.isGroup ? null : el;
- var txCfgOpt = attachedTxInfo && attachedTxInfo[state].cfg;
- // PENDING:5.0 support customize scale change and transition animation?
- if (elDisplayable) {
- // By default support auto lift color when hover whether `emphasis` specified.
- var stateObj = elDisplayable.ensureState(state);
- if (styleOpt === false) {
- var existingEmphasisState = elDisplayable.getState(state);
- if (existingEmphasisState) {
- existingEmphasisState.style = null;
- }
- } else {
- // style is needed to enable default emphasis.
- stateObj.style = styleOpt || null;
- }
- // If `elOption.styleEmphasis` or `elOption.emphasis.style` is `false`,
- // remove hover style.
- // If `elOption.textConfig` or `elOption.emphasis.textConfig` is null/undefined, it does not
- // make sense. So for simplicity, we do not ditinguish `hasOwnProperty` and null/undefined.
- if (txCfgOpt) {
- stateObj.textConfig = txCfgOpt;
- }
- setDefaultStateProxy(elDisplayable);
- }
- }
- function updateZ(el, elOption, seriesModel) {
- // Group not support textContent and not support z yet.
- if (el.isGroup) {
- return;
- }
- var elDisplayable = el;
- var currentZ = seriesModel.currentZ;
- var currentZLevel = seriesModel.currentZLevel;
- // Always erase.
- elDisplayable.z = currentZ;
- elDisplayable.zlevel = currentZLevel;
- // z2 must not be null/undefined, otherwise sort error may occur.
- var optZ2 = elOption.z2;
- optZ2 != null && (elDisplayable.z2 = optZ2 || 0);
- for (var i = 0; i < STATES.length; i++) {
- updateZForEachState(elDisplayable, elOption, STATES[i]);
- }
- }
- function updateZForEachState(elDisplayable, elOption, state) {
- var isNormal = state === NORMAL;
- var elStateOpt = isNormal ? elOption : retrieveStateOption(elOption, state);
- var optZ2 = elStateOpt ? elStateOpt.z2 : null;
- var stateObj;
- if (optZ2 != null) {
-
- stateObj = isNormal ? elDisplayable : elDisplayable.ensureState(state);
- stateObj.z2 = optZ2 || 0;
- }
- }
- function makeRenderItem(customSeries, data, ecModel, api) {
- var renderItem = customSeries.get('renderItem');
- var coordSys = customSeries.coordinateSystem;
- var prepareResult = {};
- if (coordSys) {
- if (process.env.NODE_ENV !== 'production') {
- assert(renderItem, 'series.render is required.');
- assert(coordSys.prepareCustoms || prepareCustoms[coordSys.type], 'This coordSys does not support custom series.');
- }
-
- prepareResult = coordSys.prepareCustoms ? coordSys.prepareCustoms(coordSys) : prepareCustoms[coordSys.type](coordSys);
- }
- var userAPI = defaults({
- getWidth: api.getWidth,
- getHeight: api.getHeight,
- getZr: api.getZr,
- getDevicePixelRatio: api.getDevicePixelRatio,
- value: value,
- style: style,
- ordinalRawValue: ordinalRawValue,
- styleEmphasis: styleEmphasis,
- visual: visual,
- barLayout: barLayout,
- currentSeriesIndices: currentSeriesIndices,
- font: font
- }, prepareResult.api || {});
- var userParams = {
-
-
-
- context: {},
- seriesId: customSeries.id,
- seriesName: customSeries.name,
- seriesIndex: customSeries.seriesIndex,
- coordSys: prepareResult.coordSys,
- dataInsideLength: data.count(),
- encode: wrapEncodeDef(customSeries.getData())
- };
-
-
-
-
- var currDataIndexInside;
- var currItemModel;
- var currItemStyleModels = {};
- var currLabelModels = {};
- var seriesItemStyleModels = {};
- var seriesLabelModels = {};
- for (var i = 0; i < STATES.length; i++) {
- var stateName = STATES[i];
- seriesItemStyleModels[stateName] = customSeries.getModel(PATH_ITEM_STYLE[stateName]);
- seriesLabelModels[stateName] = customSeries.getModel(PATH_LABEL[stateName]);
- }
- function getItemModel(dataIndexInside) {
- return dataIndexInside === currDataIndexInside ? currItemModel || (currItemModel = data.getItemModel(dataIndexInside)) : data.getItemModel(dataIndexInside);
- }
- function getItemStyleModel(dataIndexInside, state) {
- return !data.hasItemOption ? seriesItemStyleModels[state] : dataIndexInside === currDataIndexInside ? currItemStyleModels[state] || (currItemStyleModels[state] = getItemModel(dataIndexInside).getModel(PATH_ITEM_STYLE[state])) : getItemModel(dataIndexInside).getModel(PATH_ITEM_STYLE[state]);
- }
- function getLabelModel(dataIndexInside, state) {
- return !data.hasItemOption ? seriesLabelModels[state] : dataIndexInside === currDataIndexInside ? currLabelModels[state] || (currLabelModels[state] = getItemModel(dataIndexInside).getModel(PATH_LABEL[state])) : getItemModel(dataIndexInside).getModel(PATH_LABEL[state]);
- }
- return function (dataIndexInside, payload) {
- currDataIndexInside = dataIndexInside;
- currItemModel = null;
- currItemStyleModels = {};
- currLabelModels = {};
- return renderItem && renderItem(defaults({
- dataIndexInside: dataIndexInside,
- dataIndex: data.getRawIndex(dataIndexInside),
-
- actionType: payload ? payload.type : null
- }, userParams), userAPI);
- };
-
- function value(dim, dataIndexInside) {
- dataIndexInside == null && (dataIndexInside = currDataIndexInside);
- return data.getStore().get(data.getDimensionIndex(dim || 0), dataIndexInside);
- }
-
- function ordinalRawValue(dim, dataIndexInside) {
- dataIndexInside == null && (dataIndexInside = currDataIndexInside);
- dim = dim || 0;
- var dimInfo = data.getDimensionInfo(dim);
- if (!dimInfo) {
- var dimIndex = data.getDimensionIndex(dim);
- return dimIndex >= 0 ? data.getStore().get(dimIndex, dataIndexInside) : undefined;
- }
- var val = data.get(dimInfo.name, dataIndexInside);
- var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
- return ordinalMeta ? ordinalMeta.categories[val] : val;
- }
-
- function style(userProps, dataIndexInside) {
- if (process.env.NODE_ENV !== 'production') {
- warnDeprecated('api.style', 'Please write literal style directly instead.');
- }
- dataIndexInside == null && (dataIndexInside = currDataIndexInside);
- var style = data.getItemVisual(dataIndexInside, 'style');
- var visualColor = style && style.fill;
- var opacity = style && style.opacity;
- var itemStyle = getItemStyleModel(dataIndexInside, NORMAL).getItemStyle();
- visualColor != null && (itemStyle.fill = visualColor);
- opacity != null && (itemStyle.opacity = opacity);
- var opt = {
- inheritColor: isString(visualColor) ? visualColor : '#000'
- };
- var labelModel = getLabelModel(dataIndexInside, NORMAL);
-
-
-
- var textStyle = labelStyleHelper.createTextStyle(labelModel, null, opt, false, true);
- textStyle.text = labelModel.getShallow('show') ? retrieve2(customSeries.getFormattedLabel(dataIndexInside, NORMAL), getDefaultLabel(data, dataIndexInside)) : null;
- var textConfig = labelStyleHelper.createTextConfig(labelModel, opt, false);
- preFetchFromExtra(userProps, itemStyle);
- itemStyle = convertToEC4StyleForCustomSerise(itemStyle, textStyle, textConfig);
- userProps && applyUserPropsAfter(itemStyle, userProps);
- itemStyle.legacy = true;
- return itemStyle;
- }
-
- function styleEmphasis(userProps, dataIndexInside) {
- if (process.env.NODE_ENV !== 'production') {
- warnDeprecated('api.styleEmphasis', 'Please write literal style directly instead.');
- }
- dataIndexInside == null && (dataIndexInside = currDataIndexInside);
- var itemStyle = getItemStyleModel(dataIndexInside, EMPHASIS).getItemStyle();
- var labelModel = getLabelModel(dataIndexInside, EMPHASIS);
- var textStyle = labelStyleHelper.createTextStyle(labelModel, null, null, true, true);
- textStyle.text = labelModel.getShallow('show') ? retrieve3(customSeries.getFormattedLabel(dataIndexInside, EMPHASIS), customSeries.getFormattedLabel(dataIndexInside, NORMAL), getDefaultLabel(data, dataIndexInside)) : null;
- var textConfig = labelStyleHelper.createTextConfig(labelModel, null, true);
- preFetchFromExtra(userProps, itemStyle);
- itemStyle = convertToEC4StyleForCustomSerise(itemStyle, textStyle, textConfig);
- userProps && applyUserPropsAfter(itemStyle, userProps);
- itemStyle.legacy = true;
- return itemStyle;
- }
- function applyUserPropsAfter(itemStyle, extra) {
- for (var key in extra) {
- if (hasOwn(extra, key)) {
- itemStyle[key] = extra[key];
- }
- }
- }
- function preFetchFromExtra(extra, itemStyle) {
-
-
-
- if (extra) {
- extra.textFill && (itemStyle.textFill = extra.textFill);
- extra.textPosition && (itemStyle.textPosition = extra.textPosition);
- }
- }
-
- function visual(visualType, dataIndexInside) {
- dataIndexInside == null && (dataIndexInside = currDataIndexInside);
- if (hasOwn(STYLE_VISUAL_TYPE, visualType)) {
- var style_1 = data.getItemVisual(dataIndexInside, 'style');
- return style_1 ? style_1[STYLE_VISUAL_TYPE[visualType]] : null;
- }
-
-
- if (hasOwn(NON_STYLE_VISUAL_PROPS, visualType)) {
- return data.getItemVisual(dataIndexInside, visualType);
- }
- }
-
- function barLayout(opt) {
- if (coordSys.type === 'cartesian2d') {
- var baseAxis = coordSys.getBaseAxis();
- return getLayoutOnAxis(defaults({
- axis: baseAxis
- }, opt));
- }
- }
-
- function currentSeriesIndices() {
- return ecModel.getCurrentSeriesIndices();
- }
-
- function font(opt) {
- return labelStyleHelper.getFont(opt, ecModel);
- }
- }
- function wrapEncodeDef(data) {
- var encodeDef = {};
- each(data.dimensions, function (dimName) {
- var dimInfo = data.getDimensionInfo(dimName);
- if (!dimInfo.isExtraCoord) {
- var coordDim = dimInfo.coordDim;
- var dataDims = encodeDef[coordDim] = encodeDef[coordDim] || [];
- dataDims[dimInfo.coordDimIndex] = data.getDimensionIndex(dimName);
- }
- });
- return encodeDef;
- }
- function createOrUpdateItem(api, existsEl, dataIndex, elOption, seriesModel, group, data) {
-
-
-
-
-
-
-
- if (!elOption) {
- group.remove(existsEl);
- return;
- }
- var el = doCreateOrUpdateEl(api, existsEl, dataIndex, elOption, seriesModel, group);
- el && data.setItemGraphicEl(dataIndex, el);
- el && toggleHoverEmphasis(el, elOption.focus, elOption.blurScope, elOption.emphasisDisabled);
- return el;
- }
- function doCreateOrUpdateEl(api, existsEl, dataIndex, elOption, seriesModel, group) {
- if (process.env.NODE_ENV !== 'production') {
- assert(elOption, 'should not have an null/undefined element setting');
- }
- var toBeReplacedIdx = -1;
- var oldEl = existsEl;
- if (existsEl && doesElNeedRecreate(existsEl, elOption, seriesModel)
-
-
-
-
-
-
- ) {
-
- toBeReplacedIdx = indexOf(group.childrenRef(), existsEl);
- existsEl = null;
- }
- var isInit = !existsEl;
- var el = existsEl;
- if (!el) {
- el = createEl(elOption);
- if (oldEl) {
- copyElement(oldEl, el);
- }
- } else {
-
-
-
- el.clearStates();
- }
-
- if (elOption.morph === false) {
- el.disableMorphing = true;
- } else if (el.disableMorphing) {
- el.disableMorphing = false;
- }
- attachedTxInfoTmp.normal.cfg = attachedTxInfoTmp.normal.conOpt = attachedTxInfoTmp.emphasis.cfg = attachedTxInfoTmp.emphasis.conOpt = attachedTxInfoTmp.blur.cfg = attachedTxInfoTmp.blur.conOpt = attachedTxInfoTmp.select.cfg = attachedTxInfoTmp.select.conOpt = null;
- attachedTxInfoTmp.isLegacy = false;
- doCreateOrUpdateAttachedTx(el, dataIndex, elOption, seriesModel, isInit, attachedTxInfoTmp);
- doCreateOrUpdateClipPath(el, dataIndex, elOption, seriesModel, isInit);
- updateElNormal(api, el, dataIndex, elOption, attachedTxInfoTmp, seriesModel, isInit);
-
-
-
- hasOwn(elOption, 'info') && (customInnerStore(el).info = elOption.info);
- for (var i = 0; i < STATES.length; i++) {
- var stateName = STATES[i];
- if (stateName !== NORMAL) {
- var otherStateOpt = retrieveStateOption(elOption, stateName);
- var otherStyleOpt = retrieveStyleOptionOnState(elOption, otherStateOpt, stateName);
- updateElOnState(stateName, el, otherStateOpt, otherStyleOpt, attachedTxInfoTmp);
- }
- }
- updateZ(el, elOption, seriesModel);
- if (elOption.type === 'group') {
- mergeChildren(api, el, dataIndex, elOption, seriesModel);
- }
- if (toBeReplacedIdx >= 0) {
- group.replaceAt(el, toBeReplacedIdx);
- } else {
- group.add(el);
- }
- return el;
- }
- function doesElNeedRecreate(el, elOption, seriesModel) {
- var elInner = customInnerStore(el);
- var elOptionType = elOption.type;
- var elOptionShape = elOption.shape;
- var elOptionStyle = elOption.style;
- return (
-
-
- seriesModel.isUniversalTransitionEnabled()
-
- || elOptionType != null && elOptionType !== elInner.customGraphicType || elOptionType === 'path' && hasOwnPathData(elOptionShape) && getPathData(elOptionShape) !== elInner.customPathData || elOptionType === 'image' && hasOwn(elOptionStyle, 'image') && elOptionStyle.image !== elInner.customImagePath
-
-
-
-
-
- );
- }
- function doCreateOrUpdateClipPath(el, dataIndex, elOption, seriesModel, isInit) {
-
-
-
- var clipPathOpt = elOption.clipPath;
- if (clipPathOpt === false) {
- if (el && el.getClipPath()) {
- el.removeClipPath();
- }
- } else if (clipPathOpt) {
- var clipPath = el.getClipPath();
- if (clipPath && doesElNeedRecreate(clipPath, clipPathOpt, seriesModel)) {
- clipPath = null;
- }
- if (!clipPath) {
- clipPath = createEl(clipPathOpt);
- if (process.env.NODE_ENV !== 'production') {
- assert(isPath(clipPath), 'Only any type of `path` can be used in `clipPath`, rather than ' + clipPath.type + '.');
- }
- el.setClipPath(clipPath);
- }
- updateElNormal(null, clipPath, dataIndex, clipPathOpt, null, seriesModel, isInit);
- }
-
- }
- function doCreateOrUpdateAttachedTx(el, dataIndex, elOption, seriesModel, isInit, attachedTxInfo) {
-
- if (el.isGroup) {
- return;
- }
-
- processTxInfo(elOption, null, attachedTxInfo);
- processTxInfo(elOption, EMPHASIS, attachedTxInfo);
-
-
-
-
-
-
- var txConOptNormal = attachedTxInfo.normal.conOpt;
- var txConOptEmphasis = attachedTxInfo.emphasis.conOpt;
- var txConOptBlur = attachedTxInfo.blur.conOpt;
- var txConOptSelect = attachedTxInfo.select.conOpt;
- if (txConOptNormal != null || txConOptEmphasis != null || txConOptSelect != null || txConOptBlur != null) {
- var textContent = el.getTextContent();
- if (txConOptNormal === false) {
- textContent && el.removeTextContent();
- } else {
- txConOptNormal = attachedTxInfo.normal.conOpt = txConOptNormal || {
- type: 'text'
- };
- if (!textContent) {
- textContent = createEl(txConOptNormal);
- el.setTextContent(textContent);
- } else {
-
-
- textContent.clearStates();
- }
- updateElNormal(null, textContent, dataIndex, txConOptNormal, null, seriesModel, isInit);
- var txConStlOptNormal = txConOptNormal && txConOptNormal.style;
- for (var i = 0; i < STATES.length; i++) {
- var stateName = STATES[i];
- if (stateName !== NORMAL) {
- var txConOptOtherState = attachedTxInfo[stateName].conOpt;
- updateElOnState(stateName, textContent, txConOptOtherState, retrieveStyleOptionOnState(txConOptNormal, txConOptOtherState, stateName), null);
- }
- }
- txConStlOptNormal ? textContent.dirty() : textContent.markRedraw();
- }
- }
- }
- function processTxInfo(elOption, state, attachedTxInfo) {
- var stateOpt = !state ? elOption : retrieveStateOption(elOption, state);
- var styleOpt = !state ? elOption.style : retrieveStyleOptionOnState(elOption, stateOpt, EMPHASIS);
- var elType = elOption.type;
- var txCfg = stateOpt ? stateOpt.textConfig : null;
- var txConOptNormal = elOption.textContent;
- var txConOpt = !txConOptNormal ? null : !state ? txConOptNormal : retrieveStateOption(txConOptNormal, state);
- if (styleOpt && (
-
-
- attachedTxInfo.isLegacy || isEC4CompatibleStyle(styleOpt, elType, !!txCfg, !!txConOpt))) {
- attachedTxInfo.isLegacy = true;
- var convertResult = convertFromEC4CompatibleStyle(styleOpt, elType, !state);
-
-
-
- if (!txCfg && convertResult.textConfig) {
- txCfg = convertResult.textConfig;
- }
- if (!txConOpt && convertResult.textContent) {
- txConOpt = convertResult.textContent;
- }
- }
- if (!state && txConOpt) {
- var txConOptNormal_1 = txConOpt;
-
- !txConOptNormal_1.type && (txConOptNormal_1.type = 'text');
- if (process.env.NODE_ENV !== 'production') {
-
- assert(txConOptNormal_1.type === 'text', 'textContent.type must be "text"');
- }
- }
- var info = !state ? attachedTxInfo.normal : attachedTxInfo[state];
- info.cfg = txCfg;
- info.conOpt = txConOpt;
- }
- function retrieveStateOption(elOption, state) {
- return !state ? elOption : elOption ? elOption[state] : null;
- }
- function retrieveStyleOptionOnState(stateOptionNormal, stateOption, state) {
- var style = stateOption && stateOption.style;
- if (style == null && state === EMPHASIS && stateOptionNormal) {
- style = stateOptionNormal.styleEmphasis;
- }
- return style;
- }
- function mergeChildren(api, el, dataIndex, elOption, seriesModel) {
- var newChildren = elOption.children;
- var newLen = newChildren ? newChildren.length : 0;
- var mergeChildren = elOption.$mergeChildren;
-
- var byName = mergeChildren === 'byName' || elOption.diffChildrenByName;
- var notMerge = mergeChildren === false;
-
- if (!newLen && !byName && !notMerge) {
- return;
- }
- if (byName) {
- diffGroupChildren({
- api: api,
- oldChildren: el.children() || [],
- newChildren: newChildren || [],
- dataIndex: dataIndex,
- seriesModel: seriesModel,
- group: el
- });
- return;
- }
- notMerge && el.removeAll();
-
-
- var index = 0;
- for (; index < newLen; index++) {
- var newChild = newChildren[index];
- var oldChild = el.childAt(index);
- if (newChild) {
- if (newChild.ignore == null) {
-
-
- newChild.ignore = false;
- }
- doCreateOrUpdateEl(api, oldChild, dataIndex, newChild, seriesModel, el);
- } else {
- if (process.env.NODE_ENV !== 'production') {
- assert(oldChild, 'renderItem should not return a group containing elements' + ' as null/undefined/{} if they do not exist before.');
- }
-
-
-
-
- oldChild.ignore = true;
- }
- }
- for (var i = el.childCount() - 1; i >= index; i--) {
- var child = el.childAt(i);
- removeChildFromGroup(el, child, seriesModel);
- }
- }
- function removeChildFromGroup(group, child, seriesModel) {
-
-
-
- child && applyLeaveTransition(child, customInnerStore(group).option, seriesModel);
- }
- function diffGroupChildren(context) {
- new DataDiffer(context.oldChildren, context.newChildren, getKey, getKey, context).add(processAddUpdate).update(processAddUpdate).remove(processRemove).execute();
- }
- function getKey(item, idx) {
- var name = item && item.name;
- return name != null ? name : GROUP_DIFF_PREFIX + idx;
- }
- function processAddUpdate(newIndex, oldIndex) {
- var context = this.context;
- var childOption = newIndex != null ? context.newChildren[newIndex] : null;
- var child = oldIndex != null ? context.oldChildren[oldIndex] : null;
- doCreateOrUpdateEl(context.api, child, context.dataIndex, childOption, context.seriesModel, context.group);
- }
- function processRemove(oldIndex) {
- var context = this.context;
- var child = context.oldChildren[oldIndex];
- child && applyLeaveTransition(child, customInnerStore(child).option, context.seriesModel);
- }
- function getPathData(shape) {
-
- return shape && (shape.pathData || shape.d);
- }
- function hasOwnPathData(shape) {
- return shape && (hasOwn(shape, 'pathData') || hasOwn(shape, 'd'));
- }
|