@antv/gpt-vis 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +261 -137
- package/README.zh-CN.md +263 -116
- package/dist/cjs/annotation/components/bottom-n.d.ts +2 -0
- package/dist/cjs/annotation/components/bottom-n.js +57 -0
- package/dist/cjs/annotation/components/centroid.d.ts +2 -0
- package/dist/cjs/annotation/components/centroid.js +75 -0
- package/dist/cjs/annotation/components/connector.d.ts +25 -0
- package/dist/cjs/annotation/components/connector.js +298 -0
- package/dist/cjs/annotation/components/contribution.d.ts +3 -0
- package/dist/cjs/annotation/components/contribution.js +136 -0
- package/dist/cjs/annotation/components/crossing.d.ts +3 -0
- package/dist/cjs/annotation/components/crossing.js +504 -0
- package/dist/cjs/annotation/components/event.d.ts +2 -0
- package/dist/cjs/annotation/components/event.js +62 -0
- package/dist/cjs/annotation/components/first.d.ts +2 -0
- package/dist/cjs/annotation/components/first.js +42 -0
- package/dist/cjs/annotation/components/group.d.ts +3 -0
- package/dist/cjs/annotation/components/group.js +73 -0
- package/dist/cjs/annotation/components/highlight.d.ts +14 -0
- package/dist/cjs/annotation/components/highlight.js +552 -0
- package/dist/cjs/annotation/components/index.d.ts +34 -0
- package/dist/cjs/annotation/components/index.js +128 -0
- package/dist/cjs/annotation/components/last.d.ts +2 -0
- package/dist/cjs/annotation/components/last.js +42 -0
- package/dist/cjs/annotation/components/max-x.d.ts +2 -0
- package/dist/cjs/annotation/components/max-x.js +41 -0
- package/dist/cjs/annotation/components/max-y.d.ts +2 -0
- package/dist/cjs/annotation/components/max-y.js +41 -0
- package/dist/cjs/annotation/components/mean.d.ts +2 -0
- package/dist/cjs/annotation/components/mean.js +50 -0
- package/dist/cjs/annotation/components/median.d.ts +2 -0
- package/dist/cjs/annotation/components/median.js +49 -0
- package/dist/cjs/annotation/components/min-x.d.ts +2 -0
- package/dist/cjs/annotation/components/min-x.js +41 -0
- package/dist/cjs/annotation/components/min-y.d.ts +2 -0
- package/dist/cjs/annotation/components/min-y.js +41 -0
- package/dist/cjs/annotation/components/outlier.d.ts +3 -0
- package/dist/cjs/annotation/components/outlier.js +83 -0
- package/dist/cjs/annotation/components/path.d.ts +20 -0
- package/dist/cjs/annotation/components/path.js +147 -0
- package/dist/cjs/annotation/components/peak.d.ts +2 -0
- package/dist/cjs/annotation/components/peak.js +42 -0
- package/dist/cjs/annotation/components/point.d.ts +26 -0
- package/dist/cjs/annotation/components/point.js +241 -0
- package/dist/cjs/annotation/components/quadrant.d.ts +3 -0
- package/dist/cjs/annotation/components/quadrant.js +97 -0
- package/dist/cjs/annotation/components/quantile.d.ts +2 -0
- package/dist/cjs/annotation/components/quantile.js +49 -0
- package/dist/cjs/annotation/components/range-inside.d.ts +2 -0
- package/dist/cjs/annotation/components/range-inside.js +65 -0
- package/dist/cjs/annotation/components/range-outside.d.ts +2 -0
- package/dist/cjs/annotation/components/range-outside.js +65 -0
- package/dist/cjs/annotation/components/range-x.d.ts +2 -0
- package/dist/cjs/annotation/components/range-x.js +39 -0
- package/dist/cjs/annotation/components/range-y.d.ts +2 -0
- package/dist/cjs/annotation/components/range-y.js +39 -0
- package/dist/cjs/annotation/components/range.d.ts +15 -0
- package/dist/cjs/annotation/components/range.js +87 -0
- package/dist/cjs/annotation/components/target.d.ts +2 -0
- package/dist/cjs/annotation/components/target.js +51 -0
- package/dist/cjs/annotation/components/text.d.ts +15 -0
- package/dist/cjs/annotation/components/text.js +74 -0
- package/dist/cjs/annotation/components/threshold-highlight.d.ts +3 -0
- package/dist/cjs/annotation/components/threshold-highlight.js +223 -0
- package/dist/cjs/annotation/components/threshold-x.d.ts +2 -0
- package/dist/cjs/annotation/components/threshold-x.js +39 -0
- package/dist/cjs/annotation/components/threshold-y.d.ts +2 -0
- package/dist/cjs/annotation/components/threshold-y.js +40 -0
- package/dist/cjs/annotation/components/top-n.d.ts +2 -0
- package/dist/cjs/annotation/components/top-n.js +57 -0
- package/dist/cjs/annotation/components/valley.d.ts +2 -0
- package/dist/cjs/annotation/components/valley.js +42 -0
- package/dist/cjs/annotation/index.d.ts +1 -0
- package/dist/cjs/annotation/index.js +29 -0
- package/dist/cjs/annotation/label.d.ts +38 -0
- package/dist/cjs/annotation/label.js +347 -0
- package/dist/cjs/annotation/layout.d.ts +12 -0
- package/dist/cjs/annotation/layout.js +142 -0
- package/dist/cjs/annotation/merge.d.ts +19 -0
- package/dist/cjs/annotation/merge.js +60 -0
- package/dist/cjs/annotation/registry.d.ts +190 -0
- package/dist/cjs/annotation/registry.js +134 -0
- package/dist/cjs/annotation/runtime/g2.d.ts +90 -0
- package/dist/cjs/annotation/runtime/g2.js +521 -0
- package/dist/cjs/annotation/runtime/g6.d.ts +40 -0
- package/dist/cjs/annotation/runtime/g6.js +310 -0
- package/dist/cjs/annotation/runtime/index.d.ts +11 -0
- package/dist/cjs/annotation/runtime/index.js +41 -0
- package/dist/cjs/annotation/runtime/summary.d.ts +17 -0
- package/dist/cjs/annotation/runtime/summary.js +39 -0
- package/dist/cjs/annotation/runtime/table.d.ts +16 -0
- package/dist/cjs/annotation/runtime/table.js +39 -0
- package/dist/cjs/annotation/utils.d.ts +40 -0
- package/dist/cjs/annotation/utils.js +275 -0
- package/dist/cjs/theme/annotation.d.ts +236 -0
- package/dist/cjs/theme/annotation.js +167 -0
- package/dist/cjs/theme/g2.js +13 -15
- package/dist/cjs/theme/g6.js +2 -2
- package/dist/cjs/theme/summary.js +2 -2
- package/dist/cjs/types/annotation.d.ts +310 -0
- package/dist/cjs/types/annotation.js +17 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/util/axis.d.ts +28 -0
- package/dist/cjs/util/axis.js +184 -0
- package/dist/cjs/util/components.d.ts +0 -10
- package/dist/cjs/util/components.js +9 -64
- package/dist/cjs/util/index.d.ts +7 -4
- package/dist/cjs/util/index.js +53 -9
- package/dist/cjs/vis/area/index.d.ts +2 -0
- package/dist/cjs/vis/area/index.js +30 -13
- package/dist/cjs/vis/bar/index.d.ts +2 -0
- package/dist/cjs/vis/bar/index.js +37 -7
- package/dist/cjs/vis/boxplot/index.js +14 -3
- package/dist/cjs/vis/column/index.d.ts +2 -0
- package/dist/cjs/vis/column/index.js +28 -9
- package/dist/cjs/vis/dual-axes/index.js +9 -9
- package/dist/cjs/vis/fishbone-diagram/index.js +2 -2
- package/dist/cjs/vis/flow-diagram/index.js +2 -2
- package/dist/cjs/vis/funnel/index.js +10 -13
- package/dist/cjs/vis/histogram/index.js +2 -2
- package/dist/cjs/vis/indented-tree/index.js +2 -2
- package/dist/cjs/vis/line/index.d.ts +2 -0
- package/dist/cjs/vis/line/index.js +26 -10
- package/dist/cjs/vis/liquid/index.js +2 -2
- package/dist/cjs/vis/mindmap/index.js +2 -2
- package/dist/cjs/vis/network-graph/index.d.ts +2 -0
- package/dist/cjs/vis/network-graph/index.js +24 -3
- package/dist/cjs/vis/organization-chart/index.js +2 -2
- package/dist/cjs/vis/pie/index.d.ts +2 -0
- package/dist/cjs/vis/pie/index.js +21 -10
- package/dist/cjs/vis/radar/index.js +4 -6
- package/dist/cjs/vis/sankey/index.js +14 -1
- package/dist/cjs/vis/scatter/index.d.ts +10 -3
- package/dist/cjs/vis/scatter/index.js +18 -7
- package/dist/cjs/vis/summary/index.d.ts +9 -2
- package/dist/cjs/vis/summary/index.js +25 -8
- package/dist/cjs/vis/table/index.d.ts +2 -0
- package/dist/cjs/vis/table/index.js +48 -30
- package/dist/cjs/vis/venn/index.js +2 -2
- package/dist/cjs/vis/violin/index.js +14 -3
- package/dist/cjs/vis/waterfall/index.js +17 -9
- package/dist/cjs/vis/word-cloud/index.js +4 -6
- package/dist/cjs/vis-wrapper/index.js +2 -1
- package/dist/esm/annotation/components/bottom-n.d.ts +2 -0
- package/dist/esm/annotation/components/bottom-n.js +42 -0
- package/dist/esm/annotation/components/centroid.d.ts +2 -0
- package/dist/esm/annotation/components/centroid.js +73 -0
- package/dist/esm/annotation/components/connector.d.ts +25 -0
- package/dist/esm/annotation/components/connector.js +332 -0
- package/dist/esm/annotation/components/contribution.d.ts +3 -0
- package/dist/esm/annotation/components/contribution.js +174 -0
- package/dist/esm/annotation/components/crossing.d.ts +3 -0
- package/dist/esm/annotation/components/crossing.js +665 -0
- package/dist/esm/annotation/components/event.d.ts +2 -0
- package/dist/esm/annotation/components/event.js +46 -0
- package/dist/esm/annotation/components/first.d.ts +2 -0
- package/dist/esm/annotation/components/first.js +18 -0
- package/dist/esm/annotation/components/group.d.ts +3 -0
- package/dist/esm/annotation/components/group.js +64 -0
- package/dist/esm/annotation/components/highlight.d.ts +14 -0
- package/dist/esm/annotation/components/highlight.js +838 -0
- package/dist/esm/annotation/components/index.d.ts +34 -0
- package/dist/esm/annotation/components/index.js +34 -0
- package/dist/esm/annotation/components/last.d.ts +2 -0
- package/dist/esm/annotation/components/last.js +18 -0
- package/dist/esm/annotation/components/max-x.d.ts +2 -0
- package/dist/esm/annotation/components/max-x.js +17 -0
- package/dist/esm/annotation/components/max-y.d.ts +2 -0
- package/dist/esm/annotation/components/max-y.js +17 -0
- package/dist/esm/annotation/components/mean.d.ts +2 -0
- package/dist/esm/annotation/components/mean.js +40 -0
- package/dist/esm/annotation/components/median.d.ts +2 -0
- package/dist/esm/annotation/components/median.js +32 -0
- package/dist/esm/annotation/components/min-x.d.ts +2 -0
- package/dist/esm/annotation/components/min-x.js +17 -0
- package/dist/esm/annotation/components/min-y.d.ts +2 -0
- package/dist/esm/annotation/components/min-y.js +17 -0
- package/dist/esm/annotation/components/outlier.d.ts +3 -0
- package/dist/esm/annotation/components/outlier.js +98 -0
- package/dist/esm/annotation/components/path.d.ts +20 -0
- package/dist/esm/annotation/components/path.js +165 -0
- package/dist/esm/annotation/components/peak.d.ts +2 -0
- package/dist/esm/annotation/components/peak.js +20 -0
- package/dist/esm/annotation/components/point.d.ts +26 -0
- package/dist/esm/annotation/components/point.js +277 -0
- package/dist/esm/annotation/components/quadrant.d.ts +3 -0
- package/dist/esm/annotation/components/quadrant.js +83 -0
- package/dist/esm/annotation/components/quantile.d.ts +2 -0
- package/dist/esm/annotation/components/quantile.js +32 -0
- package/dist/esm/annotation/components/range-inside.d.ts +2 -0
- package/dist/esm/annotation/components/range-inside.js +55 -0
- package/dist/esm/annotation/components/range-outside.d.ts +2 -0
- package/dist/esm/annotation/components/range-outside.js +55 -0
- package/dist/esm/annotation/components/range-x.d.ts +2 -0
- package/dist/esm/annotation/components/range-x.js +15 -0
- package/dist/esm/annotation/components/range-y.d.ts +2 -0
- package/dist/esm/annotation/components/range-y.js +15 -0
- package/dist/esm/annotation/components/range.d.ts +15 -0
- package/dist/esm/annotation/components/range.js +92 -0
- package/dist/esm/annotation/components/target.d.ts +2 -0
- package/dist/esm/annotation/components/target.js +44 -0
- package/dist/esm/annotation/components/text.d.ts +15 -0
- package/dist/esm/annotation/components/text.js +78 -0
- package/dist/esm/annotation/components/threshold-highlight.d.ts +3 -0
- package/dist/esm/annotation/components/threshold-highlight.js +297 -0
- package/dist/esm/annotation/components/threshold-x.d.ts +2 -0
- package/dist/esm/annotation/components/threshold-x.js +23 -0
- package/dist/esm/annotation/components/threshold-y.d.ts +2 -0
- package/dist/esm/annotation/components/threshold-y.js +24 -0
- package/dist/esm/annotation/components/top-n.d.ts +2 -0
- package/dist/esm/annotation/components/top-n.js +42 -0
- package/dist/esm/annotation/components/valley.d.ts +2 -0
- package/dist/esm/annotation/components/valley.js +20 -0
- package/dist/esm/annotation/index.d.ts +1 -0
- package/dist/esm/annotation/index.js +1 -0
- package/dist/esm/annotation/label.d.ts +38 -0
- package/dist/esm/annotation/label.js +449 -0
- package/dist/esm/annotation/layout.d.ts +12 -0
- package/dist/esm/annotation/layout.js +182 -0
- package/dist/esm/annotation/merge.d.ts +19 -0
- package/dist/esm/annotation/merge.js +67 -0
- package/dist/esm/annotation/registry.d.ts +190 -0
- package/dist/esm/annotation/registry.js +220 -0
- package/dist/esm/annotation/runtime/g2.d.ts +90 -0
- package/dist/esm/annotation/runtime/g2.js +754 -0
- package/dist/esm/annotation/runtime/g6.d.ts +40 -0
- package/dist/esm/annotation/runtime/g6.js +447 -0
- package/dist/esm/annotation/runtime/index.d.ts +11 -0
- package/dist/esm/annotation/runtime/index.js +26 -0
- package/dist/esm/annotation/runtime/summary.d.ts +17 -0
- package/dist/esm/annotation/runtime/summary.js +21 -0
- package/dist/esm/annotation/runtime/table.d.ts +16 -0
- package/dist/esm/annotation/runtime/table.js +21 -0
- package/dist/esm/annotation/utils.d.ts +40 -0
- package/dist/esm/annotation/utils.js +370 -0
- package/dist/esm/theme/annotation.d.ts +236 -0
- package/dist/esm/theme/annotation.js +186 -0
- package/dist/esm/theme/g2.js +2 -10
- package/dist/esm/theme/g6.js +1 -1
- package/dist/esm/theme/summary.js +1 -1
- package/dist/esm/types/annotation.d.ts +310 -0
- package/dist/esm/types/annotation.js +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/util/axis.d.ts +28 -0
- package/dist/esm/util/axis.js +222 -0
- package/dist/esm/util/components.d.ts +0 -10
- package/dist/esm/util/components.js +24 -69
- package/dist/esm/util/index.d.ts +7 -4
- package/dist/esm/util/index.js +7 -4
- package/dist/esm/vis/area/index.d.ts +2 -0
- package/dist/esm/vis/area/index.js +32 -9
- package/dist/esm/vis/bar/index.d.ts +2 -0
- package/dist/esm/vis/bar/index.js +37 -6
- package/dist/esm/vis/boxplot/index.js +10 -2
- package/dist/esm/vis/column/index.d.ts +2 -0
- package/dist/esm/vis/column/index.js +33 -12
- package/dist/esm/vis/dual-axes/index.js +10 -10
- package/dist/esm/vis/fishbone-diagram/index.js +1 -1
- package/dist/esm/vis/flow-diagram/index.js +1 -1
- package/dist/esm/vis/funnel/index.js +2 -7
- package/dist/esm/vis/histogram/index.js +4 -3
- package/dist/esm/vis/indented-tree/index.js +1 -1
- package/dist/esm/vis/line/index.d.ts +2 -0
- package/dist/esm/vis/line/index.js +31 -9
- package/dist/esm/vis/liquid/index.js +1 -1
- package/dist/esm/vis/mindmap/index.js +1 -1
- package/dist/esm/vis/network-graph/index.d.ts +2 -0
- package/dist/esm/vis/network-graph/index.js +29 -2
- package/dist/esm/vis/organization-chart/index.js +1 -1
- package/dist/esm/vis/pie/index.d.ts +2 -0
- package/dist/esm/vis/pie/index.js +25 -8
- package/dist/esm/vis/radar/index.js +1 -3
- package/dist/esm/vis/sankey/index.js +15 -1
- package/dist/esm/vis/scatter/index.d.ts +10 -3
- package/dist/esm/vis/scatter/index.js +28 -5
- package/dist/esm/vis/summary/index.d.ts +9 -2
- package/dist/esm/vis/summary/index.js +31 -13
- package/dist/esm/vis/table/index.d.ts +2 -0
- package/dist/esm/vis/table/index.js +50 -33
- package/dist/esm/vis/venn/index.js +1 -1
- package/dist/esm/vis/violin/index.js +10 -2
- package/dist/esm/vis/waterfall/index.js +16 -13
- package/dist/esm/vis/word-cloud/index.js +1 -3
- package/dist/esm/vis-wrapper/index.js +2 -1
- package/dist/umd/index.min.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { Annotation, RendererAnnotationOptions } from '../types/annotation';
|
|
2
|
+
import type { ChartType } from '../types/theme';
|
|
3
|
+
import { type AnnotationEntry, type AnnotationGroup } from './merge';
|
|
4
|
+
import type { G2AnnotationContext, G6AnnotationContext, MarkOptions, SummaryContext, TableContext } from './runtime';
|
|
5
|
+
interface AnnotationContexts<T extends object> {
|
|
6
|
+
g2: G2AnnotationContext<T>;
|
|
7
|
+
g6: G6AnnotationContext<T>;
|
|
8
|
+
table: TableContext<T>;
|
|
9
|
+
summary: SummaryContext;
|
|
10
|
+
}
|
|
11
|
+
type AnnotationRenderer = keyof AnnotationContexts<object>;
|
|
12
|
+
type AnnotationType = Annotation['type'];
|
|
13
|
+
type ComponentRenderer<K extends AnnotationType> = {
|
|
14
|
+
[R in AnnotationRenderer]: Extract<RendererAnnotationOptions<object, R>, {
|
|
15
|
+
type: K;
|
|
16
|
+
}> extends never ? never : R;
|
|
17
|
+
}[AnnotationRenderer];
|
|
18
|
+
/** Internal renderer constraints keep table mappings out of statistical-chart suggestions. */
|
|
19
|
+
export type RendererAnnotation<T extends object, R extends AnnotationRenderer, C extends ChartType | undefined = undefined> = [C] extends [undefined] ? RendererAnnotationOptions<T, R> : Extract<RendererAnnotationOptions<T, R>, {
|
|
20
|
+
type: SupportedAnnotationType<Exclude<C, undefined>>;
|
|
21
|
+
}>;
|
|
22
|
+
type SupportedAnnotationType<C extends ChartType> = {
|
|
23
|
+
[K in AnnotationType]: Extract<C, (typeof components)[K]['charts'][number]> extends never ? never : K;
|
|
24
|
+
}[AnnotationType];
|
|
25
|
+
/** Expansion reads source data and defaults; only deferred drawing can change a scene. */
|
|
26
|
+
interface AnnotationSources<T extends object> {
|
|
27
|
+
g2: Pick<G2AnnotationContext<T>, 'mapping' | 'defaults' | 'chartType'> & Partial<Pick<G2AnnotationContext<T>, 'sourceMarks' | 'isVisible'>>;
|
|
28
|
+
g6: Pick<G6AnnotationContext<T>, 'chartType' | 'data'>;
|
|
29
|
+
table: Pick<TableContext<T>, 'chartType' | 'data' | 'defaults'>;
|
|
30
|
+
summary: SummaryContext;
|
|
31
|
+
}
|
|
32
|
+
export interface AnnotationResult {
|
|
33
|
+
marks?: MarkOptions[];
|
|
34
|
+
update?: () => void;
|
|
35
|
+
cleanup?: () => void;
|
|
36
|
+
}
|
|
37
|
+
export type AnnotationDraw<K extends AnnotationType, R extends AnnotationRenderer> = <T extends object>(annotations: Extract<RendererAnnotation<T, R>, {
|
|
38
|
+
type: K;
|
|
39
|
+
}>[], context: AnnotationContexts<T>[R]) => AnnotationResult;
|
|
40
|
+
/** Components return configurations and/or deferred drawing, never drawing during preparation. */
|
|
41
|
+
export type AnnotationComponent<K extends AnnotationType, R extends AnnotationRenderer = ComponentRenderer<K>> = {
|
|
42
|
+
[P in R]: <T extends object>(annotations: Extract<RendererAnnotation<T, P>, {
|
|
43
|
+
type: K;
|
|
44
|
+
}>[], context: AnnotationSources<T>[P]) => (RendererAnnotation<T, P> | AnnotationDraw<K, P>)[] | AnnotationDraw<K, P>;
|
|
45
|
+
};
|
|
46
|
+
type DrawingEntry<T extends object, R extends AnnotationRenderer> = AnnotationEntry<RendererAnnotation<T, R>, AnnotationContexts<T>[R]>;
|
|
47
|
+
/** Registration is the single source for chart support in both types and runtime checks. */
|
|
48
|
+
declare const components: {
|
|
49
|
+
readonly path: {
|
|
50
|
+
readonly component: AnnotationComponent<"path", "g2" | "g6">;
|
|
51
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "network-graph"];
|
|
52
|
+
};
|
|
53
|
+
readonly range: {
|
|
54
|
+
readonly component: AnnotationComponent<"range", "g2">;
|
|
55
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
56
|
+
};
|
|
57
|
+
readonly connector: {
|
|
58
|
+
readonly component: AnnotationComponent<"connector", "g2" | "g6">;
|
|
59
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "network-graph"];
|
|
60
|
+
};
|
|
61
|
+
readonly point: {
|
|
62
|
+
readonly component: AnnotationComponent<"point", "g2" | "g6">;
|
|
63
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "network-graph"];
|
|
64
|
+
};
|
|
65
|
+
readonly text: {
|
|
66
|
+
readonly component: AnnotationComponent<"text", "g2" | "g6">;
|
|
67
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "network-graph"];
|
|
68
|
+
};
|
|
69
|
+
readonly highlight: {
|
|
70
|
+
readonly component: AnnotationComponent<"highlight", ComponentRenderer<"highlight">>;
|
|
71
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "pie", "network-graph", "table", "summary"];
|
|
72
|
+
};
|
|
73
|
+
readonly mean: {
|
|
74
|
+
readonly component: AnnotationComponent<"mean">;
|
|
75
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
76
|
+
};
|
|
77
|
+
readonly median: {
|
|
78
|
+
readonly component: AnnotationComponent<"median">;
|
|
79
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
80
|
+
};
|
|
81
|
+
readonly quantile: {
|
|
82
|
+
readonly component: AnnotationComponent<"quantile">;
|
|
83
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
84
|
+
};
|
|
85
|
+
readonly thresholdX: {
|
|
86
|
+
readonly component: AnnotationComponent<"thresholdX">;
|
|
87
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
88
|
+
};
|
|
89
|
+
readonly thresholdY: {
|
|
90
|
+
readonly component: AnnotationComponent<"thresholdY">;
|
|
91
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
92
|
+
};
|
|
93
|
+
readonly target: {
|
|
94
|
+
readonly component: AnnotationComponent<"target">;
|
|
95
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
96
|
+
};
|
|
97
|
+
readonly event: {
|
|
98
|
+
readonly component: AnnotationComponent<"event">;
|
|
99
|
+
readonly charts: readonly ["line", "area", "column", "bar"];
|
|
100
|
+
};
|
|
101
|
+
readonly rangeX: {
|
|
102
|
+
readonly component: AnnotationComponent<"rangeX">;
|
|
103
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
104
|
+
};
|
|
105
|
+
readonly rangeY: {
|
|
106
|
+
readonly component: AnnotationComponent<"rangeY">;
|
|
107
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
108
|
+
};
|
|
109
|
+
readonly quadrant: {
|
|
110
|
+
readonly component: AnnotationComponent<"quadrant">;
|
|
111
|
+
readonly charts: readonly ["scatter"];
|
|
112
|
+
};
|
|
113
|
+
readonly centroid: {
|
|
114
|
+
readonly component: AnnotationComponent<"centroid">;
|
|
115
|
+
readonly charts: readonly ["scatter"];
|
|
116
|
+
};
|
|
117
|
+
readonly crossing: {
|
|
118
|
+
readonly component: AnnotationComponent<"crossing">;
|
|
119
|
+
readonly charts: readonly ["line", "area"];
|
|
120
|
+
};
|
|
121
|
+
readonly maxX: {
|
|
122
|
+
readonly component: AnnotationComponent<"maxX", "g2">;
|
|
123
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
124
|
+
};
|
|
125
|
+
readonly minX: {
|
|
126
|
+
readonly component: AnnotationComponent<"minX", "g2">;
|
|
127
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
128
|
+
};
|
|
129
|
+
readonly maxY: {
|
|
130
|
+
readonly component: AnnotationComponent<"maxY", "g2">;
|
|
131
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
132
|
+
};
|
|
133
|
+
readonly minY: {
|
|
134
|
+
readonly component: AnnotationComponent<"minY", "g2">;
|
|
135
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
136
|
+
};
|
|
137
|
+
readonly first: {
|
|
138
|
+
readonly component: AnnotationComponent<"first", "g2">;
|
|
139
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
140
|
+
};
|
|
141
|
+
readonly last: {
|
|
142
|
+
readonly component: AnnotationComponent<"last", "g2">;
|
|
143
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
144
|
+
};
|
|
145
|
+
readonly peak: {
|
|
146
|
+
readonly component: AnnotationComponent<"peak", "g2">;
|
|
147
|
+
readonly charts: readonly ["line", "area"];
|
|
148
|
+
};
|
|
149
|
+
readonly valley: {
|
|
150
|
+
readonly component: AnnotationComponent<"valley", "g2">;
|
|
151
|
+
readonly charts: readonly ["line", "area"];
|
|
152
|
+
};
|
|
153
|
+
readonly topN: {
|
|
154
|
+
readonly component: AnnotationComponent<"topN", "table" | "g2">;
|
|
155
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "pie", "table"];
|
|
156
|
+
};
|
|
157
|
+
readonly bottomN: {
|
|
158
|
+
readonly component: AnnotationComponent<"bottomN", "table" | "g2">;
|
|
159
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "pie", "table"];
|
|
160
|
+
};
|
|
161
|
+
readonly thresholdHighlight: {
|
|
162
|
+
readonly component: AnnotationComponent<"thresholdHighlight", "table" | "g2">;
|
|
163
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "table"];
|
|
164
|
+
};
|
|
165
|
+
readonly rangeInside: {
|
|
166
|
+
readonly component: AnnotationComponent<"rangeInside", "table" | "g2">;
|
|
167
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "table"];
|
|
168
|
+
};
|
|
169
|
+
readonly rangeOutside: {
|
|
170
|
+
readonly component: AnnotationComponent<"rangeOutside", "table" | "g2">;
|
|
171
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "table"];
|
|
172
|
+
};
|
|
173
|
+
readonly outlier: {
|
|
174
|
+
readonly component: AnnotationComponent<"outlier", "table" | "g2">;
|
|
175
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "table"];
|
|
176
|
+
};
|
|
177
|
+
readonly group: {
|
|
178
|
+
readonly component: AnnotationComponent<"group", "g2">;
|
|
179
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter"];
|
|
180
|
+
};
|
|
181
|
+
readonly contribution: {
|
|
182
|
+
readonly component: AnnotationComponent<"contribution", "table" | "g2">;
|
|
183
|
+
readonly charts: readonly ["line", "area", "column", "bar", "scatter", "pie", "table"];
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
export declare function renderAnnotations<T extends object, R extends AnnotationRenderer>(renderer: R, annotations: RendererAnnotation<T, R>[], context: AnnotationContexts<T>[R]): AnnotationResult;
|
|
187
|
+
/** Expand semantic configurations and prepare deferred drawing without changing the scene. */
|
|
188
|
+
export declare function prepareAnnotations<T extends object, R extends AnnotationRenderer>(renderer: R, annotations: RendererAnnotation<T, R>[], context: AnnotationSources<T>[R]): DrawingEntry<T, R>[];
|
|
189
|
+
export declare function drawAnnotations<T extends object, R extends AnnotationRenderer>(groups: AnnotationGroup<RendererAnnotation<T, R>, AnnotationContexts<T>[R]>[], context: AnnotationContexts<T>[R]): AnnotationResult;
|
|
190
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target2, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target2, 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/registry.ts
|
|
20
|
+
var registry_exports = {};
|
|
21
|
+
__export(registry_exports, {
|
|
22
|
+
drawAnnotations: () => drawAnnotations,
|
|
23
|
+
prepareAnnotations: () => prepareAnnotations,
|
|
24
|
+
renderAnnotations: () => renderAnnotations
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(registry_exports);
|
|
27
|
+
var import_components = require("./components");
|
|
28
|
+
var import_merge = require("./merge");
|
|
29
|
+
var drawingComponents = {
|
|
30
|
+
path: import_components.path,
|
|
31
|
+
range: import_components.range,
|
|
32
|
+
connector: import_components.connector,
|
|
33
|
+
point: import_components.point,
|
|
34
|
+
text: import_components.text,
|
|
35
|
+
highlight: import_components.highlight,
|
|
36
|
+
thresholdHighlight: import_components.thresholdHighlight
|
|
37
|
+
};
|
|
38
|
+
var cartesianCharts = ["line", "area", "column", "bar", "scatter"];
|
|
39
|
+
var components = {
|
|
40
|
+
path: {
|
|
41
|
+
component: import_components.path,
|
|
42
|
+
charts: [...cartesianCharts, "network-graph"]
|
|
43
|
+
},
|
|
44
|
+
range: { component: import_components.range, charts: cartesianCharts },
|
|
45
|
+
connector: {
|
|
46
|
+
component: import_components.connector,
|
|
47
|
+
charts: [...cartesianCharts, "network-graph"]
|
|
48
|
+
},
|
|
49
|
+
point: {
|
|
50
|
+
component: import_components.point,
|
|
51
|
+
charts: [...cartesianCharts, "network-graph"]
|
|
52
|
+
},
|
|
53
|
+
text: {
|
|
54
|
+
component: import_components.text,
|
|
55
|
+
charts: [...cartesianCharts, "network-graph"]
|
|
56
|
+
},
|
|
57
|
+
highlight: {
|
|
58
|
+
component: import_components.highlight,
|
|
59
|
+
charts: [...cartesianCharts, "pie", "network-graph", "table", "summary"]
|
|
60
|
+
},
|
|
61
|
+
mean: { component: import_components.mean, charts: cartesianCharts },
|
|
62
|
+
median: { component: import_components.median, charts: cartesianCharts },
|
|
63
|
+
quantile: { component: import_components.quantile, charts: cartesianCharts },
|
|
64
|
+
thresholdX: { component: import_components.thresholdX, charts: cartesianCharts },
|
|
65
|
+
thresholdY: { component: import_components.thresholdY, charts: cartesianCharts },
|
|
66
|
+
target: { component: import_components.target, charts: cartesianCharts },
|
|
67
|
+
event: { component: import_components.event, charts: ["line", "area", "column", "bar"] },
|
|
68
|
+
rangeX: { component: import_components.rangeX, charts: cartesianCharts },
|
|
69
|
+
rangeY: { component: import_components.rangeY, charts: cartesianCharts },
|
|
70
|
+
quadrant: { component: import_components.quadrant, charts: ["scatter"] },
|
|
71
|
+
centroid: { component: import_components.centroid, charts: ["scatter"] },
|
|
72
|
+
crossing: { component: import_components.crossing, charts: ["line", "area"] },
|
|
73
|
+
maxX: { component: import_components.maxX, charts: cartesianCharts },
|
|
74
|
+
minX: { component: import_components.minX, charts: cartesianCharts },
|
|
75
|
+
maxY: { component: import_components.maxY, charts: cartesianCharts },
|
|
76
|
+
minY: { component: import_components.minY, charts: cartesianCharts },
|
|
77
|
+
first: { component: import_components.first, charts: cartesianCharts },
|
|
78
|
+
last: { component: import_components.last, charts: cartesianCharts },
|
|
79
|
+
peak: { component: import_components.peak, charts: ["line", "area"] },
|
|
80
|
+
valley: { component: import_components.valley, charts: ["line", "area"] },
|
|
81
|
+
topN: { component: import_components.topN, charts: [...cartesianCharts, "pie", "table"] },
|
|
82
|
+
bottomN: { component: import_components.bottomN, charts: [...cartesianCharts, "pie", "table"] },
|
|
83
|
+
thresholdHighlight: { component: import_components.thresholdHighlight, charts: [...cartesianCharts, "table"] },
|
|
84
|
+
rangeInside: { component: import_components.rangeInside, charts: [...cartesianCharts, "table"] },
|
|
85
|
+
rangeOutside: { component: import_components.rangeOutside, charts: [...cartesianCharts, "table"] },
|
|
86
|
+
outlier: { component: import_components.outlier, charts: [...cartesianCharts, "table"] },
|
|
87
|
+
group: { component: import_components.group, charts: cartesianCharts },
|
|
88
|
+
contribution: { component: import_components.contribution, charts: [...cartesianCharts, "pie", "table"] }
|
|
89
|
+
};
|
|
90
|
+
function renderAnnotations(renderer, annotations, context) {
|
|
91
|
+
const prepared = prepareAnnotations(renderer, annotations, context);
|
|
92
|
+
const groups = (0, import_merge.mergeAnnotations)(prepared);
|
|
93
|
+
return drawAnnotations(groups, context);
|
|
94
|
+
}
|
|
95
|
+
function prepareAnnotations(renderer, annotations, context) {
|
|
96
|
+
const expanded = expandAnnotations(renderer, annotations, context);
|
|
97
|
+
const groups = (0, import_merge.mergeAnnotations)(expanded);
|
|
98
|
+
return groups.flatMap(({ annotations: annotations2, draw: prepare }) => {
|
|
99
|
+
const result = prepare(annotations2, context);
|
|
100
|
+
return (Array.isArray(result) ? result : [result]).flatMap(
|
|
101
|
+
(prepared) => typeof prepared === "function" ? annotations2.map((annotation) => ({ annotation, draw: prepared })) : prepareAnnotations(renderer, [prepared], context)
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function drawAnnotations(groups, context) {
|
|
106
|
+
return (0, import_merge.mergeResults)(groups.map(({ annotations, draw }) => draw(annotations, context)));
|
|
107
|
+
}
|
|
108
|
+
function expandAnnotations(renderer, annotations, context) {
|
|
109
|
+
const entries = annotations.map((annotation) => {
|
|
110
|
+
const registration = Object.hasOwn(components, annotation.type) ? components[annotation.type] : void 0;
|
|
111
|
+
const prepare = registration && registration.component[renderer];
|
|
112
|
+
if (!registration || !prepare || !registration.charts.includes(context.chartType))
|
|
113
|
+
throw new Error(`Unsupported ${context.chartType} annotation type: ${annotation.type}.`);
|
|
114
|
+
return { annotation, draw: prepare };
|
|
115
|
+
});
|
|
116
|
+
return entries.flatMap(({ annotation, draw: prepare }) => {
|
|
117
|
+
if (Object.hasOwn(drawingComponents, annotation.type))
|
|
118
|
+
return [{ annotation, draw: prepare }];
|
|
119
|
+
const result = prepare([annotation], context);
|
|
120
|
+
if (typeof result === "function")
|
|
121
|
+
throw new Error("Semantic annotations must return configurations.");
|
|
122
|
+
return result.flatMap((config) => {
|
|
123
|
+
if (typeof config === "function")
|
|
124
|
+
throw new Error("Semantic annotations must return configurations.");
|
|
125
|
+
return expandAnnotations(renderer, [config], context);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
130
|
+
0 && (module.exports = {
|
|
131
|
+
drawAnnotations,
|
|
132
|
+
prepareAnnotations,
|
|
133
|
+
renderAnnotations
|
|
134
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Chart, G2Context, MarkComponent, ShapeComponent, SingleMark } from '@antv/g2';
|
|
2
|
+
import { getAnnotationStyle } from '../../theme/annotation';
|
|
3
|
+
import type { getThemeObject } from '../../theme/g2';
|
|
4
|
+
import type { ChartType } from '../../types';
|
|
5
|
+
import type { Annotation, AnnotationData } from '../../types/annotation';
|
|
6
|
+
import { type Point } from '../layout';
|
|
7
|
+
import type { RendererAnnotation } from '../registry';
|
|
8
|
+
import type { AnnotationBindingOptions } from './index';
|
|
9
|
+
type View = NonNullable<G2Context['views']>[number];
|
|
10
|
+
export type MarkOptions = NonNullable<Parameters<MarkComponent>[0]>;
|
|
11
|
+
export type Scene = NonNullable<Parameters<ShapeComponent>[1]>['document'];
|
|
12
|
+
type Shape = ReturnType<ReturnType<ShapeComponent>>;
|
|
13
|
+
/** Rendering stays independent of the growing set of public analysis configurations. */
|
|
14
|
+
type MarkAnnotation<T extends object> = Extract<Annotation<T>, {
|
|
15
|
+
type: 'path' | 'range' | 'connector' | 'point' | 'text';
|
|
16
|
+
}> | Extract<RendererAnnotation<T, 'g2'>, {
|
|
17
|
+
type: 'highlight';
|
|
18
|
+
}>;
|
|
19
|
+
export type MarkElement = Shape & {
|
|
20
|
+
markType: unknown;
|
|
21
|
+
__data__: {
|
|
22
|
+
points: Point[];
|
|
23
|
+
data?: object;
|
|
24
|
+
seriesIndex?: number[];
|
|
25
|
+
};
|
|
26
|
+
__removed__?: boolean;
|
|
27
|
+
};
|
|
28
|
+
export type LabelElement = Shape & {
|
|
29
|
+
__data__: {
|
|
30
|
+
dependentElement?: MarkElement;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export interface G2AnnotationContext<T extends object> {
|
|
34
|
+
library: NonNullable<G2Context['library']>;
|
|
35
|
+
chartType: ChartType;
|
|
36
|
+
defaults: ReturnType<typeof getAnnotationStyle>;
|
|
37
|
+
sourceMarks: MarkOptions[];
|
|
38
|
+
/** Original fields and data remain internal to the chart runtime. */
|
|
39
|
+
mapping: {
|
|
40
|
+
x: keyof T & string;
|
|
41
|
+
y: keyof T & string;
|
|
42
|
+
data: T[];
|
|
43
|
+
interval?: boolean;
|
|
44
|
+
series?: keyof T & string;
|
|
45
|
+
};
|
|
46
|
+
position(data: AnnotationData<T>, coordinate: View['coordinate'], useSourceGeometry?: boolean): Point | undefined;
|
|
47
|
+
color(data: AnnotationData<T>): string;
|
|
48
|
+
axisValue(axis: 'x' | 'y', value: unknown, center?: boolean): number;
|
|
49
|
+
bandWidth(axis: 'x' | 'y', value: unknown): number;
|
|
50
|
+
onlyAxisFields(data: object): boolean;
|
|
51
|
+
createMark(annotation: MarkAnnotation<T>, definition: G2MarkDefinition): MarkOptions;
|
|
52
|
+
getTextStyle(annotation: MarkAnnotation<T>): Record<string, unknown> & {
|
|
53
|
+
wordWrapWidth(): number;
|
|
54
|
+
};
|
|
55
|
+
getScene(): Scene;
|
|
56
|
+
getSourceData(element: MarkElement): T[];
|
|
57
|
+
isVisible(data: AnnotationData<T>): boolean;
|
|
58
|
+
getCoordinate(): View['coordinate'];
|
|
59
|
+
getGeometry(data: T): {
|
|
60
|
+
points: Point[];
|
|
61
|
+
y?: number;
|
|
62
|
+
y1?: number;
|
|
63
|
+
} | undefined;
|
|
64
|
+
}
|
|
65
|
+
interface G2MarkDefinition {
|
|
66
|
+
nativeType: keyof ReturnType<typeof getThemeObject>['theme'];
|
|
67
|
+
geometry(native: SingleMark): SingleMark;
|
|
68
|
+
shape?: string;
|
|
69
|
+
draw?: (scene: Scene) => Shape;
|
|
70
|
+
decorate?: (element: Shape, points: number[][]) => void;
|
|
71
|
+
style: Record<string, unknown>;
|
|
72
|
+
encode?: MarkOptions['encode'];
|
|
73
|
+
label?: Record<string, unknown> | false;
|
|
74
|
+
labelGap?: number;
|
|
75
|
+
zIndex?: number;
|
|
76
|
+
clip?: boolean;
|
|
77
|
+
/** Resolve annotation-only data after source scales and geometry are available. */
|
|
78
|
+
data?: (coordinate: View['coordinate']) => object[];
|
|
79
|
+
}
|
|
80
|
+
export interface G2AnnotationOptions<T extends object> {
|
|
81
|
+
renderer: 'g2';
|
|
82
|
+
chartType: ChartType;
|
|
83
|
+
chart: Chart;
|
|
84
|
+
annotations?: RendererAnnotation<T, 'g2'>[];
|
|
85
|
+
mapping: G2AnnotationContext<T>['mapping'];
|
|
86
|
+
themeObject: ReturnType<typeof getThemeObject>;
|
|
87
|
+
}
|
|
88
|
+
/** Bind native marks, source coordinates and shared label layout to a G2 chart. */
|
|
89
|
+
export declare function bindAnnotations<T extends object>(binding: AnnotationBindingOptions<T>): (() => void) | undefined;
|
|
90
|
+
export {};
|