CustomView.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import { hasOwn, assert, isString, retrieve2, retrieve3, defaults, each, keys, bind, eqNaN, indexOf } from 'zrender/lib/core/util';
  42. import * as graphicUtil from '../../util/graphic';
  43. import { setDefaultStateProxy, enableHoverEmphasis } from '../../util/states';
  44. import * as labelStyleHelper from '../../label/labelStyle';
  45. import { getDefaultLabel } from '../helper/labelHelper';
  46. import { getLayoutOnAxis } from '../../layout/barGrid';
  47. import DataDiffer from '../../data/DataDiffer';
  48. import ChartView from '../../view/Chart';
  49. import { createClipPath } from '../helper/createClipPathFromCoordSys';
  50. import prepareCartesian2d from '../../coord/cartesian/prepareCustom';
  51. import prepareGeo from '../../coord/geo/prepareCustom';
  52. import prepareSingleAxis from '../../coord/single/prepareCustom';
  53. import preparePolar from '../../coord/polar/prepareCustom';
  54. import prepareCalendar from '../../coord/calendar/prepareCustom';
  55. import Displayable from 'zrender/lib/graphic/Displayable';
  56. import { convertToEC4StyleForCustomSerise, isEC4CompatibleStyle, convertFromEC4CompatibleStyle, warnDeprecated } from '../../util/styleCompat';
  57. import { warn, throwError } from '../../util/log';
  58. import { createOrUpdatePatternFromDecal } from '../../util/decal';
  59. import { TRANSFORM_PROPS, STYLE_VISUAL_TYPE, NON_STYLE_VISUAL_PROPS, customInnerStore } from './CustomSeries';
  60. import { prepareShapeOrExtraAllPropsFinal, prepareShapeOrExtraTransitionFrom, prepareStyleTransitionFrom, prepareTransformAllPropsFinal, prepareTransformTransitionFrom } from './prepare';
  61. var transformPropNamesStr = keys(TRANSFORM_PROPS).join(', ');
  62. var EMPHASIS = 'emphasis';
  63. var NORMAL = 'normal';
  64. var BLUR = 'blur';
  65. var SELECT = 'select';
  66. var STATES = [NORMAL, EMPHASIS, BLUR, SELECT];
  67. var PATH_ITEM_STYLE = {
  68. normal: ['itemStyle'],
  69. emphasis: [EMPHASIS, 'itemStyle'],
  70. blur: [BLUR, 'itemStyle'],
  71. select: [SELECT, 'itemStyle']
  72. };
  73. var PATH_LABEL = {
  74. normal: ['label'],
  75. emphasis: [EMPHASIS, 'label'],
  76. blur: [BLUR, 'label'],
  77. select: [SELECT, 'label']
  78. }; // Use prefix to avoid index to be the same as el.name,
  79. // which will cause weird update animation.
  80. var GROUP_DIFF_PREFIX = 'e\0\0';
  81. var attachedTxInfoTmp = {
  82. normal: {},
  83. emphasis: {},
  84. blur: {},
  85. select: {}
  86. };
  87. /**
  88. * To reduce total package size of each coordinate systems, the modules `prepareCustom`
  89. * of each coordinate systems are not required by each coordinate systems directly, but
  90. * required by the module `custom`.
  91. *
  92. * prepareInfoForCustomSeries {Function}: optional
  93. * @return {Object} {coordSys: {...}, api: {
  94. * coord: function (data, clamp) {}, // return point in global.
  95. * size: function (dataSize, dataItem) {} // return size of each axis in coordSys.
  96. * }}
  97. */
  98. var prepareCustoms = {
  99. cartesian2d: prepareCartesian2d,
  100. geo: prepareGeo,
  101. singleAxis: prepareSingleAxis,
  102. polar: preparePolar,
  103. calendar: prepareCalendar
  104. };
  105. function isPath(el) {
  106. return el instanceof graphicUtil.Path;
  107. }
  108. function isDisplayable(el) {
  109. return el instanceof Displayable;
  110. }
  111. function copyElement(sourceEl, targetEl) {
  112. targetEl.copyTransform(sourceEl);
  113. if (isDisplayable(targetEl) && isDisplayable(sourceEl)) {
  114. targetEl.setStyle(sourceEl.style);
  115. targetEl.z = sourceEl.z;
  116. targetEl.z2 = sourceEl.z2;
  117. targetEl.zlevel = sourceEl.zlevel;
  118. targetEl.invisible = sourceEl.invisible;
  119. targetEl.ignore = sourceEl.ignore;
  120. if (isPath(targetEl) && isPath(sourceEl)) {
  121. targetEl.setShape(sourceEl.shape);
  122. }
  123. }
  124. }
  125. var CustomChartView =
  126. /** @class */
  127. function (_super) {
  128. __extends(CustomChartView, _super);
  129. function CustomChartView() {
  130. var _this = _super !== null && _super.apply(this, arguments) || this;
  131. _this.type = CustomChartView.type;
  132. return _this;
  133. }
  134. CustomChartView.prototype.render = function (customSeries, ecModel, api, payload) {
  135. var oldData = this._data;
  136. var data = customSeries.getData();
  137. var group = this.group;
  138. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  139. if (!oldData) {
  140. // Previous render is incremental render or first render.
  141. // Needs remove the incremental rendered elements.
  142. group.removeAll();
  143. }
  144. data.diff(oldData).add(function (newIdx) {
  145. createOrUpdateItem(api, null, newIdx, renderItem(newIdx, payload), customSeries, group, data);
  146. }).remove(function (oldIdx) {
  147. doRemoveEl(oldData.getItemGraphicEl(oldIdx), customSeries, group);
  148. }).update(function (newIdx, oldIdx) {
  149. var oldEl = oldData.getItemGraphicEl(oldIdx);
  150. createOrUpdateItem(api, oldEl, newIdx, renderItem(newIdx, payload), customSeries, group, data);
  151. }).execute(); // Do clipping
  152. var clipPath = customSeries.get('clip', true) ? createClipPath(customSeries.coordinateSystem, false, customSeries) : null;
  153. if (clipPath) {
  154. group.setClipPath(clipPath);
  155. } else {
  156. group.removeClipPath();
  157. }
  158. this._data = data;
  159. };
  160. CustomChartView.prototype.incrementalPrepareRender = function (customSeries, ecModel, api) {
  161. this.group.removeAll();
  162. this._data = null;
  163. };
  164. CustomChartView.prototype.incrementalRender = function (params, customSeries, ecModel, api, payload) {
  165. var data = customSeries.getData();
  166. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  167. function setIncrementalAndHoverLayer(el) {
  168. if (!el.isGroup) {
  169. el.incremental = true;
  170. el.ensureState('emphasis').hoverLayer = true;
  171. }
  172. }
  173. for (var idx = params.start; idx < params.end; idx++) {
  174. var el = createOrUpdateItem(null, null, idx, renderItem(idx, payload), customSeries, this.group, data);
  175. el && el.traverse(setIncrementalAndHoverLayer);
  176. }
  177. };
  178. CustomChartView.prototype.filterForExposedEvent = function (eventType, query, targetEl, packedEvent) {
  179. var elementName = query.element;
  180. if (elementName == null || targetEl.name === elementName) {
  181. return true;
  182. } // Enable to give a name on a group made by `renderItem`, and listen
  183. // events that triggerd by its descendents.
  184. while ((targetEl = targetEl.__hostTarget || targetEl.parent) && targetEl !== this.group) {
  185. if (targetEl.name === elementName) {
  186. return true;
  187. }
  188. }
  189. return false;
  190. };
  191. CustomChartView.type = 'custom';
  192. return CustomChartView;
  193. }(ChartView);
  194. export default CustomChartView;
  195. function createEl(elOption) {
  196. var graphicType = elOption.type;
  197. var el; // Those graphic elements are not shapes. They should not be
  198. // overwritten by users, so do them first.
  199. if (graphicType === 'path') {
  200. var shape = elOption.shape; // Using pathRect brings convenience to users sacle svg path.
  201. var pathRect = shape.width != null && shape.height != null ? {
  202. x: shape.x || 0,
  203. y: shape.y || 0,
  204. width: shape.width,
  205. height: shape.height
  206. } : null;
  207. var pathData = getPathData(shape); // Path is also used for icon, so layout 'center' by default.
  208. el = graphicUtil.makePath(pathData, null, pathRect, shape.layout || 'center');
  209. customInnerStore(el).customPathData = pathData;
  210. } else if (graphicType === 'image') {
  211. el = new graphicUtil.Image({});
  212. customInnerStore(el).customImagePath = elOption.style.image;
  213. } else if (graphicType === 'text') {
  214. el = new graphicUtil.Text({}); // customInnerStore(el).customText = (elOption.style as TextStyleProps).text;
  215. } else if (graphicType === 'group') {
  216. el = new graphicUtil.Group();
  217. } else if (graphicType === 'compoundPath') {
  218. throw new Error('"compoundPath" is not supported yet.');
  219. } else {
  220. var Clz = graphicUtil.getShapeClass(graphicType);
  221. if (!Clz) {
  222. var errMsg = '';
  223. if (process.env.NODE_ENV !== 'production') {
  224. errMsg = 'graphic type "' + graphicType + '" can not be found.';
  225. }
  226. throwError(errMsg);
  227. }
  228. el = new Clz();
  229. }
  230. customInnerStore(el).customGraphicType = graphicType;
  231. el.name = elOption.name; // Compat ec4: the default z2 lift is 1. If changing the number,
  232. // some cases probably be broken: hierarchy layout along z, like circle packing,
  233. // where emphasis only intending to modify color/border rather than lift z2.
  234. el.z2EmphasisLift = 1;
  235. el.z2SelectLift = 1;
  236. return el;
  237. }
  238. function updateElNormal( // Can be null/undefined
  239. api, el, dataIndex, elOption, attachedTxInfo, seriesModel, isInit, isTextContent) {
  240. var txCfgOpt = attachedTxInfo && attachedTxInfo.normal.cfg;
  241. if (txCfgOpt) {
  242. // PENDING: whether use user object directly rather than clone?
  243. // TODO:5.0 textConfig transition animation?
  244. el.setTextConfig(txCfgOpt);
  245. } // Do some normalization on style.
  246. var styleOpt = elOption && elOption.style;
  247. if (styleOpt) {
  248. if (el.type === 'text') {
  249. var textOptionStyle = styleOpt; // Compatible with ec4: if `textFill` or `textStroke` exists use them.
  250. hasOwn(textOptionStyle, 'textFill') && (textOptionStyle.fill = textOptionStyle.textFill);
  251. hasOwn(textOptionStyle, 'textStroke') && (textOptionStyle.stroke = textOptionStyle.textStroke);
  252. }
  253. var decalPattern = void 0;
  254. var decalObj = isPath(el) ? styleOpt.decal : null;
  255. if (api && decalObj) {
  256. decalObj.dirty = true;
  257. decalPattern = createOrUpdatePatternFromDecal(decalObj, api);
  258. } // Always overwrite in case user specify this prop.
  259. styleOpt.__decalPattern = decalPattern;
  260. } // Save the meta info for further morphing. Like apply on the sub morphing elements.
  261. var store = customInnerStore(el);
  262. store.userDuring = elOption.during;
  263. var transFromProps = {};
  264. var propsToSet = {};
  265. prepareShapeOrExtraTransitionFrom('shape', el, elOption, transFromProps, isInit);
  266. prepareShapeOrExtraAllPropsFinal('shape', elOption, propsToSet);
  267. prepareTransformTransitionFrom(el, elOption, transFromProps, isInit);
  268. prepareTransformAllPropsFinal(el, elOption, propsToSet);
  269. prepareShapeOrExtraTransitionFrom('extra', el, elOption, transFromProps, isInit);
  270. prepareShapeOrExtraAllPropsFinal('extra', elOption, propsToSet);
  271. prepareStyleTransitionFrom(el, elOption, styleOpt, transFromProps, isInit);
  272. propsToSet.style = styleOpt;
  273. applyPropsDirectly(el, propsToSet);
  274. applyPropsTransition(el, dataIndex, seriesModel, transFromProps, isInit);
  275. applyMiscProps(el, elOption, isTextContent);
  276. styleOpt ? el.dirty() : el.markRedraw();
  277. }
  278. function applyMiscProps(el, elOption, isTextContent) {
  279. // Merge by default.
  280. hasOwn(elOption, 'silent') && (el.silent = elOption.silent);
  281. hasOwn(elOption, 'ignore') && (el.ignore = elOption.ignore);
  282. if (isDisplayable(el)) {
  283. hasOwn(elOption, 'invisible') && (el.invisible = elOption.invisible);
  284. }
  285. if (isPath(el)) {
  286. hasOwn(elOption, 'autoBatch') && (el.autoBatch = elOption.autoBatch);
  287. }
  288. if (!isTextContent) {
  289. // `elOption.info` enables user to mount some info on
  290. // elements and use them in event handlers.
  291. // Update them only when user specified, otherwise, remain.
  292. hasOwn(elOption, 'info') && (customInnerStore(el).info = elOption.info);
  293. }
  294. }
  295. function applyPropsDirectly(el, // Can be null/undefined
  296. allPropsFinal) {
  297. var elDisplayable = el.isGroup ? null : el;
  298. var styleOpt = allPropsFinal.style;
  299. if (elDisplayable && styleOpt) {
  300. // PENDING: here the input style object is used directly.
  301. // Good for performance but bad for compatibility control.
  302. elDisplayable.useStyle(styleOpt);
  303. var decalPattern = styleOpt.__decalPattern;
  304. if (decalPattern) {
  305. elDisplayable.style.decal = decalPattern;
  306. } // When style object changed, how to trade the existing animation?
  307. // It is probably complicated and not needed to cover all the cases.
  308. // But still need consider the case:
  309. // (1) When using init animation on `style.opacity`, and before the animation
  310. // ended users triggers an update by mousewhel. At that time the init
  311. // animation should better be continued rather than terminated.
  312. // So after `useStyle` called, we should change the animation target manually
  313. // to continue the effect of the init animation.
  314. // (2) PENDING: If the previous animation targeted at a `val1`, and currently we need
  315. // to update the value to `val2` and no animation declared, should be terminate
  316. // the previous animation or just modify the target of the animation?
  317. // Therotically That will happen not only on `style` but also on `shape` and
  318. // `transfrom` props. But we haven't handle this case at present yet.
  319. // (3) PENDING: Is it proper to visit `animators` and `targetName`?
  320. var animators = elDisplayable.animators;
  321. for (var i = 0; i < animators.length; i++) {
  322. var animator = animators[i]; // targetName is the "topKey".
  323. if (animator.targetName === 'style') {
  324. animator.changeTarget(elDisplayable.style);
  325. }
  326. }
  327. }
  328. if (allPropsFinal) {
  329. // Not set style here.
  330. allPropsFinal.style = null; // Set el to the final state firstly.
  331. allPropsFinal && el.attr(allPropsFinal);
  332. allPropsFinal.style = styleOpt;
  333. }
  334. }
  335. function applyPropsTransition(el, dataIndex, seriesModel, // Can be null/undefined
  336. transFromProps, isInit) {
  337. if (transFromProps) {
  338. // NOTE: Do not use `el.updateDuringAnimation` here becuase `el.updateDuringAnimation` will
  339. // be called mutiple time in each animation frame. For example, if both "transform" props
  340. // and shape props and style props changed, it will generate three animator and called
  341. // one-by-one in each animation frame.
  342. // We use the during in `animateTo/From` params.
  343. var userDuring = customInnerStore(el).userDuring; // For simplicity, if during not specified, the previous during will not work any more.
  344. var cfgDuringCall = userDuring ? bind(duringCall, {
  345. el: el,
  346. userDuring: userDuring
  347. }) : null;
  348. var cfg = {
  349. dataIndex: dataIndex,
  350. isFrom: true,
  351. during: cfgDuringCall
  352. };
  353. isInit ? graphicUtil.initProps(el, transFromProps, seriesModel, cfg) : graphicUtil.updateProps(el, transFromProps, seriesModel, cfg);
  354. }
  355. } // Use it to avoid it be exposed to user.
  356. var tmpDuringScope = {};
  357. var customDuringAPI = {
  358. // Usually other props do not need to be changed in animation during.
  359. setTransform: function (key, val) {
  360. if (process.env.NODE_ENV !== 'production') {
  361. assert(hasOwn(TRANSFORM_PROPS, key), 'Only ' + transformPropNamesStr + ' available in `setTransform`.');
  362. }
  363. tmpDuringScope.el[key] = val;
  364. return this;
  365. },
  366. getTransform: function (key) {
  367. if (process.env.NODE_ENV !== 'production') {
  368. assert(hasOwn(TRANSFORM_PROPS, key), 'Only ' + transformPropNamesStr + ' available in `getTransform`.');
  369. }
  370. return tmpDuringScope.el[key];
  371. },
  372. setShape: function (key, val) {
  373. if (process.env.NODE_ENV !== 'production') {
  374. assertNotReserved(key);
  375. }
  376. var shape = tmpDuringScope.el.shape || (tmpDuringScope.el.shape = {});
  377. shape[key] = val;
  378. tmpDuringScope.isShapeDirty = true;
  379. return this;
  380. },
  381. getShape: function (key) {
  382. if (process.env.NODE_ENV !== 'production') {
  383. assertNotReserved(key);
  384. }
  385. var shape = tmpDuringScope.el.shape;
  386. if (shape) {
  387. return shape[key];
  388. }
  389. },
  390. setStyle: function (key, val) {
  391. if (process.env.NODE_ENV !== 'production') {
  392. assertNotReserved(key);
  393. }
  394. var style = tmpDuringScope.el.style;
  395. if (style) {
  396. if (process.env.NODE_ENV !== 'production') {
  397. if (eqNaN(val)) {
  398. warn('style.' + key + ' must not be assigned with NaN.');
  399. }
  400. }
  401. style[key] = val;
  402. tmpDuringScope.isStyleDirty = true;
  403. }
  404. return this;
  405. },
  406. getStyle: function (key) {
  407. if (process.env.NODE_ENV !== 'production') {
  408. assertNotReserved(key);
  409. }
  410. var style = tmpDuringScope.el.style;
  411. if (style) {
  412. return style[key];
  413. }
  414. },
  415. setExtra: function (key, val) {
  416. if (process.env.NODE_ENV !== 'production') {
  417. assertNotReserved(key);
  418. }
  419. var extra = tmpDuringScope.el.extra || (tmpDuringScope.el.extra = {});
  420. extra[key] = val;
  421. return this;
  422. },
  423. getExtra: function (key) {
  424. if (process.env.NODE_ENV !== 'production') {
  425. assertNotReserved(key);
  426. }
  427. var extra = tmpDuringScope.el.extra;
  428. if (extra) {
  429. return extra[key];
  430. }
  431. }
  432. };
  433. function assertNotReserved(key) {
  434. if (process.env.NODE_ENV !== 'production') {
  435. if (key === 'transition' || key === 'enterFrom' || key === 'leaveTo') {
  436. throw new Error('key must not be "' + key + '"');
  437. }
  438. }
  439. }
  440. function duringCall() {
  441. // Do not provide "percent" until some requirements come.
  442. // Because consider thies case:
  443. // enterFrom: {x: 100, y: 30}, transition: 'x'.
  444. // And enter duration is different from update duration.
  445. // Thus it might be confused about the meaning of "percent" in during callback.
  446. var scope = this;
  447. var el = scope.el;
  448. if (!el) {
  449. return;
  450. } // If el is remove from zr by reason like legend, during still need to called,
  451. // becuase el will be added back to zr and the prop value should not be incorrect.
  452. var latestUserDuring = customInnerStore(el).userDuring;
  453. var scopeUserDuring = scope.userDuring; // Ensured a during is only called once in each animation frame.
  454. // If a during is called multiple times in one frame, maybe some users' calulation logic
  455. // might be wrong (not sure whether this usage exists).
  456. // The case of a during might be called twice can be: by default there is a animator for
  457. // 'x', 'y' when init. Before the init animation finished, call `setOption` to start
  458. // another animators for 'style'/'shape'/'extra'.
  459. if (latestUserDuring !== scopeUserDuring) {
  460. // release
  461. scope.el = scope.userDuring = null;
  462. return;
  463. }
  464. tmpDuringScope.el = el;
  465. tmpDuringScope.isShapeDirty = false;
  466. tmpDuringScope.isStyleDirty = false; // Give no `this` to user in "during" calling.
  467. scopeUserDuring(customDuringAPI);
  468. if (tmpDuringScope.isShapeDirty && el.dirtyShape) {
  469. el.dirtyShape();
  470. }
  471. if (tmpDuringScope.isStyleDirty && el.dirtyStyle) {
  472. el.dirtyStyle();
  473. } // markRedraw() will be called by default in during.
  474. // FIXME `this.markRedraw();` directly ?
  475. // FIXME: if in future meet the case that some prop will be both modified in `during` and `state`,
  476. // consider the issue that the prop might be incorrect when return to "normal" state.
  477. }
  478. function updateElOnState(state, el, elStateOpt, styleOpt, attachedTxInfo, isRoot, isTextContent) {
  479. var elDisplayable = el.isGroup ? null : el;
  480. var txCfgOpt = attachedTxInfo && attachedTxInfo[state].cfg; // PENDING:5.0 support customize scale change and transition animation?
  481. if (elDisplayable) {
  482. // By default support auto lift color when hover whether `emphasis` specified.
  483. var stateObj = elDisplayable.ensureState(state);
  484. if (styleOpt === false) {
  485. var existingEmphasisState = elDisplayable.getState(state);
  486. if (existingEmphasisState) {
  487. existingEmphasisState.style = null;
  488. }
  489. } else {
  490. // style is needed to enable defaut emphasis.
  491. stateObj.style = styleOpt || null;
  492. } // If `elOption.styleEmphasis` or `elOption.emphasis.style` is `false`,
  493. // remove hover style.
  494. // If `elOption.textConfig` or `elOption.emphasis.textConfig` is null/undefined, it does not
  495. // make sense. So for simplicity, we do not ditinguish `hasOwnProperty` and null/undefined.
  496. if (txCfgOpt) {
  497. stateObj.textConfig = txCfgOpt;
  498. }
  499. setDefaultStateProxy(elDisplayable);
  500. }
  501. }
  502. function updateZ(el, elOption, seriesModel) {
  503. // Group not support textContent and not support z yet.
  504. if (el.isGroup) {
  505. return;
  506. }
  507. var elDisplayable = el;
  508. var currentZ = seriesModel.currentZ;
  509. var currentZLevel = seriesModel.currentZLevel; // Always erase.
  510. elDisplayable.z = currentZ;
  511. elDisplayable.zlevel = currentZLevel; // z2 must not be null/undefined, otherwise sort error may occur.
  512. var optZ2 = elOption.z2;
  513. optZ2 != null && (elDisplayable.z2 = optZ2 || 0);
  514. for (var i = 0; i < STATES.length; i++) {
  515. updateZForEachState(elDisplayable, elOption, STATES[i]);
  516. }
  517. }
  518. function updateZForEachState(elDisplayable, elOption, state) {
  519. var isNormal = state === NORMAL;
  520. var elStateOpt = isNormal ? elOption : retrieveStateOption(elOption, state);
  521. var optZ2 = elStateOpt ? elStateOpt.z2 : null;
  522. var stateObj;
  523. if (optZ2 != null) {
  524. // Do not `ensureState` until required.
  525. stateObj = isNormal ? elDisplayable : elDisplayable.ensureState(state);
  526. stateObj.z2 = optZ2 || 0;
  527. }
  528. }
  529. function makeRenderItem(customSeries, data, ecModel, api) {
  530. var renderItem = customSeries.get('renderItem');
  531. var coordSys = customSeries.coordinateSystem;
  532. var prepareResult = {};
  533. if (coordSys) {
  534. if (process.env.NODE_ENV !== 'production') {
  535. assert(renderItem, 'series.render is required.');
  536. assert(coordSys.prepareCustoms || prepareCustoms[coordSys.type], 'This coordSys does not support custom series.');
  537. } // `coordSys.prepareCustoms` is used for external coord sys like bmap.
  538. prepareResult = coordSys.prepareCustoms ? coordSys.prepareCustoms(coordSys) : prepareCustoms[coordSys.type](coordSys);
  539. }
  540. var userAPI = defaults({
  541. getWidth: api.getWidth,
  542. getHeight: api.getHeight,
  543. getZr: api.getZr,
  544. getDevicePixelRatio: api.getDevicePixelRatio,
  545. value: value,
  546. style: style,
  547. ordinalRawValue: ordinalRawValue,
  548. styleEmphasis: styleEmphasis,
  549. visual: visual,
  550. barLayout: barLayout,
  551. currentSeriesIndices: currentSeriesIndices,
  552. font: font
  553. }, prepareResult.api || {});
  554. var userParams = {
  555. // The life cycle of context: current round of rendering.
  556. // The global life cycle is probably not necessary, because
  557. // user can store global status by themselves.
  558. context: {},
  559. seriesId: customSeries.id,
  560. seriesName: customSeries.name,
  561. seriesIndex: customSeries.seriesIndex,
  562. coordSys: prepareResult.coordSys,
  563. dataInsideLength: data.count(),
  564. encode: wrapEncodeDef(customSeries.getData())
  565. }; // If someday intending to refactor them to a class, should consider do not
  566. // break change: currently these attribute member are encapsulated in a closure
  567. // so that do not need to force user to call these method with a scope.
  568. // Do not support call `api` asynchronously without dataIndexInside input.
  569. var currDataIndexInside;
  570. var currItemModel;
  571. var currItemStyleModels = {};
  572. var currLabelModels = {};
  573. var seriesItemStyleModels = {};
  574. var seriesLabelModels = {};
  575. for (var i = 0; i < STATES.length; i++) {
  576. var stateName = STATES[i];
  577. seriesItemStyleModels[stateName] = customSeries.getModel(PATH_ITEM_STYLE[stateName]);
  578. seriesLabelModels[stateName] = customSeries.getModel(PATH_LABEL[stateName]);
  579. }
  580. function getItemModel(dataIndexInside) {
  581. return dataIndexInside === currDataIndexInside ? currItemModel || (currItemModel = data.getItemModel(dataIndexInside)) : data.getItemModel(dataIndexInside);
  582. }
  583. function getItemStyleModel(dataIndexInside, state) {
  584. 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]);
  585. }
  586. function getLabelModel(dataIndexInside, state) {
  587. return !data.hasItemOption ? seriesLabelModels[state] : dataIndexInside === currDataIndexInside ? currLabelModels[state] || (currLabelModels[state] = getItemModel(dataIndexInside).getModel(PATH_LABEL[state])) : getItemModel(dataIndexInside).getModel(PATH_LABEL[state]);
  588. }
  589. return function (dataIndexInside, payload) {
  590. currDataIndexInside = dataIndexInside;
  591. currItemModel = null;
  592. currItemStyleModels = {};
  593. currLabelModels = {};
  594. return renderItem && renderItem(defaults({
  595. dataIndexInside: dataIndexInside,
  596. dataIndex: data.getRawIndex(dataIndexInside),
  597. // Can be used for optimization when zoom or roam.
  598. actionType: payload ? payload.type : null
  599. }, userParams), userAPI);
  600. };
  601. /**
  602. * @public
  603. * @param dim by default 0.
  604. * @param dataIndexInside by default `currDataIndexInside`.
  605. */
  606. function value(dim, dataIndexInside) {
  607. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  608. return data.getStore().get(data.getDimensionIndex(dim || 0), dataIndexInside);
  609. }
  610. /**
  611. * @public
  612. * @param dim by default 0.
  613. * @param dataIndexInside by default `currDataIndexInside`.
  614. */
  615. function ordinalRawValue(dim, dataIndexInside) {
  616. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  617. dim = dim || 0;
  618. var dimInfo = data.getDimensionInfo(dim);
  619. if (!dimInfo) {
  620. var dimIndex = data.getDimensionIndex(dim);
  621. return dimIndex >= 0 ? data.getStore().get(dimIndex, dataIndexInside) : undefined;
  622. }
  623. var val = data.get(dimInfo.name, dataIndexInside);
  624. var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
  625. return ordinalMeta ? ordinalMeta.categories[val] : val;
  626. }
  627. /**
  628. * @deprecated The orgininal intention of `api.style` is enable to set itemStyle
  629. * like other series. But it not necessary and not easy to give a strict definition
  630. * of what it return. And since echarts5 it needs to be make compat work. So
  631. * deprecates it since echarts5.
  632. *
  633. * By default, `visual` is applied to style (to support visualMap).
  634. * `visual.color` is applied at `fill`. If user want apply visual.color on `stroke`,
  635. * it can be implemented as:
  636. * `api.style({stroke: api.visual('color'), fill: null})`;
  637. *
  638. * [Compat]: since ec5, RectText has been separated from its hosts el.
  639. * so `api.style()` will only return the style from `itemStyle` but not handle `label`
  640. * any more. But `series.label` config is never published in doc.
  641. * We still compat it in `api.style()`. But not encourage to use it and will still not
  642. * to pulish it to doc.
  643. * @public
  644. * @param dataIndexInside by default `currDataIndexInside`.
  645. */
  646. function style(userProps, dataIndexInside) {
  647. if (process.env.NODE_ENV !== 'production') {
  648. warnDeprecated('api.style', 'Please write literal style directly instead.');
  649. }
  650. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  651. var style = data.getItemVisual(dataIndexInside, 'style');
  652. var visualColor = style && style.fill;
  653. var opacity = style && style.opacity;
  654. var itemStyle = getItemStyleModel(dataIndexInside, NORMAL).getItemStyle();
  655. visualColor != null && (itemStyle.fill = visualColor);
  656. opacity != null && (itemStyle.opacity = opacity);
  657. var opt = {
  658. inheritColor: isString(visualColor) ? visualColor : '#000'
  659. };
  660. var labelModel = getLabelModel(dataIndexInside, NORMAL); // Now that the feture of "auto adjust text fill/stroke" has been migrated to zrender
  661. // since ec5, we should set `isAttached` as `false` here and make compat in
  662. // `convertToEC4StyleForCustomSerise`.
  663. var textStyle = labelStyleHelper.createTextStyle(labelModel, null, opt, false, true);
  664. textStyle.text = labelModel.getShallow('show') ? retrieve2(customSeries.getFormattedLabel(dataIndexInside, NORMAL), getDefaultLabel(data, dataIndexInside)) : null;
  665. var textConfig = labelStyleHelper.createTextConfig(labelModel, opt, false);
  666. preFetchFromExtra(userProps, itemStyle);
  667. itemStyle = convertToEC4StyleForCustomSerise(itemStyle, textStyle, textConfig);
  668. userProps && applyUserPropsAfter(itemStyle, userProps);
  669. itemStyle.legacy = true;
  670. return itemStyle;
  671. }
  672. /**
  673. * @deprecated The reason see `api.style()`
  674. * @public
  675. * @param dataIndexInside by default `currDataIndexInside`.
  676. */
  677. function styleEmphasis(userProps, dataIndexInside) {
  678. if (process.env.NODE_ENV !== 'production') {
  679. warnDeprecated('api.styleEmphasis', 'Please write literal style directly instead.');
  680. }
  681. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  682. var itemStyle = getItemStyleModel(dataIndexInside, EMPHASIS).getItemStyle();
  683. var labelModel = getLabelModel(dataIndexInside, EMPHASIS);
  684. var textStyle = labelStyleHelper.createTextStyle(labelModel, null, null, true, true);
  685. textStyle.text = labelModel.getShallow('show') ? retrieve3(customSeries.getFormattedLabel(dataIndexInside, EMPHASIS), customSeries.getFormattedLabel(dataIndexInside, NORMAL), getDefaultLabel(data, dataIndexInside)) : null;
  686. var textConfig = labelStyleHelper.createTextConfig(labelModel, null, true);
  687. preFetchFromExtra(userProps, itemStyle);
  688. itemStyle = convertToEC4StyleForCustomSerise(itemStyle, textStyle, textConfig);
  689. userProps && applyUserPropsAfter(itemStyle, userProps);
  690. itemStyle.legacy = true;
  691. return itemStyle;
  692. }
  693. function applyUserPropsAfter(itemStyle, extra) {
  694. for (var key in extra) {
  695. if (hasOwn(extra, key)) {
  696. itemStyle[key] = extra[key];
  697. }
  698. }
  699. }
  700. function preFetchFromExtra(extra, itemStyle) {
  701. // A trick to retrieve those props firstly, which are used to
  702. // apply auto inside fill/stroke in `convertToEC4StyleForCustomSerise`.
  703. // (It's not reasonable but only for a degree of compat)
  704. if (extra) {
  705. extra.textFill && (itemStyle.textFill = extra.textFill);
  706. extra.textPosition && (itemStyle.textPosition = extra.textPosition);
  707. }
  708. }
  709. /**
  710. * @public
  711. * @param dataIndexInside by default `currDataIndexInside`.
  712. */
  713. function visual(visualType, dataIndexInside) {
  714. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  715. if (hasOwn(STYLE_VISUAL_TYPE, visualType)) {
  716. var style_1 = data.getItemVisual(dataIndexInside, 'style');
  717. return style_1 ? style_1[STYLE_VISUAL_TYPE[visualType]] : null;
  718. } // Only support these visuals. Other visual might be inner tricky
  719. // for performance (like `style`), do not expose to users.
  720. if (hasOwn(NON_STYLE_VISUAL_PROPS, visualType)) {
  721. return data.getItemVisual(dataIndexInside, visualType);
  722. }
  723. }
  724. /**
  725. * @public
  726. * @return If not support, return undefined.
  727. */
  728. function barLayout(opt) {
  729. if (coordSys.type === 'cartesian2d') {
  730. var baseAxis = coordSys.getBaseAxis();
  731. return getLayoutOnAxis(defaults({
  732. axis: baseAxis
  733. }, opt));
  734. }
  735. }
  736. /**
  737. * @public
  738. */
  739. function currentSeriesIndices() {
  740. return ecModel.getCurrentSeriesIndices();
  741. }
  742. /**
  743. * @public
  744. * @return font string
  745. */
  746. function font(opt) {
  747. return labelStyleHelper.getFont(opt, ecModel);
  748. }
  749. }
  750. function wrapEncodeDef(data) {
  751. var encodeDef = {};
  752. each(data.dimensions, function (dimName) {
  753. var dimInfo = data.getDimensionInfo(dimName);
  754. if (!dimInfo.isExtraCoord) {
  755. var coordDim = dimInfo.coordDim;
  756. var dataDims = encodeDef[coordDim] = encodeDef[coordDim] || [];
  757. dataDims[dimInfo.coordDimIndex] = data.getDimensionIndex(dimName);
  758. }
  759. });
  760. return encodeDef;
  761. }
  762. function createOrUpdateItem(api, existsEl, dataIndex, elOption, seriesModel, group, data) {
  763. // [Rule]
  764. // If `renderItem` returns `null`/`undefined`/`false`, remove the previous el if existing.
  765. // (It seems that violate the "merge" principle, but most of users probably intuitively
  766. // regard "return;" as "show nothing element whatever", so make a exception to meet the
  767. // most cases.)
  768. // The rule or "merge" see [STRATEGY_MERGE].
  769. // If `elOption` is `null`/`undefined`/`false` (when `renderItem` returns nothing).
  770. if (!elOption) {
  771. group.remove(existsEl);
  772. return;
  773. }
  774. var el = doCreateOrUpdateEl(api, existsEl, dataIndex, elOption, seriesModel, group, true);
  775. el && data.setItemGraphicEl(dataIndex, el);
  776. el && enableHoverEmphasis(el, elOption.focus, elOption.blurScope);
  777. return el;
  778. }
  779. function doCreateOrUpdateEl(api, existsEl, dataIndex, elOption, seriesModel, group, isRoot) {
  780. if (process.env.NODE_ENV !== 'production') {
  781. assert(elOption, 'should not have an null/undefined element setting');
  782. }
  783. var toBeReplacedIdx = -1;
  784. var oldEl = existsEl;
  785. if (existsEl && doesElNeedRecreate(existsEl, elOption, seriesModel) // || (
  786. // // PENDING: even in one-to-one mapping case, if el is marked as morph,
  787. // // do not sure whether the el will be mapped to another el with different
  788. // // hierarchy in Group tree. So always recreate el rather than reuse the el.
  789. // morphHelper && morphHelper.isOneToOneFrom(el)
  790. // )
  791. ) {
  792. // Should keep at the original index, otherwise "merge by index" will be incorrect.
  793. toBeReplacedIdx = indexOf(group.childrenRef(), existsEl);
  794. existsEl = null;
  795. }
  796. var isInit = !existsEl;
  797. var el = existsEl;
  798. if (!el) {
  799. el = createEl(elOption);
  800. if (oldEl) {
  801. copyElement(oldEl, el);
  802. }
  803. } else {
  804. // FIMXE:NEXT unified clearState?
  805. // If in some case the performance issue arised, consider
  806. // do not clearState but update cached normal state directly.
  807. el.clearStates();
  808. } // Need to set morph: false explictly to disable automatically morphing.
  809. if (elOption.morph === false) {
  810. el.disableMorphing = true;
  811. } else if (el.disableMorphing) {
  812. el.disableMorphing = false;
  813. }
  814. 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;
  815. attachedTxInfoTmp.isLegacy = false;
  816. doCreateOrUpdateAttachedTx(el, dataIndex, elOption, seriesModel, isInit, attachedTxInfoTmp);
  817. doCreateOrUpdateClipPath(el, dataIndex, elOption, seriesModel, isInit);
  818. updateElNormal(api, el, dataIndex, elOption, attachedTxInfoTmp, seriesModel, isInit, false);
  819. for (var i = 0; i < STATES.length; i++) {
  820. var stateName = STATES[i];
  821. if (stateName !== NORMAL) {
  822. var otherStateOpt = retrieveStateOption(elOption, stateName);
  823. var otherStyleOpt = retrieveStyleOptionOnState(elOption, otherStateOpt, stateName);
  824. updateElOnState(stateName, el, otherStateOpt, otherStyleOpt, attachedTxInfoTmp, isRoot, false);
  825. }
  826. }
  827. updateZ(el, elOption, seriesModel);
  828. if (elOption.type === 'group') {
  829. mergeChildren(api, el, dataIndex, elOption, seriesModel);
  830. }
  831. if (toBeReplacedIdx >= 0) {
  832. group.replaceAt(el, toBeReplacedIdx);
  833. } else {
  834. group.add(el);
  835. }
  836. return el;
  837. } // `el` must not be null/undefined.
  838. function doesElNeedRecreate(el, elOption, seriesModel) {
  839. var elInner = customInnerStore(el);
  840. var elOptionType = elOption.type;
  841. var elOptionShape = elOption.shape;
  842. var elOptionStyle = elOption.style;
  843. return (// Always create new if universal transition is enabled.
  844. // Because we do transition after render. It needs to know what old element is. Replacement will loose it.
  845. seriesModel.isUniversalTransitionEnabled() // If `elOptionType` is `null`, follow the merge principle.
  846. || elOptionType != null && elOptionType !== elInner.customGraphicType || elOptionType === 'path' && hasOwnPathData(elOptionShape) && getPathData(elOptionShape) !== elInner.customPathData || elOptionType === 'image' && hasOwn(elOptionStyle, 'image') && elOptionStyle.image !== elInner.customImagePath // // FIXME test and remove this restriction?
  847. // || (elOptionType === 'text'
  848. // && hasOwn(elOptionStyle, 'text')
  849. // && (elOptionStyle as TextStyleProps).text !== elInner.customText
  850. // )
  851. );
  852. }
  853. function doCreateOrUpdateClipPath(el, dataIndex, elOption, seriesModel, isInit) {
  854. // Based on the "merge" principle, if no clipPath provided,
  855. // do nothing. The exists clip will be totally removed only if
  856. // `el.clipPath` is `false`. Otherwise it will be merged/replaced.
  857. var clipPathOpt = elOption.clipPath;
  858. if (clipPathOpt === false) {
  859. if (el && el.getClipPath()) {
  860. el.removeClipPath();
  861. }
  862. } else if (clipPathOpt) {
  863. var clipPath = el.getClipPath();
  864. if (clipPath && doesElNeedRecreate(clipPath, clipPathOpt, seriesModel)) {
  865. clipPath = null;
  866. }
  867. if (!clipPath) {
  868. clipPath = createEl(clipPathOpt);
  869. if (process.env.NODE_ENV !== 'production') {
  870. assert(isPath(clipPath), 'Only any type of `path` can be used in `clipPath`, rather than ' + clipPath.type + '.');
  871. }
  872. el.setClipPath(clipPath);
  873. }
  874. updateElNormal(null, clipPath, dataIndex, clipPathOpt, null, seriesModel, isInit, false);
  875. } // If not define `clipPath` in option, do nothing unnecessary.
  876. }
  877. function doCreateOrUpdateAttachedTx(el, dataIndex, elOption, seriesModel, isInit, attachedTxInfo) {
  878. // group do not support textContent temporarily untill necessary.
  879. if (el.isGroup) {
  880. return;
  881. } // Normal must be called before emphasis, for `isLegacy` detection.
  882. processTxInfo(elOption, null, attachedTxInfo);
  883. processTxInfo(elOption, EMPHASIS, attachedTxInfo); // If `elOption.textConfig` or `elOption.textContent` is null/undefined, it does not make sence.
  884. // So for simplicity, if "elOption hasOwnProperty of them but be null/undefined", we do not
  885. // trade them as set to null to el.
  886. // Especially:
  887. // `elOption.textContent: false` means remove textContent.
  888. // `elOption.textContent.emphasis.style: false` means remove the style from emphasis state.
  889. var txConOptNormal = attachedTxInfo.normal.conOpt;
  890. var txConOptEmphasis = attachedTxInfo.emphasis.conOpt;
  891. var txConOptBlur = attachedTxInfo.blur.conOpt;
  892. var txConOptSelect = attachedTxInfo.select.conOpt;
  893. if (txConOptNormal != null || txConOptEmphasis != null || txConOptSelect != null || txConOptBlur != null) {
  894. var textContent = el.getTextContent();
  895. if (txConOptNormal === false) {
  896. textContent && el.removeTextContent();
  897. } else {
  898. txConOptNormal = attachedTxInfo.normal.conOpt = txConOptNormal || {
  899. type: 'text'
  900. };
  901. if (!textContent) {
  902. textContent = createEl(txConOptNormal);
  903. el.setTextContent(textContent);
  904. } else {
  905. // If in some case the performance issue arised, consider
  906. // do not clearState but update cached normal state directly.
  907. textContent.clearStates();
  908. }
  909. updateElNormal(null, textContent, dataIndex, txConOptNormal, null, seriesModel, isInit, true);
  910. var txConStlOptNormal = txConOptNormal && txConOptNormal.style;
  911. for (var i = 0; i < STATES.length; i++) {
  912. var stateName = STATES[i];
  913. if (stateName !== NORMAL) {
  914. var txConOptOtherState = attachedTxInfo[stateName].conOpt;
  915. updateElOnState(stateName, textContent, txConOptOtherState, retrieveStyleOptionOnState(txConOptNormal, txConOptOtherState, stateName), null, false, true);
  916. }
  917. }
  918. txConStlOptNormal ? textContent.dirty() : textContent.markRedraw();
  919. }
  920. }
  921. }
  922. function processTxInfo(elOption, state, attachedTxInfo) {
  923. var stateOpt = !state ? elOption : retrieveStateOption(elOption, state);
  924. var styleOpt = !state ? elOption.style : retrieveStyleOptionOnState(elOption, stateOpt, EMPHASIS);
  925. var elType = elOption.type;
  926. var txCfg = stateOpt ? stateOpt.textConfig : null;
  927. var txConOptNormal = elOption.textContent;
  928. var txConOpt = !txConOptNormal ? null : !state ? txConOptNormal : retrieveStateOption(txConOptNormal, state);
  929. if (styleOpt && ( // Because emphasis style has little info to detect legacy,
  930. // if normal is legacy, emphasis is trade as legacy.
  931. attachedTxInfo.isLegacy || isEC4CompatibleStyle(styleOpt, elType, !!txCfg, !!txConOpt))) {
  932. attachedTxInfo.isLegacy = true;
  933. var convertResult = convertFromEC4CompatibleStyle(styleOpt, elType, !state); // Explicitly specified `textConfig` and `textContent` has higher priority than
  934. // the ones generated by legacy style. Otherwise if users use them and `api.style`
  935. // at the same time, they not both work and hardly to known why.
  936. if (!txCfg && convertResult.textConfig) {
  937. txCfg = convertResult.textConfig;
  938. }
  939. if (!txConOpt && convertResult.textContent) {
  940. txConOpt = convertResult.textContent;
  941. }
  942. }
  943. if (!state && txConOpt) {
  944. var txConOptNormal_1 = txConOpt; // `textContent: {type: 'text'}`, the "type" is easy to be missing. So we tolerate it.
  945. !txConOptNormal_1.type && (txConOptNormal_1.type = 'text');
  946. if (process.env.NODE_ENV !== 'production') {
  947. // Do not tolerate incorret type for forward compat.
  948. assert(txConOptNormal_1.type === 'text', 'textContent.type must be "text"');
  949. }
  950. }
  951. var info = !state ? attachedTxInfo.normal : attachedTxInfo[state];
  952. info.cfg = txCfg;
  953. info.conOpt = txConOpt;
  954. }
  955. function retrieveStateOption(elOption, state) {
  956. return !state ? elOption : elOption ? elOption[state] : null;
  957. }
  958. function retrieveStyleOptionOnState(stateOptionNormal, stateOption, state) {
  959. var style = stateOption && stateOption.style;
  960. if (style == null && state === EMPHASIS && stateOptionNormal) {
  961. style = stateOptionNormal.styleEmphasis;
  962. }
  963. return style;
  964. } // Usage:
  965. // (1) By default, `elOption.$mergeChildren` is `'byIndex'`, which indicates that
  966. // the existing children will not be removed, and enables the feature that
  967. // update some of the props of some of the children simply by construct
  968. // the returned children of `renderItem` like:
  969. // `var children = group.children = []; children[3] = {opacity: 0.5};`
  970. // (2) If `elOption.$mergeChildren` is `'byName'`, add/update/remove children
  971. // by child.name. But that might be lower performance.
  972. // (3) If `elOption.$mergeChildren` is `false`, the existing children will be
  973. // replaced totally.
  974. // (4) If `!elOption.children`, following the "merge" principle, nothing will happen.
  975. //
  976. // For implementation simpleness, do not provide a direct way to remove sinlge
  977. // child (otherwise the total indicies of the children array have to be modified).
  978. // User can remove a single child by set its `ignore` as `true`.
  979. function mergeChildren(api, el, dataIndex, elOption, seriesModel) {
  980. var newChildren = elOption.children;
  981. var newLen = newChildren ? newChildren.length : 0;
  982. var mergeChildren = elOption.$mergeChildren; // `diffChildrenByName` has been deprecated.
  983. var byName = mergeChildren === 'byName' || elOption.diffChildrenByName;
  984. var notMerge = mergeChildren === false; // For better performance on roam update, only enter if necessary.
  985. if (!newLen && !byName && !notMerge) {
  986. return;
  987. }
  988. if (byName) {
  989. diffGroupChildren({
  990. api: api,
  991. oldChildren: el.children() || [],
  992. newChildren: newChildren || [],
  993. dataIndex: dataIndex,
  994. seriesModel: seriesModel,
  995. group: el
  996. });
  997. return;
  998. }
  999. notMerge && el.removeAll(); // Mapping children of a group simply by index, which
  1000. // might be better performance.
  1001. var index = 0;
  1002. for (; index < newLen; index++) {
  1003. newChildren[index] && doCreateOrUpdateEl(api, el.childAt(index), dataIndex, newChildren[index], seriesModel, el, false);
  1004. }
  1005. for (var i = el.childCount() - 1; i >= index; i--) {
  1006. // Do not supprot leave elements that are not mentioned in the latest
  1007. // `renderItem` return. Otherwise users may not have a clear and simple
  1008. // concept that how to contorl all of the elements.
  1009. doRemoveEl(el.childAt(i), seriesModel, el);
  1010. }
  1011. }
  1012. function diffGroupChildren(context) {
  1013. new DataDiffer(context.oldChildren, context.newChildren, getKey, getKey, context).add(processAddUpdate).update(processAddUpdate).remove(processRemove).execute();
  1014. }
  1015. function getKey(item, idx) {
  1016. var name = item && item.name;
  1017. return name != null ? name : GROUP_DIFF_PREFIX + idx;
  1018. }
  1019. function processAddUpdate(newIndex, oldIndex) {
  1020. var context = this.context;
  1021. var childOption = newIndex != null ? context.newChildren[newIndex] : null;
  1022. var child = oldIndex != null ? context.oldChildren[oldIndex] : null;
  1023. doCreateOrUpdateEl(context.api, child, context.dataIndex, childOption, context.seriesModel, context.group, false);
  1024. }
  1025. function processRemove(oldIndex) {
  1026. var context = this.context;
  1027. var child = context.oldChildren[oldIndex];
  1028. doRemoveEl(child, context.seriesModel, context.group);
  1029. }
  1030. function doRemoveEl(el, seriesModel, group) {
  1031. if (el) {
  1032. var leaveToProps = customInnerStore(el).leaveToProps;
  1033. leaveToProps ? graphicUtil.updateProps(el, leaveToProps, seriesModel, {
  1034. cb: function () {
  1035. group.remove(el);
  1036. }
  1037. }) : group.remove(el);
  1038. }
  1039. }
  1040. /**
  1041. * @return SVG Path data.
  1042. */
  1043. function getPathData(shape) {
  1044. // "d" follows the SVG convention.
  1045. return shape && (shape.pathData || shape.d);
  1046. }
  1047. function hasOwnPathData(shape) {
  1048. return shape && (hasOwn(shape, 'pathData') || hasOwn(shape, 'd'));
  1049. }