@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,504 @@
|
|
|
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/crossing.ts
|
|
20
|
+
var crossing_exports = {};
|
|
21
|
+
__export(crossing_exports, {
|
|
22
|
+
crossing: () => crossing
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(crossing_exports);
|
|
25
|
+
var import_utils = require("../utils");
|
|
26
|
+
var import_path = require("./path");
|
|
27
|
+
var import_point = require("./point");
|
|
28
|
+
var crossing = {
|
|
29
|
+
g2: (annotations, context) => annotations.flatMap((annotation) => {
|
|
30
|
+
var _a, _b, _c, _d, _e;
|
|
31
|
+
const { mapping, defaults } = context;
|
|
32
|
+
const type = ((_c = (_b = (_a = context.sourceMarks) == null ? void 0 : _a.find((mark) => mark.type === "line")) == null ? void 0 : _b.style) == null ? void 0 : _c.shape) ?? "line";
|
|
33
|
+
if ((_d = context.sourceMarks) == null ? void 0 : _d.some(
|
|
34
|
+
(mark) => {
|
|
35
|
+
var _a2;
|
|
36
|
+
return (_a2 = mark.transform) == null ? void 0 : _a2.some((t) => (t == null ? void 0 : t.type) === "stackY");
|
|
37
|
+
}
|
|
38
|
+
))
|
|
39
|
+
throw new Error("Invalid annotation: automatic crossing requires unstacked series.");
|
|
40
|
+
let deferred = false;
|
|
41
|
+
switch (type) {
|
|
42
|
+
case "line":
|
|
43
|
+
case "linear":
|
|
44
|
+
break;
|
|
45
|
+
case "smooth":
|
|
46
|
+
case "hv":
|
|
47
|
+
case "vh":
|
|
48
|
+
case "hvh":
|
|
49
|
+
deferred = true;
|
|
50
|
+
break;
|
|
51
|
+
default:
|
|
52
|
+
throw new Error(`Invalid annotation: unsupported crossing curve ${String(type)}.`);
|
|
53
|
+
}
|
|
54
|
+
const direction = annotation.direction ?? "both";
|
|
55
|
+
if (!["up", "down", "both"].includes(direction))
|
|
56
|
+
throw new Error("Invalid annotation: crossing direction must be up, down or both.");
|
|
57
|
+
const samples = (rows) => {
|
|
58
|
+
requireOneSeries(rows, mapping.series);
|
|
59
|
+
if (!rows.length)
|
|
60
|
+
return [];
|
|
61
|
+
const selected2 = new Set(rows.map((row) => row[mapping.x]));
|
|
62
|
+
const all = mapping.series ? mapping.data.filter((row) => row[mapping.series] === rows[0][mapping.series]) : mapping.data;
|
|
63
|
+
return seriesSamples(all, mapping.x, mapping.y).map(
|
|
64
|
+
(sample) => selected2.has(sample.x) ? sample : { ...sample, y: null }
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
let compared;
|
|
68
|
+
let selected;
|
|
69
|
+
if (annotation.threshold !== void 0) {
|
|
70
|
+
const threshold = (0, import_utils.finiteValue)(annotation.threshold, "threshold");
|
|
71
|
+
const rows = (0, import_utils.selectRows)(
|
|
72
|
+
mapping.data,
|
|
73
|
+
annotation.data
|
|
74
|
+
);
|
|
75
|
+
selected = [rows];
|
|
76
|
+
compared = samples(rows).map((sample) => ({
|
|
77
|
+
...sample,
|
|
78
|
+
other: threshold,
|
|
79
|
+
difference: sample.y === null ? null : sample.y - threshold
|
|
80
|
+
}));
|
|
81
|
+
} else {
|
|
82
|
+
const selection = annotation.data;
|
|
83
|
+
if (!selection || Array.isArray(selection) || !("series" in selection) || !Array.isArray(selection.series) || selection.series.length !== 2)
|
|
84
|
+
throw new Error(
|
|
85
|
+
"Invalid annotation: crossing needs a threshold or two series selectors in data.series."
|
|
86
|
+
);
|
|
87
|
+
const [first, second] = selection.series.map(
|
|
88
|
+
(selector) => (0, import_utils.selectRows)(mapping.data, selector)
|
|
89
|
+
);
|
|
90
|
+
selected = [first, second];
|
|
91
|
+
const firstRows = new Set(first);
|
|
92
|
+
if (second.some((row) => firstRows.has(row)))
|
|
93
|
+
throw new Error("Invalid annotation: crossing series selectors must not overlap.");
|
|
94
|
+
compared = compareSeries(samples(first), samples(second));
|
|
95
|
+
}
|
|
96
|
+
const visible = () => selected.every((rows) => rows.some((row) => {
|
|
97
|
+
var _a2;
|
|
98
|
+
return ((_a2 = context.isVisible) == null ? void 0 : _a2.call(context, row)) ?? true;
|
|
99
|
+
}));
|
|
100
|
+
const position = (sample) => ({
|
|
101
|
+
[mapping.x]: sample.x,
|
|
102
|
+
[mapping.y]: sample.y
|
|
103
|
+
});
|
|
104
|
+
const createMarker = (sample, positions) => {
|
|
105
|
+
var _a2, _b2, _c2, _d2, _e2, _f;
|
|
106
|
+
const color = ((_a2 = annotation.style) == null ? void 0 : _a2.stroke) ?? ((_b2 = annotation.style) == null ? void 0 : _b2.fill) ?? defaults.directions[sample.direction];
|
|
107
|
+
return import_point.point.create(
|
|
108
|
+
{
|
|
109
|
+
data: position(sample),
|
|
110
|
+
label: annotation.label ?? `${sample.direction === "up" ? "Crosses above" : "Crosses below"}${annotation.threshold === void 0 ? "" : ` ${(0, import_utils.formatNumber)(annotation.threshold)}`}`,
|
|
111
|
+
pulse: annotation.pulse ?? false,
|
|
112
|
+
style: {
|
|
113
|
+
...annotation.style,
|
|
114
|
+
size: ((_c2 = annotation.style) == null ? void 0 : _c2.size) ?? Math.max(defaults.size, 7),
|
|
115
|
+
lineWidth: ((_d2 = annotation.style) == null ? void 0 : _d2.lineWidth) ?? 2,
|
|
116
|
+
fill: ((_e2 = annotation.style) == null ? void 0 : _e2.fill) ?? color,
|
|
117
|
+
stroke: color
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
shape: sample.direction === "up" ? "triangle" : "triangleDown",
|
|
122
|
+
outline: ((_f = annotation.style) == null ? void 0 : _f.stroke) ?? defaults.pointStroke,
|
|
123
|
+
zIndex: 2,
|
|
124
|
+
visible,
|
|
125
|
+
positions
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
const references = annotation.threshold === void 0 ? [] : import_path.path.create({
|
|
130
|
+
data: (0, import_utils.axisPosition)(mapping.y, annotation.threshold),
|
|
131
|
+
label: annotation.label === "" ? "" : `Threshold: ${(0, import_utils.formatNumber)(annotation.threshold)}`,
|
|
132
|
+
style: { lineDash: [4, 4], stroke: (_e = annotation.style) == null ? void 0 : _e.stroke }
|
|
133
|
+
});
|
|
134
|
+
const createBand = (band, positions) => {
|
|
135
|
+
var _a2, _b2;
|
|
136
|
+
return import_path.path.create(
|
|
137
|
+
{
|
|
138
|
+
data: [...band.upper, ...band.lower.slice().reverse(), band.upper[0]].map(position),
|
|
139
|
+
label: ""
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
fill: ((_a2 = annotation.style) == null ? void 0 : _a2.fill) ?? ((_b2 = annotation.style) == null ? void 0 : _b2.stroke) ?? defaults.directions[band.direction],
|
|
143
|
+
fillOpacity: 0.07,
|
|
144
|
+
visible,
|
|
145
|
+
positions
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
if (!deferred || compared.some(({ x }) => typeof x === "string")) {
|
|
150
|
+
const marks2 = intersections(compared).filter((sample) => direction === "both" || direction === sample.direction).flatMap((sample) => createMarker(sample));
|
|
151
|
+
const bands2 = (context.chartType === "area" ? [] : relationshipBands(compared)).filter(({ direction: side }) => direction === "both" || direction === side).flatMap((band) => createBand(band));
|
|
152
|
+
return [...bands2, ...references, ...marks2];
|
|
153
|
+
}
|
|
154
|
+
const series = selected.map((rows) => {
|
|
155
|
+
var _a2;
|
|
156
|
+
const group = mapping.series && ((_a2 = rows[0]) == null ? void 0 : _a2[mapping.series]);
|
|
157
|
+
const all = mapping.series ? mapping.data.filter((row) => row[mapping.series] === group) : mapping.data;
|
|
158
|
+
const full = seriesSamples(all, mapping.x, mapping.y);
|
|
159
|
+
const chosen = new Set(rows.map((row) => row[mapping.x]));
|
|
160
|
+
const runs = [];
|
|
161
|
+
let run;
|
|
162
|
+
for (const sample of full) {
|
|
163
|
+
if (!chosen.has(sample.x))
|
|
164
|
+
run = void 0;
|
|
165
|
+
else {
|
|
166
|
+
if (!run)
|
|
167
|
+
runs.push(run = []);
|
|
168
|
+
run.push(sample);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (full.length && Number(all[0][mapping.x]) > Number(all.at(-1)[mapping.x]))
|
|
172
|
+
full.reverse();
|
|
173
|
+
return { samples: full, runs, chosen };
|
|
174
|
+
});
|
|
175
|
+
const resolve = (geometry, coordinate) => {
|
|
176
|
+
const tolerance = 2e-3 / Math.max(1, Math.min(...coordinate.getSize()));
|
|
177
|
+
const paths = series.map(({ samples: samples2, runs, chosen }) => {
|
|
178
|
+
const source = type === "smooth" ? samples2 : samples2.map((sample) => chosen.has(sample.x) ? sample : { ...sample, y: null });
|
|
179
|
+
const full = sampleCurve(type, source, geometry, coordinate);
|
|
180
|
+
if (type !== "smooth")
|
|
181
|
+
return full;
|
|
182
|
+
return runs.filter((run) => run.length > 1).flatMap((run, i) => {
|
|
183
|
+
const from = geometry.axisValue("x", run[0].x);
|
|
184
|
+
const to = geometry.axisValue("x", run.at(-1).x);
|
|
185
|
+
const clipped = clipSamples(full, Math.min(from, to), Math.max(from, to), tolerance);
|
|
186
|
+
return i ? [{ x: from, y: null }, ...clipped] : clipped;
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
if (annotation.threshold !== void 0) {
|
|
190
|
+
const threshold = -geometry.axisValue("y", annotation.threshold);
|
|
191
|
+
return paths[0].map((sample) => ({
|
|
192
|
+
...sample,
|
|
193
|
+
other: threshold,
|
|
194
|
+
difference: sample.y === null ? null : Math.abs(sample.y - threshold) <= tolerance ? 0 : sample.y - threshold
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
return comparePaths(paths[0], paths[1], tolerance);
|
|
198
|
+
};
|
|
199
|
+
const sides = direction === "both" ? ["up", "down"] : [direction];
|
|
200
|
+
const seed = { x: 0, y: 0 };
|
|
201
|
+
const marks = sides.flatMap(
|
|
202
|
+
(side) => createMarker(
|
|
203
|
+
{ ...seed, direction: side },
|
|
204
|
+
(geometry, coordinate) => intersections(resolve(geometry, coordinate)).filter((sample) => sample.direction === side).map((sample) => [Number(sample.x), -sample.y])
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
const bands = context.chartType === "area" ? [] : sides.flatMap(
|
|
208
|
+
(side) => createBand(
|
|
209
|
+
{ upper: [seed], lower: [seed], direction: side },
|
|
210
|
+
(geometry, coordinate) => relationshipBands(resolve(geometry, coordinate)).filter((band) => band.direction === side).map(
|
|
211
|
+
(band) => [...band.upper, ...band.lower.slice().reverse(), band.upper[0]].map(
|
|
212
|
+
(sample) => [Number(sample.x), -sample.y]
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
);
|
|
217
|
+
return [...bands, ...references, ...marks];
|
|
218
|
+
})
|
|
219
|
+
};
|
|
220
|
+
function sampleCurve(type, samples, context, coordinate) {
|
|
221
|
+
var _a, _b, _c;
|
|
222
|
+
const library = context.library;
|
|
223
|
+
const line = library["mark.line"];
|
|
224
|
+
const shape = line.props.shape[type];
|
|
225
|
+
const element = shape({}, { document: context.getScene(), coordinate })(
|
|
226
|
+
samples.map(
|
|
227
|
+
({ x, y }) => y === null ? [NaN, NaN] : coordinate.map([context.axisValue("x", x), context.axisValue("y", y)])
|
|
228
|
+
),
|
|
229
|
+
{},
|
|
230
|
+
{ color: "none", lineWidth: 0 }
|
|
231
|
+
);
|
|
232
|
+
let commands;
|
|
233
|
+
try {
|
|
234
|
+
const path2 = element.getAttribute("d");
|
|
235
|
+
commands = typeof path2 === "string" ? Array.from(path2.matchAll(/([MLCZ])([^MLCZ]*)/g), ([, command, values]) => [
|
|
236
|
+
command,
|
|
237
|
+
...(values.match(/[-+]?(?:\d*\.\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/g) ?? []).map(Number)
|
|
238
|
+
]) : [];
|
|
239
|
+
} finally {
|
|
240
|
+
element.destroy();
|
|
241
|
+
}
|
|
242
|
+
const paths = [];
|
|
243
|
+
for (const [command, ...values] of commands) {
|
|
244
|
+
const end = [values.at(-2), values.at(-1)];
|
|
245
|
+
switch (command) {
|
|
246
|
+
case "M":
|
|
247
|
+
paths.push([end]);
|
|
248
|
+
break;
|
|
249
|
+
case "L":
|
|
250
|
+
paths.at(-1).push(end);
|
|
251
|
+
break;
|
|
252
|
+
case "C": {
|
|
253
|
+
const path2 = paths.at(-1);
|
|
254
|
+
flattenCubic(path2.at(-1), [values[0], values[1]], [values[2], values[3]], end, path2);
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case "Z":
|
|
258
|
+
break;
|
|
259
|
+
default:
|
|
260
|
+
throw new Error(`Invalid annotation: unsupported crossing path command ${command}.`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const projected = paths.map(
|
|
264
|
+
(points) => points.map((point2) => {
|
|
265
|
+
const [x, y] = coordinate.invert(point2);
|
|
266
|
+
return { x, y: -y };
|
|
267
|
+
})
|
|
268
|
+
);
|
|
269
|
+
if (Number((_a = projected[0]) == null ? void 0 : _a[0].x) > Number((_c = (_b = projected.at(-1)) == null ? void 0 : _b.at(-1)) == null ? void 0 : _c.x)) {
|
|
270
|
+
projected.reverse();
|
|
271
|
+
projected.forEach((path2) => path2.reverse());
|
|
272
|
+
}
|
|
273
|
+
const result = [];
|
|
274
|
+
for (const path2 of projected) {
|
|
275
|
+
if (result.length)
|
|
276
|
+
result.push({ x: (Number(result.at(-1).x) + Number(path2[0].x)) / 2, y: null });
|
|
277
|
+
result.push(...path2);
|
|
278
|
+
}
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
function flattenCubic(a, b, c, d, points, depth = 0) {
|
|
282
|
+
const length = Math.hypot(d[0] - a[0], d[1] - a[1]);
|
|
283
|
+
const distance = (p) => length ? Math.abs((d[0] - a[0]) * (a[1] - p[1]) - (a[0] - p[0]) * (d[1] - a[1])) / length : Math.hypot(p[0] - a[0], p[1] - a[1]);
|
|
284
|
+
if (depth >= 16 || Math.max(distance(b), distance(c)) <= 0.1) {
|
|
285
|
+
points.push(d);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const middle = (a2, b2) => [(a2[0] + b2[0]) / 2, (a2[1] + b2[1]) / 2];
|
|
289
|
+
const ab = middle(a, b), bc = middle(b, c), cd = middle(c, d);
|
|
290
|
+
const abc = middle(ab, bc), bcd = middle(bc, cd), center = middle(abc, bcd);
|
|
291
|
+
flattenCubic(a, ab, abc, center, points, depth + 1);
|
|
292
|
+
flattenCubic(center, bcd, cd, d, points, depth + 1);
|
|
293
|
+
}
|
|
294
|
+
function sampleAt(samples, x, side) {
|
|
295
|
+
var _a;
|
|
296
|
+
let from = 0, to = samples.length;
|
|
297
|
+
while (from < to) {
|
|
298
|
+
const mid = from + to >>> 1;
|
|
299
|
+
if (Number(samples[mid].x) < x || side === "after" && samples[mid].x === x)
|
|
300
|
+
from = mid + 1;
|
|
301
|
+
else
|
|
302
|
+
to = mid;
|
|
303
|
+
}
|
|
304
|
+
if (side === "before" && ((_a = samples[from]) == null ? void 0 : _a.x) === x)
|
|
305
|
+
return samples[from].y;
|
|
306
|
+
const a = samples[from - 1], b = samples[from];
|
|
307
|
+
if ((a == null ? void 0 : a.x) === x)
|
|
308
|
+
return a.y;
|
|
309
|
+
if (!a || !b || a.y === null || b.y === null)
|
|
310
|
+
return null;
|
|
311
|
+
const t = interpolationFraction(Number(a.x), Number(b.x), x);
|
|
312
|
+
return a.y * (1 - t) + b.y * t;
|
|
313
|
+
}
|
|
314
|
+
function clipSamples(samples, from, to, tolerance) {
|
|
315
|
+
if (!samples.length || from > to)
|
|
316
|
+
return [];
|
|
317
|
+
const result = samples.filter(
|
|
318
|
+
({ x }) => Number(x) >= from - tolerance && Number(x) <= to + tolerance
|
|
319
|
+
);
|
|
320
|
+
if (!result.length || Math.abs(Number(result[0].x) - from) > tolerance)
|
|
321
|
+
result.unshift({ x: from, y: sampleAt(samples, from, "after") });
|
|
322
|
+
if (Math.abs(Number(result.at(-1).x) - to) > tolerance)
|
|
323
|
+
result.push({ x: to, y: sampleAt(samples, to, "before") });
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
function comparePaths(first, second, tolerance) {
|
|
327
|
+
if (!first.length || !second.length)
|
|
328
|
+
return [];
|
|
329
|
+
const from = Math.max(Number(first[0].x), Number(second[0].x));
|
|
330
|
+
const to = Math.min(Number(first.at(-1).x), Number(second.at(-1).x));
|
|
331
|
+
const xs = [...new Set([...first, ...second].map(({ x }) => Number(x)))].filter((x) => x >= from && x <= to).sort((a, b) => a - b);
|
|
332
|
+
const result = [];
|
|
333
|
+
for (const x of xs) {
|
|
334
|
+
const a0 = sampleAt(first, x, "before"), a1 = sampleAt(first, x, "after");
|
|
335
|
+
const b0 = sampleAt(second, x, "before"), b1 = sampleAt(second, x, "after");
|
|
336
|
+
const compared = (a, b) => ({
|
|
337
|
+
x,
|
|
338
|
+
y: a,
|
|
339
|
+
other: a !== null && b !== null && Math.abs(a - b) <= tolerance ? a : b,
|
|
340
|
+
difference: a === null || b === null ? null : Math.abs(a - b) <= tolerance ? 0 : a - b
|
|
341
|
+
});
|
|
342
|
+
result.push(compared(a0, b0));
|
|
343
|
+
if (a0 !== a1 && b0 !== b1)
|
|
344
|
+
result.push({ x, y: null, other: null, difference: null });
|
|
345
|
+
if (a0 !== a1 || b0 !== b1)
|
|
346
|
+
result.push(compared(a1, b1));
|
|
347
|
+
}
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
function seriesSamples(rows, x, y) {
|
|
351
|
+
var _a;
|
|
352
|
+
const samples = rows.map((row) => {
|
|
353
|
+
const value = row[x];
|
|
354
|
+
(0, import_utils.axisPosition)(x, value);
|
|
355
|
+
const raw = row[y];
|
|
356
|
+
if (raw === null || raw === void 0 || typeof raw === "number" && !Number.isFinite(raw))
|
|
357
|
+
return { x: value, y: null };
|
|
358
|
+
return { x: value, y: (0, import_utils.finiteValue)(raw, y) };
|
|
359
|
+
});
|
|
360
|
+
if (new Set(samples.map(({ x: x2 }) => x2)).size !== samples.length)
|
|
361
|
+
throw new Error("Invalid annotation: crossing requires unique x values per series.");
|
|
362
|
+
if (samples.some((sample) => typeof sample.x !== typeof samples[0].x))
|
|
363
|
+
throw new Error("Invalid annotation: crossing x values must have a consistent type.");
|
|
364
|
+
if (typeof ((_a = samples[0]) == null ? void 0 : _a.x) === "number" && samples.length > 1) {
|
|
365
|
+
const direction = Number(samples[1].x) - Number(samples[0].x);
|
|
366
|
+
if (samples.slice(1).some((sample, i) => (Number(sample.x) - Number(samples[i].x)) * direction <= 0))
|
|
367
|
+
throw new Error("Invalid annotation: crossing x values must be monotonic.");
|
|
368
|
+
if (direction < 0)
|
|
369
|
+
samples.reverse();
|
|
370
|
+
}
|
|
371
|
+
return samples;
|
|
372
|
+
}
|
|
373
|
+
function interpolate(samples, x) {
|
|
374
|
+
let left = 0;
|
|
375
|
+
let right = samples.length - 1;
|
|
376
|
+
while (left < right) {
|
|
377
|
+
const middle = Math.ceil((left + right) / 2);
|
|
378
|
+
if (Number(samples[middle].x) <= x)
|
|
379
|
+
left = middle;
|
|
380
|
+
else
|
|
381
|
+
right = middle - 1;
|
|
382
|
+
}
|
|
383
|
+
const a = samples[left];
|
|
384
|
+
if (a.x === x)
|
|
385
|
+
return a.y;
|
|
386
|
+
const b = samples[left + 1];
|
|
387
|
+
if (!b || a.y === null || b.y === null)
|
|
388
|
+
return null;
|
|
389
|
+
const t = interpolationFraction(Number(a.x), Number(b.x), x);
|
|
390
|
+
return a.y * (1 - t) + b.y * t;
|
|
391
|
+
}
|
|
392
|
+
function compareSeries(first, second) {
|
|
393
|
+
if (!first.length || !second.length)
|
|
394
|
+
return [];
|
|
395
|
+
if (typeof first[0].x === "number" && typeof second[0].x === "number") {
|
|
396
|
+
const min = Math.max(Number(first[0].x), Number(second[0].x));
|
|
397
|
+
const max = Math.min(Number(first[first.length - 1].x), Number(second[second.length - 1].x));
|
|
398
|
+
return [...new Set([...first, ...second].map(({ x }) => Number(x)))].filter((x) => x >= min && x <= max).sort((a, b) => a - b).map((x) => {
|
|
399
|
+
const y = interpolate(first, x);
|
|
400
|
+
const other = interpolate(second, x);
|
|
401
|
+
return { x, y, other, difference: y === null || other === null ? null : y - other };
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
if (first.length !== second.length || first.some((sample, i) => sample.x !== second[i].x))
|
|
405
|
+
throw new Error(
|
|
406
|
+
"Invalid annotation: categorical crossing requires identical categories in identical order."
|
|
407
|
+
);
|
|
408
|
+
return first.map((sample, i) => ({
|
|
409
|
+
...sample,
|
|
410
|
+
other: second[i].y,
|
|
411
|
+
difference: sample.y === null || second[i].y === null ? null : sample.y - second[i].y
|
|
412
|
+
}));
|
|
413
|
+
}
|
|
414
|
+
function intersections(samples) {
|
|
415
|
+
const points = [];
|
|
416
|
+
let previous = -1;
|
|
417
|
+
for (let i = 0; i < samples.length; i++) {
|
|
418
|
+
const current = samples[i];
|
|
419
|
+
if (current.difference === null) {
|
|
420
|
+
previous = -1;
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
if (current.difference === 0)
|
|
424
|
+
continue;
|
|
425
|
+
const start = samples[previous];
|
|
426
|
+
if (start && Math.sign(start.difference) !== Math.sign(current.difference)) {
|
|
427
|
+
const direction = current.difference > 0 ? "up" : "down";
|
|
428
|
+
if (i > previous + 1)
|
|
429
|
+
points.push({ ...samples[previous + 1], direction });
|
|
430
|
+
else if (typeof start.x === "number" && typeof current.x === "number") {
|
|
431
|
+
const t = crossingFraction(start, current);
|
|
432
|
+
points.push({
|
|
433
|
+
x: start.x * (1 - t) + current.x * t,
|
|
434
|
+
y: start.y * (1 - t) + current.y * t,
|
|
435
|
+
direction
|
|
436
|
+
});
|
|
437
|
+
} else
|
|
438
|
+
points.push({ ...current, direction });
|
|
439
|
+
}
|
|
440
|
+
previous = i;
|
|
441
|
+
}
|
|
442
|
+
return points;
|
|
443
|
+
}
|
|
444
|
+
function relationshipBands(samples) {
|
|
445
|
+
const bands = [];
|
|
446
|
+
if (!samples.every(({ x }) => typeof x === "number"))
|
|
447
|
+
return bands;
|
|
448
|
+
let active;
|
|
449
|
+
const append = (a, b) => {
|
|
450
|
+
const difference = a.difference || b.difference;
|
|
451
|
+
if (!difference) {
|
|
452
|
+
active = void 0;
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const direction = difference > 0 ? "up" : "down";
|
|
456
|
+
if (!active || active.direction !== direction) {
|
|
457
|
+
active = { upper: [a], lower: [{ x: a.x, y: a.other }], direction };
|
|
458
|
+
bands.push(active);
|
|
459
|
+
}
|
|
460
|
+
active.upper.push(b);
|
|
461
|
+
active.lower.push({ x: b.x, y: b.other });
|
|
462
|
+
};
|
|
463
|
+
for (let i = 1; i < samples.length; i++) {
|
|
464
|
+
const a = samples[i - 1], b = samples[i];
|
|
465
|
+
if (a.difference === null || b.difference === null) {
|
|
466
|
+
active = void 0;
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
if (Math.sign(a.difference) * Math.sign(b.difference) < 0) {
|
|
470
|
+
const t = crossingFraction(a, b);
|
|
471
|
+
const intersection = {
|
|
472
|
+
x: Number(a.x) * (1 - t) + Number(b.x) * t,
|
|
473
|
+
y: a.y * (1 - t) + b.y * t,
|
|
474
|
+
other: a.y * (1 - t) + b.y * t,
|
|
475
|
+
difference: 0
|
|
476
|
+
};
|
|
477
|
+
append(a, intersection);
|
|
478
|
+
append(intersection, b);
|
|
479
|
+
} else
|
|
480
|
+
append(a, b);
|
|
481
|
+
}
|
|
482
|
+
return bands;
|
|
483
|
+
}
|
|
484
|
+
function crossingFraction(a, b) {
|
|
485
|
+
const scale = Math.max(Math.abs(a.y), Math.abs(a.other), Math.abs(b.y), Math.abs(b.other));
|
|
486
|
+
const difference = (sample) => Number.isFinite(sample.difference) ? sample.difference / scale : sample.y / scale - sample.other / scale;
|
|
487
|
+
const left = Math.abs(difference(a));
|
|
488
|
+
const right = Math.abs(difference(b));
|
|
489
|
+
return left / (left + right);
|
|
490
|
+
}
|
|
491
|
+
function interpolationFraction(from, to, value) {
|
|
492
|
+
if (Number.isFinite(to - from))
|
|
493
|
+
return (value - from) / (to - from);
|
|
494
|
+
const scale = Math.max(Math.abs(from), Math.abs(to));
|
|
495
|
+
return (value / scale - from / scale) / (to / scale - from / scale);
|
|
496
|
+
}
|
|
497
|
+
function requireOneSeries(rows, series) {
|
|
498
|
+
if (series && new Set(rows.map((row) => row[series])).size > 1)
|
|
499
|
+
throw new Error("Invalid annotation: select a single series with data.");
|
|
500
|
+
}
|
|
501
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
502
|
+
0 && (module.exports = {
|
|
503
|
+
crossing
|
|
504
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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/event.ts
|
|
20
|
+
var event_exports = {};
|
|
21
|
+
__export(event_exports, {
|
|
22
|
+
event: () => event
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(event_exports);
|
|
25
|
+
var import_utils = require("../utils");
|
|
26
|
+
var import_path = require("./path");
|
|
27
|
+
var event = {
|
|
28
|
+
g2: (annotations, { mapping }) => annotations.flatMap((annotation) => {
|
|
29
|
+
const field = (0, import_utils.annotationField)(mapping, annotation.axis ?? "x");
|
|
30
|
+
const targets = Array.isArray(annotation.data) ? annotation.data : [annotation.data];
|
|
31
|
+
if (!targets.length)
|
|
32
|
+
throw new Error("Invalid annotation: event needs target data.");
|
|
33
|
+
return targets.flatMap((selector) => {
|
|
34
|
+
const anchor = (selector == null ? void 0 : selector[field]) !== void 0 && Object.keys(selector).every((key) => key === field) ? selector : resolveAnchor(selector, mapping);
|
|
35
|
+
const value = anchor[field];
|
|
36
|
+
return import_path.path.create({
|
|
37
|
+
data: (0, import_utils.axisPosition)(field, value),
|
|
38
|
+
label: annotation.label ?? `Event: ${value}`,
|
|
39
|
+
style: { lineDash: [4, 4], ...annotation.style }
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
function resolveAnchor(selector, mapping) {
|
|
45
|
+
if (!selector || typeof selector !== "object" || Array.isArray(selector))
|
|
46
|
+
throw new Error("Invalid annotation: anchor needs an original-field selector or coordinates.");
|
|
47
|
+
if (selector[mapping.x] !== void 0 && selector[mapping.y] !== void 0 && Object.keys(selector).every((key) => key === mapping.x || key === mapping.y)) {
|
|
48
|
+
(0, import_utils.axisPosition)(mapping.x, selector[mapping.x]);
|
|
49
|
+
(0, import_utils.finiteValue)(selector[mapping.y], mapping.y);
|
|
50
|
+
return selector;
|
|
51
|
+
}
|
|
52
|
+
const rows = (0, import_utils.selectRows)(mapping.data, selector);
|
|
53
|
+
if (rows.length !== 1)
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Invalid annotation: anchor matches ${rows.length} observations; expected one.`
|
|
56
|
+
);
|
|
57
|
+
return rows[0];
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
event
|
|
62
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
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/first.ts
|
|
20
|
+
var first_exports = {};
|
|
21
|
+
__export(first_exports, {
|
|
22
|
+
first: () => first
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(first_exports);
|
|
25
|
+
var import_utils = require("../utils");
|
|
26
|
+
var import_highlight = require("./highlight");
|
|
27
|
+
var first = {
|
|
28
|
+
g2: (annotations, { mapping }) => annotations.flatMap((annotation) => {
|
|
29
|
+
const rows = (0, import_utils.selectRows)(mapping.data, annotation.data);
|
|
30
|
+
return rows.slice(0, 1).flatMap(
|
|
31
|
+
(row) => import_highlight.highlight.create({
|
|
32
|
+
data: [row],
|
|
33
|
+
label: annotation.label ?? `First: ${row[mapping.y]}`,
|
|
34
|
+
style: annotation.style
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
first
|
|
42
|
+
});
|