@antv/gpt-vis 1.3.1 → 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/cjs/vis-wrapper/index.js +2 -1
- 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/esm/vis-wrapper/index.js +2 -1
- package/dist/umd/index.min.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/annotation/runtime/g2.ts
|
|
20
|
+
var g2_exports = {};
|
|
21
|
+
__export(g2_exports, {
|
|
22
|
+
bindAnnotations: () => bindAnnotations
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(g2_exports);
|
|
25
|
+
var import_annotation = require("../../theme/annotation");
|
|
26
|
+
var import_label = require("../label");
|
|
27
|
+
var import_layout = require("../layout");
|
|
28
|
+
var import_registry = require("../registry");
|
|
29
|
+
function axisValue(scale, value, center = true) {
|
|
30
|
+
var _a;
|
|
31
|
+
const { domain, type } = scale.getOptions();
|
|
32
|
+
if ((type === "band" || type === "point" || type === "ordinal") && !domain.includes(value))
|
|
33
|
+
throw new Error(`Invalid annotation: unknown category ${String(value)}.`);
|
|
34
|
+
return Number(scale.map(value)) + (center ? (((_a = scale.getBandWidth) == null ? void 0 : _a.call(scale, value)) ?? 0) / 2 : 0);
|
|
35
|
+
}
|
|
36
|
+
var annotationSource = ({ capture }) => capture;
|
|
37
|
+
function replaceOptions(chart, options) {
|
|
38
|
+
chart.children = [];
|
|
39
|
+
chart.map(() => ({}));
|
|
40
|
+
chart.options(options);
|
|
41
|
+
}
|
|
42
|
+
function bindAnnotations(binding) {
|
|
43
|
+
var _a;
|
|
44
|
+
if (binding.renderer !== "g2")
|
|
45
|
+
return;
|
|
46
|
+
const { chart, chartType, annotations, mapping, themeObject } = binding;
|
|
47
|
+
if (!(annotations == null ? void 0 : annotations.length))
|
|
48
|
+
return () => {
|
|
49
|
+
};
|
|
50
|
+
const defaults = (0, import_annotation.getAnnotationStyle)(themeObject);
|
|
51
|
+
const library = chart.getContext().library;
|
|
52
|
+
let disposed = false;
|
|
53
|
+
let visibleData = [];
|
|
54
|
+
let sourceGeometry = [];
|
|
55
|
+
let sourceRows = [];
|
|
56
|
+
let sourceScale;
|
|
57
|
+
let plotWidth = 0;
|
|
58
|
+
let plotHeight = 0;
|
|
59
|
+
let labelGutter = 0;
|
|
60
|
+
let coordinate;
|
|
61
|
+
const capture = (index, mark) => {
|
|
62
|
+
if (disposed)
|
|
63
|
+
return [index, mark];
|
|
64
|
+
sourceRows = mark.data;
|
|
65
|
+
visibleData = index.map((i) => mark.data[i]);
|
|
66
|
+
return [index, mark];
|
|
67
|
+
};
|
|
68
|
+
const originalRows = new Set(mapping.data);
|
|
69
|
+
const onlyAxisFields = (data) => Object.keys(data).every((key) => key === mapping.x || key === mapping.y);
|
|
70
|
+
const position = (data, coordinate2, useSourceGeometry = false) => {
|
|
71
|
+
var _a2;
|
|
72
|
+
const mapped = (row2) => [
|
|
73
|
+
axisValue(sourceScale.x, row2[mapping.x]),
|
|
74
|
+
axisValue(sourceScale.y, row2[mapping.y])
|
|
75
|
+
];
|
|
76
|
+
if (!useSourceGeometry && data[mapping.x] !== void 0 && data[mapping.y] !== void 0 && onlyAxisFields(data))
|
|
77
|
+
return mapped(data);
|
|
78
|
+
const matches = useSourceGeometry && originalRows.has(data) ? [data] : mapping.data.filter(
|
|
79
|
+
(row2) => Object.entries(data).every(([key, value]) => row2[key] === value)
|
|
80
|
+
);
|
|
81
|
+
if (matches.length !== 1)
|
|
82
|
+
throw new Error(
|
|
83
|
+
`Invalid annotation: position matches ${matches.length} data objects; expected one.`
|
|
84
|
+
);
|
|
85
|
+
const row = matches[0];
|
|
86
|
+
const same = (datum) => useSourceGeometry && originalRows.has(datum) ? datum === row : Object.entries(row).every(([key, value]) => datum[key] === value);
|
|
87
|
+
if (!visibleData.some(same))
|
|
88
|
+
return void 0;
|
|
89
|
+
if (!mapping.interval && source.type !== "interval") {
|
|
90
|
+
const index = sourceRows.findIndex(same);
|
|
91
|
+
const series = sourceGeometry.find((item) => {
|
|
92
|
+
var _a3;
|
|
93
|
+
return (_a3 = item.seriesIndex) == null ? void 0 : _a3.includes(index);
|
|
94
|
+
});
|
|
95
|
+
if (series) {
|
|
96
|
+
const point = series.points[series.seriesIndex.indexOf(index)];
|
|
97
|
+
return coordinate2.invert(point);
|
|
98
|
+
}
|
|
99
|
+
return mapped(row);
|
|
100
|
+
}
|
|
101
|
+
const target = sourceGeometry.find(({ data: data2 }) => same(data2));
|
|
102
|
+
if (!target)
|
|
103
|
+
return void 0;
|
|
104
|
+
if (chartType === "pie") {
|
|
105
|
+
const { y, y1 } = target;
|
|
106
|
+
if (!Number.isFinite(y) || !Number.isFinite(y1) || y === y1)
|
|
107
|
+
return void 0;
|
|
108
|
+
return [0.5, (y + y1) / 2];
|
|
109
|
+
}
|
|
110
|
+
if ((_a2 = coordinate2.getOptions().transformations) == null ? void 0 : _a2.some(([type]) => type === "polar")) {
|
|
111
|
+
const from = coordinate2.invert(target.points[0]);
|
|
112
|
+
const to = coordinate2.invert(target.points[2]);
|
|
113
|
+
const end = to[1] < from[1] - 1e-6 ? to[1] + 1 : to[1];
|
|
114
|
+
return [(from[0] + to[0]) / 2, (from[1] + end) / 2 % 1];
|
|
115
|
+
}
|
|
116
|
+
const [a, b] = target.points;
|
|
117
|
+
return coordinate2.invert([(a[0] + b[0]) / 2, (a[1] + b[1]) / 2]);
|
|
118
|
+
};
|
|
119
|
+
function getTextStyle(annotation) {
|
|
120
|
+
var _a2, _b;
|
|
121
|
+
const label = defaults.labels[annotation.type];
|
|
122
|
+
const fontSize = ((_a2 = annotation.style) == null ? void 0 : _a2.labelFontSize) ?? defaults.labelFontSize;
|
|
123
|
+
return {
|
|
124
|
+
fill: ((_b = annotation.style) == null ? void 0 : _b.labelFill) ?? label.fill,
|
|
125
|
+
// Keep annotation labels legible when G2's base label theme dims text.
|
|
126
|
+
opacity: 1,
|
|
127
|
+
fillOpacity: 1,
|
|
128
|
+
fontFamily: defaults.fontFamily,
|
|
129
|
+
fontSize,
|
|
130
|
+
fontWeight: label.fontWeight,
|
|
131
|
+
lineHeight: Math.ceil(fontSize * 1.5),
|
|
132
|
+
wordWrap: true,
|
|
133
|
+
wordWrapWidth: () => Math.max(fontSize, Math.min(label.maxWidth, plotWidth) - label.padding[1] * 2),
|
|
134
|
+
maxLines: Infinity,
|
|
135
|
+
textOverflow: "clip",
|
|
136
|
+
pointerEvents: "none"
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function createMark(annotation, definition) {
|
|
140
|
+
const { nativeType, style } = definition;
|
|
141
|
+
const native = library[`mark.${nativeType}`];
|
|
142
|
+
const type = (options2) => {
|
|
143
|
+
const geometry = definition.geometry(native(options2));
|
|
144
|
+
return (index, scale, value, coordinate2) => {
|
|
145
|
+
if (disposed)
|
|
146
|
+
return [[], []];
|
|
147
|
+
if (definition.data) {
|
|
148
|
+
const data = definition.data(coordinate2);
|
|
149
|
+
const rows = options2.data;
|
|
150
|
+
rows.length = 0;
|
|
151
|
+
rows.push(...data);
|
|
152
|
+
index = data.map((_, i) => i);
|
|
153
|
+
for (const [channel, values] of Object.entries(value))
|
|
154
|
+
value[channel] = data.map(() => {
|
|
155
|
+
var _a2;
|
|
156
|
+
return values[0] ?? ((_a2 = definition.encode) == null ? void 0 : _a2[channel]);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return geometry(index, scale, value, coordinate2);
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const shapeName = definition.shape ?? native.props.defaultShape;
|
|
163
|
+
const shape = native.props.shape[shapeName];
|
|
164
|
+
const themedShape = (options2, shapeContext) => {
|
|
165
|
+
const draw = shape(options2, shapeContext);
|
|
166
|
+
return (points, value) => {
|
|
167
|
+
var _a2, _b, _c;
|
|
168
|
+
const element = definition.draw ? definition.draw(shapeContext.document) : draw(points, value, {
|
|
169
|
+
color: themeObject.theme.color,
|
|
170
|
+
...((_a2 = themeObject.theme[nativeType]) == null ? void 0 : _a2[shapeName]) ?? ((_b = themeObject.theme[nativeType]) == null ? void 0 : _b[native.props.defaultShape])
|
|
171
|
+
});
|
|
172
|
+
element.setAttribute("annotationKind", annotation.type);
|
|
173
|
+
(_c = definition.decorate) == null ? void 0 : _c.call(definition, element, points);
|
|
174
|
+
return element;
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
themedShape.props = shape.props;
|
|
178
|
+
type.props = { ...native.props, defaultShape: shapeName, shape: { [shapeName]: themedShape } };
|
|
179
|
+
const label = defaults.labels[annotation.type];
|
|
180
|
+
const gap = label.gap + (definition.labelGap ?? 0);
|
|
181
|
+
return {
|
|
182
|
+
type,
|
|
183
|
+
data: Array.isArray(annotation.data) ? annotation.data : [annotation.data],
|
|
184
|
+
encode: { x: () => 0, y: () => 0, ...definition.encode },
|
|
185
|
+
// Resolved positions never contribute to the main-axis domains.
|
|
186
|
+
scale: {
|
|
187
|
+
x: { type: "linear", domain: [0, 1], range: [0, 1], key: "annotation-x" },
|
|
188
|
+
y: { type: "linear", domain: [0, 1], range: [0, 1], key: "annotation-y" },
|
|
189
|
+
color: { key: "annotation-color" },
|
|
190
|
+
size: { type: "identity" }
|
|
191
|
+
},
|
|
192
|
+
axis: false,
|
|
193
|
+
legend: false,
|
|
194
|
+
tooltip: false,
|
|
195
|
+
animate: false,
|
|
196
|
+
zIndex: definition.zIndex ?? 0,
|
|
197
|
+
clip: definition.clip,
|
|
198
|
+
style: { pointerEvents: "none", ...style },
|
|
199
|
+
labels: definition.label !== false && annotation.label !== void 0 && annotation.label !== "" ? [
|
|
200
|
+
{
|
|
201
|
+
text: () => annotation.label,
|
|
202
|
+
annotationLabel: annotation.type,
|
|
203
|
+
annotationGap: gap,
|
|
204
|
+
annotationPaddingX: label.padding[1],
|
|
205
|
+
...getTextStyle(annotation),
|
|
206
|
+
position: "top",
|
|
207
|
+
textAlign: "center",
|
|
208
|
+
textBaseline: "bottom",
|
|
209
|
+
dx: 0,
|
|
210
|
+
dy: -gap - label.padding[0],
|
|
211
|
+
background: true,
|
|
212
|
+
backgroundFill: label.background,
|
|
213
|
+
backgroundFillOpacity: label.backgroundOpacity,
|
|
214
|
+
backgroundStroke: label.border,
|
|
215
|
+
backgroundStrokeOpacity: label.borderOpacity,
|
|
216
|
+
backgroundLineWidth: 1,
|
|
217
|
+
backgroundPadding: label.padding,
|
|
218
|
+
backgroundRadius: label.radius,
|
|
219
|
+
connectorStroke: style.stroke,
|
|
220
|
+
connectorLineWidth: 1,
|
|
221
|
+
connectorFill: "none",
|
|
222
|
+
...definition.label
|
|
223
|
+
}
|
|
224
|
+
] : []
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const options = chart.options();
|
|
228
|
+
let baseMarks;
|
|
229
|
+
let viewOptions;
|
|
230
|
+
if (options.type === "view") {
|
|
231
|
+
const { data, encode, scale, transform = [], children, ...rest } = options;
|
|
232
|
+
baseMarks = children.map((mark) => ({
|
|
233
|
+
...mark,
|
|
234
|
+
data: mark.data ?? data,
|
|
235
|
+
encode: { ...encode, ...mark.encode },
|
|
236
|
+
scale: { ...scale, ...mark.scale },
|
|
237
|
+
transform: [...transform, ...mark.transform ?? []]
|
|
238
|
+
}));
|
|
239
|
+
viewOptions = rest;
|
|
240
|
+
} else {
|
|
241
|
+
const {
|
|
242
|
+
type,
|
|
243
|
+
data,
|
|
244
|
+
encode,
|
|
245
|
+
scale,
|
|
246
|
+
transform,
|
|
247
|
+
style,
|
|
248
|
+
labels,
|
|
249
|
+
tooltip,
|
|
250
|
+
state,
|
|
251
|
+
animate,
|
|
252
|
+
...rest
|
|
253
|
+
} = options;
|
|
254
|
+
baseMarks = [{ type, data, encode, scale, transform, style, labels, tooltip, state, animate }];
|
|
255
|
+
viewOptions = rest;
|
|
256
|
+
}
|
|
257
|
+
const context = {
|
|
258
|
+
library,
|
|
259
|
+
chartType,
|
|
260
|
+
defaults,
|
|
261
|
+
sourceMarks: baseMarks,
|
|
262
|
+
mapping,
|
|
263
|
+
position,
|
|
264
|
+
color: (selector) => {
|
|
265
|
+
var _a2;
|
|
266
|
+
const index = sourceRows.findIndex(
|
|
267
|
+
(row) => Object.entries(selector).every(([key, value]) => row[key] === value)
|
|
268
|
+
);
|
|
269
|
+
return ((_a2 = sourceGeometry.find(
|
|
270
|
+
(item) => {
|
|
271
|
+
var _a3;
|
|
272
|
+
return item.data === sourceRows[index] || ((_a3 = item.seriesIndex) == null ? void 0 : _a3.includes(index));
|
|
273
|
+
}
|
|
274
|
+
)) == null ? void 0 : _a2.color) ?? defaults.stroke;
|
|
275
|
+
},
|
|
276
|
+
onlyAxisFields,
|
|
277
|
+
axisValue: (axis, value, center = true) => axisValue(sourceScale[axis], value, center),
|
|
278
|
+
bandWidth: (axis, value) => {
|
|
279
|
+
var _a2, _b;
|
|
280
|
+
return ((_b = (_a2 = sourceScale[axis]).getBandWidth) == null ? void 0 : _b.call(_a2, value)) ?? 0;
|
|
281
|
+
},
|
|
282
|
+
createMark,
|
|
283
|
+
getTextStyle,
|
|
284
|
+
getSourceData: (element) => element.__data__.seriesIndex ? element.__data__.seriesIndex.map((index) => sourceRows[index]) : [element.__data__.data],
|
|
285
|
+
isVisible: (data) => visibleData.some(
|
|
286
|
+
(row) => Object.entries(data).every(([key, value]) => Object.is(row[key], value))
|
|
287
|
+
),
|
|
288
|
+
getCoordinate: () => coordinate,
|
|
289
|
+
getGeometry: (row) => sourceGeometry.find((item) => item.data === row),
|
|
290
|
+
getScene: () => chart.getContext().canvas.document
|
|
291
|
+
};
|
|
292
|
+
const result = (0, import_registry.renderAnnotations)("g2", annotations, context);
|
|
293
|
+
const marks = result.marks ?? [];
|
|
294
|
+
const layoutLabels = () => (labels, context2) => {
|
|
295
|
+
var _a2, _b;
|
|
296
|
+
if (disposed)
|
|
297
|
+
return labels;
|
|
298
|
+
coordinate = context2.coordinate;
|
|
299
|
+
(_a2 = result.update) == null ? void 0 : _a2.call(result);
|
|
300
|
+
const annotationLabels = labels.filter(
|
|
301
|
+
(label) => label.getAttribute("annotationLabel") && !label.getAttribute("annotationInside") && label.style.visibility !== "hidden"
|
|
302
|
+
);
|
|
303
|
+
for (const label of annotationLabels) {
|
|
304
|
+
const anchor = label.getAttribute("annotationAnchor");
|
|
305
|
+
if (anchor)
|
|
306
|
+
label.attr({ x: anchor[0], y: anchor[1] });
|
|
307
|
+
label.attr({
|
|
308
|
+
x0: Number(label.style.x),
|
|
309
|
+
y0: Number(label.style.y),
|
|
310
|
+
connector: false,
|
|
311
|
+
connectorPoints: []
|
|
312
|
+
});
|
|
313
|
+
label.getElementById("connector").style.lineWidth = 0;
|
|
314
|
+
if (!label.getAttribute("annotationPreferSide"))
|
|
315
|
+
continue;
|
|
316
|
+
const { min, max } = label.getElementById("background").getLocalBounds();
|
|
317
|
+
const gap = Number(label.getAttribute("annotationGap"));
|
|
318
|
+
const right = Number(label.style.x) + gap + max[0] - min[0] <= plotWidth;
|
|
319
|
+
const left = Number(label.style.x) - gap - (max[0] - min[0]) >= 0;
|
|
320
|
+
if (!right && !left)
|
|
321
|
+
continue;
|
|
322
|
+
label.attr({
|
|
323
|
+
textAlign: right ? "left" : "right",
|
|
324
|
+
dx: (right ? 1 : -1) * (gap + Number(label.getAttribute("annotationPaddingX")))
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
const paths = annotationLabels.filter((label) => label.getAttribute("annotationPath"));
|
|
328
|
+
const attached = annotationLabels.filter((label) => !label.getAttribute("annotationPath"));
|
|
329
|
+
const boxes = [];
|
|
330
|
+
for (const label of paths)
|
|
331
|
+
boxes.push(
|
|
332
|
+
placePathLabel(label, [plotWidth, plotHeight || context2.coordinate.getSize()[1]], boxes)
|
|
333
|
+
);
|
|
334
|
+
const anchors = new Map(
|
|
335
|
+
attached.map((label) => [label, [Number(label.style.x), Number(label.style.y)]])
|
|
336
|
+
);
|
|
337
|
+
library["labelTransform.overlapDodgeY"]({ padding: 4 })(attached, context2);
|
|
338
|
+
library["labelTransform.exceedAdjust"]({ bounds: "main" })(attached, context2);
|
|
339
|
+
const segments = [];
|
|
340
|
+
for (const element of context2.canvas.document.querySelectorAll(".element")) {
|
|
341
|
+
const kind = element.getAttribute("annotationKind");
|
|
342
|
+
if (element.getAttribute("annotationIgnoreObstacle") || element.__removed__)
|
|
343
|
+
continue;
|
|
344
|
+
if (chartType === "pie" && !kind)
|
|
345
|
+
continue;
|
|
346
|
+
const annotationSegments = element.getAttribute("annotationSegments");
|
|
347
|
+
if (annotationSegments) {
|
|
348
|
+
segments.push(...annotationSegments);
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const points = element.__data__.points;
|
|
352
|
+
if (!kind && source.type === "line" && element.nodeName === "path") {
|
|
353
|
+
points.slice(1).forEach((point, index) => {
|
|
354
|
+
const previous = points[index];
|
|
355
|
+
if (previous.every(Number.isFinite) && point.every(Number.isFinite))
|
|
356
|
+
segments.push([previous, point]);
|
|
357
|
+
});
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
const bounds = element.getAttribute("annotationBounds");
|
|
361
|
+
if (bounds)
|
|
362
|
+
boxes.push(bounds);
|
|
363
|
+
else {
|
|
364
|
+
const { min, max } = element.getLocalBounds();
|
|
365
|
+
boxes.push({ x: min[0], y: min[1], width: max[0] - min[0], height: max[1] - min[1] });
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
for (const label of labels.filter(
|
|
369
|
+
(label2) => !label2.getAttribute("annotationLabel") && label2.style.visibility !== "hidden"
|
|
370
|
+
)) {
|
|
371
|
+
const { min, max } = label.getElementById("background").getLocalBounds();
|
|
372
|
+
boxes.push({
|
|
373
|
+
x: Number(label.style.x) + min[0],
|
|
374
|
+
y: Number(label.style.y) + min[1],
|
|
375
|
+
width: max[0] - min[0],
|
|
376
|
+
height: max[1] - min[1]
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
for (const label of attached) {
|
|
380
|
+
const bracket = label.getAttribute("annotationBracket");
|
|
381
|
+
for (const path of (bracket == null ? void 0 : bracket.paths) ?? [])
|
|
382
|
+
path.slice(1).forEach((point, index) => segments.push([path[index], point]));
|
|
383
|
+
}
|
|
384
|
+
const cards = attached.map((label) => {
|
|
385
|
+
const bracket = label.getAttribute("annotationBracket");
|
|
386
|
+
const anchor = (bracket == null ? void 0 : bracket.anchor) ?? anchors.get(label);
|
|
387
|
+
const { min, max } = label.getElementById("background").getLocalBounds();
|
|
388
|
+
const gap = Number(label.getAttribute("annotationGap"));
|
|
389
|
+
const width = max[0] - min[0], height = max[1] - min[1];
|
|
390
|
+
const preferred = (bracket == null ? void 0 : bracket.labelAnchor) ? [bracket.labelAnchor[0] - width / 2, bracket.labelAnchor[1] - height / 2] : bracket ? [
|
|
391
|
+
anchor[0] - width / 2 + bracket.direction[0] * (width / 2 + gap),
|
|
392
|
+
anchor[1] - height / 2 + bracket.direction[1] * (height / 2 + gap)
|
|
393
|
+
] : void 0;
|
|
394
|
+
const box = (0, import_layout.placeLabel)(
|
|
395
|
+
anchor,
|
|
396
|
+
[max[0] - min[0], max[1] - min[1]],
|
|
397
|
+
[plotWidth + labelGutter, plotHeight || context2.coordinate.getSize()[1]],
|
|
398
|
+
Number(label.getAttribute("annotationGap")),
|
|
399
|
+
boxes,
|
|
400
|
+
segments,
|
|
401
|
+
preferred ?? (label.getAttribute("annotationRadial") ? [anchor[0] - (max[0] - min[0]) / 2, anchor[1] - (max[1] - min[1]) / 2] : [Number(label.style.x) + min[0], Number(label.style.y) + min[1]])
|
|
402
|
+
);
|
|
403
|
+
label.attr({ x: box.x - min[0], y: box.y - min[1] });
|
|
404
|
+
boxes.push(box);
|
|
405
|
+
return { label, anchor, box };
|
|
406
|
+
});
|
|
407
|
+
for (const {
|
|
408
|
+
label,
|
|
409
|
+
anchor: [x0, y0],
|
|
410
|
+
box
|
|
411
|
+
} of cards) {
|
|
412
|
+
const sources = label.getAttribute("annotationAnchors") ?? [
|
|
413
|
+
[x0, y0]
|
|
414
|
+
];
|
|
415
|
+
const bracket = label.getAttribute("annotationBracket");
|
|
416
|
+
const routes = label.getAttribute("annotationNote") ? [] : (bracket ? [bracket.anchor] : sources).map((anchor) => (0, import_layout.routeLeader)(anchor, box, boxes, segments)).filter((route) => route.length);
|
|
417
|
+
const relative = [...(bracket == null ? void 0 : bracket.paths) ?? [], ...routes].flatMap(
|
|
418
|
+
(route) => route.map(([x, y], index) => [
|
|
419
|
+
index ? "L" : "M",
|
|
420
|
+
x - Number(label.style.x),
|
|
421
|
+
y - Number(label.style.y)
|
|
422
|
+
])
|
|
423
|
+
);
|
|
424
|
+
const edge = relative[relative.length - 1] ?? [0, 0];
|
|
425
|
+
label.attr({
|
|
426
|
+
x0,
|
|
427
|
+
y0,
|
|
428
|
+
connector: relative.length > 0,
|
|
429
|
+
connectorPoints: [edge.slice(-2), edge.slice(-2)]
|
|
430
|
+
});
|
|
431
|
+
label.getElementById("connector").setAttribute("d", relative);
|
|
432
|
+
routes.forEach(
|
|
433
|
+
(route) => route.slice(1).forEach((point, index) => segments.push([route[index], point]))
|
|
434
|
+
);
|
|
435
|
+
const colors = label.getAttribute("annotationColors");
|
|
436
|
+
if (colors == null ? void 0 : colors.length) {
|
|
437
|
+
(_b = label.querySelector(".annotation-label-colors")) == null ? void 0 : _b.remove();
|
|
438
|
+
const { min, max } = label.getElementById("background").getLocalBounds();
|
|
439
|
+
(0, import_label.drawLabelColors)(
|
|
440
|
+
label,
|
|
441
|
+
context2.canvas.document,
|
|
442
|
+
colors,
|
|
443
|
+
{
|
|
444
|
+
x: min[0],
|
|
445
|
+
y: min[1],
|
|
446
|
+
width: max[0] - min[0],
|
|
447
|
+
height: max[1] - min[1]
|
|
448
|
+
},
|
|
449
|
+
defaults.labels.highlight.padding[1]
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return labels;
|
|
454
|
+
};
|
|
455
|
+
const source = baseMarks[0];
|
|
456
|
+
if (marks.some(
|
|
457
|
+
(mark) => {
|
|
458
|
+
var _a2;
|
|
459
|
+
return (_a2 = mark.labels) == null ? void 0 : _a2.some((label) => label.annotationBracket);
|
|
460
|
+
}
|
|
461
|
+
)) {
|
|
462
|
+
if (chartType === "pie") {
|
|
463
|
+
viewOptions.coordinate = {
|
|
464
|
+
...viewOptions.coordinate,
|
|
465
|
+
outerRadius: Math.min(Number(((_a = viewOptions.coordinate) == null ? void 0 : _a.outerRadius) ?? 1), 0.82)
|
|
466
|
+
};
|
|
467
|
+
} else if (chartType === "bar") {
|
|
468
|
+
labelGutter = 120;
|
|
469
|
+
viewOptions.paddingRight = Math.max(Number(viewOptions.paddingRight ?? 0), labelGutter);
|
|
470
|
+
} else {
|
|
471
|
+
viewOptions.insetTop = Math.max(Number(viewOptions.insetTop ?? 0), 54);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
library["transform.annotationSource"] = annotationSource;
|
|
475
|
+
source.transform = [...source.transform ?? [], { type: "annotationSource", capture }];
|
|
476
|
+
source.children = (data, scale, layout) => {
|
|
477
|
+
sourceGeometry = data;
|
|
478
|
+
sourceScale = scale;
|
|
479
|
+
plotWidth = layout.innerWidth;
|
|
480
|
+
plotHeight = layout.innerHeight ?? 0;
|
|
481
|
+
return [];
|
|
482
|
+
};
|
|
483
|
+
replaceOptions(chart, {
|
|
484
|
+
...viewOptions,
|
|
485
|
+
type: "view",
|
|
486
|
+
children: [...baseMarks, ...marks],
|
|
487
|
+
labelTransform: [...options.labelTransform ?? [], { type: layoutLabels }]
|
|
488
|
+
});
|
|
489
|
+
const cleanup = () => {
|
|
490
|
+
var _a2;
|
|
491
|
+
if (disposed)
|
|
492
|
+
return;
|
|
493
|
+
disposed = true;
|
|
494
|
+
chart.off("beforedestroy", cleanup);
|
|
495
|
+
(_a2 = result.cleanup) == null ? void 0 : _a2.call(result);
|
|
496
|
+
replaceOptions(chart, options);
|
|
497
|
+
};
|
|
498
|
+
chart.on("beforedestroy", cleanup);
|
|
499
|
+
return cleanup;
|
|
500
|
+
}
|
|
501
|
+
function placePathLabel(label, view, boxes) {
|
|
502
|
+
const points = label.getAttribute("annotationPath");
|
|
503
|
+
const [first, last = first] = points;
|
|
504
|
+
const horizontal = Math.abs(last[0] - first[0]) >= Math.abs(last[1] - first[1]);
|
|
505
|
+
let anchor = last;
|
|
506
|
+
if (horizontal && first[0] > last[0])
|
|
507
|
+
anchor = first;
|
|
508
|
+
if (!horizontal && first[1] < last[1])
|
|
509
|
+
anchor = first;
|
|
510
|
+
const { min, max } = label.getElementById("background").getLocalBounds();
|
|
511
|
+
const size = [max[0] - min[0], max[1] - min[1]];
|
|
512
|
+
const gap = Math.min(Number(label.getAttribute("annotationGap")), 6);
|
|
513
|
+
const preferred = horizontal ? [anchor[0] - size[0] - gap, anchor[1] - size[1] - gap] : [anchor[0] + gap, anchor[1] + gap];
|
|
514
|
+
const box = (0, import_layout.placeLabel)(anchor, size, view, gap, boxes, [], preferred);
|
|
515
|
+
label.attr({ x: box.x - min[0], y: box.y - min[1] });
|
|
516
|
+
return box;
|
|
517
|
+
}
|
|
518
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
519
|
+
0 && (module.exports = {
|
|
520
|
+
bindAnnotations
|
|
521
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Graph } from '@antv/g6';
|
|
2
|
+
import type { getAnnotationDefaults } from '../../theme/annotation';
|
|
3
|
+
import type { GraphData } from '../../types';
|
|
4
|
+
import type { AnnotationData } from '../../types/annotation';
|
|
5
|
+
import { type Box, type Point, type Segment } from '../layout';
|
|
6
|
+
import type { RendererAnnotation } from '../registry';
|
|
7
|
+
import { createPointPulse } from '../utils';
|
|
8
|
+
import type { AnnotationBindingOptions } from './index';
|
|
9
|
+
type Scene = ReturnType<Graph['getCanvas']>['document'];
|
|
10
|
+
export interface G6AnnotationContext<T extends object> {
|
|
11
|
+
chartType: 'network-graph';
|
|
12
|
+
data: T[];
|
|
13
|
+
scene: Scene;
|
|
14
|
+
root: Pick<ReturnType<Scene['createElement']>, 'appendChild'>;
|
|
15
|
+
defaults: ReturnType<typeof getAnnotationDefaults>;
|
|
16
|
+
size: Point;
|
|
17
|
+
centers: Point[];
|
|
18
|
+
boxes: Box[];
|
|
19
|
+
segments: Segment[];
|
|
20
|
+
pulse(): ReturnType<typeof createPointPulse>;
|
|
21
|
+
position(data: AnnotationData<T>): Point | undefined;
|
|
22
|
+
add(tag: string, style: Record<string, unknown>, className?: string): void;
|
|
23
|
+
label(annotation: RendererAnnotation<T, 'g6'>, anchor: Point, options?: {
|
|
24
|
+
standalone?: boolean;
|
|
25
|
+
gap?: number;
|
|
26
|
+
fill?: string;
|
|
27
|
+
}): void;
|
|
28
|
+
}
|
|
29
|
+
type Datum = GraphData['nodes'][number] | GraphData['edges'][number];
|
|
30
|
+
export interface G6AnnotationOptions {
|
|
31
|
+
renderer: 'g6';
|
|
32
|
+
graph: Graph;
|
|
33
|
+
annotations?: RendererAnnotation<Datum, 'g6'>[];
|
|
34
|
+
data: GraphData;
|
|
35
|
+
edgeIds: string[];
|
|
36
|
+
defaults: ReturnType<typeof getAnnotationDefaults>;
|
|
37
|
+
}
|
|
38
|
+
/** Business data selects graph elements; generated edge IDs stay inside the runtime. */
|
|
39
|
+
export declare function bindAnnotations<T extends object>(options: AnnotationBindingOptions<T>): (() => void) | undefined;
|
|
40
|
+
export {};
|