@visactor/vrender-components 0.14.5 → 0.14.6-alpha.1
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.
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/label/arc.d.ts +6 -3
- package/cjs/label/arc.js +31 -1
- package/cjs/label/arc.js.map +1 -1
- package/cjs/label/base.d.ts +12 -9
- package/cjs/label/base.js +107 -130
- package/cjs/label/base.js.map +1 -1
- package/cjs/label/dataLabel.js +4 -4
- package/cjs/label/dataLabel.js.map +1 -1
- package/cjs/label/polygon.d.ts +12 -0
- package/cjs/label/polygon.js +35 -0
- package/cjs/label/polygon.js.map +1 -0
- package/cjs/label/type.d.ts +4 -2
- package/cjs/label/type.js.map +1 -1
- package/cjs/link-path/link-path.js +1 -2
- package/cjs/link-path/type.js +2 -1
- package/cjs/marker/type.js +1 -1
- package/cjs/util/labelSmartInvert.d.ts +1 -0
- package/cjs/util/labelSmartInvert.js +20 -2
- package/cjs/util/labelSmartInvert.js.map +1 -1
- package/dist/index.js +163 -146
- package/dist/index.min.js +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/label/arc.d.ts +6 -3
- package/es/label/arc.js +31 -0
- package/es/label/arc.js.map +1 -1
- package/es/label/base.d.ts +12 -9
- package/es/label/base.js +108 -127
- package/es/label/base.js.map +1 -1
- package/es/label/dataLabel.js +5 -3
- package/es/label/dataLabel.js.map +1 -1
- package/es/label/polygon.d.ts +12 -0
- package/es/label/polygon.js +31 -0
- package/es/label/polygon.js.map +1 -0
- package/es/label/type.d.ts +4 -2
- package/es/label/type.js.map +1 -1
- package/es/link-path/link-path.js +1 -2
- package/es/link-path/type.js +2 -1
- package/es/marker/type.js +1 -1
- package/es/util/labelSmartInvert.d.ts +1 -0
- package/es/util/labelSmartInvert.js +17 -0
- package/es/util/labelSmartInvert.js.map +1 -1
- package/package.json +1 -1
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];
|
|
@@ -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
|
-
|
|
1536
|
-
|
|
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
|
-
|
|
1585
|
-
|
|
1586
|
-
}
|
|
1587
|
-
setBitmapTool(bmpTool) {
|
|
1588
|
-
this._bmpTool = bmpTool;
|
|
1598
|
+
labeling(textBounds, graphicBounds, position, offset) {
|
|
1599
|
+
return;
|
|
1589
1600
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
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.
|
|
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
|
-
|
|
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 (
|
|
1696
|
-
|
|
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) &&
|
|
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
|
|
1842
|
-
const labelLine = (
|
|
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 (
|
|
1841
|
+
if (relatedGraphic) {
|
|
1856
1842
|
const { from, to } = getAnimationAttributes(text.attribute, 'fadeIn');
|
|
1857
1843
|
this.add(text);
|
|
1858
|
-
|
|
1859
|
-
|
|
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
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
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
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
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
|
-
|
|
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
|
|
1993
|
+
const similarColor = contrastAccessibilityChecker(invertColor, brightColor) ? brightColor : darkColor;
|
|
2002
1994
|
if (isInside) {
|
|
2003
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2020
|
-
|
|
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
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
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
|
}
|
|
@@ -3059,7 +3075,8 @@
|
|
|
3059
3075
|
const prevComponentMap = this._componentMap;
|
|
3060
3076
|
for (let i = 0; i < dataLabels.length; i++) {
|
|
3061
3077
|
const dataLabel = dataLabels[i];
|
|
3062
|
-
|
|
3078
|
+
const labelComponent = labelComponentMap[dataLabel.type] || LabelBase;
|
|
3079
|
+
if (labelComponent) {
|
|
3063
3080
|
const { baseMarkGroupName } = dataLabel;
|
|
3064
3081
|
let component = this._componentMap.get(baseMarkGroupName);
|
|
3065
3082
|
if (component) {
|
|
@@ -3069,7 +3086,7 @@
|
|
|
3069
3086
|
currentComponentMap.set(baseMarkGroupName, component);
|
|
3070
3087
|
}
|
|
3071
3088
|
else {
|
|
3072
|
-
component = new
|
|
3089
|
+
component = new labelComponent(dataLabel);
|
|
3073
3090
|
component.setBitmap(bitmap);
|
|
3074
3091
|
component.setBitmapTool(tool);
|
|
3075
3092
|
this.add(component);
|
|
@@ -10119,7 +10136,7 @@
|
|
|
10119
10136
|
}
|
|
10120
10137
|
Tooltip.defaultAttributes = defaultAttributes;
|
|
10121
10138
|
|
|
10122
|
-
const version = "0.14.
|
|
10139
|
+
const version = "0.14.6-alpha.1";
|
|
10123
10140
|
|
|
10124
10141
|
exports.AbstractComponent = AbstractComponent;
|
|
10125
10142
|
exports.ArcInfo = ArcInfo;
|