@antv/gpt-vis 1.3.2 → 1.4.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/README.md +261 -137
- package/README.zh-CN.md +263 -116
- package/dist/cjs/annotation/components/bottom-n.d.ts +2 -0
- package/dist/cjs/annotation/components/bottom-n.js +57 -0
- package/dist/cjs/annotation/components/centroid.d.ts +2 -0
- package/dist/cjs/annotation/components/centroid.js +75 -0
- package/dist/cjs/annotation/components/connector.d.ts +25 -0
- package/dist/cjs/annotation/components/connector.js +298 -0
- package/dist/cjs/annotation/components/contribution.d.ts +3 -0
- package/dist/cjs/annotation/components/contribution.js +136 -0
- package/dist/cjs/annotation/components/crossing.d.ts +3 -0
- package/dist/cjs/annotation/components/crossing.js +504 -0
- package/dist/cjs/annotation/components/event.d.ts +2 -0
- package/dist/cjs/annotation/components/event.js +62 -0
- package/dist/cjs/annotation/components/first.d.ts +2 -0
- package/dist/cjs/annotation/components/first.js +42 -0
- package/dist/cjs/annotation/components/group.d.ts +3 -0
- package/dist/cjs/annotation/components/group.js +73 -0
- package/dist/cjs/annotation/components/highlight.d.ts +14 -0
- package/dist/cjs/annotation/components/highlight.js +552 -0
- package/dist/cjs/annotation/components/index.d.ts +34 -0
- package/dist/cjs/annotation/components/index.js +128 -0
- package/dist/cjs/annotation/components/last.d.ts +2 -0
- package/dist/cjs/annotation/components/last.js +42 -0
- package/dist/cjs/annotation/components/max-x.d.ts +2 -0
- package/dist/cjs/annotation/components/max-x.js +41 -0
- package/dist/cjs/annotation/components/max-y.d.ts +2 -0
- package/dist/cjs/annotation/components/max-y.js +41 -0
- package/dist/cjs/annotation/components/mean.d.ts +2 -0
- package/dist/cjs/annotation/components/mean.js +50 -0
- package/dist/cjs/annotation/components/median.d.ts +2 -0
- package/dist/cjs/annotation/components/median.js +49 -0
- package/dist/cjs/annotation/components/min-x.d.ts +2 -0
- package/dist/cjs/annotation/components/min-x.js +41 -0
- package/dist/cjs/annotation/components/min-y.d.ts +2 -0
- package/dist/cjs/annotation/components/min-y.js +41 -0
- package/dist/cjs/annotation/components/outlier.d.ts +3 -0
- package/dist/cjs/annotation/components/outlier.js +83 -0
- package/dist/cjs/annotation/components/path.d.ts +20 -0
- package/dist/cjs/annotation/components/path.js +147 -0
- package/dist/cjs/annotation/components/peak.d.ts +2 -0
- package/dist/cjs/annotation/components/peak.js +42 -0
- package/dist/cjs/annotation/components/point.d.ts +26 -0
- package/dist/cjs/annotation/components/point.js +241 -0
- package/dist/cjs/annotation/components/quadrant.d.ts +3 -0
- package/dist/cjs/annotation/components/quadrant.js +97 -0
- package/dist/cjs/annotation/components/quantile.d.ts +2 -0
- package/dist/cjs/annotation/components/quantile.js +49 -0
- package/dist/cjs/annotation/components/range-inside.d.ts +2 -0
- package/dist/cjs/annotation/components/range-inside.js +65 -0
- package/dist/cjs/annotation/components/range-outside.d.ts +2 -0
- package/dist/cjs/annotation/components/range-outside.js +65 -0
- package/dist/cjs/annotation/components/range-x.d.ts +2 -0
- package/dist/cjs/annotation/components/range-x.js +39 -0
- package/dist/cjs/annotation/components/range-y.d.ts +2 -0
- package/dist/cjs/annotation/components/range-y.js +39 -0
- package/dist/cjs/annotation/components/range.d.ts +15 -0
- package/dist/cjs/annotation/components/range.js +87 -0
- package/dist/cjs/annotation/components/target.d.ts +2 -0
- package/dist/cjs/annotation/components/target.js +51 -0
- package/dist/cjs/annotation/components/text.d.ts +15 -0
- package/dist/cjs/annotation/components/text.js +74 -0
- package/dist/cjs/annotation/components/threshold-highlight.d.ts +3 -0
- package/dist/cjs/annotation/components/threshold-highlight.js +223 -0
- package/dist/cjs/annotation/components/threshold-x.d.ts +2 -0
- package/dist/cjs/annotation/components/threshold-x.js +39 -0
- package/dist/cjs/annotation/components/threshold-y.d.ts +2 -0
- package/dist/cjs/annotation/components/threshold-y.js +40 -0
- package/dist/cjs/annotation/components/top-n.d.ts +2 -0
- package/dist/cjs/annotation/components/top-n.js +57 -0
- package/dist/cjs/annotation/components/valley.d.ts +2 -0
- package/dist/cjs/annotation/components/valley.js +42 -0
- package/dist/cjs/annotation/index.d.ts +1 -0
- package/dist/cjs/annotation/index.js +29 -0
- package/dist/cjs/annotation/label.d.ts +38 -0
- package/dist/cjs/annotation/label.js +347 -0
- package/dist/cjs/annotation/layout.d.ts +12 -0
- package/dist/cjs/annotation/layout.js +142 -0
- package/dist/cjs/annotation/merge.d.ts +19 -0
- package/dist/cjs/annotation/merge.js +60 -0
- package/dist/cjs/annotation/registry.d.ts +190 -0
- package/dist/cjs/annotation/registry.js +134 -0
- package/dist/cjs/annotation/runtime/g2.d.ts +90 -0
- package/dist/cjs/annotation/runtime/g2.js +521 -0
- package/dist/cjs/annotation/runtime/g6.d.ts +40 -0
- package/dist/cjs/annotation/runtime/g6.js +310 -0
- package/dist/cjs/annotation/runtime/index.d.ts +11 -0
- package/dist/cjs/annotation/runtime/index.js +41 -0
- package/dist/cjs/annotation/runtime/summary.d.ts +17 -0
- package/dist/cjs/annotation/runtime/summary.js +39 -0
- package/dist/cjs/annotation/runtime/table.d.ts +16 -0
- package/dist/cjs/annotation/runtime/table.js +39 -0
- package/dist/cjs/annotation/utils.d.ts +40 -0
- package/dist/cjs/annotation/utils.js +275 -0
- package/dist/cjs/theme/annotation.d.ts +236 -0
- package/dist/cjs/theme/annotation.js +167 -0
- package/dist/cjs/theme/g2.js +13 -15
- package/dist/cjs/theme/g6.js +2 -2
- package/dist/cjs/theme/summary.js +2 -2
- package/dist/cjs/types/annotation.d.ts +310 -0
- package/dist/cjs/types/annotation.js +17 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/util/axis.d.ts +28 -0
- package/dist/cjs/util/axis.js +184 -0
- package/dist/cjs/util/components.d.ts +0 -10
- package/dist/cjs/util/components.js +9 -64
- package/dist/cjs/util/index.d.ts +7 -4
- package/dist/cjs/util/index.js +53 -9
- package/dist/cjs/vis/area/index.d.ts +2 -0
- package/dist/cjs/vis/area/index.js +30 -13
- package/dist/cjs/vis/bar/index.d.ts +2 -0
- package/dist/cjs/vis/bar/index.js +37 -7
- package/dist/cjs/vis/boxplot/index.js +14 -3
- package/dist/cjs/vis/column/index.d.ts +2 -0
- package/dist/cjs/vis/column/index.js +28 -9
- package/dist/cjs/vis/dual-axes/index.js +9 -9
- package/dist/cjs/vis/fishbone-diagram/index.js +2 -2
- package/dist/cjs/vis/flow-diagram/index.js +2 -2
- package/dist/cjs/vis/funnel/index.js +10 -13
- package/dist/cjs/vis/histogram/index.js +2 -2
- package/dist/cjs/vis/indented-tree/index.js +2 -2
- package/dist/cjs/vis/line/index.d.ts +2 -0
- package/dist/cjs/vis/line/index.js +26 -10
- package/dist/cjs/vis/liquid/index.js +2 -2
- package/dist/cjs/vis/mindmap/index.js +2 -2
- package/dist/cjs/vis/network-graph/index.d.ts +2 -0
- package/dist/cjs/vis/network-graph/index.js +24 -3
- package/dist/cjs/vis/organization-chart/index.js +2 -2
- package/dist/cjs/vis/pie/index.d.ts +2 -0
- package/dist/cjs/vis/pie/index.js +21 -10
- package/dist/cjs/vis/radar/index.js +4 -6
- package/dist/cjs/vis/sankey/index.js +14 -1
- package/dist/cjs/vis/scatter/index.d.ts +10 -3
- package/dist/cjs/vis/scatter/index.js +18 -7
- package/dist/cjs/vis/summary/index.d.ts +9 -2
- package/dist/cjs/vis/summary/index.js +25 -8
- package/dist/cjs/vis/table/index.d.ts +2 -0
- package/dist/cjs/vis/table/index.js +48 -30
- package/dist/cjs/vis/venn/index.js +2 -2
- package/dist/cjs/vis/violin/index.js +14 -3
- package/dist/cjs/vis/waterfall/index.js +17 -9
- package/dist/cjs/vis/word-cloud/index.js +4 -6
- package/dist/esm/annotation/components/bottom-n.d.ts +2 -0
- package/dist/esm/annotation/components/bottom-n.js +42 -0
- package/dist/esm/annotation/components/centroid.d.ts +2 -0
- package/dist/esm/annotation/components/centroid.js +73 -0
- package/dist/esm/annotation/components/connector.d.ts +25 -0
- package/dist/esm/annotation/components/connector.js +332 -0
- package/dist/esm/annotation/components/contribution.d.ts +3 -0
- package/dist/esm/annotation/components/contribution.js +174 -0
- package/dist/esm/annotation/components/crossing.d.ts +3 -0
- package/dist/esm/annotation/components/crossing.js +665 -0
- package/dist/esm/annotation/components/event.d.ts +2 -0
- package/dist/esm/annotation/components/event.js +46 -0
- package/dist/esm/annotation/components/first.d.ts +2 -0
- package/dist/esm/annotation/components/first.js +18 -0
- package/dist/esm/annotation/components/group.d.ts +3 -0
- package/dist/esm/annotation/components/group.js +64 -0
- package/dist/esm/annotation/components/highlight.d.ts +14 -0
- package/dist/esm/annotation/components/highlight.js +838 -0
- package/dist/esm/annotation/components/index.d.ts +34 -0
- package/dist/esm/annotation/components/index.js +34 -0
- package/dist/esm/annotation/components/last.d.ts +2 -0
- package/dist/esm/annotation/components/last.js +18 -0
- package/dist/esm/annotation/components/max-x.d.ts +2 -0
- package/dist/esm/annotation/components/max-x.js +17 -0
- package/dist/esm/annotation/components/max-y.d.ts +2 -0
- package/dist/esm/annotation/components/max-y.js +17 -0
- package/dist/esm/annotation/components/mean.d.ts +2 -0
- package/dist/esm/annotation/components/mean.js +40 -0
- package/dist/esm/annotation/components/median.d.ts +2 -0
- package/dist/esm/annotation/components/median.js +32 -0
- package/dist/esm/annotation/components/min-x.d.ts +2 -0
- package/dist/esm/annotation/components/min-x.js +17 -0
- package/dist/esm/annotation/components/min-y.d.ts +2 -0
- package/dist/esm/annotation/components/min-y.js +17 -0
- package/dist/esm/annotation/components/outlier.d.ts +3 -0
- package/dist/esm/annotation/components/outlier.js +98 -0
- package/dist/esm/annotation/components/path.d.ts +20 -0
- package/dist/esm/annotation/components/path.js +165 -0
- package/dist/esm/annotation/components/peak.d.ts +2 -0
- package/dist/esm/annotation/components/peak.js +20 -0
- package/dist/esm/annotation/components/point.d.ts +26 -0
- package/dist/esm/annotation/components/point.js +277 -0
- package/dist/esm/annotation/components/quadrant.d.ts +3 -0
- package/dist/esm/annotation/components/quadrant.js +83 -0
- package/dist/esm/annotation/components/quantile.d.ts +2 -0
- package/dist/esm/annotation/components/quantile.js +32 -0
- package/dist/esm/annotation/components/range-inside.d.ts +2 -0
- package/dist/esm/annotation/components/range-inside.js +55 -0
- package/dist/esm/annotation/components/range-outside.d.ts +2 -0
- package/dist/esm/annotation/components/range-outside.js +55 -0
- package/dist/esm/annotation/components/range-x.d.ts +2 -0
- package/dist/esm/annotation/components/range-x.js +15 -0
- package/dist/esm/annotation/components/range-y.d.ts +2 -0
- package/dist/esm/annotation/components/range-y.js +15 -0
- package/dist/esm/annotation/components/range.d.ts +15 -0
- package/dist/esm/annotation/components/range.js +92 -0
- package/dist/esm/annotation/components/target.d.ts +2 -0
- package/dist/esm/annotation/components/target.js +44 -0
- package/dist/esm/annotation/components/text.d.ts +15 -0
- package/dist/esm/annotation/components/text.js +78 -0
- package/dist/esm/annotation/components/threshold-highlight.d.ts +3 -0
- package/dist/esm/annotation/components/threshold-highlight.js +297 -0
- package/dist/esm/annotation/components/threshold-x.d.ts +2 -0
- package/dist/esm/annotation/components/threshold-x.js +23 -0
- package/dist/esm/annotation/components/threshold-y.d.ts +2 -0
- package/dist/esm/annotation/components/threshold-y.js +24 -0
- package/dist/esm/annotation/components/top-n.d.ts +2 -0
- package/dist/esm/annotation/components/top-n.js +42 -0
- package/dist/esm/annotation/components/valley.d.ts +2 -0
- package/dist/esm/annotation/components/valley.js +20 -0
- package/dist/esm/annotation/index.d.ts +1 -0
- package/dist/esm/annotation/index.js +1 -0
- package/dist/esm/annotation/label.d.ts +38 -0
- package/dist/esm/annotation/label.js +449 -0
- package/dist/esm/annotation/layout.d.ts +12 -0
- package/dist/esm/annotation/layout.js +182 -0
- package/dist/esm/annotation/merge.d.ts +19 -0
- package/dist/esm/annotation/merge.js +67 -0
- package/dist/esm/annotation/registry.d.ts +190 -0
- package/dist/esm/annotation/registry.js +220 -0
- package/dist/esm/annotation/runtime/g2.d.ts +90 -0
- package/dist/esm/annotation/runtime/g2.js +754 -0
- package/dist/esm/annotation/runtime/g6.d.ts +40 -0
- package/dist/esm/annotation/runtime/g6.js +447 -0
- package/dist/esm/annotation/runtime/index.d.ts +11 -0
- package/dist/esm/annotation/runtime/index.js +26 -0
- package/dist/esm/annotation/runtime/summary.d.ts +17 -0
- package/dist/esm/annotation/runtime/summary.js +21 -0
- package/dist/esm/annotation/runtime/table.d.ts +16 -0
- package/dist/esm/annotation/runtime/table.js +21 -0
- package/dist/esm/annotation/utils.d.ts +40 -0
- package/dist/esm/annotation/utils.js +370 -0
- package/dist/esm/theme/annotation.d.ts +236 -0
- package/dist/esm/theme/annotation.js +186 -0
- package/dist/esm/theme/g2.js +2 -10
- package/dist/esm/theme/g6.js +1 -1
- package/dist/esm/theme/summary.js +1 -1
- package/dist/esm/types/annotation.d.ts +310 -0
- package/dist/esm/types/annotation.js +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/util/axis.d.ts +28 -0
- package/dist/esm/util/axis.js +222 -0
- package/dist/esm/util/components.d.ts +0 -10
- package/dist/esm/util/components.js +24 -69
- package/dist/esm/util/index.d.ts +7 -4
- package/dist/esm/util/index.js +7 -4
- package/dist/esm/vis/area/index.d.ts +2 -0
- package/dist/esm/vis/area/index.js +32 -9
- package/dist/esm/vis/bar/index.d.ts +2 -0
- package/dist/esm/vis/bar/index.js +37 -6
- package/dist/esm/vis/boxplot/index.js +10 -2
- package/dist/esm/vis/column/index.d.ts +2 -0
- package/dist/esm/vis/column/index.js +33 -12
- package/dist/esm/vis/dual-axes/index.js +10 -10
- package/dist/esm/vis/fishbone-diagram/index.js +1 -1
- package/dist/esm/vis/flow-diagram/index.js +1 -1
- package/dist/esm/vis/funnel/index.js +2 -7
- package/dist/esm/vis/histogram/index.js +4 -3
- package/dist/esm/vis/indented-tree/index.js +1 -1
- package/dist/esm/vis/line/index.d.ts +2 -0
- package/dist/esm/vis/line/index.js +31 -9
- package/dist/esm/vis/liquid/index.js +1 -1
- package/dist/esm/vis/mindmap/index.js +1 -1
- package/dist/esm/vis/network-graph/index.d.ts +2 -0
- package/dist/esm/vis/network-graph/index.js +29 -2
- package/dist/esm/vis/organization-chart/index.js +1 -1
- package/dist/esm/vis/pie/index.d.ts +2 -0
- package/dist/esm/vis/pie/index.js +25 -8
- package/dist/esm/vis/radar/index.js +1 -3
- package/dist/esm/vis/sankey/index.js +15 -1
- package/dist/esm/vis/scatter/index.d.ts +10 -3
- package/dist/esm/vis/scatter/index.js +28 -5
- package/dist/esm/vis/summary/index.d.ts +9 -2
- package/dist/esm/vis/summary/index.js +31 -13
- package/dist/esm/vis/table/index.d.ts +2 -0
- package/dist/esm/vis/table/index.js +50 -33
- package/dist/esm/vis/venn/index.js +1 -1
- package/dist/esm/vis/violin/index.js +10 -2
- package/dist/esm/vis/waterfall/index.js +16 -13
- package/dist/esm/vis/word-cloud/index.js +1 -3
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { rankedLabels } from "../label";
|
|
2
|
+
import { selectRank, selectRows } from "../utils";
|
|
3
|
+
import { highlight } from "./highlight";
|
|
4
|
+
export var topN = {
|
|
5
|
+
g2: function g2(annotations, _ref) {
|
|
6
|
+
var mapping = _ref.mapping;
|
|
7
|
+
return annotations.flatMap(function (annotation) {
|
|
8
|
+
var rows = selectRows(mapping.data, annotation.data);
|
|
9
|
+
var field = mapping.y;
|
|
10
|
+
return selectRank(rows, field, annotation.n, true).flatMap(function (row, index) {
|
|
11
|
+
var _annotation$label;
|
|
12
|
+
var highlights = highlight.create({
|
|
13
|
+
data: [row],
|
|
14
|
+
label: (_annotation$label = annotation.label) !== null && _annotation$label !== void 0 ? _annotation$label : "Top ".concat(index + 1),
|
|
15
|
+
style: annotation.style
|
|
16
|
+
});
|
|
17
|
+
highlights.forEach(function (highlight) {
|
|
18
|
+
return rankedLabels.set(highlight, annotation);
|
|
19
|
+
});
|
|
20
|
+
return highlights;
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
table: function table(annotations, _ref2) {
|
|
25
|
+
var data = _ref2.data;
|
|
26
|
+
return annotations.flatMap(function (annotation) {
|
|
27
|
+
var rows = selectRows(data, annotation.data.row);
|
|
28
|
+
var field = annotation.data.field;
|
|
29
|
+
return selectRank(rows, field, annotation.n, true).flatMap(function (row, index) {
|
|
30
|
+
var _annotation$label2;
|
|
31
|
+
return highlight.create({
|
|
32
|
+
data: [{
|
|
33
|
+
row: row,
|
|
34
|
+
column: annotation.data.column
|
|
35
|
+
}],
|
|
36
|
+
label: (_annotation$label2 = annotation.label) !== null && _annotation$label2 !== void 0 ? _annotation$label2 : "Top ".concat(index + 1),
|
|
37
|
+
style: annotation.style
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { selectLocalExtrema, selectRows } from "../utils";
|
|
2
|
+
import { highlight } from "./highlight";
|
|
3
|
+
export var valley = {
|
|
4
|
+
g2: function g2(annotations, _ref) {
|
|
5
|
+
var mapping = _ref.mapping;
|
|
6
|
+
return annotations.flatMap(function (annotation) {
|
|
7
|
+
var selected = new Set(selectRows(mapping.data, annotation.data));
|
|
8
|
+
return selectLocalExtrema(mapping.data, mapping.y, false, mapping.series, annotation).filter(function (row) {
|
|
9
|
+
return selected.has(row);
|
|
10
|
+
}).flatMap(function (row) {
|
|
11
|
+
var _annotation$label;
|
|
12
|
+
return highlight.create({
|
|
13
|
+
data: [row],
|
|
14
|
+
label: (_annotation$label = annotation.label) !== null && _annotation$label !== void 0 ? _annotation$label : "Valley: ".concat(row[mapping.y]),
|
|
15
|
+
style: annotation.style
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { bindAnnotations } from './runtime';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { bindAnnotations } from "./runtime";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { getAnnotationDefaults } from '../theme/annotation';
|
|
2
|
+
import type { ConnectorShape } from './components/connector';
|
|
3
|
+
import type { Box, Point } from './layout';
|
|
4
|
+
import type { AnnotationResult, RendererAnnotation } from './registry';
|
|
5
|
+
import type { G2AnnotationContext, LabelElement, Scene } from './runtime/g2';
|
|
6
|
+
/** Only automatically computed pie percentages may reuse a native percentage label. */
|
|
7
|
+
export declare const nativePercentageLabels: WeakSet<object>;
|
|
8
|
+
/** Composing annotations supply connector geometry after their targets are measured. */
|
|
9
|
+
export type LabelConnector = (anchors: Point[], geometry: {
|
|
10
|
+
points: Point[];
|
|
11
|
+
y?: number;
|
|
12
|
+
y1?: number;
|
|
13
|
+
}[], coordinate: ReturnType<G2AnnotationContext<object>['getCoordinate']> | undefined, index: number, count: number) => ConnectorShape | undefined;
|
|
14
|
+
export declare const labelConnectors: WeakMap<object, LabelConnector>;
|
|
15
|
+
/** Ranks from one analysis annotation share a native label configuration. */
|
|
16
|
+
export declare const rankedLabels: WeakMap<object, object>;
|
|
17
|
+
/** Group explanations identify their selected native colors without adding public options. */
|
|
18
|
+
export declare const groupLabels: WeakSet<object>;
|
|
19
|
+
type Defaults = ReturnType<typeof getAnnotationDefaults>;
|
|
20
|
+
/** Shared DOM labels; renderers provide the current geometry of their own targets. */
|
|
21
|
+
export declare function bindLabels(container: HTMLElement, content: HTMLElement, items: {
|
|
22
|
+
annotation: Pick<Extract<RendererAnnotation<Record<string, unknown>, 'g2'>, {
|
|
23
|
+
type: 'highlight';
|
|
24
|
+
}>, 'label' | 'style'>;
|
|
25
|
+
bounds: () => DOMRect | DOMRect[] | undefined;
|
|
26
|
+
}[], defaults: Defaults): () => void;
|
|
27
|
+
/** Reserve space inside the measured card, so color keys participate in label avoidance. */
|
|
28
|
+
export declare function getLabelColorWidth(colors: string[]): number;
|
|
29
|
+
/** Native canvas color keys stay inside their label and share its movement and cleanup. */
|
|
30
|
+
export declare function drawLabelColors(label: Pick<LabelElement, 'appendChild'>, scene: Scene, colors: string[], box: Box, padding: number): void;
|
|
31
|
+
/** Decide after native overlap hiding, so a hidden percentage never suppresses the fallback. */
|
|
32
|
+
export declare function bindPieLabels<T extends object>(selections: {
|
|
33
|
+
annotation: Extract<RendererAnnotation<T, 'g2'>, {
|
|
34
|
+
type: 'highlight';
|
|
35
|
+
}>;
|
|
36
|
+
rows: T[];
|
|
37
|
+
}[], context: G2AnnotationContext<T>): AnnotationResult;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
16
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
18
|
+
/** Only automatically computed pie percentages may reuse a native percentage label. */
|
|
19
|
+
export var nativePercentageLabels = new WeakSet();
|
|
20
|
+
|
|
21
|
+
/** Composing annotations supply connector geometry after their targets are measured. */
|
|
22
|
+
|
|
23
|
+
export var labelConnectors = new WeakMap();
|
|
24
|
+
|
|
25
|
+
/** Ranks from one analysis annotation share a native label configuration. */
|
|
26
|
+
export var rankedLabels = new WeakMap();
|
|
27
|
+
|
|
28
|
+
/** Group explanations identify their selected native colors without adding public options. */
|
|
29
|
+
export var groupLabels = new WeakSet();
|
|
30
|
+
var colorSize = 10;
|
|
31
|
+
var colorGap = 6;
|
|
32
|
+
/** Shared DOM labels; renderers provide the current geometry of their own targets. */
|
|
33
|
+
export function bindLabels(container, content, items, defaults) {
|
|
34
|
+
var labeled = items.filter(function (_ref) {
|
|
35
|
+
var annotation = _ref.annotation;
|
|
36
|
+
return annotation.label;
|
|
37
|
+
});
|
|
38
|
+
if (!labeled.length) return function () {};
|
|
39
|
+
var previous = container.getAttribute('style');
|
|
40
|
+
var previousContent = content.getAttribute('style');
|
|
41
|
+
var notes = document.createElement('aside');
|
|
42
|
+
notes.className = 'annotation-labels';
|
|
43
|
+
notes.setAttribute('aria-label', 'Annotations');
|
|
44
|
+
Object.assign(notes.style, {
|
|
45
|
+
display: 'grid',
|
|
46
|
+
alignContent: 'start',
|
|
47
|
+
justifyItems: 'start',
|
|
48
|
+
gap: "".concat(defaults.highlight.labelGap, "px"),
|
|
49
|
+
minWidth: '0',
|
|
50
|
+
width: 'max-content',
|
|
51
|
+
maxWidth: "".concat(defaults.labels.highlight.maxWidth, "px")
|
|
52
|
+
});
|
|
53
|
+
var cards = labeled.map(function (_ref2) {
|
|
54
|
+
var _annotation$style$lab, _annotation$style, _annotation$style$lab2, _annotation$style2, _annotation$style$str, _annotation$style3;
|
|
55
|
+
var annotation = _ref2.annotation;
|
|
56
|
+
var card = document.createElement('div');
|
|
57
|
+
card.textContent = annotation.label;
|
|
58
|
+
Object.assign(card.style, {
|
|
59
|
+
position: 'relative',
|
|
60
|
+
zIndex: '1',
|
|
61
|
+
color: (_annotation$style$lab = (_annotation$style = annotation.style) === null || _annotation$style === void 0 ? void 0 : _annotation$style.labelFill) !== null && _annotation$style$lab !== void 0 ? _annotation$style$lab : defaults.labelFill,
|
|
62
|
+
fontFamily: defaults.fontFamily,
|
|
63
|
+
fontSize: "".concat((_annotation$style$lab2 = (_annotation$style2 = annotation.style) === null || _annotation$style2 === void 0 ? void 0 : _annotation$style2.labelFontSize) !== null && _annotation$style$lab2 !== void 0 ? _annotation$style$lab2 : defaults.labelFontSize, "px"),
|
|
64
|
+
fontWeight: String(defaults.fontWeight),
|
|
65
|
+
lineHeight: '1.6',
|
|
66
|
+
overflowWrap: 'anywhere',
|
|
67
|
+
background: defaults.highlight.labelBackground,
|
|
68
|
+
border: "1px solid ".concat(defaults.highlight.labelBorder),
|
|
69
|
+
borderLeft: "3px solid ".concat((_annotation$style$str = (_annotation$style3 = annotation.style) === null || _annotation$style3 === void 0 ? void 0 : _annotation$style3.stroke) !== null && _annotation$style$str !== void 0 ? _annotation$style$str : defaults.stroke),
|
|
70
|
+
borderRadius: '6px',
|
|
71
|
+
width: 'fit-content',
|
|
72
|
+
maxWidth: '100%',
|
|
73
|
+
boxSizing: 'border-box',
|
|
74
|
+
padding: "".concat(defaults.labels.highlight.padding[0], "px ").concat(defaults.labels.highlight.padding[1], "px")
|
|
75
|
+
});
|
|
76
|
+
notes.appendChild(card);
|
|
77
|
+
return card;
|
|
78
|
+
});
|
|
79
|
+
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
80
|
+
svg.classList.add('annotation-leaders');
|
|
81
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
82
|
+
Object.assign(svg.style, {
|
|
83
|
+
position: 'absolute',
|
|
84
|
+
top: '0',
|
|
85
|
+
left: '0',
|
|
86
|
+
width: '100%',
|
|
87
|
+
height: '100%',
|
|
88
|
+
overflow: 'visible',
|
|
89
|
+
pointerEvents: 'none'
|
|
90
|
+
});
|
|
91
|
+
Object.assign(container.style, {
|
|
92
|
+
position: 'relative',
|
|
93
|
+
display: 'grid',
|
|
94
|
+
gap: "".concat(defaults.highlight.labelGap * 2, "px"),
|
|
95
|
+
alignItems: 'start',
|
|
96
|
+
alignContent: 'start',
|
|
97
|
+
justifyContent: 'start'
|
|
98
|
+
});
|
|
99
|
+
Object.assign(content.style, {
|
|
100
|
+
minWidth: '0',
|
|
101
|
+
width: 'fit-content',
|
|
102
|
+
maxWidth: '100%'
|
|
103
|
+
});
|
|
104
|
+
container.append(notes, svg);
|
|
105
|
+
var disposed = false;
|
|
106
|
+
var draw = function draw() {
|
|
107
|
+
if (disposed) return;
|
|
108
|
+
// Measure intrinsic content before reserving room for explanations.
|
|
109
|
+
container.style.gridTemplateColumns = 'minmax(0, max-content)';
|
|
110
|
+
notes.style.position = '';
|
|
111
|
+
notes.style.height = '';
|
|
112
|
+
notes.style.width = 'max-content';
|
|
113
|
+
cards.forEach(function (card) {
|
|
114
|
+
return Object.assign(card.style, {
|
|
115
|
+
position: 'relative',
|
|
116
|
+
top: ''
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
var style = getComputedStyle(container);
|
|
120
|
+
var width = container.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
|
|
121
|
+
notes.style.maxWidth = "".concat(Math.min(defaults.labels.highlight.maxWidth, width), "px");
|
|
122
|
+
var gap = defaults.highlight.labelGap * 2;
|
|
123
|
+
var side = content.getBoundingClientRect().width + gap + notes.offsetWidth <= width || width >= 650;
|
|
124
|
+
if (side) {
|
|
125
|
+
container.style.gridTemplateColumns = 'minmax(0, max-content) max-content';
|
|
126
|
+
notes.style.width = "".concat(notes.offsetWidth, "px");
|
|
127
|
+
notes.style.position = 'relative';
|
|
128
|
+
}
|
|
129
|
+
var root = container.getBoundingClientRect();
|
|
130
|
+
var body = content.getBoundingClientRect();
|
|
131
|
+
var targets = labeled.map(function (item) {
|
|
132
|
+
var bounds = item.bounds();
|
|
133
|
+
return Array.isArray(bounds) ? bounds : bounds ? [bounds] : [];
|
|
134
|
+
});
|
|
135
|
+
if (side) {
|
|
136
|
+
var placements = cards.map(function (card, index) {
|
|
137
|
+
return {
|
|
138
|
+
card: card,
|
|
139
|
+
height: card.offsetHeight,
|
|
140
|
+
y: targets[index].length ? targets[index].reduce(function (sum, box) {
|
|
141
|
+
return sum + (box.top + box.bottom) / 2;
|
|
142
|
+
}, 0) / targets[index].length - body.top : 0,
|
|
143
|
+
top: 0
|
|
144
|
+
};
|
|
145
|
+
}).sort(function (a, b) {
|
|
146
|
+
return a.y - b.y;
|
|
147
|
+
});
|
|
148
|
+
var height = Math.max(body.height, placements.reduce(function (sum, item) {
|
|
149
|
+
return sum + item.height;
|
|
150
|
+
}, 0) + (cards.length - 1) * defaults.highlight.labelGap);
|
|
151
|
+
var bottom = 0;
|
|
152
|
+
var _iterator = _createForOfIteratorHelper(placements),
|
|
153
|
+
_step;
|
|
154
|
+
try {
|
|
155
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
156
|
+
var item = _step.value;
|
|
157
|
+
item.top = Math.max(bottom, item.y - item.height / 2);
|
|
158
|
+
bottom = item.top + item.height + defaults.highlight.labelGap;
|
|
159
|
+
}
|
|
160
|
+
} catch (err) {
|
|
161
|
+
_iterator.e(err);
|
|
162
|
+
} finally {
|
|
163
|
+
_iterator.f();
|
|
164
|
+
}
|
|
165
|
+
bottom = height;
|
|
166
|
+
var _iterator2 = _createForOfIteratorHelper(placements.reverse()),
|
|
167
|
+
_step2;
|
|
168
|
+
try {
|
|
169
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
170
|
+
var _item = _step2.value;
|
|
171
|
+
_item.top = Math.min(_item.top, bottom - _item.height);
|
|
172
|
+
bottom = _item.top - defaults.highlight.labelGap;
|
|
173
|
+
Object.assign(_item.card.style, {
|
|
174
|
+
position: 'absolute',
|
|
175
|
+
top: "".concat(_item.top, "px")
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
} catch (err) {
|
|
179
|
+
_iterator2.e(err);
|
|
180
|
+
} finally {
|
|
181
|
+
_iterator2.f();
|
|
182
|
+
}
|
|
183
|
+
notes.style.height = "".concat(height, "px");
|
|
184
|
+
}
|
|
185
|
+
svg.textContent = '';
|
|
186
|
+
var _iterator3 = _createForOfIteratorHelper(targets.entries()),
|
|
187
|
+
_step3;
|
|
188
|
+
try {
|
|
189
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
190
|
+
var _step3$value = _slicedToArray(_step3.value, 2),
|
|
191
|
+
_index = _step3$value[0],
|
|
192
|
+
bounds = _step3$value[1];
|
|
193
|
+
var connect = labelConnectors.get(labeled[_index].annotation);
|
|
194
|
+
if (connect) {
|
|
195
|
+
var _labeled$_index$annot, _labeled$_index$annot2;
|
|
196
|
+
var points = bounds.filter(function (box) {
|
|
197
|
+
return box.width && box.height;
|
|
198
|
+
}).flatMap(function (box) {
|
|
199
|
+
return [[Math.min(box.right, body.right) - root.left, box.top - root.top], [Math.min(box.right, body.right) - root.left, box.bottom - root.top]];
|
|
200
|
+
});
|
|
201
|
+
var bracket = connect(points, [], undefined, _index, labeled.length);
|
|
202
|
+
if (!bracket) continue;
|
|
203
|
+
var card = cards[_index].getBoundingClientRect();
|
|
204
|
+
var endX = (side ? card.left : card.right) - root.left;
|
|
205
|
+
var endY = card.top + card.height / 2 - root.top;
|
|
206
|
+
var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
207
|
+
var outline = bracket.paths.map(function (points) {
|
|
208
|
+
return points.map(function (_ref3, i) {
|
|
209
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
210
|
+
x = _ref4[0],
|
|
211
|
+
y = _ref4[1];
|
|
212
|
+
return "".concat(i ? 'L' : 'M').concat(x, ",").concat(y);
|
|
213
|
+
}).join(' ');
|
|
214
|
+
}).join(' ');
|
|
215
|
+
var leader = side ? "H".concat(endX, " V").concat(endY) : "H".concat(Math.max(bracket.anchor[0] + 8, body.right - root.left + gap / 2), " V").concat(endY, " H").concat(endX);
|
|
216
|
+
path.setAttribute('d', "".concat(outline, " M").concat(bracket.anchor.join(','), " ").concat(leader));
|
|
217
|
+
path.setAttribute('fill', 'none');
|
|
218
|
+
path.setAttribute('stroke', (_labeled$_index$annot = (_labeled$_index$annot2 = labeled[_index].annotation.style) === null || _labeled$_index$annot2 === void 0 ? void 0 : _labeled$_index$annot2.stroke) !== null && _labeled$_index$annot !== void 0 ? _labeled$_index$annot : defaults.stroke);
|
|
219
|
+
path.setAttribute('stroke-width', '1.5');
|
|
220
|
+
path.setAttribute('stroke-linejoin', 'round');
|
|
221
|
+
svg.appendChild(path);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
var _iterator4 = _createForOfIteratorHelper(bounds),
|
|
225
|
+
_step4;
|
|
226
|
+
try {
|
|
227
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
228
|
+
var _labeled$_index$annot3, _labeled$_index$annot4;
|
|
229
|
+
var target = _step4.value;
|
|
230
|
+
var _card = cards[_index].getBoundingClientRect();
|
|
231
|
+
if (!target || !target.width || !target.height) continue;
|
|
232
|
+
var x = Math.max(body.left, Math.min(target.right, body.right)) - root.left;
|
|
233
|
+
var y = (target.top + target.bottom) / 2 - root.top;
|
|
234
|
+
var _endX = (side ? _card.left : _card.right) - root.left;
|
|
235
|
+
var _endY = _card.top + _card.height / 2 - root.top;
|
|
236
|
+
var lane = side ? (body.right - root.left + _endX) / 2 : body.right - root.left + gap / 2;
|
|
237
|
+
var _path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
238
|
+
_path.setAttribute('d', "M".concat(x, ",").concat(y, " H").concat(lane, " V").concat(_endY, " H").concat(_endX));
|
|
239
|
+
_path.setAttribute('fill', 'none');
|
|
240
|
+
_path.setAttribute('stroke', (_labeled$_index$annot3 = (_labeled$_index$annot4 = labeled[_index].annotation.style) === null || _labeled$_index$annot4 === void 0 ? void 0 : _labeled$_index$annot4.stroke) !== null && _labeled$_index$annot3 !== void 0 ? _labeled$_index$annot3 : defaults.stroke);
|
|
241
|
+
_path.setAttribute('stroke-width', '1.5');
|
|
242
|
+
_path.setAttribute('stroke-linejoin', 'round');
|
|
243
|
+
svg.appendChild(_path);
|
|
244
|
+
}
|
|
245
|
+
} catch (err) {
|
|
246
|
+
_iterator4.e(err);
|
|
247
|
+
} finally {
|
|
248
|
+
_iterator4.f();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
} catch (err) {
|
|
252
|
+
_iterator3.e(err);
|
|
253
|
+
} finally {
|
|
254
|
+
_iterator3.f();
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
var frame;
|
|
258
|
+
var scheduleDraw = function scheduleDraw() {
|
|
259
|
+
if (disposed || frame !== undefined) return;
|
|
260
|
+
frame = requestAnimationFrame(function () {
|
|
261
|
+
frame = undefined;
|
|
262
|
+
draw();
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
var resize = new ResizeObserver(scheduleDraw);
|
|
266
|
+
resize.observe(container);
|
|
267
|
+
resize.observe(content);
|
|
268
|
+
content.addEventListener('scroll', scheduleDraw, true);
|
|
269
|
+
document.fonts.ready.then(scheduleDraw);
|
|
270
|
+
document.fonts.addEventListener('loadingdone', scheduleDraw);
|
|
271
|
+
draw();
|
|
272
|
+
return function () {
|
|
273
|
+
disposed = true;
|
|
274
|
+
if (frame !== undefined) cancelAnimationFrame(frame);
|
|
275
|
+
resize.disconnect();
|
|
276
|
+
content.removeEventListener('scroll', scheduleDraw, true);
|
|
277
|
+
document.fonts.removeEventListener('loadingdone', scheduleDraw);
|
|
278
|
+
notes.remove();
|
|
279
|
+
svg.remove();
|
|
280
|
+
if (previous === null) container.removeAttribute('style');else container.setAttribute('style', previous);
|
|
281
|
+
if (previousContent === null) content.removeAttribute('style');else content.setAttribute('style', previousContent);
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Reserve space inside the measured card, so color keys participate in label avoidance. */
|
|
286
|
+
export function getLabelColorWidth(colors) {
|
|
287
|
+
return colors.length * (colorSize + colorGap);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Native canvas color keys stay inside their label and share its movement and cleanup. */
|
|
291
|
+
export function drawLabelColors(label, scene, colors, box, padding) {
|
|
292
|
+
var keys = scene.createElement('g', {
|
|
293
|
+
className: 'annotation-label-colors',
|
|
294
|
+
style: {
|
|
295
|
+
pointerEvents: 'none'
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
label.appendChild(keys);
|
|
299
|
+
colors.forEach(function (fill, index) {
|
|
300
|
+
return keys.appendChild(scene.createElement('rect', {
|
|
301
|
+
className: 'annotation-label-color',
|
|
302
|
+
style: {
|
|
303
|
+
x: box.x + padding + index * (colorSize + colorGap),
|
|
304
|
+
y: box.y + (box.height - colorSize) / 2,
|
|
305
|
+
width: colorSize,
|
|
306
|
+
height: colorSize,
|
|
307
|
+
radius: 2,
|
|
308
|
+
fill: fill,
|
|
309
|
+
stroke: 'none',
|
|
310
|
+
pointerEvents: 'none'
|
|
311
|
+
}
|
|
312
|
+
}));
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Decide after native overlap hiding, so a hidden percentage never suppresses the fallback. */
|
|
317
|
+
export function bindPieLabels(selections, context) {
|
|
318
|
+
bindRankLabels(selections, context);
|
|
319
|
+
var automatic = selections.filter(function (_ref5) {
|
|
320
|
+
var annotation = _ref5.annotation;
|
|
321
|
+
return nativePercentageLabels.has(annotation);
|
|
322
|
+
});
|
|
323
|
+
if (!automatic.length) return {};
|
|
324
|
+
return {
|
|
325
|
+
update: function update() {
|
|
326
|
+
var labels = context.getScene().querySelectorAll('.label');
|
|
327
|
+
var _iterator5 = _createForOfIteratorHelper(automatic),
|
|
328
|
+
_step5;
|
|
329
|
+
try {
|
|
330
|
+
var _loop = function _loop() {
|
|
331
|
+
var _step5$value = _step5.value,
|
|
332
|
+
annotation = _step5$value.annotation,
|
|
333
|
+
rows = _step5$value.rows;
|
|
334
|
+
var native = labels.find(function (label) {
|
|
335
|
+
var _label$__data__, _label$style$opacity;
|
|
336
|
+
var element = (_label$__data__ = label.__data__) === null || _label$__data__ === void 0 ? void 0 : _label$__data__.dependentElement;
|
|
337
|
+
return label.getAttribute('annotationNativePercentage') && element && rows.includes(element.__data__.data) && label.style.visibility !== 'hidden' && Number((_label$style$opacity = label.style.opacity) !== null && _label$style$opacity !== void 0 ? _label$style$opacity : 1) > 0 && label.querySelectorAll('text').some(function (text) {
|
|
338
|
+
var _text$style$opacity, _text$style$fillOpaci;
|
|
339
|
+
return text.style.visibility !== 'hidden' && Number((_text$style$opacity = text.style.opacity) !== null && _text$style$opacity !== void 0 ? _text$style$opacity : 1) > 0 && Number((_text$style$fillOpaci = text.style.fillOpacity) !== null && _text$style$fillOpaci !== void 0 ? _text$style$fillOpaci : 1) > 0;
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
var _iterator6 = _createForOfIteratorHelper(labels),
|
|
343
|
+
_step6;
|
|
344
|
+
try {
|
|
345
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
346
|
+
var _label$__data__2;
|
|
347
|
+
var label = _step6.value;
|
|
348
|
+
var element = (_label$__data__2 = label.__data__) === null || _label$__data__2 === void 0 ? void 0 : _label$__data__2.dependentElement;
|
|
349
|
+
if ((element === null || element === void 0 ? void 0 : element.getAttribute('annotationSelection')) !== annotation) continue;
|
|
350
|
+
var visibility = native ? 'hidden' : 'visible';
|
|
351
|
+
// G2 applies text, background and connector styles separately when labels redraw.
|
|
352
|
+
label.attr({
|
|
353
|
+
visibility: visibility,
|
|
354
|
+
backgroundVisibility: visibility,
|
|
355
|
+
connectorVisibility: visibility
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
} catch (err) {
|
|
359
|
+
_iterator6.e(err);
|
|
360
|
+
} finally {
|
|
361
|
+
_iterator6.f();
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
365
|
+
_loop();
|
|
366
|
+
}
|
|
367
|
+
} catch (err) {
|
|
368
|
+
_iterator5.e(err);
|
|
369
|
+
} finally {
|
|
370
|
+
_iterator5.f();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** Ranks from one analysis annotation share its native label configuration. */
|
|
377
|
+
function bindRankLabels(selections, context) {
|
|
378
|
+
var _mark$labels;
|
|
379
|
+
var groups = new Map();
|
|
380
|
+
var _iterator7 = _createForOfIteratorHelper(selections),
|
|
381
|
+
_step7;
|
|
382
|
+
try {
|
|
383
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
384
|
+
var _step7$value = _step7.value,
|
|
385
|
+
annotation = _step7$value.annotation,
|
|
386
|
+
rows = _step7$value.rows;
|
|
387
|
+
var source = rankedLabels.get(annotation);
|
|
388
|
+
if (!source || !annotation.label) continue;
|
|
389
|
+
var group = groups.get(source);
|
|
390
|
+
if (!group) {
|
|
391
|
+
group = {
|
|
392
|
+
annotation: annotation,
|
|
393
|
+
text: new Map()
|
|
394
|
+
};
|
|
395
|
+
groups.set(source, group);
|
|
396
|
+
}
|
|
397
|
+
var _iterator8 = _createForOfIteratorHelper(rows),
|
|
398
|
+
_step8;
|
|
399
|
+
try {
|
|
400
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
401
|
+
var row = _step8.value;
|
|
402
|
+
group.text.set(row, annotation.label);
|
|
403
|
+
}
|
|
404
|
+
} catch (err) {
|
|
405
|
+
_iterator8.e(err);
|
|
406
|
+
} finally {
|
|
407
|
+
_iterator8.f();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
} catch (err) {
|
|
411
|
+
_iterator7.e(err);
|
|
412
|
+
} finally {
|
|
413
|
+
_iterator7.f();
|
|
414
|
+
}
|
|
415
|
+
if (!groups.size) return;
|
|
416
|
+
var mark = context.sourceMarks[0];
|
|
417
|
+
mark.labels = [].concat(_toConsumableArray((_mark$labels = mark.labels) !== null && _mark$labels !== void 0 ? _mark$labels : []), _toConsumableArray(_toConsumableArray(groups.values()).map(function (_ref6) {
|
|
418
|
+
var _annotation$style4;
|
|
419
|
+
var annotation = _ref6.annotation,
|
|
420
|
+
_text = _ref6.text;
|
|
421
|
+
return _objectSpread(_objectSpread({}, context.getTextStyle(annotation)), {}, {
|
|
422
|
+
text: function text(row) {
|
|
423
|
+
var _text$get;
|
|
424
|
+
return (_text$get = _text.get(row)) !== null && _text$get !== void 0 ? _text$get : '';
|
|
425
|
+
},
|
|
426
|
+
position: 'inside',
|
|
427
|
+
annotationLabel: 'highlight',
|
|
428
|
+
annotationInside: true,
|
|
429
|
+
background: false,
|
|
430
|
+
connector: false,
|
|
431
|
+
transform: [{
|
|
432
|
+
type: function type() {
|
|
433
|
+
return removeEmptyLabels;
|
|
434
|
+
}
|
|
435
|
+
}].concat(_toConsumableArray(((_annotation$style4 = annotation.style) === null || _annotation$style4 === void 0 ? void 0 : _annotation$style4.labelFill) === undefined ? [{
|
|
436
|
+
type: 'contrastReverse'
|
|
437
|
+
}] : []))
|
|
438
|
+
});
|
|
439
|
+
})));
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// Native interval labels do not support selectors; remove empty candidates before layout.
|
|
443
|
+
function removeEmptyLabels(labels) {
|
|
444
|
+
return labels.filter(function (label) {
|
|
445
|
+
if (label.getAttribute('text')) return true;
|
|
446
|
+
label.destroy();
|
|
447
|
+
return false;
|
|
448
|
+
});
|
|
449
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Point = [number, number];
|
|
2
|
+
export interface Box {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export type Segment = [Point, Point];
|
|
9
|
+
/** Keep a preferred native position when clear; otherwise try nearby spaces and obstacle edges. */
|
|
10
|
+
export declare function placeLabel(anchor: Point, size: Point, view: Point, gap: number, boxes: Box[], segments: Segment[], preferred?: Point): Box;
|
|
11
|
+
/** Route only explanation leaders; explicit annotation lines retain their original geometry. */
|
|
12
|
+
export declare function routeLeader(anchor: Point, target: Box, boxes: Box[], segments: Segment[]): Point[];
|