@visactor/vrender-components 0.18.5 → 0.18.6
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/animate/group-transition.d.ts +0 -1
- package/cjs/axis/animate/group-transition.js +2 -10
- package/cjs/axis/animate/group-transition.js.map +1 -1
- package/cjs/axis/base.d.ts +8 -3
- package/cjs/axis/base.js +6 -2
- package/cjs/axis/base.js.map +1 -1
- package/cjs/axis/grid/base.d.ts +8 -3
- package/cjs/axis/grid/base.js +6 -2
- package/cjs/axis/grid/base.js.map +1 -1
- package/cjs/axis/line.js +18 -3
- package/cjs/axis/line.js.map +1 -1
- package/cjs/axis/overlap/auto-limit.d.ts +1 -0
- package/cjs/axis/overlap/auto-limit.js +30 -6
- package/cjs/axis/overlap/auto-limit.js.map +1 -1
- package/cjs/axis/overlap/util.d.ts +12 -0
- package/cjs/axis/overlap/util.js +40 -2
- package/cjs/axis/overlap/util.js.map +1 -1
- package/cjs/axis/util.d.ts +3 -1
- package/cjs/axis/util.js +11 -3
- package/cjs/axis/util.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/legend/discrete/discrete.d.ts +5 -0
- package/cjs/legend/discrete/discrete.js +120 -85
- package/cjs/legend/discrete/discrete.js.map +1 -1
- package/es/axis/animate/group-transition.d.ts +0 -1
- package/es/axis/animate/group-transition.js +2 -10
- package/es/axis/animate/group-transition.js.map +1 -1
- package/es/axis/base.d.ts +8 -3
- package/es/axis/base.js +7 -1
- package/es/axis/base.js.map +1 -1
- package/es/axis/grid/base.d.ts +8 -3
- package/es/axis/grid/base.js +7 -1
- package/es/axis/grid/base.js.map +1 -1
- package/es/axis/line.js +18 -3
- package/es/axis/line.js.map +1 -1
- package/es/axis/overlap/auto-limit.d.ts +1 -0
- package/es/axis/overlap/auto-limit.js +30 -5
- package/es/axis/overlap/auto-limit.js.map +1 -1
- package/es/axis/overlap/util.d.ts +12 -0
- package/es/axis/overlap/util.js +37 -0
- package/es/axis/overlap/util.js.map +1 -1
- package/es/axis/util.d.ts +3 -1
- package/es/axis/util.js +9 -0
- package/es/axis/util.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/legend/discrete/discrete.d.ts +5 -0
- package/es/legend/discrete/discrete.js +122 -86
- package/es/legend/discrete/discrete.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,15 +1,40 @@
|
|
|
1
1
|
import { isEmpty, isNil, isValidNumber } from "@visactor/vutils";
|
|
2
2
|
|
|
3
|
+
import { borderPoint } from "./util";
|
|
4
|
+
|
|
3
5
|
export function autoLimit(labels, config) {
|
|
4
|
-
const {limitLength: limitLength, verticalLimitLength: verticalLimitLength, ellipsis: ellipsis = "...", orient: orient} = config;
|
|
6
|
+
const {limitLength: limitLength, verticalLimitLength: verticalLimitLength, ellipsis: ellipsis = "...", orient: orient, axisLength: axisLength} = config;
|
|
5
7
|
!isEmpty(labels) && isValidNumber(limitLength) && labels.forEach((label => {
|
|
6
8
|
var _a;
|
|
7
|
-
const angle = label.attribute.angle,
|
|
8
|
-
if (
|
|
9
|
+
const angle = label.attribute.angle, hasAngle = !isNil(angle), isHorizontal = !hasAngle || 0 === angle || angle === Math.PI, isVertical = hasAngle && (angle === Math.PI / 2 || angle === 2 * Math.PI / 3), isX = "top" === orient || "bottom" === orient;
|
|
10
|
+
if (isX) {
|
|
11
|
+
if (isVertical && Math.floor(label.AABBBounds.height()) <= limitLength) return;
|
|
12
|
+
if (isHorizontal && Math.floor(label.AABBBounds.width()) <= verticalLimitLength) return;
|
|
13
|
+
}
|
|
9
14
|
const direction = label.attribute.direction;
|
|
10
|
-
if (
|
|
15
|
+
if (!isX) {
|
|
16
|
+
if ("vertical" === direction && Math.floor(label.AABBBounds.height()) <= verticalLimitLength) return;
|
|
17
|
+
if ("vertical" !== direction) {
|
|
18
|
+
if (isHorizontal && Math.floor(label.AABBBounds.width()) <= limitLength) return;
|
|
19
|
+
if (isVertical && Math.floor(label.AABBBounds.height()) <= verticalLimitLength) return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
11
22
|
let limitLabelLength = null;
|
|
12
|
-
|
|
23
|
+
if (isHorizontal || isVertical) limitLabelLength = isX || "vertical" === direction ? verticalLimitLength : limitLength; else {
|
|
24
|
+
const {x1: x, y1: y} = label.AABBBounds, intersection = borderPoint({
|
|
25
|
+
width: isX ? axisLength : limitLength,
|
|
26
|
+
height: isX ? limitLength : axisLength,
|
|
27
|
+
left: 0,
|
|
28
|
+
top: 0
|
|
29
|
+
}, {
|
|
30
|
+
x: x,
|
|
31
|
+
y: y
|
|
32
|
+
}, label.attribute.angle);
|
|
33
|
+
if (intersection) {
|
|
34
|
+
const {x: _x, y: _y} = intersection;
|
|
35
|
+
limitLabelLength = Math.floor(Math.sqrt((_x - x) ** 2 + (_y - y) ** 2));
|
|
36
|
+
} else limitLabelLength = Math.abs(limitLength / Math.sin(angle));
|
|
37
|
+
}
|
|
13
38
|
isValidNumber(label.attribute.maxLineWidth) && (limitLabelLength = isValidNumber(limitLabelLength) ? Math.min(label.attribute.maxLineWidth, limitLabelLength) : label.attribute.maxLineWidth),
|
|
14
39
|
label.setAttributes({
|
|
15
40
|
maxLineWidth: limitLabelLength,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/axis/overlap/auto-limit.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"sources":["../src/axis/overlap/auto-limit.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAUrC,MAAM,UAAU,SAAS,CAAC,MAAe,EAAE,MAAmB;IAC5D,MAAM,E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CAAC,KAAK,CAAC,CAAC,CAAC;aAC5D;SACF;aAAM,IAAI,GAAG,EAAE;YACd,gBAAgB,GAAG,mBAAmB,CAAC;SACxC;aAAM;YACL,gBAAgB,GAAG,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,WAAW,CAAC;SACjF;QAED,IAAI,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE;YAC/C,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,CAAC;gBAChD,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,YAAY,EAAE,gBAAgB,CAAC;gBAC1D,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC;SAClC;QACD,KAAK,CAAC,aAAa,CAAC;YAClB,YAAY,EAAE,gBAAgB;YAC9B,QAAQ,EAAE,MAAA,KAAK,CAAC,SAAS,CAAC,QAAQ,mCAAI,QAAQ;SAC/C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","file":"auto-limit.js","sourcesContent":["/**\n * 自动省略\n */\nimport type { IText } from '@visactor/vrender-core';\nimport { isEmpty, isNil, isValidNumber } from '@visactor/vutils';\nimport { borderPoint } from './util';\n\ntype LimitConfig = {\n orient: string;\n limitLength: number;\n axisLength: number;\n verticalLimitLength?: number;\n ellipsis?: string;\n};\n\nexport function autoLimit(labels: IText[], config: LimitConfig) {\n const { limitLength, verticalLimitLength, ellipsis = '...', orient, axisLength } = config;\n if (isEmpty(labels) || !isValidNumber(limitLength)) {\n return;\n }\n\n labels.forEach(label => {\n const angle = label.attribute.angle;\n\n const hasAngle = !isNil(angle);\n const isHorizontal = !hasAngle || angle === 0 || angle === Math.PI;\n const isVertical = hasAngle && (angle === Math.PI / 2 || angle === (Math.PI * 2) / 3);\n const isX = orient === 'top' || orient === 'bottom';\n\n if (isX) {\n if (isVertical && Math.floor(label.AABBBounds.height()) <= limitLength) {\n return;\n }\n if (isHorizontal && Math.floor(label.AABBBounds.width()) <= verticalLimitLength) {\n return;\n }\n }\n\n const direction = label.attribute.direction;\n if (!isX) {\n if (direction === 'vertical' && Math.floor(label.AABBBounds.height()) <= verticalLimitLength) {\n return;\n }\n\n if (direction !== 'vertical') {\n if (isHorizontal && Math.floor(label.AABBBounds.width()) <= limitLength) {\n return;\n }\n if (isVertical && Math.floor(label.AABBBounds.height()) <= verticalLimitLength) {\n return;\n }\n }\n }\n\n // 如果水平并且文本未发生旋转,则不配置 maxLineWidth\n let limitLabelLength = null;\n\n if (!isHorizontal && !isVertical) {\n const { x1: x, y1: y } = label.AABBBounds;\n\n const width = isX ? axisLength : limitLength;\n const height = isX ? limitLength : axisLength;\n\n const intersection = borderPoint({ width, height, left: 0, top: 0 }, { x, y }, label.attribute.angle);\n if (intersection) {\n const { x: _x, y: _y } = intersection;\n limitLabelLength = Math.floor(Math.sqrt((_x - x) ** 2 + (_y - y) ** 2));\n } else {\n limitLabelLength = Math.abs(limitLength / Math.sin(angle));\n }\n } else if (isX) {\n limitLabelLength = verticalLimitLength;\n } else {\n limitLabelLength = direction === 'vertical' ? verticalLimitLength : limitLength;\n }\n\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"]}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import type { IText } from '@visactor/vrender-core';
|
|
2
2
|
export declare function genRotateBounds(items: IText[]): void;
|
|
3
3
|
export declare function itemIntersect(item1: IText, item2: IText): boolean;
|
|
4
|
+
export declare function borderPoint(rect: {
|
|
5
|
+
left: number;
|
|
6
|
+
top: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}, pt: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}, angle: number): {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
};
|
package/es/axis/overlap/util.js
CHANGED
|
@@ -32,4 +32,41 @@ export function genRotateBounds(items) {
|
|
|
32
32
|
export function itemIntersect(item1, item2) {
|
|
33
33
|
return isRectIntersect(item1.AABBBounds, item2.AABBBounds, !1) && (!item1.rotatedBounds || !item2.rotatedBounds || isRotateAABBIntersect(item1.rotatedBounds, item2.rotatedBounds, !0));
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
export function borderPoint(rect, pt, angle) {
|
|
37
|
+
if (pt.x < rect.left) return null;
|
|
38
|
+
if (pt.x > rect.left + rect.width) return null;
|
|
39
|
+
if (pt.y < rect.top) return null;
|
|
40
|
+
if (pt.y > rect.top + rect.height) return null;
|
|
41
|
+
const dx = Math.cos(angle), dy = Math.sin(angle);
|
|
42
|
+
if (dx < 1e-16) {
|
|
43
|
+
const y = (rect.left - pt.x) * dy / dx + pt.y;
|
|
44
|
+
if (y >= rect.top && y <= rect.top + rect.height) return {
|
|
45
|
+
x: rect.left,
|
|
46
|
+
y: y
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (dx > 1e-16) {
|
|
50
|
+
const y = (rect.left + rect.width - pt.x) * dy / dx + pt.y;
|
|
51
|
+
if (y >= rect.top && y <= rect.top + rect.height) return {
|
|
52
|
+
x: rect.left + rect.width,
|
|
53
|
+
y: y
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (dy < 1e-16) {
|
|
57
|
+
const x = (rect.top - pt.y) * dx / dy + pt.x;
|
|
58
|
+
if (x >= rect.left && x <= rect.left + rect.width) return {
|
|
59
|
+
x: x,
|
|
60
|
+
y: rect.top
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (dy > 1e-16) {
|
|
64
|
+
const x = (rect.top + rect.height - pt.y) * dx / dy + pt.x;
|
|
65
|
+
if (x >= rect.left && x <= rect.left + rect.width) return {
|
|
66
|
+
x: x,
|
|
67
|
+
y: rect.top + rect.height
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
35
72
|
//# sourceMappingURL=util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/axis/overlap/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;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,CAAC;QACzB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK;KAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,KAAK,CAAC,OAAO,CAAC,IAAI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} 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"]}
|
|
1
|
+
{"version":3,"sources":["../src/axis/overlap/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;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,C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G,EAAE,CAAC;SAC9B;KACF;IAED,IAAI,EAAE,GAAG,OAAO,EAAE;QAEhB,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE;YACjD,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;SAC5C;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC","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\n// 计算矩形内的点与矩形边的交点\nexport function borderPoint(\n rect: { left: number; top: number; width: number; height: number },\n pt: { x: number; y: number },\n angle: number\n) {\n // catch cases where point is outside rectangle\n if (pt.x < rect.left) {\n return null;\n }\n if (pt.x > rect.left + rect.width) {\n return null;\n }\n if (pt.y < rect.top) {\n return null;\n }\n if (pt.y > rect.top + rect.height) {\n return null;\n }\n\n const dx = Math.cos(angle);\n const dy = Math.sin(angle);\n\n if (dx < 1.0e-16) {\n // left border\n const y = ((rect.left - pt.x) * dy) / dx + pt.y;\n\n if (y >= rect.top && y <= rect.top + rect.height) {\n return { x: rect.left, y: y };\n }\n }\n\n if (dx > 1.0e-16) {\n // right border\n const y = ((rect.left + rect.width - pt.x) * dy) / dx + pt.y;\n\n if (y >= rect.top && y <= rect.top + rect.height) {\n return { x: rect.left + rect.width, y: y };\n }\n }\n\n if (dy < 1.0e-16) {\n // top border\n const x = ((rect.top - pt.y) * dx) / dy + pt.x;\n\n if (x >= rect.left && x <= rect.left + rect.width) {\n return { x: x, y: rect.top };\n }\n }\n\n if (dy > 1.0e-16) {\n // bottom border\n const x = ((rect.top + rect.height - pt.y) * dx) / dy + pt.x;\n if (x >= rect.left && x <= rect.left + rect.width) {\n return { x: x, y: rect.top + rect.height };\n }\n }\n\n return null;\n}\n"]}
|
package/es/axis/util.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ITextGraphicAttribute } from '@visactor/vrender-core';
|
|
1
|
+
import type { IGraphic, IGroup, ITextGraphicAttribute } from '@visactor/vrender-core';
|
|
2
|
+
import type { Dict } from '@visactor/vutils';
|
|
2
3
|
import { type Point } from '@visactor/vutils';
|
|
3
4
|
export declare const clampRadian: (angle?: number) => number;
|
|
4
5
|
export declare function isInRange(a: number, min: number, max: number): boolean;
|
|
@@ -6,3 +7,4 @@ export declare function getLabelPosition(tickPosition: Point, tickVector: [numbe
|
|
|
6
7
|
x: number;
|
|
7
8
|
y: number;
|
|
8
9
|
};
|
|
10
|
+
export declare function getElMap(g: IGroup): Dict<IGraphic<Partial<import("@visactor/vrender-core").IGraphicAttribute>>>;
|
package/es/axis/util.js
CHANGED
|
@@ -2,6 +2,8 @@ import { getTextBounds } from "@visactor/vrender-core";
|
|
|
2
2
|
|
|
3
3
|
import { isGreater, isLess, tau } from "@visactor/vutils";
|
|
4
4
|
|
|
5
|
+
import { traverseGroup } from "../util/common";
|
|
6
|
+
|
|
5
7
|
export const clampRadian = (angle = 0) => {
|
|
6
8
|
if (angle < 0) for (;angle < 0; ) angle += tau; else if (angle > 0) for (;angle > tau; ) angle -= tau;
|
|
7
9
|
return angle;
|
|
@@ -25,4 +27,11 @@ export function getLabelPosition(tickPosition, tickVector, text, style) {
|
|
|
25
27
|
y: baseY - dy
|
|
26
28
|
};
|
|
27
29
|
}
|
|
30
|
+
|
|
31
|
+
export function getElMap(g) {
|
|
32
|
+
const elMap = {};
|
|
33
|
+
return traverseGroup(g, (el => {
|
|
34
|
+
"group" !== el.type && el.id && (elMap[el.id] = el);
|
|
35
|
+
})), elMap;
|
|
36
|
+
}
|
|
28
37
|
//# sourceMappingURL=util.js.map
|
package/es/axis/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/axis/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"sources":["../src/axis/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAIvD,OAAO,EAAE,SAAS,EAAE,MA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,GAAG,CAAC,GAAG,GAAG,WAAW,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;KAC5D;IACD,MAAM,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;IAErB,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,CAAS;IAChC,MAAM,KAAK,GAAmB,EAAE,CAAC;IACjC,aAAa,CAAC,CAAC,EAAE,CAAC,EAAY,EAAE,EAAE;QAChC,IAAK,EAAe,CAAC,IAAI,KAAK,OAAO,IAAI,EAAE,CAAC,EAAE,EAAE;YAC9C,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;SACnB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC","file":"util.js","sourcesContent":["import { getTextBounds } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IGraphic, IGroup, ITextGraphicAttribute } from '@visactor/vrender-core';\nimport type { Dict } from '@visactor/vutils';\nimport { isGreater, isLess, tau, type Point } from '@visactor/vutils';\nimport { traverseGroup } from '../util/common';\n\n// 和 vutils 版本不同\nexport const clampRadian = (angle: number = 0) => {\n if (angle < 0) {\n while (angle < 0) {\n angle += tau;\n }\n } else if (angle > 0) {\n while (angle > tau) {\n angle -= tau;\n }\n }\n return angle;\n};\n\n// 判断数值是否在制定范围内,包含误差\nexport function isInRange(a: number, min: number, max: number) {\n return !isLess(a, min, 0, 1e-6) && !isGreater(a, max, 0, 1e-6);\n}\n\nexport function getLabelPosition(\n tickPosition: Point,\n tickVector: [number, number],\n text: string | number,\n style: Partial<ITextGraphicAttribute>\n) {\n const labelBounds = getTextBounds({\n text,\n ...style\n });\n const width = labelBounds.width();\n const height = labelBounds.height();\n const angle = clampRadian(Math.atan2(tickVector[1], tickVector[0])) - Math.PI;\n\n const PI_3_4 = (Math.PI * 3) / 4;\n const PI_1_4 = Math.PI / 4;\n const PI_1_2 = Math.PI / 2;\n\n // x\n const baseX = tickPosition.x;\n let dx = 0;\n if (isInRange(angle, -PI_3_4, -PI_1_4)) {\n dx = ((angle + PI_3_4) / PI_1_2 - 0.5) * width;\n } else if (isInRange(angle, PI_1_4, PI_3_4)) {\n dx = (0.5 - (angle - PI_1_4) / PI_1_2) * width;\n } else if (Math.cos(angle) >= 0) {\n dx = width * 0.5;\n } else {\n dx = -width * 0.5;\n }\n const x = baseX - dx;\n\n const baseY = tickPosition.y;\n let dy = 0;\n if (isInRange(angle, -PI_3_4, -PI_1_4)) {\n dy = -height * 0.5;\n } else if (isInRange(angle, PI_1_4, PI_3_4)) {\n dy = height * 0.5;\n } else if (Math.cos(angle) >= 0) {\n dy = (0.5 - (PI_1_4 - angle) / PI_1_2) * height;\n } else {\n dy = (0.5 - clampRadian(angle - PI_3_4) / PI_1_2) * height;\n }\n const y = baseY - dy;\n\n return { x, y };\n}\n\nexport function getElMap(g: IGroup) {\n const elMap: Dict<IGraphic> = {};\n traverseGroup(g, (el: IGraphic) => {\n if ((el as IGraphic).type !== 'group' && el.id) {\n elMap[el.id] = el;\n }\n });\n return elMap;\n}\n"]}
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;AAEhC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.18.
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;AAEhC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.18.6\";\n\nexport * from './core/base';\nexport * from './core/type';\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';\nexport * from './util';\n"]}
|
|
@@ -26,14 +26,19 @@ export declare class DiscreteLegend extends LegendBase<DiscreteLegendAttrs> {
|
|
|
26
26
|
isHorizontal: boolean;
|
|
27
27
|
currentPage: number;
|
|
28
28
|
totalPage: number;
|
|
29
|
+
isScrollbar: boolean;
|
|
29
30
|
};
|
|
30
31
|
protected _renderContent(): void;
|
|
31
32
|
protected _bindEvents(): void;
|
|
32
33
|
private _autoEllipsis;
|
|
33
34
|
private _renderEachItem;
|
|
34
35
|
private _createPager;
|
|
36
|
+
private _createScrollbar;
|
|
35
37
|
private _updatePositionOfPager;
|
|
38
|
+
private _updatePositionOfScrollbar;
|
|
36
39
|
private _bindEventsOfPager;
|
|
40
|
+
private _renderPager;
|
|
41
|
+
private _renderScrollbar;
|
|
37
42
|
private _renderPagerComponent;
|
|
38
43
|
private _onHover;
|
|
39
44
|
private _onUnHover;
|
|
@@ -95,32 +95,29 @@ export class DiscreteLegend extends LegendBase {
|
|
|
95
95
|
}));
|
|
96
96
|
}
|
|
97
97
|
_renderItems() {
|
|
98
|
-
const {item: itemAttrs = {}, maxCol: maxCol = 1, maxRow: maxRow = 2, maxWidth: maxWidth, maxHeight: maxHeight, defaultSelected: defaultSelected = [], lazyload: lazyload} = this.attribute, {spaceCol: spaceCol = DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = DEFAULT_ITEM_SPACE_ROW} = itemAttrs, itemsContainer = this._itemsContainer, {items: legendItems, isHorizontal: isHorizontal, startIndex: startIndex} = this._itemContext, maxPages = isHorizontal ? maxRow : maxCol;
|
|
98
|
+
const {item: itemAttrs = {}, maxCol: maxCol = 1, maxRow: maxRow = 2, maxWidth: maxWidth, maxHeight: maxHeight, defaultSelected: defaultSelected = [], lazyload: lazyload, autoPage: autoPage} = this.attribute, {spaceCol: spaceCol = DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = DEFAULT_ITEM_SPACE_ROW} = itemAttrs, itemsContainer = this._itemsContainer, {items: legendItems, isHorizontal: isHorizontal, startIndex: startIndex, isScrollbar: isScrollbar} = this._itemContext, maxPages = isScrollbar ? 1 : isHorizontal ? maxRow : maxCol;
|
|
99
99
|
let item, {doWrap: doWrap, maxWidthInCol: maxWidthInCol, startX: startX, startY: startY, pages: pages} = this._itemContext;
|
|
100
|
-
for (let index = startIndex, len = legendItems.length; index < len; index++) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
item = legendItems[index], item.id || (item.id = item.label), item.index = index;
|
|
100
|
+
for (let index = startIndex, len = legendItems.length; index < len && !(lazyload && pages > this._itemContext.currentPage * maxPages); index++) {
|
|
101
|
+
lazyload && (this._itemContext.startIndex = index + 1), item = legendItems[index],
|
|
102
|
+
item.id || (item.id = item.label), item.index = index;
|
|
106
103
|
const itemGroup = this._renderEachItem(item, !!isEmpty(defaultSelected) || (null == defaultSelected ? void 0 : defaultSelected.includes(item.label)), index, legendItems), itemWidth = itemGroup.attribute.width, itemHeight = itemGroup.attribute.height;
|
|
107
104
|
this._itemHeight = Math.max(this._itemHeight, itemHeight), maxWidthInCol = Math.max(itemWidth, maxWidthInCol),
|
|
108
|
-
this._itemMaxWidth = Math.max(itemWidth, this._itemMaxWidth), isHorizontal ? (isValid(maxWidth) && (
|
|
109
|
-
|
|
110
|
-
startX = 0, startY += itemHeight + spaceRow
|
|
105
|
+
this._itemMaxWidth = Math.max(itemWidth, this._itemMaxWidth), isHorizontal ? (isValid(maxWidth) && (isScrollbar && autoPage ? (pages = Math.ceil((startX + itemWidth) / maxWidth),
|
|
106
|
+
doWrap = pages > 1) : startX + itemWidth > maxWidth && (doWrap = !0, startX > 0 && (pages += 1,
|
|
107
|
+
startX = 0, startY += itemHeight + spaceRow))), 0 === startX && 0 === startY || itemGroup.setAttributes({
|
|
111
108
|
x: startX,
|
|
112
109
|
y: startY
|
|
113
|
-
}), startX += spaceCol + itemWidth) : (isValid(maxHeight) &&
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
}), startX += spaceCol + itemWidth) : (isValid(maxHeight) && (isScrollbar && autoPage ? (pages = Math.ceil((startY + itemHeight) / maxHeight),
|
|
111
|
+
doWrap = pages > 1) : maxHeight < startY + itemHeight && (pages += 1, doWrap = !0,
|
|
112
|
+
startY = 0, startX += maxWidthInCol + spaceCol, maxWidthInCol = 0)), 0 === startX && 0 === startY || itemGroup.setAttributes({
|
|
116
113
|
x: startX,
|
|
117
114
|
y: startY
|
|
118
115
|
}), startY += spaceRow + itemHeight), itemsContainer.add(itemGroup);
|
|
119
116
|
}
|
|
120
117
|
return this._itemContext.doWrap = doWrap, this._itemContext.startX = startX, this._itemContext.startY = startY,
|
|
121
118
|
this._itemContext.maxWidthInCol = maxWidthInCol, this._itemContext.pages = pages,
|
|
122
|
-
this._itemContext.maxPages = maxPages,
|
|
123
|
-
this._itemContext;
|
|
119
|
+
this._itemContext.maxPages = maxPages, isScrollbar && (this._itemContext.totalPage = pages),
|
|
120
|
+
lazyload || (this._itemContext.startIndex = legendItems.length), this._itemContext;
|
|
124
121
|
}
|
|
125
122
|
_renderContent() {
|
|
126
123
|
const {item: item = {}, items: items, reversed: reversed, maxWidth: maxWidth} = this.attribute;
|
|
@@ -135,8 +132,10 @@ export class DiscreteLegend extends LegendBase {
|
|
|
135
132
|
const {layout: layout, autoPage: autoPage} = this.attribute, isHorizontal = "horizontal" === layout, {maxWidth: maxItemWidth, width: itemWidth, height: itemHeight} = item, widthsOptions = [];
|
|
136
133
|
isValid(maxItemWidth) && widthsOptions.push(maxItemWidth), isValid(itemWidth) && widthsOptions.push(itemWidth),
|
|
137
134
|
widthsOptions.length && (isValid(maxWidth) && widthsOptions.push(maxWidth), this._itemWidthByUser = minInArray(widthsOptions)),
|
|
138
|
-
isValid(itemHeight) && (this._itemHeightByUser = itemHeight)
|
|
139
|
-
|
|
135
|
+
isValid(itemHeight) && (this._itemHeightByUser = itemHeight);
|
|
136
|
+
const pager = this.attribute.pager;
|
|
137
|
+
this._itemContext = {
|
|
138
|
+
currentPage: pager && pager.defaultCurrent || 1,
|
|
140
139
|
doWrap: !1,
|
|
141
140
|
maxWidthInCol: 0,
|
|
142
141
|
maxPages: 1,
|
|
@@ -146,10 +145,11 @@ export class DiscreteLegend extends LegendBase {
|
|
|
146
145
|
startIndex: 0,
|
|
147
146
|
items: legendItems,
|
|
148
147
|
isHorizontal: isHorizontal,
|
|
149
|
-
totalPage: 1 / 0
|
|
148
|
+
totalPage: 1 / 0,
|
|
149
|
+
isScrollbar: pager && "scrollbar" === pager.type
|
|
150
150
|
}, this._itemContext = this._renderItems();
|
|
151
151
|
let pagerRendered = !1;
|
|
152
|
-
this._itemContext.doWrap && autoPage && this._itemContext.pages > this._itemContext.maxPages && (pagerRendered = this._renderPagerComponent(
|
|
152
|
+
this._itemContext.doWrap && autoPage && this._itemContext.pages > this._itemContext.maxPages && (pagerRendered = this._renderPagerComponent()),
|
|
153
153
|
pagerRendered || (itemsContainer.setAttribute("y", this._title ? this._title.AABBBounds.height() + get(this.attribute, "title.space", 8) : 0),
|
|
154
154
|
this._innerView.add(itemsContainer));
|
|
155
155
|
}
|
|
@@ -274,24 +274,10 @@ export class DiscreteLegend extends LegendBase {
|
|
|
274
274
|
focusShape && focusShape.setAttribute("visible", !1), innerGroup.translateTo(-innerGroupBounds.x1 + parsedPadding[3], -innerGroupBounds.y1 + parsedPadding[0]),
|
|
275
275
|
itemGroup;
|
|
276
276
|
}
|
|
277
|
-
_createPager(
|
|
277
|
+
_createPager(compStyle) {
|
|
278
278
|
var _a, _b;
|
|
279
279
|
const {disableTriggerEvent: disableTriggerEvent, maxRow: maxRow} = this.attribute;
|
|
280
|
-
return
|
|
281
|
-
direction: "vertical",
|
|
282
|
-
width: 12,
|
|
283
|
-
range: [ 0, .5 ]
|
|
284
|
-
}, compStyle), {
|
|
285
|
-
height: compSize,
|
|
286
|
-
disableTriggerEvent: disableTriggerEvent
|
|
287
|
-
}) : Object.assign(Object.assign({
|
|
288
|
-
direction: "horizontal",
|
|
289
|
-
disableTriggerEvent: disableTriggerEvent,
|
|
290
|
-
range: [ 0, .5 ],
|
|
291
|
-
height: 12
|
|
292
|
-
}, compStyle), {
|
|
293
|
-
width: compSize
|
|
294
|
-
})) : new Pager(isHorizontal ? Object.assign(Object.assign({
|
|
280
|
+
return this._itemContext.isHorizontal ? new Pager(Object.assign(Object.assign({
|
|
295
281
|
layout: 1 === maxRow ? "horizontal" : "vertical",
|
|
296
282
|
total: 99
|
|
297
283
|
}, merge({
|
|
@@ -302,43 +288,62 @@ export class DiscreteLegend extends LegendBase {
|
|
|
302
288
|
}, compStyle)), {
|
|
303
289
|
defaultCurrent: null === (_a = this.attribute.pager) || void 0 === _a ? void 0 : _a.defaultCurrent,
|
|
304
290
|
disableTriggerEvent: disableTriggerEvent
|
|
305
|
-
}) : Object.assign({
|
|
291
|
+
})) : new Pager(Object.assign({
|
|
306
292
|
layout: "horizontal",
|
|
307
293
|
total: 99,
|
|
308
294
|
disableTriggerEvent: disableTriggerEvent,
|
|
309
295
|
defaultCurrent: null === (_b = this.attribute.pager) || void 0 === _b ? void 0 : _b.defaultCurrent
|
|
310
296
|
}, compStyle));
|
|
311
297
|
}
|
|
312
|
-
|
|
313
|
-
const {
|
|
314
|
-
|
|
298
|
+
_createScrollbar(compStyle, compSize) {
|
|
299
|
+
const {disableTriggerEvent: disableTriggerEvent} = this.attribute;
|
|
300
|
+
return this._itemContext.isHorizontal ? new ScrollBar(Object.assign(Object.assign({
|
|
301
|
+
direction: "horizontal",
|
|
302
|
+
disableTriggerEvent: disableTriggerEvent,
|
|
303
|
+
range: [ 0, .5 ],
|
|
304
|
+
height: 12
|
|
305
|
+
}, compStyle), {
|
|
306
|
+
width: compSize
|
|
307
|
+
})) : new ScrollBar(Object.assign(Object.assign({
|
|
308
|
+
direction: "vertical",
|
|
309
|
+
width: 12,
|
|
310
|
+
range: [ 0, .5 ]
|
|
311
|
+
}, compStyle), {
|
|
312
|
+
height: compSize,
|
|
313
|
+
disableTriggerEvent: disableTriggerEvent
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
316
|
+
_updatePositionOfPager(contentWidth, contentHeight, renderStartY, compWidth, compHeight) {
|
|
317
|
+
const {maxHeight: maxHeight, pager: pager} = this.attribute, {totalPage: totalPage, isHorizontal: isHorizontal} = this._itemContext, position = pager && pager.position || "middle";
|
|
318
|
+
if (this._pagerComponent.setTotal(totalPage), isHorizontal) {
|
|
319
|
+
let y;
|
|
320
|
+
y = "start" === position ? renderStartY : "end" === position ? renderStartY + compHeight - this._pagerComponent.AABBBounds.height() / 2 : renderStartY + compHeight / 2 - this._pagerComponent.AABBBounds.height() / 2,
|
|
321
|
+
this._pagerComponent.setAttributes({
|
|
322
|
+
x: contentWidth,
|
|
323
|
+
y: y
|
|
324
|
+
});
|
|
325
|
+
} else {
|
|
326
|
+
let x;
|
|
327
|
+
x = "start" === position ? 0 : "end" === position ? compWidth - this._pagerComponent.AABBBounds.width() : (compWidth - this._pagerComponent.AABBBounds.width()) / 2,
|
|
328
|
+
this._pagerComponent.setAttributes({
|
|
329
|
+
x: x,
|
|
330
|
+
y: maxHeight - this._pagerComponent.AABBBounds.height()
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
_updatePositionOfScrollbar(contentWidth, contentHeight, renderStartY) {
|
|
335
|
+
const {currentPage: currentPage, totalPage: totalPage, isHorizontal: isHorizontal} = this._itemContext;
|
|
336
|
+
this._pagerComponent.setScrollRange([ (currentPage - 1) / totalPage, currentPage / totalPage ]),
|
|
315
337
|
isHorizontal ? this._pagerComponent.setAttributes({
|
|
316
|
-
x: contentSize,
|
|
317
|
-
y: renderStartY
|
|
318
|
-
}) : this._pagerComponent.setAttributes({
|
|
319
338
|
x: 0,
|
|
320
|
-
y:
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
y = "start" === position ? renderStartY : "end" === position ? renderStartY + compSize - this._pagerComponent.AABBBounds.height() / 2 : renderStartY + compSize / 2 - this._pagerComponent.AABBBounds.height() / 2,
|
|
326
|
-
this._pagerComponent.setAttributes({
|
|
327
|
-
x: contentSize,
|
|
328
|
-
y: y
|
|
329
|
-
});
|
|
330
|
-
} else {
|
|
331
|
-
let x;
|
|
332
|
-
x = "start" === position ? 0 : "end" === position ? compSize - this._pagerComponent.AABBBounds.width() : (compSize - this._pagerComponent.AABBBounds.width()) / 2,
|
|
333
|
-
this._pagerComponent.setAttributes({
|
|
334
|
-
x: x,
|
|
335
|
-
y: maxHeight - this._pagerComponent.AABBBounds.height()
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
+
y: renderStartY + contentHeight
|
|
340
|
+
}) : this._pagerComponent.setAttributes({
|
|
341
|
+
x: contentWidth,
|
|
342
|
+
y: renderStartY
|
|
343
|
+
});
|
|
339
344
|
}
|
|
340
|
-
_bindEventsOfPager(
|
|
341
|
-
const pager = this.attribute.pager || {}, {animation: animation = !0, animationDuration: animationDuration = 450, animationEasing: animationEasing = "quadIn"} = pager, pageParser = isScrollbar ? e => {
|
|
345
|
+
_bindEventsOfPager(pageSize, channel) {
|
|
346
|
+
const pager = this.attribute.pager || {}, {animation: animation = !0, animationDuration: animationDuration = 450, animationEasing: animationEasing = "quadIn"} = pager, pageParser = this._itemContext.isScrollbar ? e => {
|
|
342
347
|
const {value: value} = e.detail;
|
|
343
348
|
let newPage = value[0] * this._itemContext.totalPage;
|
|
344
349
|
return pager.scrollByPosition ? newPage += 1 : newPage = Math.floor(newPage) + 1,
|
|
@@ -351,58 +356,89 @@ export class DiscreteLegend extends LegendBase {
|
|
|
351
356
|
const newTotalPage = Math.ceil(this._itemContext.pages / this._itemContext.maxPages);
|
|
352
357
|
this._itemContext.totalPage = newTotalPage, this._pagerComponent.setScrollRange([ (newPage - 1) / newTotalPage, newPage / newTotalPage ]);
|
|
353
358
|
}
|
|
354
|
-
animation ? this._itemsContainer.animate().to(
|
|
355
|
-
|
|
356
|
-
} :
|
|
357
|
-
x: -(newPage - 1) * (compSize + spaceSize)
|
|
358
|
-
}, animationDuration, animationEasing) : isHorizontal ? this._itemsContainer.setAttribute("y", -(newPage - 1) * (compSize + spaceSize)) : this._itemsContainer.setAttribute("x", -(newPage - 1) * (compSize + spaceSize));
|
|
359
|
+
animation ? this._itemsContainer.animate().to({
|
|
360
|
+
[channel]: -(newPage - 1) * pageSize
|
|
361
|
+
}, animationDuration, animationEasing) : this._itemsContainer.setAttribute(channel, -(newPage - 1) * pageSize);
|
|
359
362
|
}
|
|
360
363
|
};
|
|
361
|
-
isScrollbar ? (this._pagerComponent.addEventListener("scrollDrag", onPaging),
|
|
364
|
+
this._itemContext.isScrollbar ? (this._pagerComponent.addEventListener("scrollDrag", onPaging),
|
|
365
|
+
this._pagerComponent.addEventListener("scrollUp", onPaging)) : (this._pagerComponent.addEventListener("toPrev", onPaging),
|
|
362
366
|
this._pagerComponent.addEventListener("toNext", onPaging));
|
|
363
367
|
}
|
|
364
|
-
|
|
365
|
-
const renderStartY = this._title ? this._title.AABBBounds.height() + get(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth, maxHeight: maxHeight, maxCol: maxCol = 1, maxRow: maxRow = 2, item: item = {}, pager: pager = {}} = this.attribute, {spaceCol: spaceCol = DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = DEFAULT_ITEM_SPACE_ROW} = item, itemsContainer = this._itemsContainer, {space: pagerSpace = DEFAULT_PAGER_SPACE, defaultCurrent: defaultCurrent = 1} = pager, compStyle = __rest(pager, [ "space", "defaultCurrent" ]),
|
|
366
|
-
let comp,
|
|
368
|
+
_renderPager() {
|
|
369
|
+
const renderStartY = this._title ? this._title.AABBBounds.height() + get(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth, maxHeight: maxHeight, maxCol: maxCol = 1, maxRow: maxRow = 2, item: item = {}, pager: pager = {}} = this.attribute, {spaceCol: spaceCol = DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = DEFAULT_ITEM_SPACE_ROW} = item, itemsContainer = this._itemsContainer, {space: pagerSpace = DEFAULT_PAGER_SPACE, defaultCurrent: defaultCurrent = 1} = pager, compStyle = __rest(pager, [ "space", "defaultCurrent" ]), {isHorizontal: isHorizontal} = this._itemContext;
|
|
370
|
+
let comp, compWidth = 0, compHeight = 0, contentWidth = 0, contentHeight = 0, startX = 0, startY = 0, pages = 1;
|
|
367
371
|
if (isHorizontal) {
|
|
368
|
-
if (
|
|
369
|
-
this._pagerComponent = comp, this._innerView.add(comp),
|
|
370
|
-
|
|
372
|
+
if (compHeight = (maxRow - 1) * spaceRow + this._itemHeight * maxRow, compWidth = maxWidth,
|
|
373
|
+
comp = this._createPager(compStyle), this._pagerComponent = comp, this._innerView.add(comp),
|
|
374
|
+
contentWidth = maxWidth - comp.AABBBounds.width() - pagerSpace, contentWidth <= 0) return this._innerView.removeChild(comp),
|
|
375
|
+
!1;
|
|
371
376
|
itemsContainer.getChildren().forEach(((item, index) => {
|
|
372
377
|
const {width: width, height: height} = item.attribute;
|
|
373
|
-
|
|
378
|
+
contentWidth < startX + width && (startX = 0, startY += height + spaceRow, pages += 1),
|
|
374
379
|
index > 0 && item.setAttributes({
|
|
375
380
|
x: startX,
|
|
376
381
|
y: startY
|
|
377
382
|
}), startX += spaceCol + width;
|
|
378
383
|
})), this._itemContext.startX = startX, this._itemContext.startY = startY, this._itemContext.pages = pages;
|
|
379
384
|
const total = Math.ceil(pages / maxRow);
|
|
380
|
-
this._itemContext.totalPage = total, this._updatePositionOfPager(
|
|
385
|
+
this._itemContext.totalPage = total, this._updatePositionOfPager(contentWidth, contentHeight, renderStartY, compWidth, compHeight);
|
|
381
386
|
} else {
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
|
|
387
|
+
if (compWidth = this._itemMaxWidth * maxCol + (maxCol - 1) * spaceCol, compHeight = maxHeight,
|
|
388
|
+
contentWidth = compWidth, comp = this._createPager(compStyle), this._pagerComponent = comp,
|
|
389
|
+
this._innerView.add(comp), contentHeight = maxHeight - comp.AABBBounds.height() - pagerSpace - renderStartY,
|
|
390
|
+
contentHeight <= 0) return this._innerView.removeChild(comp), !1;
|
|
385
391
|
itemsContainer.getChildren().forEach(((item, index) => {
|
|
386
392
|
const {height: height} = item.attribute;
|
|
387
|
-
|
|
393
|
+
contentHeight < startY + height && (startY = 0, startX += this._itemMaxWidth + spaceCol,
|
|
388
394
|
pages += 1), index > 0 && item.setAttributes({
|
|
389
395
|
x: startX,
|
|
390
396
|
y: startY
|
|
391
397
|
}), startY += spaceRow + height;
|
|
392
398
|
}));
|
|
393
399
|
const total = Math.ceil(pages / maxCol);
|
|
394
|
-
this._itemContext.totalPage = total, this._updatePositionOfPager(
|
|
400
|
+
this._itemContext.totalPage = total, this._updatePositionOfPager(contentWidth, contentHeight, renderStartY, compWidth, compHeight);
|
|
395
401
|
}
|
|
396
|
-
defaultCurrent > 1 && (isHorizontal ? itemsContainer.setAttribute("y", -(defaultCurrent - 1) * (
|
|
402
|
+
defaultCurrent > 1 && (isHorizontal ? itemsContainer.setAttribute("y", -(defaultCurrent - 1) * (compHeight + spaceRow)) : itemsContainer.setAttribute("x", -(defaultCurrent - 1) * (compWidth + spaceCol)));
|
|
397
403
|
const clipGroup = graphicCreator.group({
|
|
398
404
|
x: 0,
|
|
399
405
|
y: renderStartY,
|
|
400
|
-
width: isHorizontal ?
|
|
401
|
-
height: isHorizontal ?
|
|
406
|
+
width: isHorizontal ? contentWidth : compWidth,
|
|
407
|
+
height: isHorizontal ? compHeight : contentHeight,
|
|
402
408
|
clip: !0,
|
|
403
409
|
pickable: !1
|
|
404
410
|
});
|
|
405
|
-
return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this._bindEventsOfPager(
|
|
411
|
+
return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this._bindEventsOfPager(isHorizontal ? compHeight + spaceRow : compWidth + spaceCol, isHorizontal ? "y" : "x"),
|
|
412
|
+
!0;
|
|
413
|
+
}
|
|
414
|
+
_renderScrollbar() {
|
|
415
|
+
const renderStartY = this._title ? this._title.AABBBounds.height() + get(this.attribute, "title.space", 8) : 0, {maxWidth: maxWidth, maxHeight: maxHeight, item: item = {}, pager: pager = {}} = this.attribute, {spaceCol: spaceCol = DEFAULT_ITEM_SPACE_COL, spaceRow: spaceRow = DEFAULT_ITEM_SPACE_ROW} = item, itemsContainer = this._itemsContainer, {space: pagerSpace = DEFAULT_PAGER_SPACE, defaultCurrent: defaultCurrent = 1} = pager, compStyle = __rest(pager, [ "space", "defaultCurrent" ]), {isHorizontal: isHorizontal} = this._itemContext;
|
|
416
|
+
let comp, compSize = 0, contentWidth = 0, contentHeight = 0, startY = 0, pages = 1;
|
|
417
|
+
if (isHorizontal) compSize = maxWidth, contentWidth = maxWidth, contentHeight = this._itemHeight,
|
|
418
|
+
comp = this._createScrollbar(compStyle, compSize), this._pagerComponent = comp,
|
|
419
|
+
this._innerView.add(comp), this._updatePositionOfScrollbar(contentWidth, contentHeight, renderStartY); else {
|
|
420
|
+
if (compSize = maxHeight, comp = this._createScrollbar(compStyle, compSize), this._pagerComponent = comp,
|
|
421
|
+
this._innerView.add(comp), contentHeight = maxHeight - renderStartY, contentWidth = this._itemMaxWidth,
|
|
422
|
+
contentHeight <= 0) return this._innerView.removeChild(comp), !1;
|
|
423
|
+
itemsContainer.getChildren().forEach(((item, index) => {
|
|
424
|
+
const {height: height} = item.attribute;
|
|
425
|
+
pages = Math.floor((startY + height) / contentHeight) + 1, startY += spaceRow + height;
|
|
426
|
+
})), this._itemContext.totalPage = pages, this._itemContext.pages = pages, this._updatePositionOfScrollbar(contentWidth, contentHeight, renderStartY);
|
|
427
|
+
}
|
|
428
|
+
defaultCurrent > 1 && (isHorizontal ? itemsContainer.setAttribute("x", -(defaultCurrent - 1) * (contentWidth + spaceCol)) : itemsContainer.setAttribute("y", -(defaultCurrent - 1) * (contentHeight + spaceRow)));
|
|
429
|
+
const clipGroup = graphicCreator.group({
|
|
430
|
+
x: 0,
|
|
431
|
+
y: renderStartY,
|
|
432
|
+
width: contentWidth,
|
|
433
|
+
height: contentHeight,
|
|
434
|
+
clip: !0,
|
|
435
|
+
pickable: !1
|
|
436
|
+
});
|
|
437
|
+
return clipGroup.add(itemsContainer), this._innerView.add(clipGroup), this._bindEventsOfPager(isHorizontal ? contentWidth : contentHeight, isHorizontal ? "x" : "y"),
|
|
438
|
+
!0;
|
|
439
|
+
}
|
|
440
|
+
_renderPagerComponent() {
|
|
441
|
+
return this._itemContext.isScrollbar ? this._renderScrollbar() : this._renderPager(),
|
|
406
442
|
!0;
|
|
407
443
|
}
|
|
408
444
|
_hover(legendItem, e) {
|