@visactor/vrender-components 0.16.9 → 0.16.10-alpha.0
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/overlap/auto-hide.js +7 -6
- package/cjs/axis/overlap/auto-hide.js.map +1 -1
- package/cjs/axis/overlap/auto-limit.js.map +1 -1
- package/cjs/axis/overlap/auto-rotate.js +3 -35
- package/cjs/axis/overlap/auto-rotate.js.map +1 -1
- package/cjs/axis/overlap/util.d.ts +3 -0
- package/cjs/axis/overlap/util.js +44 -0
- package/cjs/axis/overlap/util.js.map +1 -0
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/dist/index.js +56 -42
- package/dist/index.min.js +1 -1
- package/es/axis/overlap/auto-hide.js +8 -5
- package/es/axis/overlap/auto-hide.js.map +1 -1
- package/es/axis/overlap/auto-limit.js.map +1 -1
- package/es/axis/overlap/auto-rotate.js +3 -33
- package/es/axis/overlap/auto-rotate.js.map +1 -1
- package/es/axis/overlap/util.d.ts +3 -0
- package/es/axis/overlap/util.js +35 -0
- package/es/axis/overlap/util.js.map +1 -0
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.autoHide = void 0;
|
|
6
6
|
|
|
7
|
-
const vutils_1 = require("@visactor/vutils");
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), util_1 = require("./util");
|
|
8
8
|
|
|
9
9
|
function itemIntersect(item1, item2) {
|
|
10
10
|
return (0, vutils_1.isRectIntersect)(item1.AABBBounds, item2.AABBBounds, !1) && (!item1.rotatedBounds || !item2.rotatedBounds || (0,
|
|
@@ -17,17 +17,18 @@ const methods = {
|
|
|
17
17
|
},
|
|
18
18
|
greedy: function(items, sep) {
|
|
19
19
|
let a;
|
|
20
|
-
return items.filter(((b, i) => i && intersect(a
|
|
20
|
+
return items.filter(((b, i) => i && intersect(a, b, sep) ? b.setAttribute("opacity", 0) : (a = b,
|
|
21
21
|
1)));
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
function intersect(
|
|
26
|
-
|
|
25
|
+
function intersect(textA, textB, sep) {
|
|
26
|
+
const a = textA.AABBBounds, b = textB.AABBBounds;
|
|
27
|
+
return sep > Math.max(b.x1 - a.x2, a.x1 - b.x2, b.y1 - a.y2, a.y1 - b.y2) && (!textA.rotatedBounds || !textB.rotatedBounds || sep > Math.max(textB.rotatedBounds.x1 - textA.rotatedBounds.x2, textA.rotatedBounds.x1 - textB.rotatedBounds.x2, textB.rotatedBounds.y1 - textA.rotatedBounds.y2, textA.rotatedBounds.y1 - textB.rotatedBounds.y2));
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
function hasOverlap(items, pad) {
|
|
30
|
-
for (let b, i = 1, n = items.length, a = items[0]
|
|
31
|
+
for (let b, i = 1, n = items.length, a = items[0]; i < n; a = b, ++i) if (intersect(a, b = items[i], pad)) return !0;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
function hasBounds(item) {
|
|
@@ -44,7 +45,7 @@ function autoHide(labels, config) {
|
|
|
44
45
|
const source = labels.filter(hasBounds);
|
|
45
46
|
if ((0, vutils_1.isEmpty)(source)) return;
|
|
46
47
|
let items;
|
|
47
|
-
items = reset(source);
|
|
48
|
+
items = reset(source), (0, util_1.genRotateBounds)(items);
|
|
48
49
|
const {method: method = "parity", separation: sep = 0} = config, reduce = (0, vutils_1.isFunction)(method) ? method : methods[method] || methods.parity;
|
|
49
50
|
if (items.length >= 3 && hasOverlap(items, sep)) {
|
|
50
51
|
do {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/axis/overlap/auto-hide.ts"],"names":[],"mappings":";;;AAOA,6CAAqG;
|
|
1
|
+
{"version":3,"sources":["../src/axis/overlap/auto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C,MAAM,GAAG,CAAC,EAAE;gBACpB,IAAA,aAAI,EAAC,KAAK,CAAC,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;aACxC;SAEF;KACF;IAED,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACpB,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC;AArCD,4BAqCC","file":"auto-hide.js","sourcesContent":["/**\n * @description 自动隐藏\n */\n\nimport type { IText } from '@visactor/vrender-core';\nimport type { IBounds } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isEmpty, isFunction, isRectIntersect, isRotateAABBIntersect, last } from '@visactor/vutils';\nimport type { CustomMethod } from '../type';\nimport { genRotateBounds } from './util';\n\nfunction itemIntersect(item1: IText, item2: IText) {\n return (\n isRectIntersect(item1.AABBBounds, item2.AABBBounds, false) &&\n (item1.rotatedBounds && item2.rotatedBounds\n ? isRotateAABBIntersect(item1.rotatedBounds, item2.rotatedBounds, true)\n : true)\n );\n}\n\nconst methods = {\n parity: function (items: IText[]) {\n return items.filter((item, i) => (i % 2 ? item.setAttribute('opacity', 0) : 1));\n },\n greedy: function (items: IText[], sep: number) {\n let a: IText;\n return items.filter((b, i) => {\n if (!i || !intersect(a, b, sep)) {\n a = b;\n return 1;\n }\n return b.setAttribute('opacity', 0);\n });\n }\n};\n\nfunction intersect(textA: IText, textB: IText, sep: number) {\n const a = textA.AABBBounds;\n const b = textB.AABBBounds;\n return (\n sep > Math.max(b.x1 - a.x2, a.x1 - b.x2, b.y1 - a.y2, a.y1 - b.y2) &&\n (textA.rotatedBounds && textB.rotatedBounds\n ? sep >\n Math.max(\n textB.rotatedBounds.x1 - textA.rotatedBounds.x2,\n textA.rotatedBounds.x1 - textB.rotatedBounds.x2,\n textB.rotatedBounds.y1 - textA.rotatedBounds.y2,\n textA.rotatedBounds.y1 - textB.rotatedBounds.y2\n )\n : true)\n );\n}\n\nfunction hasOverlap(items: IText[], pad: number) {\n for (let i = 1, n = items.length, a = items[0], b; i < n; a = b, ++i) {\n if (intersect(a, (b = items[i]), pad)) {\n return true;\n }\n }\n}\n\nfunction hasBounds(item: IText) {\n const b = item.AABBBounds;\n return b.width() > 1 && b.height() > 1;\n}\n\n// reset all items to be fully opaque\nfunction reset(items: IText[]) {\n items.forEach(item => item.setAttribute('opacity', 1));\n return items;\n}\n\ntype HideConfig = {\n /**\n * 轴的方向\n */\n orient: string;\n /**\n * 防重叠策略。\n * - 'parity': 奇偶校验,使用删除所有其他标签的策略(这对于标准线性轴非常有效)。\n * - 'greedy': 将执行标签的线性扫描,并删除与最后一个可见标签重叠的所有标签。\n * - 也可以传入函数用于自定义策略\n */\n method?: 'parity' | 'greedy' | CustomMethod;\n /**\n * 设置文本之间的间隔距离,单位 px\n */\n separation?: number;\n};\n\nexport function autoHide(labels: IText[], config: HideConfig) {\n if (isEmpty(labels)) {\n return;\n }\n\n const source = labels.filter(hasBounds);\n if (isEmpty(source)) {\n return;\n }\n\n let items;\n\n items = reset(source);\n\n // 计算旋转包围盒\n genRotateBounds(items);\n\n const { method = 'parity', separation: sep = 0 } = config;\n\n const reduce = isFunction(method) ? method : methods[method] || methods.parity;\n\n if (items.length >= 3 && hasOverlap(items, sep)) {\n do {\n items = reduce(items, sep);\n } while (items.length >= 3 && hasOverlap(items, sep));\n\n if (items.length < 3 && !last(source).attribute.opacity) {\n if (items.length > 1) {\n last(items).setAttribute('opacity', 0);\n }\n // last(source).setAttribute('opacity', 1);\n }\n }\n\n source.forEach(item => {\n item.setAttribute('visible', !!item.attribute.opacity);\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/axis/overlap/auto-limit.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/axis/overlap/auto-limit.ts"],"names":[],"mappings":";;;AAIA,6CA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AC1D,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC;SAClC;QACD,KAAK,CAAC,aAAa,CAAC;YAClB,YAAY,EAAE,gBAAgB;YAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,IAAI,QAAQ;SAC/C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhCD,8BAgCC","file":"auto-limit.js","sourcesContent":["/**\n * 自动省略\n */\nimport type { IText } from '@visactor/vrender-core';\nimport { isEmpty, isNil, isValidNumber } from '@visactor/vutils';\n\ntype LimitConfig = {\n orient: string;\n limitLength: number;\n ellipsis?: string;\n};\n\nexport function autoLimit(labels: IText[], config: LimitConfig) {\n const { limitLength, ellipsis = '...', orient } = config;\n\n if (isEmpty(labels) || !isValidNumber(limitLength)) {\n return;\n }\n\n labels.forEach(label => {\n if ((orient === 'top' || orient === 'bottom') && Math.floor(label.AABBBounds.height()) <= limitLength) {\n return;\n }\n if ((orient === 'left' || orient === 'right') && Math.floor(label.AABBBounds.width()) <= limitLength) {\n return;\n }\n\n // 如果水平并且文本未发生旋转,则不配置 maxLineWidth\n let limitLabelLength =\n label.attribute.angle === 0 || isNil(label.attribute.angle)\n ? orient === 'top' || orient === 'bottom'\n ? null\n : limitLength\n : Math.abs(limitLength / Math.sin(label.attribute.angle));\n if (isValidNumber(label.attribute.maxLineWidth)) {\n limitLabelLength = isValidNumber(limitLabelLength)\n ? Math.min(label.attribute.maxLineWidth, limitLabelLength)\n : label.attribute.maxLineWidth;\n }\n label.setAttributes({\n maxLineWidth: limitLabelLength,\n ellipsis: label.attribute.ellipsis || ellipsis\n });\n });\n}\n"]}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.getYAxisLabelAlign = exports.getXAxisLabelAlign = exports.rotateXAxis = exports.rotateYAxis = exports.autoRotate = void 0;
|
|
6
6
|
|
|
7
|
-
const vutils_1 = require("@visactor/vutils");
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), util_1 = require("./util");
|
|
8
8
|
|
|
9
9
|
function autoRotate(items, rotateConfig) {
|
|
10
10
|
if ((0, vutils_1.isEmpty)(items)) return;
|
|
@@ -20,45 +20,13 @@ function autoRotate(items, rotateConfig) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function hasIntersect(items) {
|
|
23
|
-
for (let i = 1; i < items.length; i++) if (itemIntersect(items[i - 1], items[i])) return !0;
|
|
23
|
+
for (let i = 1; i < items.length; i++) if ((0, util_1.itemIntersect)(items[i - 1], items[i])) return !0;
|
|
24
24
|
return !1;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function itemIntersect(item1, item2) {
|
|
28
|
-
return (0, vutils_1.isRotateAABBIntersect)(item1.rotatedBounds, item2.rotatedBounds, !0);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
27
|
function tryRotate(orient, items) {
|
|
32
28
|
"bottom" !== orient && "top" !== orient || rotateXAxis(orient, items), "left" !== orient && "right" !== orient || rotateYAxis(orient, items),
|
|
33
|
-
genRotateBounds(items);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function rotate(x, y, deg, originX, originY) {
|
|
37
|
-
return {
|
|
38
|
-
x: (x - originX) * Math.cos(deg) + (y - originY) * Math.sin(deg) + originX,
|
|
39
|
-
y: (x - originX) * Math.sin(deg) + (originY - y) * Math.cos(deg) + originY
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function genNormalBounds(item) {
|
|
44
|
-
const bounds = item.AABBBounds;
|
|
45
|
-
return {
|
|
46
|
-
x1: bounds.x1,
|
|
47
|
-
x2: bounds.x2,
|
|
48
|
-
y1: bounds.y1,
|
|
49
|
-
y2: bounds.y2,
|
|
50
|
-
centerX: item.attribute.x,
|
|
51
|
-
centerY: item.attribute.y,
|
|
52
|
-
angle: item.attribute.angle
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function genRotateBounds(items) {
|
|
57
|
-
items.forEach((item => {
|
|
58
|
-
const bounds = genNormalBounds(item), rotatedCenter = rotate(bounds.centerX, bounds.centerY, bounds.angle, item.attribute.x, item.attribute.y), deltaX = rotatedCenter.x - bounds.centerX, deltaY = rotatedCenter.y - bounds.centerY;
|
|
59
|
-
bounds.x1 += deltaX, bounds.x2 += deltaX, bounds.y1 += deltaY, bounds.y2 += deltaY,
|
|
60
|
-
bounds.centerX += deltaX, bounds.centerY += deltaY, item.rotatedBounds = bounds;
|
|
61
|
-
}));
|
|
29
|
+
(0, util_1.genRotateBounds)(items);
|
|
62
30
|
}
|
|
63
31
|
|
|
64
32
|
function clampAngle(angle = 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/axis/overlap/auto-rotate.ts"],"names":[],"mappings":";;;AAIA,6CAAkF;AAalF,SAAgB,UAAU,CAAC,KAAc,EAAE,YAA0B;IACnE,IAAI,IAAA,gBAAO,EAAC,KAAK,CAAC,EAAE;QAClB,OAAO;KACR;IAED,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC;IAChE,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QAC/E,OAAO;KACR;IAED,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QACnD,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC;KAC7B;IAED,OAAO,CAAC,GAAG,CAAC,EAAE;QACZ,MAAM,KAAK,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC;QACpC,KAA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xC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAqB;KAClD,CAAC;AACJ,CAAC;AAxBD,gDAwBC","file":"auto-rotate.js","sourcesContent":["/**\n * @description 坐标轴标签自动旋转\n */\nimport type { IText, TextAlignType, TextBaselineType } from '@visactor/vrender-core';\nimport { degreeToRadian, isEmpty, isRotateAABBIntersect } from '@visactor/vutils';\n\ntype RotateConfig = {\n /**\n * 坐标轴的显示位置\n */\n orient: string;\n /**\n * 自动旋转的可选角度\n */\n labelRotateAngle?: number[];\n};\n\nexport function autoRotate(items: IText[], rotateConfig: RotateConfig) {\n if (isEmpty(items)) {\n return;\n }\n\n const { orient, labelRotateAngle = [0, 45, 90] } = rotateConfig;\n if (labelRotateAngle.length === 0 || items.some(item => !!item.attribute.angle)) {\n return;\n }\n\n let i = 0;\n let n = 0;\n if (labelRotateAngle && labelRotateAngle.length > 0) {\n n = labelRotateAngle.length;\n }\n\n while (i < n) {\n const angle = labelRotateAngle[i++];\n items.forEach(item => {\n // item.angle = angle;\n item.attribute.angle = degreeToRadian(angle);\n });\n tryRotate(orient, items);\n if (!hasIntersect(items)) {\n break;\n }\n }\n}\n\nfunction hasIntersect(items: IText[]): boolean {\n for (let i = 1; i < items.length; i++) {\n if (itemIntersect(items[i - 1], items[i])) {\n return true;\n }\n }\n return false;\n}\n\nfunction itemIntersect(item1: IText, item2: IText) {\n return isRotateAABBIntersect(item1.rotatedBounds, item2.rotatedBounds, true);\n}\n\nfunction tryRotate(orient: string, items: IText[]) {\n // 针对 top bottom轴的自动旋转逻辑\n if (orient === 'bottom' || orient === 'top') {\n rotateXAxis(orient, items);\n }\n if (orient === 'left' || orient === 'right') {\n rotateYAxis(orient, items);\n }\n // 先旋转,再计算这个limit,避免算limit后发现不需要旋转,导致莫名的水平limit\n genRotateBounds(items);\n}\n\nfunction rotate(x: number, y: number, deg: number, originX: number, originY: number) {\n return {\n x: (x - originX) * Math.cos(deg) + (y - originY) * Math.sin(deg) + originX,\n y: (x - originX) * Math.sin(deg) + (originY - y) * Math.cos(deg) + originY\n };\n}\n\n// 计算水平情况下的包围盒\nfunction genNormalBounds(item: IText) {\n const bounds = item.AABBBounds;\n\n return {\n x1: bounds.x1,\n x2: bounds.x2,\n y1: bounds.y1,\n y2: bounds.y2,\n centerX: item.attribute.x,\n centerY: item.attribute.y,\n angle: item.attribute.angle\n };\n}\n\nfunction genRotateBounds(items: IText[]) {\n items.forEach(item => {\n // 计算水平情况下的包围盒\n const bounds = genNormalBounds(item);\n // 旋转\n const rotatedCenter = rotate(bounds.centerX, bounds.centerY, bounds.angle, item.attribute.x, item.attribute.y);\n const deltaX = rotatedCenter.x - bounds.centerX;\n const deltaY = rotatedCenter.y - bounds.centerY;\n bounds.x1 += deltaX;\n bounds.x2 += deltaX;\n bounds.y1 += deltaY;\n bounds.y2 += deltaY;\n bounds.centerX += deltaX;\n bounds.centerY += deltaY;\n item.rotatedBounds = bounds;\n });\n}\n\nfunction clampAngle(angle = 0) {\n if (angle < 0) {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n }\n if (angle > 0) {\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n }\n\n return angle;\n}\n\nexport function rotateYAxis(orient: string, items: IText[]) {\n // 由于左右轴会裁切,所以上下两个label需要额外处理,做tighten处理\n items.forEach((item, i) => {\n item.attribute.angle &&\n item.setAttributes({\n ...getYAxisLabelAlign(orient, item.attribute.angle),\n angle: clampAngle(item.attribute.angle)\n });\n });\n}\n\nexport function rotateXAxis(orient: string, items: IText[]) {\n items.forEach(item => {\n item.attribute.angle &&\n item.setAttributes({\n ...getXAxisLabelAlign(orient, item.attribute.angle),\n angle: clampAngle(item.attribute.angle)\n });\n });\n}\n\nexport function getXAxisLabelAlign(orient: string, angle: number = 0) {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n let align = ['center', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'left'];\n let baseline = ['top', 'top', 'middle', 'bottom', 'bottom', 'bottom', 'middle', 'top', 'top'];\n if (orient === 'top') {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n align = ['center', 'right', 'right', 'right', 'center', 'left', 'left', 'left', 'right'];\n baseline = ['bottom', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];\n }\n\n angle = clampAngle(angle);\n const step = angle / (Math.PI * 0.5);\n let index;\n if (step === Math.floor(step)) {\n index = Math.floor(step) * 2;\n } else {\n index = Math.floor(step) * 2 + 1;\n }\n\n return {\n textAlign: align[index] as TextAlignType,\n textBaseline: baseline[index] as TextBaselineType\n };\n}\n\nexport function getYAxisLabelAlign(orient: string, angle: number = 0) {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n let align = ['right', 'right', 'center', 'left', 'center', 'left', 'center', 'right', 'right'];\n let baseline = ['middle', 'middle', 'top', 'top', 'middle', 'middle', 'bottom', 'bottom', 'middle'];\n\n if (orient === 'right') {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n align = ['left', 'right', 'right', 'right', 'left', 'left', 'left', 'left', 'right'];\n baseline = ['middle', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];\n }\n\n angle = clampAngle(angle);\n const step = angle / (Math.PI * 0.5);\n let index;\n if (step === Math.floor(step)) {\n index = Math.floor(step) * 2;\n } else {\n index = Math.floor(step) * 2 + 1;\n }\n\n return {\n textAlign: align[index] as TextAlignType,\n textBaseline: baseline[index] as TextBaselineType\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/axis/overlap/auto-rotate.ts"],"names":[],"mappings":";;;AAIA,6CAA2D;AAC3D,iCAAwD;AAaxD,SAAgB,UAAU,CAAC,KAAc,EAAE,YAA0B;IACnE,IAAI,IAAA,gBAAO,EAAC,KAAK,CAAC,EAAE;QAClB,OAAO;KACR;IAED,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAA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file":"auto-rotate.js","sourcesContent":["/**\n * @description 坐标轴标签自动旋转\n */\nimport type { IText, TextAlignType, TextBaselineType } from '@visactor/vrender-core';\nimport { degreeToRadian, isEmpty } from '@visactor/vutils';\nimport { genRotateBounds, itemIntersect } from './util';\n\ntype RotateConfig = {\n /**\n * 坐标轴的显示位置\n */\n orient: string;\n /**\n * 自动旋转的可选角度\n */\n labelRotateAngle?: number[];\n};\n\nexport function autoRotate(items: IText[], rotateConfig: RotateConfig) {\n if (isEmpty(items)) {\n return;\n }\n\n const { orient, labelRotateAngle = [0, 45, 90] } = rotateConfig;\n if (labelRotateAngle.length === 0 || items.some(item => !!item.attribute.angle)) {\n return;\n }\n\n let i = 0;\n let n = 0;\n if (labelRotateAngle && labelRotateAngle.length > 0) {\n n = labelRotateAngle.length;\n }\n\n while (i < n) {\n const angle = labelRotateAngle[i++];\n items.forEach(item => {\n // item.angle = angle;\n item.attribute.angle = degreeToRadian(angle);\n });\n tryRotate(orient, items);\n if (!hasIntersect(items)) {\n break;\n }\n }\n}\n\nfunction hasIntersect(items: IText[]): boolean {\n for (let i = 1; i < items.length; i++) {\n if (itemIntersect(items[i - 1], items[i])) {\n return true;\n }\n }\n return false;\n}\n\nfunction tryRotate(orient: string, items: IText[]) {\n // 针对 top bottom轴的自动旋转逻辑\n if (orient === 'bottom' || orient === 'top') {\n rotateXAxis(orient, items);\n }\n if (orient === 'left' || orient === 'right') {\n rotateYAxis(orient, items);\n }\n // 先旋转,再计算这个limit,避免算limit后发现不需要旋转,导致莫名的水平limit\n genRotateBounds(items);\n}\n\nfunction clampAngle(angle = 0) {\n if (angle < 0) {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n }\n if (angle > 0) {\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n }\n\n return angle;\n}\n\nexport function rotateYAxis(orient: string, items: IText[]) {\n // 由于左右轴会裁切,所以上下两个label需要额外处理,做tighten处理\n items.forEach((item, i) => {\n item.attribute.angle &&\n item.setAttributes({\n ...getYAxisLabelAlign(orient, item.attribute.angle),\n angle: clampAngle(item.attribute.angle)\n });\n });\n}\n\nexport function rotateXAxis(orient: string, items: IText[]) {\n items.forEach(item => {\n item.attribute.angle &&\n item.setAttributes({\n ...getXAxisLabelAlign(orient, item.attribute.angle),\n angle: clampAngle(item.attribute.angle)\n });\n });\n}\n\nexport function getXAxisLabelAlign(orient: string, angle: number = 0) {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n let align = ['center', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'left'];\n let baseline = ['top', 'top', 'middle', 'bottom', 'bottom', 'bottom', 'middle', 'top', 'top'];\n if (orient === 'top') {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n align = ['center', 'right', 'right', 'right', 'center', 'left', 'left', 'left', 'right'];\n baseline = ['bottom', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];\n }\n\n angle = clampAngle(angle);\n const step = angle / (Math.PI * 0.5);\n let index;\n if (step === Math.floor(step)) {\n index = Math.floor(step) * 2;\n } else {\n index = Math.floor(step) * 2 + 1;\n }\n\n return {\n textAlign: align[index] as TextAlignType,\n textBaseline: baseline[index] as TextBaselineType\n };\n}\n\nexport function getYAxisLabelAlign(orient: string, angle: number = 0) {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n let align = ['right', 'right', 'center', 'left', 'center', 'left', 'center', 'right', 'right'];\n let baseline = ['middle', 'middle', 'top', 'top', 'middle', 'middle', 'bottom', 'bottom', 'middle'];\n\n if (orient === 'right') {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n align = ['left', 'right', 'right', 'right', 'left', 'left', 'left', 'left', 'right'];\n baseline = ['middle', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];\n }\n\n angle = clampAngle(angle);\n const step = angle / (Math.PI * 0.5);\n let index;\n if (step === Math.floor(step)) {\n index = Math.floor(step) * 2;\n } else {\n index = Math.floor(step) * 2 + 1;\n }\n\n return {\n textAlign: align[index] as TextAlignType,\n textBaseline: baseline[index] as TextBaselineType\n };\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.itemIntersect = exports.genRotateBounds = void 0;
|
|
6
|
+
|
|
7
|
+
const vutils_1 = require("@visactor/vutils");
|
|
8
|
+
|
|
9
|
+
function rotate(x, y, deg, originX, originY) {
|
|
10
|
+
return {
|
|
11
|
+
x: (x - originX) * Math.cos(deg) + (y - originY) * Math.sin(deg) + originX,
|
|
12
|
+
y: (x - originX) * Math.sin(deg) + (originY - y) * Math.cos(deg) + originY
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function genNormalBounds(item) {
|
|
17
|
+
const bounds = item.AABBBounds;
|
|
18
|
+
return {
|
|
19
|
+
x1: bounds.x1,
|
|
20
|
+
x2: bounds.x2,
|
|
21
|
+
y1: bounds.y1,
|
|
22
|
+
y2: bounds.y2,
|
|
23
|
+
centerX: item.attribute.x,
|
|
24
|
+
centerY: item.attribute.y,
|
|
25
|
+
angle: item.attribute.angle
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function genRotateBounds(items) {
|
|
30
|
+
items.forEach((item => {
|
|
31
|
+
if (item.rotatedBounds || !item.attribute.angle) return;
|
|
32
|
+
const bounds = genNormalBounds(item), rotatedCenter = rotate(bounds.centerX, bounds.centerY, bounds.angle, item.attribute.x, item.attribute.y), deltaX = rotatedCenter.x - bounds.centerX, deltaY = rotatedCenter.y - bounds.centerY;
|
|
33
|
+
bounds.x1 += deltaX, bounds.x2 += deltaX, bounds.y1 += deltaY, bounds.y2 += deltaY,
|
|
34
|
+
bounds.centerX += deltaX, bounds.centerY += deltaY, item.rotatedBounds = bounds;
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function itemIntersect(item1, item2) {
|
|
39
|
+
return (0, vutils_1.isRectIntersect)(item1.AABBBounds, item2.AABBBounds, !1) && (!item1.rotatedBounds || !item2.rotatedBounds || (0,
|
|
40
|
+
vutils_1.isRotateAABBIntersect)(item1.rotatedBounds, item2.rotatedBounds, !0));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.genRotateBounds = genRotateBounds, exports.itemIntersect = itemIntersect;
|
|
44
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/axis/overlap/util.ts"],"names":[],"mappings":";;;AACA,6CAA0E;AAE1E,SAAS,MAAM,CAAC,CAAS,EAAE,CAAS,EAAE,GAAW,EAAE,OAAe,EAAE,OAAe;IACjF,OAAO;QACL,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO;QAC1E,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO;KAC3E,CAAC;AACJ,CAAC;AAGD,SAAS,eAAe,CAAC,IAAW;IAClC,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;IAE/B,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACzB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,C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Aa,EAAE,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC;YACvE,CAAC,CAAC,IAAI,CAAC,CACV,CAAC;AACJ,CAAC;AAPD,sCAOC","file":"util.js","sourcesContent":["import type { IText } from '@visactor/vrender-core';\nimport { isRectIntersect, isRotateAABBIntersect } from '@visactor/vutils';\n\nfunction rotate(x: number, y: number, deg: number, originX: number, originY: number) {\n return {\n x: (x - originX) * Math.cos(deg) + (y - originY) * Math.sin(deg) + originX,\n y: (x - originX) * Math.sin(deg) + (originY - y) * Math.cos(deg) + originY\n };\n}\n\n// 计算水平情况下的包围盒\nfunction genNormalBounds(item: IText) {\n const bounds = item.AABBBounds;\n\n return {\n x1: bounds.x1,\n x2: bounds.x2,\n y1: bounds.y1,\n y2: bounds.y2,\n centerX: item.attribute.x,\n centerY: item.attribute.y,\n angle: item.attribute.angle\n };\n}\n\nexport function genRotateBounds(items: IText[]) {\n items.forEach(item => {\n if (item.rotatedBounds || !item.attribute.angle) {\n return;\n }\n // 计算水平情况下的包围盒\n const bounds = genNormalBounds(item);\n // 旋转\n const rotatedCenter = rotate(bounds.centerX, bounds.centerY, bounds.angle, item.attribute.x, item.attribute.y);\n const deltaX = rotatedCenter.x - bounds.centerX;\n const deltaY = rotatedCenter.y - bounds.centerY;\n bounds.x1 += deltaX;\n bounds.x2 += deltaX;\n bounds.y1 += deltaY;\n bounds.y2 += deltaY;\n bounds.centerX += deltaX;\n bounds.centerY += deltaY;\n item.rotatedBounds = bounds;\n });\n}\n\nexport function itemIntersect(item1: IText, item2: IText) {\n return (\n isRectIntersect(item1.AABBBounds, item2.AABBBounds, false) &&\n (item1.rotatedBounds && item2.rotatedBounds\n ? isRotateAABBIntersect(item1.rotatedBounds, item2.rotatedBounds, true)\n : true)\n );\n}\n"]}
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
|
|
|
17
17
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", {
|
|
19
19
|
value: !0
|
|
20
|
-
}), exports.version = void 0, exports.version = "0.16.
|
|
20
|
+
}), exports.version = void 0, exports.version = "0.16.10-alpha.0", __exportStar(require("./core/base"), exports),
|
|
21
21
|
__exportStar(require("./scrollbar"), exports), __exportStar(require("./tag"), exports),
|
|
22
22
|
__exportStar(require("./poptip"), exports), __exportStar(require("./crosshair"), exports),
|
|
23
23
|
__exportStar(require("./label"), exports), __exportStar(require("./axis"), exports),
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,iBAAiB,CAAC;AAEzC,8CAA4B;AAC5B,8CAA4B;AAC5B,wCAAsB;AACtB,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,8CAA4B;AAC5B,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B;AAC5B,wCAAsB;AACtB,6CAA2B","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.16.10-alpha.0\";\n\nexport * from './core/base';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './axis/grid';\nexport * from './segment';\nexport * from './data-zoom';\nexport * from './marker';\nexport * from './pager';\nexport * from './legend';\nexport * from './title';\nexport * from './indicator';\nexport * from './slider';\nexport * from './link-path';\nexport * from './player';\nexport * from './brush';\nexport * from './tooltip';\nexport * from './interface';\nexport * from './jsx';\nexport * from './checkbox';\n"]}
|
package/dist/index.js
CHANGED
|
@@ -24320,6 +24320,49 @@
|
|
|
24320
24320
|
}
|
|
24321
24321
|
}
|
|
24322
24322
|
|
|
24323
|
+
function rotate(x, y, deg, originX, originY) {
|
|
24324
|
+
return {
|
|
24325
|
+
x: (x - originX) * Math.cos(deg) + (y - originY) * Math.sin(deg) + originX,
|
|
24326
|
+
y: (x - originX) * Math.sin(deg) + (originY - y) * Math.cos(deg) + originY
|
|
24327
|
+
};
|
|
24328
|
+
}
|
|
24329
|
+
function genNormalBounds(item) {
|
|
24330
|
+
const bounds = item.AABBBounds;
|
|
24331
|
+
return {
|
|
24332
|
+
x1: bounds.x1,
|
|
24333
|
+
x2: bounds.x2,
|
|
24334
|
+
y1: bounds.y1,
|
|
24335
|
+
y2: bounds.y2,
|
|
24336
|
+
centerX: item.attribute.x,
|
|
24337
|
+
centerY: item.attribute.y,
|
|
24338
|
+
angle: item.attribute.angle
|
|
24339
|
+
};
|
|
24340
|
+
}
|
|
24341
|
+
function genRotateBounds(items) {
|
|
24342
|
+
items.forEach(item => {
|
|
24343
|
+
if (item.rotatedBounds || !item.attribute.angle) {
|
|
24344
|
+
return;
|
|
24345
|
+
}
|
|
24346
|
+
const bounds = genNormalBounds(item);
|
|
24347
|
+
const rotatedCenter = rotate(bounds.centerX, bounds.centerY, bounds.angle, item.attribute.x, item.attribute.y);
|
|
24348
|
+
const deltaX = rotatedCenter.x - bounds.centerX;
|
|
24349
|
+
const deltaY = rotatedCenter.y - bounds.centerY;
|
|
24350
|
+
bounds.x1 += deltaX;
|
|
24351
|
+
bounds.x2 += deltaX;
|
|
24352
|
+
bounds.y1 += deltaY;
|
|
24353
|
+
bounds.y2 += deltaY;
|
|
24354
|
+
bounds.centerX += deltaX;
|
|
24355
|
+
bounds.centerY += deltaY;
|
|
24356
|
+
item.rotatedBounds = bounds;
|
|
24357
|
+
});
|
|
24358
|
+
}
|
|
24359
|
+
function itemIntersect(item1, item2) {
|
|
24360
|
+
return (vutils.isRectIntersect(item1.AABBBounds, item2.AABBBounds, false) &&
|
|
24361
|
+
(item1.rotatedBounds && item2.rotatedBounds
|
|
24362
|
+
? vutils.isRotateAABBIntersect(item1.rotatedBounds, item2.rotatedBounds, true)
|
|
24363
|
+
: true));
|
|
24364
|
+
}
|
|
24365
|
+
|
|
24323
24366
|
const methods = {
|
|
24324
24367
|
parity: function (items) {
|
|
24325
24368
|
return items.filter((item, i) => (i % 2 ? item.setAttribute('opacity', 0) : 1));
|
|
@@ -24327,7 +24370,7 @@
|
|
|
24327
24370
|
greedy: function (items, sep) {
|
|
24328
24371
|
let a;
|
|
24329
24372
|
return items.filter((b, i) => {
|
|
24330
|
-
if (!i || !intersect(a
|
|
24373
|
+
if (!i || !intersect(a, b, sep)) {
|
|
24331
24374
|
a = b;
|
|
24332
24375
|
return 1;
|
|
24333
24376
|
}
|
|
@@ -24335,12 +24378,18 @@
|
|
|
24335
24378
|
});
|
|
24336
24379
|
}
|
|
24337
24380
|
};
|
|
24338
|
-
function intersect(
|
|
24339
|
-
|
|
24381
|
+
function intersect(textA, textB, sep) {
|
|
24382
|
+
const a = textA.AABBBounds;
|
|
24383
|
+
const b = textB.AABBBounds;
|
|
24384
|
+
return (sep > Math.max(b.x1 - a.x2, a.x1 - b.x2, b.y1 - a.y2, a.y1 - b.y2) &&
|
|
24385
|
+
(textA.rotatedBounds && textB.rotatedBounds
|
|
24386
|
+
? sep >
|
|
24387
|
+
Math.max(textB.rotatedBounds.x1 - textA.rotatedBounds.x2, textA.rotatedBounds.x1 - textB.rotatedBounds.x2, textB.rotatedBounds.y1 - textA.rotatedBounds.y2, textA.rotatedBounds.y1 - textB.rotatedBounds.y2)
|
|
24388
|
+
: true));
|
|
24340
24389
|
}
|
|
24341
24390
|
function hasOverlap(items, pad) {
|
|
24342
|
-
for (let i = 1, n = items.length, a = items[0]
|
|
24343
|
-
if (intersect(a, (b = items[i]
|
|
24391
|
+
for (let i = 1, n = items.length, a = items[0], b; i < n; a = b, ++i) {
|
|
24392
|
+
if (intersect(a, (b = items[i]), pad)) {
|
|
24344
24393
|
return true;
|
|
24345
24394
|
}
|
|
24346
24395
|
}
|
|
@@ -24363,6 +24412,7 @@
|
|
|
24363
24412
|
}
|
|
24364
24413
|
let items;
|
|
24365
24414
|
items = reset(source);
|
|
24415
|
+
genRotateBounds(items);
|
|
24366
24416
|
const { method = 'parity', separation: sep = 0 } = config;
|
|
24367
24417
|
const reduce = vutils.isFunction(method) ? method : methods[method] || methods.parity;
|
|
24368
24418
|
if (items.length >= 3 && hasOverlap(items, sep)) {
|
|
@@ -24412,9 +24462,6 @@
|
|
|
24412
24462
|
}
|
|
24413
24463
|
return false;
|
|
24414
24464
|
}
|
|
24415
|
-
function itemIntersect(item1, item2) {
|
|
24416
|
-
return vutils.isRotateAABBIntersect(item1.rotatedBounds, item2.rotatedBounds, true);
|
|
24417
|
-
}
|
|
24418
24465
|
function tryRotate(orient, items) {
|
|
24419
24466
|
if (orient === 'bottom' || orient === 'top') {
|
|
24420
24467
|
rotateXAxis(orient, items);
|
|
@@ -24424,39 +24471,6 @@
|
|
|
24424
24471
|
}
|
|
24425
24472
|
genRotateBounds(items);
|
|
24426
24473
|
}
|
|
24427
|
-
function rotate(x, y, deg, originX, originY) {
|
|
24428
|
-
return {
|
|
24429
|
-
x: (x - originX) * Math.cos(deg) + (y - originY) * Math.sin(deg) + originX,
|
|
24430
|
-
y: (x - originX) * Math.sin(deg) + (originY - y) * Math.cos(deg) + originY
|
|
24431
|
-
};
|
|
24432
|
-
}
|
|
24433
|
-
function genNormalBounds(item) {
|
|
24434
|
-
const bounds = item.AABBBounds;
|
|
24435
|
-
return {
|
|
24436
|
-
x1: bounds.x1,
|
|
24437
|
-
x2: bounds.x2,
|
|
24438
|
-
y1: bounds.y1,
|
|
24439
|
-
y2: bounds.y2,
|
|
24440
|
-
centerX: item.attribute.x,
|
|
24441
|
-
centerY: item.attribute.y,
|
|
24442
|
-
angle: item.attribute.angle
|
|
24443
|
-
};
|
|
24444
|
-
}
|
|
24445
|
-
function genRotateBounds(items) {
|
|
24446
|
-
items.forEach(item => {
|
|
24447
|
-
const bounds = genNormalBounds(item);
|
|
24448
|
-
const rotatedCenter = rotate(bounds.centerX, bounds.centerY, bounds.angle, item.attribute.x, item.attribute.y);
|
|
24449
|
-
const deltaX = rotatedCenter.x - bounds.centerX;
|
|
24450
|
-
const deltaY = rotatedCenter.y - bounds.centerY;
|
|
24451
|
-
bounds.x1 += deltaX;
|
|
24452
|
-
bounds.x2 += deltaX;
|
|
24453
|
-
bounds.y1 += deltaY;
|
|
24454
|
-
bounds.y2 += deltaY;
|
|
24455
|
-
bounds.centerX += deltaX;
|
|
24456
|
-
bounds.centerY += deltaY;
|
|
24457
|
-
item.rotatedBounds = bounds;
|
|
24458
|
-
});
|
|
24459
|
-
}
|
|
24460
24474
|
function clampAngle(angle = 0) {
|
|
24461
24475
|
if (angle < 0) {
|
|
24462
24476
|
while (angle < 0) {
|
|
@@ -31246,7 +31260,7 @@
|
|
|
31246
31260
|
}
|
|
31247
31261
|
};
|
|
31248
31262
|
|
|
31249
|
-
const version = "0.16.
|
|
31263
|
+
const version = "0.16.10-alpha.0";
|
|
31250
31264
|
|
|
31251
31265
|
exports.AbstractComponent = AbstractComponent;
|
|
31252
31266
|
exports.ArcInfo = ArcInfo;
|