@visactor/vrender-components 0.13.5-alpha.2 → 0.13.5
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/axis/index.js +2 -1
- package/cjs/core/type.js +1 -2
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/label/base.d.ts +12 -10
- package/cjs/label/base.js +75 -55
- package/cjs/label/base.js.map +1 -1
- package/cjs/label/overlap/place.d.ts +8 -4
- package/cjs/label/overlap/place.js +14 -2
- package/cjs/label/overlap/place.js.map +1 -1
- package/cjs/label/rect.d.ts +5 -3
- package/cjs/label/rect.js.map +1 -1
- package/cjs/label/symbol.d.ts +5 -3
- package/cjs/label/symbol.js.map +1 -1
- package/cjs/label/type.d.ts +11 -7
- package/cjs/label/type.js.map +1 -1
- package/cjs/marker/type.d.ts +5 -5
- package/cjs/marker/type.js.map +1 -1
- package/cjs/poptip/contribution.js +1 -1
- package/cjs/poptip/contribution.js.map +1 -1
- package/cjs/tag/tag.js +2 -2
- package/cjs/tag/tag.js.map +1 -1
- package/cjs/tag/type.d.ts +3 -4
- package/cjs/tag/type.js.map +1 -1
- package/dist/index.js +134 -78
- package/dist/index.min.js +1 -1
- package/es/axis/index.js +2 -1
- package/es/core/type.js +1 -2
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/label/base.d.ts +12 -10
- package/es/label/base.js +77 -57
- package/es/label/base.js.map +1 -1
- package/es/label/overlap/place.d.ts +8 -4
- package/es/label/overlap/place.js +11 -0
- package/es/label/overlap/place.js.map +1 -1
- package/es/label/rect.d.ts +5 -3
- package/es/label/rect.js.map +1 -1
- package/es/label/symbol.d.ts +5 -3
- package/es/label/symbol.js.map +1 -1
- package/es/label/type.d.ts +11 -7
- package/es/label/type.js.map +1 -1
- package/es/marker/type.d.ts +5 -5
- package/es/marker/type.js.map +1 -1
- package/es/poptip/contribution.js +1 -1
- package/es/poptip/contribution.js.map +1 -1
- package/es/tag/tag.js +2 -2
- package/es/tag/tag.js.map +1 -1
- package/es/tag/type.d.ts +3 -4
- package/es/tag/type.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -543,7 +543,7 @@
|
|
|
543
543
|
super(vutils.merge({}, Tag.defaultAttributes, attributes));
|
|
544
544
|
}
|
|
545
545
|
render() {
|
|
546
|
-
const { text = '', textStyle = {}, shape = {}, panel = {}, space = 4, minWidth, maxWidth, padding = 4, visible, state
|
|
546
|
+
const { text = '', textStyle = {}, shape = {}, panel = {}, space = 4, minWidth, maxWidth, padding = 4, visible, state } = this.attribute;
|
|
547
547
|
const parsedPadding = vutils.normalizePadding(padding);
|
|
548
548
|
const group = this.createOrUpdateChild('tag-content', { x: 0, y: 0, zIndex: 1 }, 'group');
|
|
549
549
|
let symbol;
|
|
@@ -574,7 +574,7 @@
|
|
|
574
574
|
tagWidth += symbolPlaceWidth;
|
|
575
575
|
textX += symbolPlaceWidth;
|
|
576
576
|
const textAttrs = {
|
|
577
|
-
text
|
|
577
|
+
text,
|
|
578
578
|
visible: vutils.isValid(text) && visible !== false,
|
|
579
579
|
lineHeight: textStyle?.fontSize,
|
|
580
580
|
...textStyle,
|
|
@@ -963,6 +963,7 @@
|
|
|
963
963
|
x: matrix.e,
|
|
964
964
|
y: matrix.f
|
|
965
965
|
});
|
|
966
|
+
drawContext.stage.tryInitInteractiveLayer();
|
|
966
967
|
const interactiveLayer = drawContext.stage.getLayer('_builtin_interactive');
|
|
967
968
|
if (interactiveLayer) {
|
|
968
969
|
interactiveLayer.add(this.poptipComponent);
|
|
@@ -1513,6 +1514,28 @@
|
|
|
1513
1514
|
return DefaultPositions;
|
|
1514
1515
|
}
|
|
1515
1516
|
}
|
|
1517
|
+
function clampText(text, width, height) {
|
|
1518
|
+
const { x1, x2, y1, y2 } = text.AABBBounds;
|
|
1519
|
+
const minX = Math.min(x1, x2);
|
|
1520
|
+
const maxX = Math.max(x1, x2);
|
|
1521
|
+
const minY = Math.min(y1, y2);
|
|
1522
|
+
const maxY = Math.max(y1, y2);
|
|
1523
|
+
let dx = 0;
|
|
1524
|
+
let dy = 0;
|
|
1525
|
+
if (minX < 0 && maxX - minX <= width) {
|
|
1526
|
+
dx = -minX;
|
|
1527
|
+
}
|
|
1528
|
+
else if (maxX > width && minX - (maxX - width) >= 0) {
|
|
1529
|
+
dx = width - maxX;
|
|
1530
|
+
}
|
|
1531
|
+
if (minY < 0 && maxY - minY <= height) {
|
|
1532
|
+
dy = -minY;
|
|
1533
|
+
}
|
|
1534
|
+
else if (maxY > height && minY - (maxY - height) >= 0) {
|
|
1535
|
+
dy = height - maxY;
|
|
1536
|
+
}
|
|
1537
|
+
return { dx, dy };
|
|
1538
|
+
}
|
|
1516
1539
|
|
|
1517
1540
|
const fadeIn = (textAttribute = {}) => {
|
|
1518
1541
|
return {
|
|
@@ -1563,17 +1586,37 @@
|
|
|
1563
1586
|
setBitmapTool(bmpTool) {
|
|
1564
1587
|
this._bmpTool = bmpTool;
|
|
1565
1588
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
_textMap;
|
|
1589
|
+
_graphicToText;
|
|
1590
|
+
_idToGraphic;
|
|
1569
1591
|
onAfterLabelOverlap;
|
|
1570
1592
|
_lastHover;
|
|
1571
1593
|
_lastSelect;
|
|
1572
1594
|
_enableAnimation;
|
|
1573
1595
|
render() {
|
|
1574
|
-
|
|
1575
|
-
const
|
|
1576
|
-
this.
|
|
1596
|
+
this._prepare();
|
|
1597
|
+
const { overlap, smartInvert, dataFilter, customLayoutFunc, customOverlapFunc } = this.attribute;
|
|
1598
|
+
let data = this.attribute.data;
|
|
1599
|
+
if (vutils.isFunction(dataFilter)) {
|
|
1600
|
+
data = dataFilter(data);
|
|
1601
|
+
}
|
|
1602
|
+
let labels;
|
|
1603
|
+
if (vutils.isFunction(customLayoutFunc)) {
|
|
1604
|
+
labels = customLayoutFunc(data, (d) => this._idToGraphic.get(d.id));
|
|
1605
|
+
}
|
|
1606
|
+
else {
|
|
1607
|
+
labels = this.layout(data);
|
|
1608
|
+
if (vutils.isFunction(customOverlapFunc)) {
|
|
1609
|
+
labels = customOverlapFunc(labels, (d) => this._idToGraphic.get(d.id));
|
|
1610
|
+
}
|
|
1611
|
+
else {
|
|
1612
|
+
if (overlap !== false) {
|
|
1613
|
+
labels = this._overlapping(labels);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
if (smartInvert !== false) {
|
|
1618
|
+
this._smartInvert(labels);
|
|
1619
|
+
}
|
|
1577
1620
|
this._renderLabels(labels);
|
|
1578
1621
|
}
|
|
1579
1622
|
_bindEvent(target) {
|
|
@@ -1650,7 +1693,7 @@
|
|
|
1650
1693
|
this._setStates(text);
|
|
1651
1694
|
return text;
|
|
1652
1695
|
}
|
|
1653
|
-
|
|
1696
|
+
_prepare() {
|
|
1654
1697
|
const baseMarks = this.getBaseMarks();
|
|
1655
1698
|
const currentBaseMarks = [];
|
|
1656
1699
|
baseMarks.forEach(mark => {
|
|
@@ -1658,59 +1701,58 @@
|
|
|
1658
1701
|
currentBaseMarks.push(mark);
|
|
1659
1702
|
}
|
|
1660
1703
|
});
|
|
1661
|
-
this.
|
|
1662
|
-
this.
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
layout(currentMarks) {
|
|
1666
|
-
const { textStyle, position, offset } = this.attribute;
|
|
1667
|
-
let { data } = this.attribute;
|
|
1668
|
-
if (vutils.isFunction(data)) {
|
|
1669
|
-
data = data({});
|
|
1704
|
+
this._idToGraphic?.clear();
|
|
1705
|
+
this._baseMarks = currentBaseMarks;
|
|
1706
|
+
if (!currentBaseMarks || currentBaseMarks.length === 0) {
|
|
1707
|
+
return;
|
|
1670
1708
|
}
|
|
1709
|
+
const { data } = this.attribute;
|
|
1671
1710
|
if (!data || data.length === 0) {
|
|
1672
|
-
return
|
|
1711
|
+
return;
|
|
1673
1712
|
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
currentMarks = currentMarks.sort(this.attribute.sort);
|
|
1713
|
+
if (!this._idToGraphic) {
|
|
1714
|
+
this._idToGraphic = new Map();
|
|
1677
1715
|
}
|
|
1678
|
-
|
|
1679
|
-
|
|
1716
|
+
for (let i = 0; i < currentBaseMarks.length; i++) {
|
|
1717
|
+
const textData = data[i];
|
|
1718
|
+
const baseMark = currentBaseMarks[i];
|
|
1719
|
+
if (textData && baseMark) {
|
|
1720
|
+
if (!vutils.isValid(textData.id)) {
|
|
1721
|
+
textData.id = `vrender-component-${this.name}-${i}`;
|
|
1722
|
+
}
|
|
1723
|
+
this._idToGraphic.set(textData.id, baseMark);
|
|
1724
|
+
}
|
|
1680
1725
|
}
|
|
1726
|
+
}
|
|
1727
|
+
layout(data = []) {
|
|
1728
|
+
const { textStyle = {}, position, offset } = this.attribute;
|
|
1729
|
+
const labels = [];
|
|
1681
1730
|
for (let i = 0; i < data.length; i++) {
|
|
1682
1731
|
const textData = data[i];
|
|
1683
|
-
const baseMark =
|
|
1732
|
+
const baseMark = this._idToGraphic.get(textData.id);
|
|
1684
1733
|
const labelAttribute = {
|
|
1685
1734
|
...textStyle,
|
|
1686
|
-
...textData
|
|
1687
|
-
_relatedIndex: i
|
|
1735
|
+
...textData
|
|
1688
1736
|
};
|
|
1689
|
-
this.
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
const textAttributes = this.labeling(textBounds, graphicBounds, vutils.isFunction(position) ? position(textData) : position, offset);
|
|
1696
|
-
if (!textAttributes) {
|
|
1697
|
-
continue;
|
|
1698
|
-
}
|
|
1699
|
-
labelAttribute.x = textAttributes.x;
|
|
1700
|
-
labelAttribute.y = textAttributes.y;
|
|
1701
|
-
labels.push(labelAttribute);
|
|
1737
|
+
const text = this._createLabelText(labelAttribute);
|
|
1738
|
+
const textBounds = this.getGraphicBounds(text);
|
|
1739
|
+
const graphicBounds = this.getGraphicBounds(baseMark, { x: textData.x, y: textData.y });
|
|
1740
|
+
const textLocation = this.labeling(textBounds, graphicBounds, vutils.isFunction(position) ? position(textData) : position, offset);
|
|
1741
|
+
if (!textLocation) {
|
|
1742
|
+
continue;
|
|
1702
1743
|
}
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
labels
|
|
1744
|
+
labelAttribute.x = textLocation.x;
|
|
1745
|
+
labelAttribute.y = textLocation.y;
|
|
1746
|
+
text.setAttributes(textLocation);
|
|
1747
|
+
labels.push(text);
|
|
1707
1748
|
}
|
|
1708
1749
|
return labels;
|
|
1709
1750
|
}
|
|
1710
|
-
|
|
1751
|
+
_overlapping(labels) {
|
|
1711
1752
|
if (labels.length === 0) {
|
|
1712
1753
|
return [];
|
|
1713
1754
|
}
|
|
1755
|
+
const option = this.attribute.overlap;
|
|
1714
1756
|
const result = [];
|
|
1715
1757
|
const baseMarkGroup = this.getBaseMarkGroup();
|
|
1716
1758
|
const size = option.size ?? {
|
|
@@ -1733,18 +1775,32 @@
|
|
|
1733
1775
|
if (labels[i].visible === false) {
|
|
1734
1776
|
continue;
|
|
1735
1777
|
}
|
|
1736
|
-
const text =
|
|
1737
|
-
const baseMark = this.
|
|
1778
|
+
const text = labels[i];
|
|
1779
|
+
const baseMark = this._idToGraphic.get(text.attribute.id);
|
|
1738
1780
|
text.update();
|
|
1739
1781
|
if (canPlace(bmpTool, bitmap, text.AABBBounds, clampForce)) {
|
|
1740
1782
|
if (!checkBounds) {
|
|
1741
1783
|
bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));
|
|
1742
|
-
result.push(
|
|
1784
|
+
result.push(text);
|
|
1743
1785
|
continue;
|
|
1744
1786
|
}
|
|
1745
1787
|
if (checkBounds && baseMark?.AABBBounds && canPlaceInside(text.AABBBounds, baseMark?.AABBBounds)) {
|
|
1746
1788
|
bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));
|
|
1747
|
-
result.push(
|
|
1789
|
+
result.push(text);
|
|
1790
|
+
continue;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
if (clampForce) {
|
|
1794
|
+
const { dx = 0, dy = 0 } = clampText(text, bmpTool.width, bmpTool.height);
|
|
1795
|
+
if (!(dx === 0 && dy === 0) &&
|
|
1796
|
+
canPlace(bmpTool, bitmap, {
|
|
1797
|
+
x1: text.AABBBounds.x1 + dx,
|
|
1798
|
+
x2: text.AABBBounds.x2 + dx,
|
|
1799
|
+
y1: text.AABBBounds.y1 + dy,
|
|
1800
|
+
y2: text.AABBBounds.y2 + dy
|
|
1801
|
+
})) {
|
|
1802
|
+
text.setAttributes({ x: text.attribute.x + dx, y: text.attribute.y + dy });
|
|
1803
|
+
result.push(text);
|
|
1748
1804
|
continue;
|
|
1749
1805
|
}
|
|
1750
1806
|
}
|
|
@@ -1752,15 +1808,12 @@
|
|
|
1752
1808
|
for (let j = 0; j < strategy.length; j++) {
|
|
1753
1809
|
hasPlace = place(bmpTool, bitmap, strategy[j], this.attribute, text, this.getGraphicBounds(baseMark, labels[i]), this.labeling);
|
|
1754
1810
|
if (hasPlace !== false) {
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
x: hasPlace.x,
|
|
1758
|
-
y: hasPlace.y
|
|
1759
|
-
});
|
|
1811
|
+
text.setAttributes({ x: hasPlace.x, y: hasPlace.y });
|
|
1812
|
+
result.push(text);
|
|
1760
1813
|
break;
|
|
1761
1814
|
}
|
|
1762
1815
|
}
|
|
1763
|
-
!hasPlace && !hideOnHit && result.push(
|
|
1816
|
+
!hasPlace && !hideOnHit && result.push(text);
|
|
1764
1817
|
}
|
|
1765
1818
|
if (vutils.isFunction(this.onAfterLabelOverlap)) {
|
|
1766
1819
|
this.onAfterLabelOverlap(bitmap);
|
|
@@ -1798,17 +1851,16 @@
|
|
|
1798
1851
|
const easing = animationConfig.easing ?? DefaultLabelAnimation.easing;
|
|
1799
1852
|
const delay = animationConfig.delay ?? 0;
|
|
1800
1853
|
const currentTextMap = new Map();
|
|
1801
|
-
const prevTextMap = this.
|
|
1854
|
+
const prevTextMap = this._graphicToText || new Map();
|
|
1802
1855
|
const texts = [];
|
|
1803
|
-
labels.forEach((
|
|
1804
|
-
const
|
|
1805
|
-
const relatedGraphic = this._relationMap.get(label._relatedIndex);
|
|
1856
|
+
labels.forEach((text, index) => {
|
|
1857
|
+
const relatedGraphic = this._idToGraphic.get(text.attribute.id);
|
|
1806
1858
|
const state = prevTextMap?.get(relatedGraphic) ? 'update' : 'enter';
|
|
1807
1859
|
if (state === 'enter') {
|
|
1808
1860
|
texts.push(text);
|
|
1809
1861
|
currentTextMap.set(relatedGraphic, text);
|
|
1810
1862
|
if (!disableAnimation && relatedGraphic) {
|
|
1811
|
-
const { from, to } = getAnimationAttributes(
|
|
1863
|
+
const { from, to } = getAnimationAttributes(text.attribute, 'fadeIn');
|
|
1812
1864
|
this.add(text);
|
|
1813
1865
|
relatedGraphic.onAnimateBind = () => {
|
|
1814
1866
|
text.setAttributes(from);
|
|
@@ -1858,7 +1910,7 @@
|
|
|
1858
1910
|
});
|
|
1859
1911
|
}
|
|
1860
1912
|
});
|
|
1861
|
-
this.
|
|
1913
|
+
this._graphicToText = currentTextMap;
|
|
1862
1914
|
}
|
|
1863
1915
|
_afterRelatedGraphicAttributeUpdate(text, texts, index, relatedGraphic, { mode, duration, easing, to, delay }) {
|
|
1864
1916
|
const listener = (event) => {
|
|
@@ -1909,30 +1961,34 @@
|
|
|
1909
1961
|
return listener;
|
|
1910
1962
|
}
|
|
1911
1963
|
_smartInvert(labels) {
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
}
|
|
1964
|
+
const option = (this.attribute.smartInvert || {});
|
|
1965
|
+
const { textType, contrastRatiosThreshold, alternativeColors } = option;
|
|
1915
1966
|
for (let i = 0; i < labels.length; i++) {
|
|
1916
|
-
const label = labels
|
|
1967
|
+
const label = labels[i];
|
|
1917
1968
|
if (!label) {
|
|
1918
1969
|
continue;
|
|
1919
1970
|
}
|
|
1920
|
-
const
|
|
1921
|
-
|
|
1922
|
-
|
|
1971
|
+
const baseMark = this._idToGraphic.get(label.attribute.id);
|
|
1972
|
+
const isInside = canPlaceInside(label.AABBBounds, baseMark?.AABBBounds);
|
|
1973
|
+
if (label.attribute.stroke && label.attribute.lineWidth > 0) {
|
|
1974
|
+
label.setAttributes({
|
|
1975
|
+
fill: labelSmartInvert(label.attribute.fill, label.attribute.stroke, textType, contrastRatiosThreshold, alternativeColors)
|
|
1976
|
+
});
|
|
1923
1977
|
}
|
|
1924
1978
|
else if (isInside) {
|
|
1925
|
-
const baseMark = this._relationMap.get(label._relatedIndex);
|
|
1926
1979
|
const backgroundColor = baseMark.attribute.fill;
|
|
1927
|
-
const foregroundColor = label.fill;
|
|
1928
|
-
label.
|
|
1980
|
+
const foregroundColor = label.attribute.fill;
|
|
1981
|
+
label.setAttributes({
|
|
1982
|
+
fill: labelSmartInvert(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors)
|
|
1983
|
+
});
|
|
1929
1984
|
}
|
|
1930
|
-
else if (label.lineWidth > 0) {
|
|
1931
|
-
const
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1985
|
+
else if (label.attribute.lineWidth > 0) {
|
|
1986
|
+
const backgroundColor = label.attribute.stroke;
|
|
1987
|
+
const foregroundColor = label.attribute.fill;
|
|
1988
|
+
label.setAttributes({
|
|
1989
|
+
stroke: baseMark.attribute.fill,
|
|
1990
|
+
fill: labelSmartInvert(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors)
|
|
1991
|
+
});
|
|
1936
1992
|
}
|
|
1937
1993
|
}
|
|
1938
1994
|
}
|
|
@@ -9532,7 +9588,7 @@
|
|
|
9532
9588
|
}
|
|
9533
9589
|
}
|
|
9534
9590
|
|
|
9535
|
-
const version = "0.13.5
|
|
9591
|
+
const version = "0.13.5";
|
|
9536
9592
|
|
|
9537
9593
|
exports.AbstractComponent = AbstractComponent;
|
|
9538
9594
|
exports.BasePlayer = BasePlayer;
|