@visactor/vrender-components 0.14.5-alpha.3 → 0.14.5-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/cjs/index.d.ts +1 -1
  2. package/cjs/index.js +1 -1
  3. package/cjs/index.js.map +1 -1
  4. package/cjs/label/arc.d.ts +6 -3
  5. package/cjs/label/arc.js +32 -3
  6. package/cjs/label/arc.js.map +1 -1
  7. package/cjs/label/base.d.ts +12 -9
  8. package/cjs/label/base.js +107 -130
  9. package/cjs/label/base.js.map +1 -1
  10. package/cjs/label/dataLabel.js +4 -4
  11. package/cjs/label/dataLabel.js.map +1 -1
  12. package/cjs/label/polygon.d.ts +12 -0
  13. package/cjs/label/polygon.js +35 -0
  14. package/cjs/label/polygon.js.map +1 -0
  15. package/cjs/label/type.d.ts +4 -2
  16. package/cjs/label/type.js.map +1 -1
  17. package/cjs/link-path/link-path.js +1 -2
  18. package/cjs/link-path/type.js +2 -1
  19. package/cjs/marker/type.js +1 -1
  20. package/cjs/poptip/poptip.js +3 -3
  21. package/cjs/poptip/poptip.js.map +1 -1
  22. package/cjs/slider/slider.js +16 -25
  23. package/cjs/slider/slider.js.map +1 -1
  24. package/cjs/util/labelSmartInvert.d.ts +1 -0
  25. package/cjs/util/labelSmartInvert.js +20 -2
  26. package/cjs/util/labelSmartInvert.js.map +1 -1
  27. package/dist/index.js +183 -197
  28. package/dist/index.min.js +1 -1
  29. package/es/index.d.ts +1 -1
  30. package/es/index.js +1 -1
  31. package/es/index.js.map +1 -1
  32. package/es/label/arc.d.ts +6 -3
  33. package/es/label/arc.js +32 -2
  34. package/es/label/arc.js.map +1 -1
  35. package/es/label/base.d.ts +12 -9
  36. package/es/label/base.js +108 -127
  37. package/es/label/base.js.map +1 -1
  38. package/es/label/dataLabel.js +5 -3
  39. package/es/label/dataLabel.js.map +1 -1
  40. package/es/label/polygon.d.ts +12 -0
  41. package/es/label/polygon.js +31 -0
  42. package/es/label/polygon.js.map +1 -0
  43. package/es/label/type.d.ts +4 -2
  44. package/es/label/type.js.map +1 -1
  45. package/es/link-path/link-path.js +1 -2
  46. package/es/link-path/type.js +2 -1
  47. package/es/marker/type.js +1 -1
  48. package/es/poptip/poptip.js +3 -3
  49. package/es/poptip/poptip.js.map +1 -1
  50. package/es/slider/slider.js +17 -26
  51. package/es/slider/slider.js.map +1 -1
  52. package/es/util/labelSmartInvert.d.ts +1 -0
  53. package/es/util/labelSmartInvert.js +17 -0
  54. package/es/util/labelSmartInvert.js.map +1 -1
  55. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -495,6 +495,20 @@
495
495
  const { r, g, b } = c.color;
496
496
  return '#' + vutils.ColorUtil.rgbToHex(r, g, b);
497
497
  }
498
+ function smartInvertStrategy(fillStrategy, baseColor, invertColor, similarColor) {
499
+ let result;
500
+ switch (fillStrategy) {
501
+ case 'base':
502
+ result = baseColor;
503
+ break;
504
+ case 'invertBase':
505
+ result = invertColor;
506
+ break;
507
+ case 'similarBase':
508
+ result = similarColor;
509
+ }
510
+ return result;
511
+ }
498
512
 
499
513
  function scale(vector, scale) {
500
514
  return [vector[0] * scale, vector[1] * scale];
@@ -751,10 +765,10 @@
751
765
  ? [this.stage.width, this.stage.height]
752
766
  : undefined;
753
767
  const layout = position === 'auto';
754
- let maxBBoxI;
755
- let maxBBoxSize = -Infinity;
768
+ let minifyBBoxI;
769
+ let minifyBBoxSize = Infinity;
756
770
  for (let i = 0; i < this.positionList.length + 1; i++) {
757
- const p = layout ? this.positionList[i === this.positionList.length ? maxBBoxI : i] : position;
771
+ const p = layout ? this.positionList[i === this.positionList.length ? minifyBBoxI : i] : position;
758
772
  const { angle, offset, rectOffset } = this.getAngleAndOffset(p, popTipWidth, poptipHeight, vutils.isArray(spaceSize) ? spaceSize : [spaceSize, spaceSize - lineWidth]);
759
773
  if (vutils.isBoolean(bgVisible)) {
760
774
  const offsetX = (vutils.isArray(symbolSize) ? symbolSize[0] : symbolSize) / 4;
@@ -780,9 +794,9 @@
780
794
  else {
781
795
  const bbox = vutils.getRectIntersect(b, stageBounds, false);
782
796
  const size = (bbox.x2 - bbox.x1) * (bbox.y2 - bbox.y1);
783
- if (size > maxBBoxSize) {
784
- maxBBoxSize = size;
785
- maxBBoxI = i;
797
+ if (size < minifyBBoxSize) {
798
+ minifyBBoxSize = size;
799
+ minifyBBoxI = i;
786
800
  }
787
801
  }
788
802
  }
@@ -1403,12 +1417,6 @@
1403
1417
  }
1404
1418
  return !bitmap.getRange(range);
1405
1419
  }
1406
- function canPlaceInside(textBound, shapeBound) {
1407
- if (!textBound || !shapeBound) {
1408
- return false;
1409
- }
1410
- return shapeBound.encloses(textBound);
1411
- }
1412
1420
  function placeToCandidates($, bitmap, text, candidates = [], clampForce = true) {
1413
1421
  for (let i = 0; i < candidates.length; i++) {
1414
1422
  const tempText = text.clone();
@@ -1532,8 +1540,14 @@
1532
1540
  };
1533
1541
 
1534
1542
  class LabelBase extends AbstractComponent {
1535
- constructor() {
1536
- super(...arguments);
1543
+ setBitmap(bitmap) {
1544
+ this._bitmap = bitmap;
1545
+ }
1546
+ setBitmapTool(bmpTool) {
1547
+ this._bmpTool = bmpTool;
1548
+ }
1549
+ constructor(attributes) {
1550
+ super(vutils.merge({}, LabelBase.defaultAttributes, attributes));
1537
1551
  this.name = 'label';
1538
1552
  this._onHover = (e) => {
1539
1553
  const target = e.target;
@@ -1581,15 +1595,11 @@
1581
1595
  }
1582
1596
  };
1583
1597
  }
1584
- setBitmap(bitmap) {
1585
- this._bitmap = bitmap;
1586
- }
1587
- setBitmapTool(bmpTool) {
1588
- this._bmpTool = bmpTool;
1598
+ labeling(textBounds, graphicBounds, position, offset) {
1599
+ return;
1589
1600
  }
1590
- layoutArcLabels(position, attribute, currentMarks, data, textBoundsArray, ellipsisWidth) {
1591
- const arcs = [];
1592
- return arcs;
1601
+ _labelLine(text) {
1602
+ return;
1593
1603
  }
1594
1604
  render() {
1595
1605
  this._prepare();
@@ -1603,7 +1613,7 @@
1603
1613
  labels = customLayoutFunc(data, (d) => this._idToGraphic.get(d.id));
1604
1614
  }
1605
1615
  else {
1606
- labels = this.layout(data);
1616
+ labels = this._layout(data);
1607
1617
  if (vutils.isFunction(customOverlapFunc)) {
1608
1618
  labels = customOverlapFunc(labels, (d) => this._idToGraphic.get(d.id));
1609
1619
  }
@@ -1679,49 +1689,24 @@
1679
1689
  }
1680
1690
  }
1681
1691
  }
1682
- layout(data = []) {
1692
+ _layout(data = []) {
1683
1693
  const { textStyle = {}, position, offset } = this.attribute;
1684
1694
  const labels = [];
1685
- const textBoundsArray = [];
1686
1695
  for (let i = 0; i < data.length; i++) {
1687
1696
  const textData = data[i];
1688
1697
  const baseMark = this._idToGraphic.get(textData.id);
1689
1698
  const labelAttribute = Object.assign(Object.assign({ fill: baseMark.attribute.fill }, textStyle), textData);
1690
1699
  const text = this._createLabelText(labelAttribute);
1691
1700
  const textBounds = this.getGraphicBounds(text);
1692
- textBoundsArray.push(textBounds);
1693
1701
  const graphicBounds = this.getGraphicBounds(baseMark, { x: textData.x, y: textData.y });
1694
1702
  const textLocation = this.labeling(textBounds, graphicBounds, vutils.isFunction(position) ? position(textData) : position, offset);
1695
- if (!textLocation) {
1696
- continue;
1703
+ if (textLocation) {
1704
+ labelAttribute.x = textLocation.x;
1705
+ labelAttribute.y = textLocation.y;
1706
+ text.setAttributes(textLocation);
1697
1707
  }
1698
- labelAttribute.x = textLocation.x;
1699
- labelAttribute.y = textLocation.y;
1700
- text.setAttributes(textLocation);
1701
1708
  labels.push(text);
1702
1709
  }
1703
- if (this.attribute.type === 'arc') {
1704
- const ellipsisLabelAttribute = Object.assign(Object.assign({}, this.attribute.textStyle), { text: '...' });
1705
- const ellipsisText = this._createLabelText(ellipsisLabelAttribute);
1706
- const ellipsisTextBounds = this.getGraphicBounds(ellipsisText);
1707
- const ellipsisWidth = ellipsisTextBounds.x2 - ellipsisTextBounds.x1;
1708
- const arcs = this.layoutArcLabels(position, this.attribute, Array.from(this._idToGraphic.values()), data, textBoundsArray, ellipsisWidth);
1709
- for (let i = 0; i < data.length; i++) {
1710
- const textData = data[i];
1711
- const basedArc = arcs.find(arc => arc.refDatum.id === textData.id);
1712
- const labelAttribute = {
1713
- visible: basedArc.labelVisible,
1714
- x: basedArc.labelPosition.x,
1715
- y: basedArc.labelPosition.y,
1716
- angle: basedArc.angle,
1717
- maxLineWidth: basedArc.labelLimit,
1718
- points: (basedArc === null || basedArc === void 0 ? void 0 : basedArc.pointA) && (basedArc === null || basedArc === void 0 ? void 0 : basedArc.pointB) && (basedArc === null || basedArc === void 0 ? void 0 : basedArc.pointC)
1719
- ? [basedArc.pointA, basedArc.pointB, basedArc.pointC]
1720
- : undefined
1721
- };
1722
- labels[i].setAttributes(labelAttribute);
1723
- }
1724
- }
1725
1710
  return labels;
1726
1711
  }
1727
1712
  _overlapping(labels) {
@@ -1773,7 +1758,7 @@
1773
1758
  result.push(text);
1774
1759
  continue;
1775
1760
  }
1776
- if (checkBounds && (baseMark === null || baseMark === void 0 ? void 0 : baseMark.AABBBounds) && canPlaceInside(text.AABBBounds, baseMark === null || baseMark === void 0 ? void 0 : baseMark.AABBBounds)) {
1761
+ if (checkBounds && (baseMark === null || baseMark === void 0 ? void 0 : baseMark.AABBBounds) && this._canPlaceInside(text.AABBBounds, baseMark === null || baseMark === void 0 ? void 0 : baseMark.AABBBounds)) {
1777
1762
  bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));
1778
1763
  result.push(text);
1779
1764
  continue;
@@ -1827,9 +1812,17 @@
1827
1812
  });
1828
1813
  }
1829
1814
  _renderLabels(labels) {
1815
+ const disableAnimation = this._enableAnimation === false || this.attribute.animation === false;
1816
+ if (disableAnimation) {
1817
+ this._renderWithOutAnimation(labels);
1818
+ }
1819
+ else {
1820
+ this._renderWithAnimation(labels);
1821
+ }
1822
+ }
1823
+ _renderWithAnimation(labels) {
1830
1824
  var _a, _b, _c, _d, _e;
1831
1825
  const animationConfig = ((_a = this.attribute.animation) !== null && _a !== void 0 ? _a : {});
1832
- const disableAnimation = this._enableAnimation === false || animationConfig === false;
1833
1826
  const mode = (_b = animationConfig.mode) !== null && _b !== void 0 ? _b : DefaultLabelAnimation.mode;
1834
1827
  const duration = (_c = animationConfig.duration) !== null && _c !== void 0 ? _c : DefaultLabelAnimation.duration;
1835
1828
  const easing = (_d = animationConfig.easing) !== null && _d !== void 0 ? _d : DefaultLabelAnimation.easing;
@@ -1838,27 +1831,18 @@
1838
1831
  const prevTextMap = this._graphicToText || new Map();
1839
1832
  const texts = [];
1840
1833
  labels.forEach((text, index) => {
1841
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
1842
- const labelLine = ((_a = text.attribute) === null || _a === void 0 ? void 0 : _a.points)
1843
- ? vrender.createLine({
1844
- visible: (_c = (_b = text.attribute) === null || _b === void 0 ? void 0 : _b.visible) !== null && _c !== void 0 ? _c : true,
1845
- stroke: (_f = (_e = (_d = text.attribute) === null || _d === void 0 ? void 0 : _d.line) === null || _e === void 0 ? void 0 : _e.stroke) !== null && _f !== void 0 ? _f : (_g = text.attribute) === null || _g === void 0 ? void 0 : _g.fill,
1846
- lineWidth: (_k = (_j = (_h = text.attribute) === null || _h === void 0 ? void 0 : _h.line) === null || _j === void 0 ? void 0 : _j.lineWidth) !== null && _k !== void 0 ? _k : 1,
1847
- points: (_l = text.attribute) === null || _l === void 0 ? void 0 : _l.points
1848
- })
1849
- : undefined;
1834
+ var _a;
1835
+ const labelLine = this._labelLine(text);
1850
1836
  const relatedGraphic = this._idToGraphic.get(text.attribute.id);
1851
1837
  const state = (prevTextMap === null || prevTextMap === void 0 ? void 0 : prevTextMap.get(relatedGraphic)) ? 'update' : 'enter';
1852
1838
  if (state === 'enter') {
1853
1839
  texts.push(text);
1854
1840
  currentTextMap.set(relatedGraphic, labelLine ? { text, labelLine } : { text });
1855
- if (!disableAnimation && relatedGraphic) {
1841
+ if (relatedGraphic) {
1856
1842
  const { from, to } = getAnimationAttributes(text.attribute, 'fadeIn');
1857
1843
  this.add(text);
1858
- if (labelLine) {
1859
- this.add(labelLine);
1860
- }
1861
- relatedGraphic.onAnimateBind = () => {
1844
+ labelLine && this.add(labelLine);
1845
+ relatedGraphic.once('animate-bind', () => {
1862
1846
  text.setAttributes(from);
1863
1847
  const listener = this._afterRelatedGraphicAttributeUpdate(text, texts, index, relatedGraphic, {
1864
1848
  mode,
@@ -1868,58 +1852,69 @@
1868
1852
  delay
1869
1853
  });
1870
1854
  relatedGraphic.on('afterAttributeUpdate', listener);
1871
- };
1872
- }
1873
- else {
1874
- this.add(text);
1875
- if (labelLine) {
1876
- this.add(labelLine);
1877
- }
1855
+ });
1878
1856
  }
1879
1857
  }
1880
- if (state === 'update') {
1858
+ else if (state === 'update') {
1881
1859
  const prevLabel = prevTextMap.get(relatedGraphic);
1882
1860
  prevTextMap.delete(relatedGraphic);
1883
1861
  currentTextMap.set(relatedGraphic, prevLabel);
1884
- if (!disableAnimation) {
1885
- const prevText = prevLabel.text;
1886
- prevText.animate().to(text.attribute, duration, easing);
1887
- if (prevLabel.labelLine) {
1888
- prevLabel.labelLine.animate().to(vutils.merge({}, prevLabel.labelLine.attribute, {
1889
- points: (_m = text.attribute) === null || _m === void 0 ? void 0 : _m.points
1890
- }), duration, easing);
1891
- }
1892
- if (animationConfig.increaseEffect !== false &&
1893
- prevText.attribute.text !== text.attribute.text &&
1894
- vutils.isValidNumber(Number(prevText.attribute.text) * Number(text.attribute.text))) {
1895
- prevText
1896
- .animate()
1897
- .play(new vrender.IncreaseCount({ text: prevText.attribute.text }, { text: text.attribute.text }, duration, easing));
1898
- }
1862
+ const prevText = prevLabel.text;
1863
+ prevText.animate().to(text.attribute, duration, easing);
1864
+ if (prevLabel.labelLine) {
1865
+ prevLabel.labelLine.animate().to(vutils.merge({}, prevLabel.labelLine.attribute, {
1866
+ points: (_a = text.attribute) === null || _a === void 0 ? void 0 : _a.points
1867
+ }), duration, easing);
1899
1868
  }
1900
- else {
1901
- prevLabel.text.setAttributes(text.attribute);
1902
- if (prevLabel === null || prevLabel === void 0 ? void 0 : prevLabel.labelLine) {
1903
- prevLabel.labelLine.setAttributes({ points: (_o = text.attribute) === null || _o === void 0 ? void 0 : _o.points });
1904
- }
1869
+ if (animationConfig.increaseEffect !== false &&
1870
+ prevText.attribute.text !== text.attribute.text &&
1871
+ vutils.isValidNumber(Number(prevText.attribute.text) * Number(text.attribute.text))) {
1872
+ prevText
1873
+ .animate()
1874
+ .play(new vrender.IncreaseCount({ text: prevText.attribute.text }, { text: text.attribute.text }, duration, easing));
1905
1875
  }
1906
1876
  }
1907
1877
  });
1908
1878
  prevTextMap.forEach(label => {
1909
1879
  var _a;
1910
- if (disableAnimation) {
1880
+ (_a = label.text) === null || _a === void 0 ? void 0 : _a.animate().to(getAnimationAttributes(label.text.attribute, 'fadeOut').to, duration, easing).onEnd(() => {
1911
1881
  this.removeChild(label.text);
1912
1882
  if (label === null || label === void 0 ? void 0 : label.labelLine) {
1913
1883
  this.removeChild(label.labelLine);
1914
1884
  }
1885
+ });
1886
+ });
1887
+ this._graphicToText = currentTextMap;
1888
+ }
1889
+ _renderWithOutAnimation(labels) {
1890
+ const currentTextMap = new Map();
1891
+ const prevTextMap = this._graphicToText || new Map();
1892
+ labels.forEach(text => {
1893
+ var _a;
1894
+ const labelLine = this._labelLine(text);
1895
+ const relatedGraphic = this._idToGraphic.get(text.attribute.id);
1896
+ const state = (prevTextMap === null || prevTextMap === void 0 ? void 0 : prevTextMap.get(relatedGraphic)) ? 'update' : 'enter';
1897
+ if (state === 'enter') {
1898
+ currentTextMap.set(relatedGraphic, labelLine ? { text, labelLine } : { text });
1899
+ this.add(text);
1900
+ if (labelLine) {
1901
+ this.add(labelLine);
1902
+ }
1915
1903
  }
1916
- else {
1917
- (_a = label.text) === null || _a === void 0 ? void 0 : _a.animate().to(getAnimationAttributes(label.text.attribute, 'fadeOut').to, duration, easing).onEnd(() => {
1918
- this.removeChild(label.text);
1919
- if (label === null || label === void 0 ? void 0 : label.labelLine) {
1920
- this.removeChild(label.labelLine);
1921
- }
1922
- });
1904
+ else if (state === 'update') {
1905
+ const prevLabel = prevTextMap.get(relatedGraphic);
1906
+ prevTextMap.delete(relatedGraphic);
1907
+ currentTextMap.set(relatedGraphic, prevLabel);
1908
+ prevLabel.text.setAttributes(text.attribute);
1909
+ if (prevLabel === null || prevLabel === void 0 ? void 0 : prevLabel.labelLine) {
1910
+ prevLabel.labelLine.setAttributes({ points: (_a = text.attribute) === null || _a === void 0 ? void 0 : _a.points });
1911
+ }
1912
+ }
1913
+ });
1914
+ prevTextMap.forEach(label => {
1915
+ this.removeChild(label.text);
1916
+ if (label === null || label === void 0 ? void 0 : label.labelLine) {
1917
+ this.removeChild(label.labelLine);
1923
1918
  }
1924
1919
  });
1925
1920
  this._graphicToText = currentTextMap;
@@ -1990,21 +1985,20 @@
1990
1985
  continue;
1991
1986
  }
1992
1987
  const baseMark = this._idToGraphic.get(label.attribute.id);
1993
- let isInside = canPlaceInside(label.AABBBounds, baseMark === null || baseMark === void 0 ? void 0 : baseMark.AABBBounds);
1994
- if (this.attribute.type === 'arc') {
1995
- isInside = this.attribute.position === 'inside';
1996
- }
1988
+ const isInside = this._canPlaceInside(label.AABBBounds, baseMark === null || baseMark === void 0 ? void 0 : baseMark.AABBBounds);
1997
1989
  const backgroundColor = baseMark.attribute.fill;
1998
1990
  const foregroundColor = label.attribute.fill;
1999
1991
  const baseColor = backgroundColor;
2000
1992
  const invertColor = labelSmartInvert(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors);
2001
- const simialrColor = contrastAccessibilityChecker(invertColor, brightColor) ? brightColor : darkColor;
1993
+ const similarColor = contrastAccessibilityChecker(invertColor, brightColor) ? brightColor : darkColor;
2002
1994
  if (isInside) {
2003
- this.setFillStrategy(fillStrategy, label, baseColor, invertColor, simialrColor);
1995
+ const fill = smartInvertStrategy(fillStrategy, baseColor, invertColor, similarColor);
1996
+ fill && label.setAttributes({ fill });
2004
1997
  if (label.attribute.lineWidth === 0) {
2005
1998
  continue;
2006
1999
  }
2007
- this.setStrokeStrategy(strokeStrategy, label, baseColor, invertColor, simialrColor);
2000
+ const stroke = smartInvertStrategy(strokeStrategy, baseColor, invertColor, similarColor);
2001
+ stroke && label.setAttributes({ stroke });
2008
2002
  }
2009
2003
  else {
2010
2004
  if (label.attribute.lineWidth === 0) {
@@ -2016,47 +2010,18 @@
2016
2010
  });
2017
2011
  continue;
2018
2012
  }
2019
- this.setFillStrategy(fillStrategy, label, baseColor, invertColor, simialrColor);
2020
- this.setStrokeStrategy(strokeStrategy, label, baseColor, invertColor, simialrColor);
2013
+ const fill = smartInvertStrategy(fillStrategy, baseColor, invertColor, similarColor);
2014
+ fill && label.setAttributes({ fill });
2015
+ const stroke = smartInvertStrategy(strokeStrategy, baseColor, invertColor, similarColor);
2016
+ stroke && label.setAttributes({ stroke });
2021
2017
  }
2022
2018
  }
2023
2019
  }
2024
- setFillStrategy(fillStrategy, label, baseColor, invertColor, simialrColor) {
2025
- switch (fillStrategy) {
2026
- case 'base':
2027
- label.setAttributes({
2028
- fill: baseColor
2029
- });
2030
- break;
2031
- case 'invertBase':
2032
- label.setAttributes({
2033
- fill: invertColor
2034
- });
2035
- break;
2036
- case 'similarBase':
2037
- label.setAttributes({
2038
- fill: simialrColor
2039
- });
2040
- }
2041
- }
2042
- setStrokeStrategy(strokeStrategy, label, baseColor, invertColor, simialrColor) {
2043
- switch (strokeStrategy) {
2044
- case 'base':
2045
- label.setAttributes({
2046
- stroke: baseColor
2047
- });
2048
- break;
2049
- case 'invertBase':
2050
- label.setAttributes({
2051
- stroke: invertColor
2052
- });
2053
- break;
2054
- case 'similarBase':
2055
- label.setAttributes({
2056
- stroke: simialrColor
2057
- });
2058
- break;
2020
+ _canPlaceInside(textBound, shapeBound) {
2021
+ if (!textBound || !shapeBound) {
2022
+ return false;
2059
2023
  }
2024
+ return shapeBound.encloses(textBound);
2060
2025
  }
2061
2026
  setLocation(point) {
2062
2027
  this.translateTo(point.x, point.y);
@@ -2068,6 +2033,17 @@
2068
2033
  this._enableAnimation = true;
2069
2034
  }
2070
2035
  }
2036
+ LabelBase.defaultAttributes = {
2037
+ textStyle: {
2038
+ fontSize: 12,
2039
+ fill: '#000',
2040
+ textAlign: 'center',
2041
+ textBaseline: 'middle',
2042
+ boundsPadding: [-1, 0, -1, 0]
2043
+ },
2044
+ offset: 0,
2045
+ pickable: false
2046
+ };
2071
2047
 
2072
2048
  class SymbolLabel extends LabelBase {
2073
2049
  constructor(attributes) {
@@ -2422,6 +2398,31 @@
2422
2398
  }
2423
2399
  return { x: 0, y: 0 };
2424
2400
  }
2401
+ _layout(data = []) {
2402
+ const labels = super._layout(data);
2403
+ const textBoundsArray = labels.map(label => this.getGraphicBounds(label));
2404
+ const ellipsisLabelAttribute = Object.assign(Object.assign({}, this.attribute.textStyle), { text: '...' });
2405
+ const ellipsisText = this._createLabelText(ellipsisLabelAttribute);
2406
+ const ellipsisTextBounds = this.getGraphicBounds(ellipsisText);
2407
+ const ellipsisWidth = ellipsisTextBounds.x2 - ellipsisTextBounds.x1;
2408
+ const arcs = this.layoutArcLabels(this.attribute.position, this.attribute, Array.from(this._idToGraphic.values()), data, textBoundsArray, ellipsisWidth);
2409
+ for (let i = 0; i < data.length; i++) {
2410
+ const textData = data[i];
2411
+ const basedArc = arcs.find(arc => arc.refDatum.id === textData.id);
2412
+ const labelAttribute = {
2413
+ visible: basedArc.labelVisible,
2414
+ x: basedArc.labelPosition.x,
2415
+ y: basedArc.labelPosition.y,
2416
+ angle: basedArc.angle,
2417
+ maxLineWidth: basedArc.labelLimit,
2418
+ points: (basedArc === null || basedArc === void 0 ? void 0 : basedArc.pointA) && (basedArc === null || basedArc === void 0 ? void 0 : basedArc.pointB) && (basedArc === null || basedArc === void 0 ? void 0 : basedArc.pointC)
2419
+ ? [basedArc.pointA, basedArc.pointB, basedArc.pointC]
2420
+ : undefined
2421
+ };
2422
+ labels[i].setAttributes(labelAttribute);
2423
+ }
2424
+ return labels;
2425
+ }
2425
2426
  layoutArcLabels(position, attribute, currentMarks, data, textBoundsArray, ellipsisWidth) {
2426
2427
  var _a;
2427
2428
  this._arcLeft.clear();
@@ -2988,6 +2989,18 @@
2988
2989
  }
2989
2990
  }
2990
2991
  }
2992
+ _labelLine(text) {
2993
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
2994
+ const labelLine = ((_a = text.attribute) === null || _a === void 0 ? void 0 : _a.points)
2995
+ ? vrender.createLine({
2996
+ visible: (_c = (_b = text.attribute) === null || _b === void 0 ? void 0 : _b.visible) !== null && _c !== void 0 ? _c : true,
2997
+ stroke: (_f = (_e = (_d = text.attribute) === null || _d === void 0 ? void 0 : _d.line) === null || _e === void 0 ? void 0 : _e.stroke) !== null && _f !== void 0 ? _f : (_g = text.attribute) === null || _g === void 0 ? void 0 : _g.fill,
2998
+ lineWidth: (_k = (_j = (_h = text.attribute) === null || _h === void 0 ? void 0 : _h.line) === null || _j === void 0 ? void 0 : _j.lineWidth) !== null && _k !== void 0 ? _k : 1,
2999
+ points: (_l = text.attribute) === null || _l === void 0 ? void 0 : _l.points
3000
+ })
3001
+ : undefined;
3002
+ return labelLine;
3003
+ }
2991
3004
  computeRadius(r, width, height, centerOffset, k) {
2992
3005
  var _a;
2993
3006
  return ((_a = this.computeLayoutRadius(width ? width : 0, height ? height : 0) * r * (vutils.isNil(k) ? 1 : k) + centerOffset) !== null && _a !== void 0 ? _a : 0);
@@ -2995,6 +3008,9 @@
2995
3008
  computeLayoutRadius(width, height) {
2996
3009
  return Math.min(width / 2, height / 2);
2997
3010
  }
3011
+ _canPlaceInside(textBound, shapeBound) {
3012
+ return this.attribute.position === 'inside';
3013
+ }
2998
3014
  computeLayoutOuterRadius(r, width, height) {
2999
3015
  return r / (Math.min(width, height) / 2);
3000
3016
  }
@@ -3027,8 +3043,7 @@
3027
3043
  align: 'arc',
3028
3044
  strategy: 'priority',
3029
3045
  tangentConstraint: true
3030
- },
3031
- pickable: false
3046
+ }
3032
3047
  };
3033
3048
 
3034
3049
  const labelComponentMap = {
@@ -3059,7 +3074,8 @@
3059
3074
  const prevComponentMap = this._componentMap;
3060
3075
  for (let i = 0; i < dataLabels.length; i++) {
3061
3076
  const dataLabel = dataLabels[i];
3062
- if (labelComponentMap[dataLabel.type]) {
3077
+ const labelComponent = labelComponentMap[dataLabel.type] || LabelBase;
3078
+ if (labelComponent) {
3063
3079
  const { baseMarkGroupName } = dataLabel;
3064
3080
  let component = this._componentMap.get(baseMarkGroupName);
3065
3081
  if (component) {
@@ -3069,7 +3085,7 @@
3069
3085
  currentComponentMap.set(baseMarkGroupName, component);
3070
3086
  }
3071
3087
  else {
3072
- component = new labelComponentMap[dataLabel.type](dataLabel);
3088
+ component = new labelComponent(dataLabel);
3073
3089
  component.setBitmap(bitmap);
3074
3090
  component.setBitmapTool(tool);
3075
3091
  this.add(component);
@@ -7416,9 +7432,6 @@
7416
7432
  var _a, _b;
7417
7433
  e.stopPropagation();
7418
7434
  const { railWidth, railHeight, min, max } = this.attribute;
7419
- if (max === min) {
7420
- return;
7421
- }
7422
7435
  let currentPos;
7423
7436
  let delta = 0;
7424
7437
  let originPos;
@@ -7477,9 +7490,6 @@
7477
7490
  this._onTrackPointerMove = (e) => {
7478
7491
  e.stopPropagation();
7479
7492
  const { railWidth, railHeight, min, max } = this.attribute;
7480
- if (max === min) {
7481
- return;
7482
- }
7483
7493
  const { startHandler, endHandler } = this._getHandlers();
7484
7494
  let currentPos;
7485
7495
  let trackLen;
@@ -7534,9 +7544,6 @@
7534
7544
  this._onRailPointerDown = (e) => {
7535
7545
  e.stopPropagation();
7536
7546
  const { railWidth, railHeight, min, max } = this.attribute;
7537
- if (max === min) {
7538
- return;
7539
- }
7540
7547
  const startHandler = this._startHandler;
7541
7548
  const endHandler = this._endHandler;
7542
7549
  let currentPos;
@@ -7568,11 +7575,8 @@
7568
7575
  };
7569
7576
  }
7570
7577
  setValue(value) {
7571
- const { layout, railWidth, railHeight, min, max } = this.attribute;
7572
- if (max === min) {
7573
- return;
7574
- }
7575
7578
  const [startValue, endValue] = vutils.array(value);
7579
+ const { layout, railWidth, railHeight, min, max } = this.attribute;
7576
7580
  const { startHandler, endHandler } = this._getHandlers();
7577
7581
  const railLen = layout === 'vertical' ? railHeight : railWidth;
7578
7582
  const startPos = ((startValue - min) / (max - min)) * railLen;
@@ -7664,27 +7668,27 @@
7664
7668
  const isHorizontal = this._isHorizontal;
7665
7669
  const railLen = isHorizontal ? railWidth : railHeight;
7666
7670
  const [startValue, endValue] = convertValueToRange(value);
7667
- const handlerStart = max === min ? (range ? 0 : railLen) : ((startValue - min) / (max - min)) * railLen;
7671
+ const handlerStart = ((startValue - min) / (max - min)) * railLen;
7668
7672
  const startHandler = this._renderHandler(Object.assign({ x: isHorizontal ? handlerStart : railWidth / 2, y: isHorizontal ? railHeight / 2 : handlerStart, size: handlerSize, strokeBoundsBuffer: 0, cursor: slidable === false ? 'default' : getDefaultCursor(isHorizontal) }, handlerStyle));
7669
7673
  startHandler.name = exports.SLIDER_ELEMENT_NAME.startHandler;
7670
7674
  this._startHandler = startHandler;
7671
7675
  container.add(startHandler);
7672
7676
  this._currentValue.startPos = handlerStart;
7673
7677
  if (handlerTextVisible) {
7674
- const startHandlerText = this._renderHandlerText(startValue, range ? 'start' : 'end');
7678
+ const startHandlerText = this._renderHandlerText(startValue);
7675
7679
  startHandlerText.name = exports.SLIDER_ELEMENT_NAME.startHandlerText;
7676
7680
  container.add(startHandlerText);
7677
7681
  this._startHandlerText = startHandlerText;
7678
7682
  }
7679
7683
  if (range) {
7680
- const handlerEnd = max === min ? railLen : ((endValue - min) / (max - min)) * railLen;
7684
+ const handlerEnd = ((endValue - min) / (max - min)) * railLen;
7681
7685
  const endHandler = this._renderHandler(Object.assign({ x: isHorizontal ? handlerEnd : railWidth / 2, y: isHorizontal ? railHeight / 2 : handlerEnd, size: handlerSize, strokeBoundsBuffer: 0, cursor: slidable === false ? 'default' : getDefaultCursor(isHorizontal) }, handlerStyle));
7682
7686
  endHandler.name = exports.SLIDER_ELEMENT_NAME.endHandler;
7683
7687
  this._endHandler = endHandler;
7684
7688
  container.add(endHandler);
7685
7689
  this._currentValue.endPos = handlerEnd;
7686
7690
  if (handlerTextVisible) {
7687
- const endHandlerText = this._renderHandlerText(endValue, 'end');
7691
+ const endHandlerText = this._renderHandlerText(endValue);
7688
7692
  endHandlerText.name = exports.SLIDER_ELEMENT_NAME.endHandlerText;
7689
7693
  container.add(endHandlerText);
7690
7694
  this._endHandlerText = endHandlerText;
@@ -7692,32 +7696,15 @@
7692
7696
  }
7693
7697
  }
7694
7698
  _renderTrack(container) {
7695
- const { range, min, max, railHeight, railWidth, trackStyle, railStyle, slidable, value } = this
7699
+ const { range, min, max, railHeight, railWidth, trackStyle, railStyle, slidable } = this
7696
7700
  .attribute;
7697
- let startValue;
7698
- let endValue;
7701
+ let { value } = this.attribute;
7699
7702
  if (vutils.isNil(value)) {
7700
- if (range) {
7701
- startValue = min;
7702
- endValue = max;
7703
- }
7704
- else {
7705
- startValue = endValue = min;
7706
- }
7707
- }
7708
- else {
7709
- if (range) {
7710
- const clampValue = vutils.clampRange(value, min, max);
7711
- startValue = clampValue[0];
7712
- endValue = clampValue[1];
7713
- }
7714
- else {
7715
- startValue = min;
7716
- endValue = vutils.clamp(value, min, max);
7717
- }
7703
+ value = [min, max];
7718
7704
  }
7719
7705
  const isHorizontal = this._isHorizontal;
7720
7706
  const railLen = isHorizontal ? railWidth : railHeight;
7707
+ let [startValue, endValue] = convertValueToRange(value);
7721
7708
  if (!range) {
7722
7709
  startValue = min;
7723
7710
  }
@@ -7745,9 +7732,8 @@
7745
7732
  else {
7746
7733
  cursor = getDefaultCursor(isHorizontal);
7747
7734
  }
7748
- const trackWidth = max === min ? railLen : ((endValue - startValue) / (max - min)) * railLen;
7749
- const startPos = max === min ? 0 : ((startValue - min) / (max - min)) * railLen;
7750
- const track = vrender.createRect(Object.assign({ x: isHorizontal ? startPos : 0, y: isHorizontal ? 0 : startPos, width: isHorizontal ? trackWidth : railWidth, height: isHorizontal ? railHeight : trackWidth, cursor }, trackStyle));
7735
+ const trackWidth = ((endValue - startValue) / (max - min)) * railLen;
7736
+ const track = vrender.createRect(Object.assign({ x: isHorizontal ? ((startValue - min) / (max - min)) * railLen : 0, y: isHorizontal ? 0 : ((startValue - min) / (max - min)) * railLen, width: isHorizontal ? trackWidth : railWidth, height: isHorizontal ? railHeight : trackWidth, cursor }, trackStyle));
7751
7737
  track.name = exports.SLIDER_ELEMENT_NAME.track;
7752
7738
  this._track = track;
7753
7739
  trackContainer.add(track);
@@ -7757,12 +7743,12 @@
7757
7743
  const handler = vrender.createSymbol(style);
7758
7744
  return handler;
7759
7745
  }
7760
- _renderHandlerText(value, position) {
7746
+ _renderHandlerText(value) {
7761
7747
  var _a, _b, _c;
7762
7748
  const { align, min, max, handlerSize = 14, handlerText = {}, railHeight, railWidth, slidable } = this.attribute;
7763
7749
  const isHorizontal = this._isHorizontal;
7764
7750
  const railLen = isHorizontal ? railWidth : railHeight;
7765
- const handlerStart = max === min ? (position === 'start' ? 0 : railLen) : ((value - min) / (max - min)) * railLen;
7751
+ const handlerStart = ((value - min) / (max - min)) * railLen;
7766
7752
  const textSpace = (_a = handlerText.space) !== null && _a !== void 0 ? _a : 4;
7767
7753
  const textStyle = Object.assign({ text: (handlerText === null || handlerText === void 0 ? void 0 : handlerText.formatter) ? handlerText.formatter(value) : value.toFixed((_b = handlerText === null || handlerText === void 0 ? void 0 : handlerText.precision) !== null && _b !== void 0 ? _b : 0), lineHeight: (_c = handlerText.style) === null || _c === void 0 ? void 0 : _c.lineHeight, cursor: slidable === false ? 'default' : getDefaultCursor(isHorizontal) }, handlerText.style);
7768
7754
  if (isHorizontal) {
@@ -10119,7 +10105,7 @@
10119
10105
  }
10120
10106
  Tooltip.defaultAttributes = defaultAttributes;
10121
10107
 
10122
- const version = "0.14.5-alpha.3";
10108
+ const version = "0.14.5-alpha.4";
10123
10109
 
10124
10110
  exports.AbstractComponent = AbstractComponent;
10125
10111
  exports.ArcInfo = ArcInfo;