@antv/gpt-vis 1.3.2 → 1.4.1
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 +12 -3
- package/dist/cjs/vis/summary/index.js +29 -11
- 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 +12 -3
- package/dist/esm/vis/summary/index.js +35 -16
- 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,73 @@
|
|
|
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/components/group.ts
|
|
20
|
+
var group_exports = {};
|
|
21
|
+
__export(group_exports, {
|
|
22
|
+
group: () => group
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(group_exports);
|
|
25
|
+
var import_label = require("../label");
|
|
26
|
+
var import_highlight = require("./highlight");
|
|
27
|
+
var group = {
|
|
28
|
+
g2: (annotations, { mapping, chartType, sourceMarks }) => annotations.flatMap((annotation) => {
|
|
29
|
+
switch (chartType) {
|
|
30
|
+
case "column":
|
|
31
|
+
case "bar":
|
|
32
|
+
if (!(sourceMarks == null ? void 0 : sourceMarks.some(
|
|
33
|
+
(mark) => {
|
|
34
|
+
var _a;
|
|
35
|
+
return (_a = mark.transform) == null ? void 0 : _a.some(
|
|
36
|
+
(transform) => transform.type === "dodgeX" || transform.type === "stackY"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
)))
|
|
40
|
+
throw new Error("Invalid annotation: group requires grouped or stacked bars.");
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
const field = mapping.series;
|
|
44
|
+
if (!field)
|
|
45
|
+
throw new Error("Invalid annotation: group requires a series mapping.");
|
|
46
|
+
const targets = Array.isArray(annotation.data) ? annotation.data : [annotation.data];
|
|
47
|
+
if (!targets.length || targets.some(
|
|
48
|
+
(target) => !target || Object.keys(target).length !== 1 || Object.keys(target)[0] !== "group" || typeof target.group !== "string"
|
|
49
|
+
))
|
|
50
|
+
throw new Error("Invalid annotation: group selects complete series with data.group.");
|
|
51
|
+
const names = new Set(targets.map((target) => target.group));
|
|
52
|
+
const available = new Set(mapping.data.map((row) => row[field]));
|
|
53
|
+
if (mapping.data.length && targets.some((target) => !available.has(target.group)))
|
|
54
|
+
throw new Error("Invalid annotation: group matches no series.");
|
|
55
|
+
const highlights = annotation.label === void 0 ? [...names].flatMap(
|
|
56
|
+
(name) => import_highlight.highlight.create({
|
|
57
|
+
data: mapping.data.filter((row) => row[field] === name),
|
|
58
|
+
label: String(name),
|
|
59
|
+
style: annotation.style
|
|
60
|
+
})
|
|
61
|
+
) : import_highlight.highlight.create({
|
|
62
|
+
data: mapping.data.filter((row) => names.has(row[field])),
|
|
63
|
+
label: annotation.label,
|
|
64
|
+
style: annotation.style
|
|
65
|
+
});
|
|
66
|
+
highlights.forEach((highlight2) => import_label.groupLabels.add(highlight2));
|
|
67
|
+
return highlights;
|
|
68
|
+
})
|
|
69
|
+
};
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
group
|
|
73
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Annotation } from '../../types/annotation';
|
|
2
|
+
import type { AnnotationComponent } from '../registry';
|
|
3
|
+
/** Highlight batches share selection and dimming so overlapping targets form a union. */
|
|
4
|
+
export declare const highlight: AnnotationComponent<'highlight'> & {
|
|
5
|
+
create: typeof createHighlight;
|
|
6
|
+
};
|
|
7
|
+
type HighlightConfig<T extends object> = Omit<Extract<Annotation, {
|
|
8
|
+
type: 'highlight';
|
|
9
|
+
}>, 'data'> & {
|
|
10
|
+
data: T | T[];
|
|
11
|
+
};
|
|
12
|
+
/** Create configurations for later merging and drawing; empty selections are a no-op. */
|
|
13
|
+
declare function createHighlight<T extends object>(options: Omit<HighlightConfig<T>, 'type'>, computed?: boolean): HighlightConfig<T>[];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,552 @@
|
|
|
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/components/highlight.ts
|
|
20
|
+
var highlight_exports = {};
|
|
21
|
+
__export(highlight_exports, {
|
|
22
|
+
highlight: () => highlight
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(highlight_exports);
|
|
25
|
+
var import_label = require("../label");
|
|
26
|
+
var import_merge = require("../merge");
|
|
27
|
+
var import_utils = require("../utils");
|
|
28
|
+
var import_point = require("./point");
|
|
29
|
+
var highlight = {
|
|
30
|
+
create: createHighlight,
|
|
31
|
+
g2: (annotations, context) => [drawG2, ...createSeriesMarkers(annotations, context)],
|
|
32
|
+
g6: () => drawG6,
|
|
33
|
+
table: () => drawTable,
|
|
34
|
+
summary: () => drawSummary
|
|
35
|
+
};
|
|
36
|
+
var computedHighlights = /* @__PURE__ */ new WeakSet();
|
|
37
|
+
function createHighlight(options, computed = true) {
|
|
38
|
+
if (Array.isArray(options.data) && !options.data.length)
|
|
39
|
+
return [];
|
|
40
|
+
const annotation = {
|
|
41
|
+
type: "highlight",
|
|
42
|
+
data: options.data,
|
|
43
|
+
label: options.label,
|
|
44
|
+
style: options.style
|
|
45
|
+
};
|
|
46
|
+
if (computed)
|
|
47
|
+
computedHighlights.add(annotation);
|
|
48
|
+
return [annotation];
|
|
49
|
+
}
|
|
50
|
+
var drawG2 = (annotations, context) => {
|
|
51
|
+
const selections = selectHighlights(context.mapping.data, annotations);
|
|
52
|
+
let labelSelections = selections;
|
|
53
|
+
const results = [];
|
|
54
|
+
switch (context.chartType) {
|
|
55
|
+
case "line":
|
|
56
|
+
case "area":
|
|
57
|
+
if (selections.length)
|
|
58
|
+
applySeriesHighlights(selections, context);
|
|
59
|
+
break;
|
|
60
|
+
case "bar":
|
|
61
|
+
case "column":
|
|
62
|
+
if (selections.length)
|
|
63
|
+
applyNativeHighlights(context.sourceMarks, selections, context, "interval");
|
|
64
|
+
break;
|
|
65
|
+
case "scatter":
|
|
66
|
+
if (selections.length)
|
|
67
|
+
applyNativeHighlights(context.sourceMarks, selections, context, "point");
|
|
68
|
+
break;
|
|
69
|
+
case "pie":
|
|
70
|
+
if (selections.length)
|
|
71
|
+
applyNativeHighlights(context.sourceMarks, selections, context, "interval");
|
|
72
|
+
results.push((0, import_label.bindPieLabels)(selections, context));
|
|
73
|
+
labelSelections = selections.filter(({ annotation }) => !import_label.rankedLabels.has(annotation));
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
throw new Error(`Unsupported ${context.chartType} highlight.`);
|
|
77
|
+
}
|
|
78
|
+
results.push({ marks: createHighlightLabels(labelSelections, context) });
|
|
79
|
+
return (0, import_merge.mergeResults)(results);
|
|
80
|
+
};
|
|
81
|
+
var drawG6 = (annotations, context) => {
|
|
82
|
+
for (const { annotation, rows } of selectHighlights(context.data, annotations)) {
|
|
83
|
+
if (!annotation.label)
|
|
84
|
+
continue;
|
|
85
|
+
const positions = rows.flatMap((row) => {
|
|
86
|
+
const point2 = context.position(row);
|
|
87
|
+
return point2 ? [point2] : [];
|
|
88
|
+
});
|
|
89
|
+
const anchor = positions.length ? [
|
|
90
|
+
positions.reduce((sum, point2) => sum + point2[0], 0) / positions.length,
|
|
91
|
+
positions.reduce((sum, point2) => sum + point2[1], 0) / positions.length
|
|
92
|
+
] : void 0;
|
|
93
|
+
if (anchor)
|
|
94
|
+
context.label(annotation, anchor);
|
|
95
|
+
}
|
|
96
|
+
return {};
|
|
97
|
+
};
|
|
98
|
+
var drawTable = (annotations, context) => ({
|
|
99
|
+
cleanup: bindTableHighlights(
|
|
100
|
+
context.container,
|
|
101
|
+
context.content,
|
|
102
|
+
context.data,
|
|
103
|
+
annotations,
|
|
104
|
+
context.defaults
|
|
105
|
+
)
|
|
106
|
+
});
|
|
107
|
+
var drawSummary = (annotations, context) => ({
|
|
108
|
+
cleanup: bindSummaryHighlights(context.container, context.content, annotations, context.defaults)
|
|
109
|
+
});
|
|
110
|
+
function applyNativeHighlights(marks, selections, context, outline) {
|
|
111
|
+
const { defaults } = context;
|
|
112
|
+
const annotations = selections.map(({ annotation }) => annotation);
|
|
113
|
+
const pie = context.chartType === "pie";
|
|
114
|
+
const dim = (0, import_utils.getDimOpacity)(
|
|
115
|
+
annotations,
|
|
116
|
+
pie ? defaults.highlight.pieDimOpacity : annotations.some((annotation) => import_label.labelConnectors.has(annotation)) ? defaults.highlight.contributionDimOpacity : defaults.highlight.dimOpacity
|
|
117
|
+
);
|
|
118
|
+
for (const mark of marks) {
|
|
119
|
+
const style = { ...mark.style };
|
|
120
|
+
const original = (key, fallback, args) => typeof style[key] === "function" ? style[key](...args) : style[key] ?? fallback;
|
|
121
|
+
const selectedAnnotations = (datum) => {
|
|
122
|
+
const rows = Array.isArray(datum) ? datum : [datum];
|
|
123
|
+
return selections.filter((selection) => rows.every(selection.matches));
|
|
124
|
+
};
|
|
125
|
+
mark.style = {
|
|
126
|
+
...style,
|
|
127
|
+
opacity: (...args) => {
|
|
128
|
+
const rows = Array.isArray(args[0]) ? args[0] : [args[0]];
|
|
129
|
+
return Number(original("opacity", 1, args)) * (rows.some((row) => selections.some((selection) => selection.matches(row))) ? 1 : dim);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
if (outline !== "none")
|
|
133
|
+
for (const key of ["stroke", "lineWidth"]) {
|
|
134
|
+
if (!annotations.some((annotation) => {
|
|
135
|
+
var _a;
|
|
136
|
+
return ((_a = annotation.style) == null ? void 0 : _a[key]) !== void 0;
|
|
137
|
+
}))
|
|
138
|
+
continue;
|
|
139
|
+
mark.style[key] = (...args) => selectedAnnotations(args[0]).map(({ annotation }) => {
|
|
140
|
+
var _a;
|
|
141
|
+
return (_a = annotation.style) == null ? void 0 : _a[key];
|
|
142
|
+
}).filter((value) => value !== void 0).at(-1) ?? original(
|
|
143
|
+
key,
|
|
144
|
+
key === "lineWidth" ? outline === "series" ? defaults.lineWidth.path : outline === "point" ? defaults.lineWidth.point : 0 : outline === "interval" ? "none" : context.color(Array.isArray(args[0]) ? args[0][0] : args[0]),
|
|
145
|
+
args
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
for (const key of ["fill", "fillOpacity"]) {
|
|
149
|
+
if (!annotations.some((annotation) => {
|
|
150
|
+
var _a;
|
|
151
|
+
return ((_a = annotation.style) == null ? void 0 : _a[key]) !== void 0;
|
|
152
|
+
}))
|
|
153
|
+
continue;
|
|
154
|
+
mark.style[key] = (...args) => selectedAnnotations(args[0]).map(({ annotation }) => {
|
|
155
|
+
var _a;
|
|
156
|
+
return (_a = annotation.style) == null ? void 0 : _a[key];
|
|
157
|
+
}).filter((v) => v !== void 0).at(-1) ?? original(
|
|
158
|
+
key,
|
|
159
|
+
key === "fill" ? context.color(Array.isArray(args[0]) ? args[0][0] : args[0]) : 1,
|
|
160
|
+
args
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function applySeriesHighlights(selections, context) {
|
|
166
|
+
for (const mark of context.sourceMarks) {
|
|
167
|
+
const outline = mark.type === "area" ? "none" : mark.type === "line" ? "series" : "point";
|
|
168
|
+
applyNativeHighlights([mark], selections, context, outline);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function createSeriesMarkers(annotations, {
|
|
172
|
+
chartType,
|
|
173
|
+
mapping,
|
|
174
|
+
sourceMarks
|
|
175
|
+
}) {
|
|
176
|
+
var _a;
|
|
177
|
+
switch (chartType) {
|
|
178
|
+
case "line":
|
|
179
|
+
case "area": {
|
|
180
|
+
const selections = selectHighlights(mapping.data, annotations);
|
|
181
|
+
const selected = new Set(selections.flatMap(({ rows }) => rows));
|
|
182
|
+
const series = sourceMarks == null ? void 0 : sourceMarks.find((mark) => mark.type === "line" || mark.type === "area");
|
|
183
|
+
const field = mapping.series ?? (typeof ((_a = series == null ? void 0 : series.encode) == null ? void 0 : _a.color) === "string" ? series.encode.color : void 0);
|
|
184
|
+
return [...selected].flatMap((row) => {
|
|
185
|
+
const seriesRows = mapping.data.filter(
|
|
186
|
+
(datum) => !field || datum[field] === row[field]
|
|
187
|
+
);
|
|
188
|
+
if (seriesRows.every((datum) => selected.has(datum)))
|
|
189
|
+
return [];
|
|
190
|
+
const { style } = selections.findLast((selection) => selection.matches(row)).annotation;
|
|
191
|
+
return import_point.point.create(
|
|
192
|
+
{
|
|
193
|
+
data: row,
|
|
194
|
+
style: { fill: style == null ? void 0 : style.fill, stroke: style == null ? void 0 : style.stroke, lineWidth: style == null ? void 0 : style.lineWidth }
|
|
195
|
+
},
|
|
196
|
+
{ useSourceGeometry: true, fillOpacity: style == null ? void 0 : style.fillOpacity }
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
default:
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function createHighlightLabels(selections, context) {
|
|
205
|
+
const { defaults } = context;
|
|
206
|
+
let connectorIndex = 0;
|
|
207
|
+
const connectorCount = selections.filter(
|
|
208
|
+
({ annotation }) => annotation.label && import_label.labelConnectors.has(annotation)
|
|
209
|
+
).length;
|
|
210
|
+
return selections.filter(({ annotation }) => annotation.label).map(({ annotation, rows }) => {
|
|
211
|
+
var _a, _b, _c;
|
|
212
|
+
const row = rows[0];
|
|
213
|
+
const note = import_label.groupLabels.has(annotation);
|
|
214
|
+
const pie = context.chartType === "pie";
|
|
215
|
+
const connect = import_label.labelConnectors.get(annotation);
|
|
216
|
+
const index = connect ? connectorIndex++ : 0;
|
|
217
|
+
let anchors = [];
|
|
218
|
+
let bracket;
|
|
219
|
+
const colors = () => [
|
|
220
|
+
...new Set(
|
|
221
|
+
rows.filter((row2) => context.isVisible(row2)).map(
|
|
222
|
+
(row2) => {
|
|
223
|
+
var _a2, _b2;
|
|
224
|
+
return (context.chartType === "line" ? (_a2 = annotation.style) == null ? void 0 : _a2.stroke : (_b2 = annotation.style) == null ? void 0 : _b2.fill) ?? context.color(row2);
|
|
225
|
+
}
|
|
226
|
+
)
|
|
227
|
+
)
|
|
228
|
+
];
|
|
229
|
+
const [py, px] = defaults.labels.highlight.padding;
|
|
230
|
+
const textStyle = context.getTextStyle(annotation);
|
|
231
|
+
return context.createMark(
|
|
232
|
+
{ ...annotation, data: row },
|
|
233
|
+
{
|
|
234
|
+
nativeType: "point",
|
|
235
|
+
style: { fill: "none", stroke: "none" },
|
|
236
|
+
label: {
|
|
237
|
+
connectorStroke: ((_a = annotation.style) == null ? void 0 : _a.stroke) ?? defaults.stroke,
|
|
238
|
+
...connect ? {
|
|
239
|
+
annotationBracket: () => bracket,
|
|
240
|
+
connectorStroke: ((_b = annotation.style) == null ? void 0 : _b.stroke) ?? defaults.labels.highlight.fill,
|
|
241
|
+
connectorLineWidth: 1.5
|
|
242
|
+
} : {},
|
|
243
|
+
...pie && !connect ? {
|
|
244
|
+
annotationRadial: true,
|
|
245
|
+
annotationAnchors: () => anchors,
|
|
246
|
+
connectorStroke: ((_c = annotation.style) == null ? void 0 : _c.stroke) ?? defaults.labels.highlight.fill,
|
|
247
|
+
connectorLineWidth: 1.5
|
|
248
|
+
} : {},
|
|
249
|
+
...note ? {
|
|
250
|
+
annotationNote: true,
|
|
251
|
+
annotationColors: colors,
|
|
252
|
+
connector: false,
|
|
253
|
+
position: "inside",
|
|
254
|
+
textAlign: "right",
|
|
255
|
+
textBaseline: "top",
|
|
256
|
+
dx: -px,
|
|
257
|
+
dy: py,
|
|
258
|
+
backgroundPadding: () => [py, px, py, px + (0, import_label.getLabelColorWidth)(colors())],
|
|
259
|
+
wordWrapWidth: () => {
|
|
260
|
+
var _a2;
|
|
261
|
+
return Math.max(
|
|
262
|
+
((_a2 = annotation.style) == null ? void 0 : _a2.labelFontSize) ?? defaults.labelFontSize,
|
|
263
|
+
textStyle.wordWrapWidth() - (0, import_label.getLabelColorWidth)(colors())
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
} : {}
|
|
267
|
+
},
|
|
268
|
+
// Nonzero invisible geometry keeps AntV's transform origin well-defined.
|
|
269
|
+
draw: (scene) => scene.createElement("circle", { style: { r: 1, fill: "none", stroke: "none" } }),
|
|
270
|
+
decorate: (element, [anchor]) => {
|
|
271
|
+
element.attr({ cx: anchor[0], cy: anchor[1] });
|
|
272
|
+
element.setAttribute("annotationIgnoreObstacle", true);
|
|
273
|
+
element.setAttribute("annotationSelection", annotation);
|
|
274
|
+
},
|
|
275
|
+
geometry: () => (_index, _scale, _value, coordinate) => {
|
|
276
|
+
const points = rows.flatMap((row2) => {
|
|
277
|
+
const position = context.position(row2, coordinate, true);
|
|
278
|
+
const point2 = position && coordinate.map(pie ? [0.18, position[1]] : position);
|
|
279
|
+
return (point2 == null ? void 0 : point2.every(Number.isFinite)) ? [point2] : [];
|
|
280
|
+
});
|
|
281
|
+
anchors = points;
|
|
282
|
+
if (connect) {
|
|
283
|
+
const geometry = rows.flatMap((row2) => {
|
|
284
|
+
const source = context.getGeometry(row2);
|
|
285
|
+
return source ? [source] : [];
|
|
286
|
+
});
|
|
287
|
+
bracket = connect(points, geometry, coordinate, index, connectorCount);
|
|
288
|
+
}
|
|
289
|
+
if (!points.length)
|
|
290
|
+
return [[], []];
|
|
291
|
+
if (bracket)
|
|
292
|
+
return [[0], [[bracket.anchor]], [[0]]];
|
|
293
|
+
if (pie)
|
|
294
|
+
return [[0], [[coordinate.getCenter()]], [[0]]];
|
|
295
|
+
if (note) {
|
|
296
|
+
const [width] = coordinate.getSize();
|
|
297
|
+
return [
|
|
298
|
+
[0],
|
|
299
|
+
[[[width - defaults.labels.highlight.gap, defaults.labels.highlight.gap]]],
|
|
300
|
+
[[0]]
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
const anchor = [
|
|
304
|
+
(Math.min(...points.map(([x]) => x)) + Math.max(...points.map(([x]) => x))) / 2,
|
|
305
|
+
(Math.min(...points.map(([, y]) => y)) + Math.max(...points.map(([, y]) => y))) / 2
|
|
306
|
+
];
|
|
307
|
+
return [[0], [[anchor]], [[0]]];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
function selectHighlights(data, annotations) {
|
|
314
|
+
const originals = new Set(data);
|
|
315
|
+
return annotations.map((annotation) => {
|
|
316
|
+
const targets = Array.isArray(annotation.data) ? annotation.data : [annotation.data];
|
|
317
|
+
if (!targets.length)
|
|
318
|
+
throw new Error("Invalid annotation: highlight needs target data.");
|
|
319
|
+
const selectors = [];
|
|
320
|
+
const rows = /* @__PURE__ */ new Set();
|
|
321
|
+
for (const target of targets) {
|
|
322
|
+
if (!target || typeof target !== "object" || Array.isArray(target) || !Object.keys(target).length)
|
|
323
|
+
throw new Error("Invalid annotation: highlight needs a nonempty original-field selector.");
|
|
324
|
+
const entries = Object.entries(target);
|
|
325
|
+
if (entries.some(([key]) => !data.some((row) => Object.hasOwn(row, key))))
|
|
326
|
+
throw new Error("Invalid annotation: highlight contains an unknown field.");
|
|
327
|
+
const exact = computedHighlights.has(annotation);
|
|
328
|
+
const matchesRow = (row) => exact && originals.has(row) ? row === target : entries.every(([key, value]) => row[key] === value);
|
|
329
|
+
selectors.push(matchesRow);
|
|
330
|
+
const matches = data.filter(matchesRow);
|
|
331
|
+
if (!matches.length)
|
|
332
|
+
throw new Error("Invalid annotation: highlight matches no data.");
|
|
333
|
+
matches.forEach((row) => rows.add(row));
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
annotation,
|
|
337
|
+
rows: [...rows],
|
|
338
|
+
matches: (row) => selectors.some((matches) => matches(row))
|
|
339
|
+
};
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function bindTableHighlights(container, content, data, annotations, defaults) {
|
|
343
|
+
if (!(annotations == null ? void 0 : annotations.length))
|
|
344
|
+
return () => {
|
|
345
|
+
};
|
|
346
|
+
const dim = (0, import_utils.getDimOpacity)(annotations, defaults.highlight.dimOpacity);
|
|
347
|
+
const fields = Object.keys(data[0] ?? {});
|
|
348
|
+
const rows = [...content.querySelectorAll("tbody tr")];
|
|
349
|
+
const headers = [...content.querySelectorAll("th")];
|
|
350
|
+
const selections = annotations.map((annotation) => {
|
|
351
|
+
const targets = Array.isArray(annotation.data) ? annotation.data : [annotation.data];
|
|
352
|
+
if (!targets.length)
|
|
353
|
+
throw new Error("Invalid annotation: table highlight needs target data.");
|
|
354
|
+
const selected2 = /* @__PURE__ */ new Set();
|
|
355
|
+
for (const target of targets) {
|
|
356
|
+
if (!target || typeof target !== "object" || Array.isArray(target))
|
|
357
|
+
throw new Error("Invalid annotation: table target must contain row or column.");
|
|
358
|
+
const { row: selector, column: field } = target;
|
|
359
|
+
if (Object.keys(target).some((key) => key !== "row" && key !== "column"))
|
|
360
|
+
throw new Error("Invalid annotation: table target only accepts row and column.");
|
|
361
|
+
if (selector === void 0 && field === void 0)
|
|
362
|
+
throw new Error("Invalid annotation: table target must contain row or column.");
|
|
363
|
+
const column = field === void 0 ? void 0 : fields.indexOf(field);
|
|
364
|
+
if (column === -1)
|
|
365
|
+
throw new Error(`Invalid annotation: unknown table column ${field}.`);
|
|
366
|
+
let indices;
|
|
367
|
+
if (selector === void 0) {
|
|
368
|
+
indices = data.map((_, index) => index);
|
|
369
|
+
selected2.add(headers[column]);
|
|
370
|
+
} else {
|
|
371
|
+
if (!selector || typeof selector !== "object" || Array.isArray(selector))
|
|
372
|
+
throw new Error("Invalid annotation: table row must be an original-field selector.");
|
|
373
|
+
const entries = Object.entries(selector);
|
|
374
|
+
if (!entries.length)
|
|
375
|
+
throw new Error("Invalid annotation: table row must not be empty.");
|
|
376
|
+
if (entries.some(([key]) => !fields.includes(key)))
|
|
377
|
+
throw new Error("Invalid annotation: table row contains an unknown field.");
|
|
378
|
+
const exact = computedHighlights.has(annotation) ? data.indexOf(selector) : -1;
|
|
379
|
+
indices = exact === -1 ? data.flatMap(
|
|
380
|
+
(row, index) => entries.every(([key, value]) => row[key] === value) ? [index] : []
|
|
381
|
+
) : [exact];
|
|
382
|
+
if (!indices.length)
|
|
383
|
+
throw new Error("Invalid annotation: table highlight matches no rows.");
|
|
384
|
+
}
|
|
385
|
+
for (const index of indices) {
|
|
386
|
+
const cells2 = column === void 0 ? [...rows[index].children] : [rows[index].children[column]];
|
|
387
|
+
for (const cell of cells2)
|
|
388
|
+
selected2.add(cell);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const cells = [...selected2];
|
|
392
|
+
return { annotation, cells };
|
|
393
|
+
});
|
|
394
|
+
const selected = new Set(selections.flatMap(({ cells }) => cells));
|
|
395
|
+
const all = [...content.querySelectorAll("th, td")];
|
|
396
|
+
const previous = all.map((cell) => cell.getAttribute("style"));
|
|
397
|
+
for (const cell of all) {
|
|
398
|
+
if (selected.has(cell)) {
|
|
399
|
+
const style = Object.assign(
|
|
400
|
+
{},
|
|
401
|
+
...selections.filter(({ cells }) => cells.includes(cell)).map(({ annotation }) => annotation.style)
|
|
402
|
+
);
|
|
403
|
+
const color = style.fill ?? defaults.stroke;
|
|
404
|
+
const opacity = style.fillOpacity ?? defaults.highlight.fillOpacity;
|
|
405
|
+
cell.style.background = `rgba(127, 127, 127, ${opacity})`;
|
|
406
|
+
cell.style.background = `color-mix(in srgb, ${color} ${opacity * 100}%, ${defaults.highlight.background})`;
|
|
407
|
+
cell.style.boxShadow = `inset 0 -${style.lineWidth ?? defaults.highlight.lineWidth}px ${style.stroke ?? defaults.stroke}`;
|
|
408
|
+
} else
|
|
409
|
+
cell.style.opacity = String(dim);
|
|
410
|
+
}
|
|
411
|
+
const cleanupLabels = (0, import_label.bindLabels)(
|
|
412
|
+
container,
|
|
413
|
+
content,
|
|
414
|
+
selections.map(({ annotation, cells }) => ({
|
|
415
|
+
annotation,
|
|
416
|
+
bounds: () => {
|
|
417
|
+
const clip = content.getBoundingClientRect();
|
|
418
|
+
const visible = cells.map((cell) => cell.getBoundingClientRect()).filter(
|
|
419
|
+
(box) => box.right > clip.left && box.left < clip.right && box.bottom > clip.top && box.top < clip.bottom
|
|
420
|
+
);
|
|
421
|
+
if (!visible.length)
|
|
422
|
+
return void 0;
|
|
423
|
+
const groups = import_label.labelConnectors.has(annotation) ? [...new Set(cells.map((cell) => cell.parentElement))].map(
|
|
424
|
+
(row) => cells.filter((cell) => cell.parentElement === row).map((cell) => cell.getBoundingClientRect()).filter(
|
|
425
|
+
(box) => box.right > clip.left && box.left < clip.right && box.bottom > clip.top && box.top < clip.bottom
|
|
426
|
+
)
|
|
427
|
+
) : [visible];
|
|
428
|
+
return groups.filter((boxes) => boxes.length).map((boxes) => {
|
|
429
|
+
const left = Math.max(clip.left, Math.min(...boxes.map((box) => box.left)));
|
|
430
|
+
const top = Math.max(clip.top, Math.min(...boxes.map((box) => box.top)));
|
|
431
|
+
const right = Math.min(clip.right, Math.max(...boxes.map((box) => box.right)));
|
|
432
|
+
const bottom = Math.min(clip.bottom, Math.max(...boxes.map((box) => box.bottom)));
|
|
433
|
+
return DOMRect.fromRect({ x: left, y: top, width: right - left, height: bottom - top });
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
})),
|
|
437
|
+
defaults
|
|
438
|
+
);
|
|
439
|
+
return () => {
|
|
440
|
+
cleanupLabels();
|
|
441
|
+
all.forEach((cell, index) => {
|
|
442
|
+
if (previous[index] === null)
|
|
443
|
+
cell.removeAttribute("style");
|
|
444
|
+
else
|
|
445
|
+
cell.setAttribute("style", previous[index]);
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
function bindSummaryHighlights(container, content, annotations, defaults) {
|
|
450
|
+
var _a;
|
|
451
|
+
if (!(annotations == null ? void 0 : annotations.length))
|
|
452
|
+
return () => {
|
|
453
|
+
};
|
|
454
|
+
const dim = (0, import_utils.getDimOpacity)(annotations, defaults.highlight.dimOpacity);
|
|
455
|
+
const walker = document.createTreeWalker(content, NodeFilter.SHOW_TEXT);
|
|
456
|
+
const nodes = [];
|
|
457
|
+
let text = "";
|
|
458
|
+
let lastBlock = null;
|
|
459
|
+
while (walker.nextNode()) {
|
|
460
|
+
const node = walker.currentNode;
|
|
461
|
+
const block = ((_a = node.parentElement) == null ? void 0 : _a.closest("p, h1, h2, h3, h4, h5, h6, li")) ?? null;
|
|
462
|
+
if (lastBlock && block !== lastBlock)
|
|
463
|
+
text += "\n";
|
|
464
|
+
nodes.push({ node, start: text.length });
|
|
465
|
+
text += node.data;
|
|
466
|
+
lastBlock = block;
|
|
467
|
+
}
|
|
468
|
+
const selections = annotations.map((annotation) => {
|
|
469
|
+
const data = Array.isArray(annotation.data) ? annotation.data : [annotation.data];
|
|
470
|
+
if (!data.length)
|
|
471
|
+
throw new Error("Invalid annotation: summary highlight needs text.");
|
|
472
|
+
const intervals = data.map((selector) => {
|
|
473
|
+
if (!selector.text)
|
|
474
|
+
throw new Error("Invalid annotation: summary highlight needs a nonempty text string.");
|
|
475
|
+
const start = text.indexOf(selector.text);
|
|
476
|
+
if (start < 0)
|
|
477
|
+
throw new Error(`Invalid annotation: text not found: ${selector.text}.`);
|
|
478
|
+
if (text.indexOf(selector.text, start + 1) !== -1)
|
|
479
|
+
throw new Error(`Invalid annotation: text is ambiguous: ${selector.text}.`);
|
|
480
|
+
return { start, end: start + selector.text.length };
|
|
481
|
+
});
|
|
482
|
+
return { annotation, intervals, marks: [] };
|
|
483
|
+
});
|
|
484
|
+
const spans = [];
|
|
485
|
+
for (const { node, start } of nodes) {
|
|
486
|
+
const end = start + node.length;
|
|
487
|
+
const boundaries = /* @__PURE__ */ new Set([start, end]);
|
|
488
|
+
for (const { intervals } of selections)
|
|
489
|
+
for (const interval of intervals) {
|
|
490
|
+
if (interval.start > start && interval.start < end)
|
|
491
|
+
boundaries.add(interval.start);
|
|
492
|
+
if (interval.end > start && interval.end < end)
|
|
493
|
+
boundaries.add(interval.end);
|
|
494
|
+
}
|
|
495
|
+
const offsets = [...boundaries].sort((a, b) => a - b);
|
|
496
|
+
const fragment = document.createDocumentFragment();
|
|
497
|
+
for (let i = 1; i < offsets.length; i++) {
|
|
498
|
+
const a = offsets[i - 1], b = offsets[i];
|
|
499
|
+
const matches = selections.filter(
|
|
500
|
+
({ intervals }) => intervals.some((r) => r.start <= a && r.end >= b)
|
|
501
|
+
);
|
|
502
|
+
if (!matches.length && dim === 1) {
|
|
503
|
+
fragment.appendChild(document.createTextNode(node.data.slice(a - start, b - start)));
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
const span = document.createElement(matches.length ? "mark" : "span");
|
|
507
|
+
span.textContent = node.data.slice(a - start, b - start);
|
|
508
|
+
if (matches.length) {
|
|
509
|
+
const style = Object.assign({}, ...matches.map(({ annotation }) => annotation.style));
|
|
510
|
+
const color = style.fill ?? defaults.stroke;
|
|
511
|
+
const opacity = style.fillOpacity ?? defaults.highlight.fillOpacity;
|
|
512
|
+
span.className = "annotation-highlight";
|
|
513
|
+
Object.assign(span.style, {
|
|
514
|
+
background: `rgba(127, 127, 127, ${opacity})`,
|
|
515
|
+
borderBottom: `${style.lineWidth ?? defaults.highlight.lineWidth}px solid ${style.stroke ?? defaults.stroke}`,
|
|
516
|
+
color: "inherit",
|
|
517
|
+
padding: "2px 0"
|
|
518
|
+
});
|
|
519
|
+
span.style.background = `color-mix(in srgb, ${color} ${opacity * 100}%, transparent)`;
|
|
520
|
+
for (const match of matches)
|
|
521
|
+
match.marks.push(span);
|
|
522
|
+
} else
|
|
523
|
+
span.style.opacity = String(dim);
|
|
524
|
+
spans.push(span);
|
|
525
|
+
fragment.appendChild(span);
|
|
526
|
+
}
|
|
527
|
+
node.replaceWith(fragment);
|
|
528
|
+
}
|
|
529
|
+
const cleanupLabels = (0, import_label.bindLabels)(
|
|
530
|
+
container,
|
|
531
|
+
content,
|
|
532
|
+
selections.map(({ annotation, marks }) => ({
|
|
533
|
+
annotation,
|
|
534
|
+
bounds: () => {
|
|
535
|
+
var _a2;
|
|
536
|
+
const rects = (_a2 = marks[marks.length - 1]) == null ? void 0 : _a2.getClientRects();
|
|
537
|
+
return rects == null ? void 0 : rects[rects.length - 1];
|
|
538
|
+
}
|
|
539
|
+
})),
|
|
540
|
+
defaults
|
|
541
|
+
);
|
|
542
|
+
return () => {
|
|
543
|
+
cleanupLabels();
|
|
544
|
+
for (const span of spans)
|
|
545
|
+
span.replaceWith(...span.childNodes);
|
|
546
|
+
content.normalize();
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
550
|
+
0 && (module.exports = {
|
|
551
|
+
highlight
|
|
552
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { bottomN } from './bottom-n';
|
|
2
|
+
export { centroid } from './centroid';
|
|
3
|
+
export { connector } from './connector';
|
|
4
|
+
export { contribution } from './contribution';
|
|
5
|
+
export { crossing } from './crossing';
|
|
6
|
+
export { event } from './event';
|
|
7
|
+
export { first } from './first';
|
|
8
|
+
export { group } from './group';
|
|
9
|
+
export { highlight } from './highlight';
|
|
10
|
+
export { last } from './last';
|
|
11
|
+
export { maxX } from './max-x';
|
|
12
|
+
export { maxY } from './max-y';
|
|
13
|
+
export { mean } from './mean';
|
|
14
|
+
export { median } from './median';
|
|
15
|
+
export { minX } from './min-x';
|
|
16
|
+
export { minY } from './min-y';
|
|
17
|
+
export { outlier } from './outlier';
|
|
18
|
+
export { path } from './path';
|
|
19
|
+
export { peak } from './peak';
|
|
20
|
+
export { point } from './point';
|
|
21
|
+
export { quadrant } from './quadrant';
|
|
22
|
+
export { quantile } from './quantile';
|
|
23
|
+
export { range } from './range';
|
|
24
|
+
export { rangeInside } from './range-inside';
|
|
25
|
+
export { rangeOutside } from './range-outside';
|
|
26
|
+
export { rangeX } from './range-x';
|
|
27
|
+
export { rangeY } from './range-y';
|
|
28
|
+
export { target } from './target';
|
|
29
|
+
export { text } from './text';
|
|
30
|
+
export { thresholdHighlight } from './threshold-highlight';
|
|
31
|
+
export { thresholdX } from './threshold-x';
|
|
32
|
+
export { thresholdY } from './threshold-y';
|
|
33
|
+
export { topN } from './top-n';
|
|
34
|
+
export { valley } from './valley';
|