labelStyle.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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 ZRText from 'zrender/lib/graphic/Text.js';
  41. import { isFunction, retrieve2, extend, keys, trim, retrieve3, isNumber, normalizeCssArray } from 'zrender/lib/core/util.js';
  42. import { SPECIAL_STATES, DISPLAY_STATES } from '../util/states.js';
  43. import { deprecateReplaceLog } from '../util/log.js';
  44. import { makeInner, interpolateRawValues } from '../util/model.js';
  45. import { initProps, updateProps } from '../util/graphic.js';
  46. var EMPTY_OBJ = {};
  47. export function setLabelText(label, labelTexts) {
  48. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  49. var stateName = SPECIAL_STATES[i];
  50. var text = labelTexts[stateName];
  51. var state = label.ensureState(stateName);
  52. state.style = state.style || {};
  53. state.style.text = text;
  54. }
  55. var oldStates = label.currentStates.slice();
  56. label.clearStates(true);
  57. label.setStyle({
  58. text: labelTexts.normal
  59. });
  60. label.useStates(oldStates, true);
  61. }
  62. function getLabelText(opt, stateModels, interpolatedValue) {
  63. var labelFetcher = opt.labelFetcher;
  64. var labelDataIndex = opt.labelDataIndex;
  65. var labelDimIndex = opt.labelDimIndex;
  66. var normalModel = stateModels.normal;
  67. var baseText;
  68. if (labelFetcher) {
  69. baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex, normalModel && normalModel.get('formatter'), interpolatedValue != null ? {
  70. interpolatedValue: interpolatedValue
  71. } : null);
  72. }
  73. if (baseText == null) {
  74. baseText = isFunction(opt.defaultText) ? opt.defaultText(labelDataIndex, opt, interpolatedValue) : opt.defaultText;
  75. }
  76. var statesText = {
  77. normal: baseText
  78. };
  79. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  80. var stateName = SPECIAL_STATES[i];
  81. var stateModel = stateModels[stateName];
  82. statesText[stateName] = retrieve2(labelFetcher ? labelFetcher.getFormattedLabel(labelDataIndex, stateName, null, labelDimIndex, stateModel && stateModel.get('formatter')) : null, baseText);
  83. }
  84. return statesText;
  85. }
  86. function setLabelStyle(targetEl, labelStatesModels, opt, stateSpecified
  87. // TODO specified position?
  88. ) {
  89. opt = opt || EMPTY_OBJ;
  90. var isSetOnText = targetEl instanceof ZRText;
  91. var needsCreateText = false;
  92. for (var i = 0; i < DISPLAY_STATES.length; i++) {
  93. var stateModel = labelStatesModels[DISPLAY_STATES[i]];
  94. if (stateModel && stateModel.getShallow('show')) {
  95. needsCreateText = true;
  96. break;
  97. }
  98. }
  99. var textContent = isSetOnText ? targetEl : targetEl.getTextContent();
  100. if (needsCreateText) {
  101. if (!isSetOnText) {
  102. // Reuse the previous
  103. if (!textContent) {
  104. textContent = new ZRText();
  105. targetEl.setTextContent(textContent);
  106. }
  107. // Use same state proxy
  108. if (targetEl.stateProxy) {
  109. textContent.stateProxy = targetEl.stateProxy;
  110. }
  111. }
  112. var labelStatesTexts = getLabelText(opt, labelStatesModels);
  113. var normalModel = labelStatesModels.normal;
  114. var showNormal = !!normalModel.getShallow('show');
  115. var normalStyle = createTextStyle(normalModel, stateSpecified && stateSpecified.normal, opt, false, !isSetOnText);
  116. normalStyle.text = labelStatesTexts.normal;
  117. if (!isSetOnText) {
  118. // Always create new
  119. targetEl.setTextConfig(createTextConfig(normalModel, opt, false));
  120. }
  121. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  122. var stateName = SPECIAL_STATES[i];
  123. var stateModel = labelStatesModels[stateName];
  124. if (stateModel) {
  125. var stateObj = textContent.ensureState(stateName);
  126. var stateShow = !!retrieve2(stateModel.getShallow('show'), showNormal);
  127. if (stateShow !== showNormal) {
  128. stateObj.ignore = !stateShow;
  129. }
  130. stateObj.style = createTextStyle(stateModel, stateSpecified && stateSpecified[stateName], opt, true, !isSetOnText);
  131. stateObj.style.text = labelStatesTexts[stateName];
  132. if (!isSetOnText) {
  133. var targetElEmphasisState = targetEl.ensureState(stateName);
  134. targetElEmphasisState.textConfig = createTextConfig(stateModel, opt, true);
  135. }
  136. }
  137. }
  138. // PENDING: if there is many requirements that emphasis position
  139. // need to be different from normal position, we might consider
  140. // auto silent is those cases.
  141. textContent.silent = !!normalModel.getShallow('silent');
  142. // Keep x and y
  143. if (textContent.style.x != null) {
  144. normalStyle.x = textContent.style.x;
  145. }
  146. if (textContent.style.y != null) {
  147. normalStyle.y = textContent.style.y;
  148. }
  149. textContent.ignore = !showNormal;
  150. // Always create new style.
  151. textContent.useStyle(normalStyle);
  152. textContent.dirty();
  153. if (opt.enableTextSetter) {
  154. labelInner(textContent).setLabelText = function (interpolatedValue) {
  155. var labelStatesTexts = getLabelText(opt, labelStatesModels, interpolatedValue);
  156. setLabelText(textContent, labelStatesTexts);
  157. };
  158. }
  159. } else if (textContent) {
  160. // Not display rich text.
  161. textContent.ignore = true;
  162. }
  163. targetEl.dirty();
  164. }
  165. export { setLabelStyle };
  166. export function getLabelStatesModels(itemModel, labelName) {
  167. labelName = labelName || 'label';
  168. var statesModels = {
  169. normal: itemModel.getModel(labelName)
  170. };
  171. for (var i = 0; i < SPECIAL_STATES.length; i++) {
  172. var stateName = SPECIAL_STATES[i];
  173. statesModels[stateName] = itemModel.getModel([stateName, labelName]);
  174. }
  175. return statesModels;
  176. }
  177. /**
  178. * Set basic textStyle properties.
  179. */
  180. export function createTextStyle(textStyleModel, specifiedTextStyle,
  181. // Fixed style in the code. Can't be set by model.
  182. opt, isNotNormal, isAttached // If text is attached on an element. If so, auto color will handling in zrender.
  183. ) {
  184. var textStyle = {};
  185. setTextStyleCommon(textStyle, textStyleModel, opt, isNotNormal, isAttached);
  186. specifiedTextStyle && extend(textStyle, specifiedTextStyle);
  187. // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  188. return textStyle;
  189. }
  190. export function createTextConfig(textStyleModel, opt, isNotNormal) {
  191. opt = opt || {};
  192. var textConfig = {};
  193. var labelPosition;
  194. var labelRotate = textStyleModel.getShallow('rotate');
  195. var labelDistance = retrieve2(textStyleModel.getShallow('distance'), isNotNormal ? null : 5);
  196. var labelOffset = textStyleModel.getShallow('offset');
  197. labelPosition = textStyleModel.getShallow('position') || (isNotNormal ? null : 'inside');
  198. // 'outside' is not a valid zr textPostion value, but used
  199. // in bar series, and magic type should be considered.
  200. labelPosition === 'outside' && (labelPosition = opt.defaultOutsidePosition || 'top');
  201. if (labelPosition != null) {
  202. textConfig.position = labelPosition;
  203. }
  204. if (labelOffset != null) {
  205. textConfig.offset = labelOffset;
  206. }
  207. if (labelRotate != null) {
  208. labelRotate *= Math.PI / 180;
  209. textConfig.rotation = labelRotate;
  210. }
  211. if (labelDistance != null) {
  212. textConfig.distance = labelDistance;
  213. }
  214. // fill and auto is determined by the color of path fill if it's not specified by developers.
  215. textConfig.outsideFill = textStyleModel.get('color') === 'inherit' ? opt.inheritColor || null : 'auto';
  216. if (opt.autoOverflowArea != null) {
  217. textConfig.autoOverflowArea = opt.autoOverflowArea;
  218. }
  219. if (opt.layoutRect != null) {
  220. textConfig.layoutRect = opt.layoutRect;
  221. }
  222. return textConfig;
  223. }
  224. /**
  225. * The uniform entry of set text style, that is, retrieve style definitions
  226. * from `model` and set to `textStyle` object.
  227. *
  228. * Never in merge mode, but in overwrite mode, that is, all of the text style
  229. * properties will be set. (Consider the states of normal and emphasis and
  230. * default value can be adopted, merge would make the logic too complicated
  231. * to manage.)
  232. */
  233. function setTextStyleCommon(textStyle, textStyleModel, opt, isNotNormal, isAttached) {
  234. // Consider there will be abnormal when merge hover style to normal style if given default value.
  235. opt = opt || EMPTY_OBJ;
  236. var ecModel = textStyleModel.ecModel;
  237. var globalTextStyle = ecModel && ecModel.option.textStyle;
  238. // Consider case:
  239. // {
  240. // data: [{
  241. // value: 12,
  242. // label: {
  243. // rich: {
  244. // // no 'a' here but using parent 'a'.
  245. // }
  246. // }
  247. // }],
  248. // rich: {
  249. // a: { ... }
  250. // }
  251. // }
  252. var richItemNames = getRichItemNames(textStyleModel);
  253. var richResult;
  254. if (richItemNames) {
  255. richResult = {};
  256. var richInheritPlainLabelOptionName = 'richInheritPlainLabel';
  257. var richInheritPlainLabel = retrieve2(textStyleModel.get(richInheritPlainLabelOptionName), ecModel ? ecModel.get(richInheritPlainLabelOptionName) : undefined);
  258. for (var name_1 in richItemNames) {
  259. if (richItemNames.hasOwnProperty(name_1)) {
  260. // Cascade is supported in rich.
  261. var richTextStyle = textStyleModel.getModel(['rich', name_1]);
  262. // In rich, never `disableBox`.
  263. // consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
  264. // the default color `'blue'` will not be adopted if no color declared in `rich`.
  265. // That might confuses users. So probably we should put `textStyleModel` as the
  266. // root ancestor of the `richTextStyle`. But that would be a break change.
  267. // Since v6, the rich style inherits plain label by default
  268. // but this behavior can be disabled by setting `richInheritPlainLabel` to `false`.
  269. setTokenTextStyle(richResult[name_1] = {}, richTextStyle, globalTextStyle, textStyleModel, richInheritPlainLabel, opt, isNotNormal, isAttached, false, true);
  270. }
  271. }
  272. }
  273. if (richResult) {
  274. textStyle.rich = richResult;
  275. }
  276. var overflow = textStyleModel.get('overflow');
  277. if (overflow) {
  278. textStyle.overflow = overflow;
  279. }
  280. var lineOverflow = textStyleModel.get('lineOverflow');
  281. if (lineOverflow) {
  282. textStyle.lineOverflow = lineOverflow;
  283. }
  284. var labelTextStyle = textStyle;
  285. // `minMargin` has a higher precedence than `textMargin`, because `textMargin` is allowed
  286. // to be set in `defaultOption`.
  287. var minMargin = textStyleModel.get('minMargin');
  288. if (minMargin != null) {
  289. // `minMargin` only support number value.
  290. minMargin = !isNumber(minMargin) ? 0 : minMargin / 2;
  291. labelTextStyle.margin = [minMargin, minMargin, minMargin, minMargin];
  292. labelTextStyle.__marginType = LabelMarginType.minMargin;
  293. } else {
  294. var textMargin = textStyleModel.get('textMargin');
  295. if (textMargin != null) {
  296. labelTextStyle.margin = normalizeCssArray(textMargin);
  297. labelTextStyle.__marginType = LabelMarginType.textMargin;
  298. }
  299. }
  300. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, null, null, opt, isNotNormal, isAttached, true, false);
  301. }
  302. // Consider case:
  303. // {
  304. // data: [{
  305. // value: 12,
  306. // label: {
  307. // rich: {
  308. // // no 'a' here but using parent 'a'.
  309. // }
  310. // }
  311. // }],
  312. // rich: {
  313. // a: { ... }
  314. // }
  315. // }
  316. // TODO TextStyleModel
  317. function getRichItemNames(textStyleModel) {
  318. // Use object to remove duplicated names.
  319. var richItemNameMap;
  320. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  321. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  322. if (rich) {
  323. richItemNameMap = richItemNameMap || {};
  324. var richKeys = keys(rich);
  325. for (var i = 0; i < richKeys.length; i++) {
  326. var richKey = richKeys[i];
  327. richItemNameMap[richKey] = 1;
  328. }
  329. }
  330. textStyleModel = textStyleModel.parentModel;
  331. }
  332. return richItemNameMap;
  333. }
  334. var TEXT_PROPS_WITH_GLOBAL = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY'];
  335. var TEXT_PROPS_SELF = ['align', 'lineHeight', 'width', 'height', 'tag', 'verticalAlign', 'ellipsis'];
  336. var TEXT_PROPS_BOX = ['padding', 'borderWidth', 'borderRadius', 'borderDashOffset', 'backgroundColor', 'borderColor', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  337. function setTokenTextStyle(textStyle,
  338. // FIXME: check/refactor for ellipsis handling of rich text.
  339. textStyleModel, globalTextStyle, plainTextModel, richInheritPlainLabel, opt, isNotNormal, isAttached, isBlock, inRich) {
  340. // In merge mode, default value should not be given.
  341. globalTextStyle = !isNotNormal && globalTextStyle || EMPTY_OBJ;
  342. var inheritColor = opt && opt.inheritColor;
  343. var fillColor = textStyleModel.getShallow('color');
  344. var strokeColor = textStyleModel.getShallow('textBorderColor');
  345. var opacity = retrieve2(textStyleModel.getShallow('opacity'), globalTextStyle.opacity);
  346. if (fillColor === 'inherit' || fillColor === 'auto') {
  347. if (process.env.NODE_ENV !== 'production') {
  348. if (fillColor === 'auto') {
  349. deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
  350. }
  351. }
  352. if (inheritColor) {
  353. fillColor = inheritColor;
  354. } else {
  355. fillColor = null;
  356. }
  357. }
  358. if (strokeColor === 'inherit' || strokeColor === 'auto') {
  359. if (process.env.NODE_ENV !== 'production') {
  360. if (strokeColor === 'auto') {
  361. deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
  362. }
  363. }
  364. if (inheritColor) {
  365. strokeColor = inheritColor;
  366. } else {
  367. strokeColor = null;
  368. }
  369. }
  370. if (!isAttached) {
  371. // Only use default global textStyle.color if text is individual.
  372. // Otherwise it will use the strategy of attached text color because text may be on a path.
  373. fillColor = fillColor || globalTextStyle.color;
  374. strokeColor = strokeColor || globalTextStyle.textBorderColor;
  375. }
  376. if (fillColor != null) {
  377. // Might not be a string, e.g, it's a function in axisLabel case; but assume that it will
  378. // be erased by a correct value outside.
  379. textStyle.fill = fillColor;
  380. }
  381. if (strokeColor != null) {
  382. textStyle.stroke = strokeColor;
  383. }
  384. var textBorderWidth = retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
  385. if (textBorderWidth != null) {
  386. textStyle.lineWidth = textBorderWidth;
  387. }
  388. var textBorderType = retrieve2(textStyleModel.getShallow('textBorderType'), globalTextStyle.textBorderType);
  389. if (textBorderType != null) {
  390. textStyle.lineDash = textBorderType;
  391. }
  392. var textBorderDashOffset = retrieve2(textStyleModel.getShallow('textBorderDashOffset'), globalTextStyle.textBorderDashOffset);
  393. if (textBorderDashOffset != null) {
  394. textStyle.lineDashOffset = textBorderDashOffset;
  395. }
  396. if (!isNotNormal && opacity == null && !inRich) {
  397. opacity = opt && opt.defaultOpacity;
  398. }
  399. if (opacity != null) {
  400. textStyle.opacity = opacity;
  401. }
  402. // TODO
  403. if (!isNotNormal && !isAttached) {
  404. // Set default finally.
  405. if (textStyle.fill == null && opt.inheritColor) {
  406. textStyle.fill = opt.inheritColor;
  407. }
  408. }
  409. // Do not use `getFont` here, because merge should be supported, where
  410. // part of these properties may be changed in emphasis style, and the
  411. // others should remain their original value got from normal style.
  412. for (var i = 0; i < TEXT_PROPS_WITH_GLOBAL.length; i++) {
  413. var key = TEXT_PROPS_WITH_GLOBAL[i];
  414. // props width, height, padding, margin, tag, backgroundColor, borderColor,
  415. // borderWidth, borderRadius, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY
  416. // may inappropriate to inherit from plainTextStyle.
  417. // And if some props is specified in default options, users may have to reset them one by one.
  418. // Therefore, we only allow these props to inherit from plainTextStyle.
  419. // `richInheritPlainLabel` is switch for backward compatibility
  420. var val = richInheritPlainLabel !== false && plainTextModel ? retrieve3(textStyleModel.getShallow(key), plainTextModel.getShallow(key), globalTextStyle[key]) : retrieve2(textStyleModel.getShallow(key), globalTextStyle[key]);
  421. if (val != null) {
  422. textStyle[key] = val;
  423. }
  424. }
  425. for (var i = 0; i < TEXT_PROPS_SELF.length; i++) {
  426. var key = TEXT_PROPS_SELF[i];
  427. var val = textStyleModel.getShallow(key);
  428. if (val != null) {
  429. textStyle[key] = val;
  430. }
  431. }
  432. if (textStyle.verticalAlign == null) {
  433. var baseline = textStyleModel.getShallow('baseline');
  434. if (baseline != null) {
  435. textStyle.verticalAlign = baseline;
  436. }
  437. }
  438. if (!isBlock || !opt.disableBox) {
  439. for (var i = 0; i < TEXT_PROPS_BOX.length; i++) {
  440. var key = TEXT_PROPS_BOX[i];
  441. var val = textStyleModel.getShallow(key);
  442. if (val != null) {
  443. textStyle[key] = val;
  444. }
  445. }
  446. var borderType = textStyleModel.getShallow('borderType');
  447. if (borderType != null) {
  448. textStyle.borderDash = borderType;
  449. }
  450. if ((textStyle.backgroundColor === 'auto' || textStyle.backgroundColor === 'inherit') && inheritColor) {
  451. if (process.env.NODE_ENV !== 'production') {
  452. if (textStyle.backgroundColor === 'auto') {
  453. deprecateReplaceLog('backgroundColor: \'auto\'', 'backgroundColor: \'inherit\'');
  454. }
  455. }
  456. textStyle.backgroundColor = inheritColor;
  457. }
  458. if ((textStyle.borderColor === 'auto' || textStyle.borderColor === 'inherit') && inheritColor) {
  459. if (process.env.NODE_ENV !== 'production') {
  460. if (textStyle.borderColor === 'auto') {
  461. deprecateReplaceLog('borderColor: \'auto\'', 'borderColor: \'inherit\'');
  462. }
  463. }
  464. textStyle.borderColor = inheritColor;
  465. }
  466. }
  467. }
  468. export function getFont(opt, ecModel) {
  469. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  470. return trim([
  471. // FIXME in node-canvas fontWeight is before fontStyle
  472. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '', opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '', (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px', opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'].join(' '));
  473. }
  474. export var labelInner = makeInner();
  475. export function setLabelValueAnimation(label, labelStatesModels, value, getDefaultText) {
  476. if (!label) {
  477. return;
  478. }
  479. var obj = labelInner(label);
  480. obj.prevValue = obj.value;
  481. obj.value = value;
  482. var normalLabelModel = labelStatesModels.normal;
  483. obj.valueAnimation = normalLabelModel.get('valueAnimation');
  484. if (obj.valueAnimation) {
  485. obj.precision = normalLabelModel.get('precision');
  486. obj.defaultInterpolatedText = getDefaultText;
  487. obj.statesModels = labelStatesModels;
  488. }
  489. }
  490. export function animateLabelValue(textEl, dataIndex, data, animatableModel, labelFetcher) {
  491. var labelInnerStore = labelInner(textEl);
  492. if (!labelInnerStore.valueAnimation || labelInnerStore.prevValue === labelInnerStore.value) {
  493. // Value not changed, no new label animation
  494. return;
  495. }
  496. var defaultInterpolatedText = labelInnerStore.defaultInterpolatedText;
  497. // Consider the case that being animating, do not use the `obj.value`,
  498. // Otherwise it will jump to the `obj.value` when this new animation started.
  499. var currValue = retrieve2(labelInnerStore.interpolatedValue, labelInnerStore.prevValue);
  500. var targetValue = labelInnerStore.value;
  501. function during(percent) {
  502. var interpolated = interpolateRawValues(data, labelInnerStore.precision, currValue, targetValue, percent);
  503. labelInnerStore.interpolatedValue = percent === 1 ? null : interpolated;
  504. var labelText = getLabelText({
  505. labelDataIndex: dataIndex,
  506. labelFetcher: labelFetcher,
  507. defaultText: defaultInterpolatedText ? defaultInterpolatedText(interpolated) : interpolated + ''
  508. }, labelInnerStore.statesModels, interpolated);
  509. setLabelText(textEl, labelText);
  510. }
  511. textEl.percent = 0;
  512. (labelInnerStore.prevValue == null ? initProps : updateProps)(textEl, {
  513. // percent is used to prevent animation from being aborted #15916
  514. percent: 1
  515. }, animatableModel, dataIndex, null, during);
  516. }
  517. /**
  518. * PENDING: Temporary impl. unify them?
  519. * @see {LabelCommonOption['textMargin']}
  520. * @see {LabelCommonOption['minMargin']}
  521. */
  522. export var LabelMarginType = {
  523. minMargin: 1,
  524. textMargin: 2
  525. };