@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,184 @@
|
|
|
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/util/axis.ts
|
|
20
|
+
var axis_exports = {};
|
|
21
|
+
__export(axis_exports, {
|
|
22
|
+
bindCartesianAxisLayout: () => bindCartesianAxisLayout,
|
|
23
|
+
createCartesianAxis: () => createCartesianAxis,
|
|
24
|
+
getCartesianAxis: () => getCartesianAxis
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(axis_exports);
|
|
27
|
+
var import_component = require("@antv/component");
|
|
28
|
+
var import_tokens = require("./tokens");
|
|
29
|
+
var DEFAULT_MARGIN_RIGHT = 16;
|
|
30
|
+
var MAX_DIAGONAL_MARGIN_RIGHT = 64;
|
|
31
|
+
var AXIS_HORIZONTAL_PADDING = 96;
|
|
32
|
+
function createCartesianAxis(options, theme = {}) {
|
|
33
|
+
const { axisXTitle, axisYTitle, transposed, xValues = [], xType } = options;
|
|
34
|
+
const numericX = xType === void 0 ? xValues.length > 0 && xValues.every((value) => typeof value === "number" && Number.isFinite(value)) : xType === "number";
|
|
35
|
+
const numericLabels = {
|
|
36
|
+
labelAutoRotate: false,
|
|
37
|
+
transform: [{ type: "hide" }]
|
|
38
|
+
};
|
|
39
|
+
const horizontalNumericLabels = {
|
|
40
|
+
labelTextAlign: (_datum, index, ticks) => !ticks || ticks.length === 1 ? "center" : index === 0 ? "left" : index === ticks.length - 1 ? "right" : "center"
|
|
41
|
+
};
|
|
42
|
+
const category = numericX ? void 0 : createCategoryAxis(options, theme);
|
|
43
|
+
const axis = {
|
|
44
|
+
x: {
|
|
45
|
+
title: axisXTitle || false,
|
|
46
|
+
...(category == null ? void 0 : category.labels) ?? { ...numericLabels, ...horizontalNumericLabels }
|
|
47
|
+
},
|
|
48
|
+
y: {
|
|
49
|
+
title: axisYTitle || false,
|
|
50
|
+
...numericLabels,
|
|
51
|
+
...transposed ? horizontalNumericLabels : {}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return { axis, layout: (category == null ? void 0 : category.layout) ?? (() => ({ marginRight: void 0 })) };
|
|
55
|
+
}
|
|
56
|
+
function getCartesianAxis(options, theme = {}) {
|
|
57
|
+
return createCartesianAxis(options, theme).axis;
|
|
58
|
+
}
|
|
59
|
+
function bindCartesianAxisLayout(chart, axis) {
|
|
60
|
+
chart.on("beforechangesize", () => chart.attr("marginRight", axis.layout().marginRight));
|
|
61
|
+
}
|
|
62
|
+
function createCategoryAxis(options, theme) {
|
|
63
|
+
const { xValues = [], transposed, preferHorizontal } = options;
|
|
64
|
+
const labels = [...new Set(xValues.map((value) => String(value ?? "")))];
|
|
65
|
+
const font = {
|
|
66
|
+
fontSize: 12,
|
|
67
|
+
fontFamily: import_tokens.CHART_FONT_FAMILY,
|
|
68
|
+
...theme.axis,
|
|
69
|
+
...theme.axisX
|
|
70
|
+
};
|
|
71
|
+
const labelFont = {
|
|
72
|
+
fontSize: font.labelFontSize ?? font.fontSize,
|
|
73
|
+
fontFamily: font.labelFontFamily ?? font.fontFamily,
|
|
74
|
+
fontWeight: font.labelFontWeight,
|
|
75
|
+
fontStyle: font.labelFontStyle
|
|
76
|
+
};
|
|
77
|
+
const getSize = () => {
|
|
78
|
+
const element = typeof options.container === "string" ? typeof document === "undefined" ? null : document.getElementById(options.container) || document.querySelector(options.container) : options.container;
|
|
79
|
+
const width = (element == null ? void 0 : element.clientWidth) || options.chartWidth || 640;
|
|
80
|
+
const height = (element == null ? void 0 : element.clientHeight) || options.chartHeight || 400;
|
|
81
|
+
return { width, height };
|
|
82
|
+
};
|
|
83
|
+
let fullWidth;
|
|
84
|
+
const categoryLayout = () => {
|
|
85
|
+
fullWidth ?? (fullWidth = labels.reduce(
|
|
86
|
+
(max, label) => Math.max(max, (0, import_component.measureTextWidth)(label, labelFont)),
|
|
87
|
+
0
|
|
88
|
+
));
|
|
89
|
+
return getCategoryLayout({
|
|
90
|
+
...getSize(),
|
|
91
|
+
transposed,
|
|
92
|
+
preferHorizontal,
|
|
93
|
+
xTicksAtEdges: options.xTicksAtEdges,
|
|
94
|
+
labelCount: labels.length,
|
|
95
|
+
fullWidth,
|
|
96
|
+
fontSize: Number(labelFont.fontSize)
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const categoryLabels = {
|
|
100
|
+
// Explicit rotation also prevents G2's measurement pass forcing 0°/90°.
|
|
101
|
+
labelAutoRotate: false,
|
|
102
|
+
labelTransform: () => `rotate(${categoryLayout().angle})`,
|
|
103
|
+
labelWordWrap: true,
|
|
104
|
+
labelWordWrapWidth: () => categoryLayout().textWidth,
|
|
105
|
+
labelMaxLines: 1,
|
|
106
|
+
labelTextOverflow: "…",
|
|
107
|
+
transform: [{ type: "hide" }]
|
|
108
|
+
};
|
|
109
|
+
if (preferHorizontal && !transposed) {
|
|
110
|
+
categoryLabels.labelTextAlign = (datum, index, ticks) => {
|
|
111
|
+
const layout = categoryLayout();
|
|
112
|
+
if (layout.angle !== 0)
|
|
113
|
+
return "start";
|
|
114
|
+
if (!ticks || ticks.length <= 1 || index !== 0 && index !== ticks.length - 1)
|
|
115
|
+
return "center";
|
|
116
|
+
const edge = index === 0 ? datum.value : 1 - datum.value;
|
|
117
|
+
const available = Math.max(12, getSize().width - AXIS_HORIZONTAL_PADDING) * edge + DEFAULT_MARGIN_RIGHT;
|
|
118
|
+
const text = String(datum.label);
|
|
119
|
+
const textWidth = Math.min((0, import_component.measureTextWidth)(text, labelFont), layout.textWidth);
|
|
120
|
+
return textWidth / 2 <= available ? "center" : index === 0 ? "left" : "right";
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
labels: categoryLabels,
|
|
125
|
+
layout: () => ({ marginRight: categoryLayout().marginRight })
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function getCategoryLayout({
|
|
129
|
+
width,
|
|
130
|
+
height,
|
|
131
|
+
transposed,
|
|
132
|
+
preferHorizontal,
|
|
133
|
+
xTicksAtEdges,
|
|
134
|
+
labelCount,
|
|
135
|
+
fullWidth,
|
|
136
|
+
fontSize
|
|
137
|
+
}) {
|
|
138
|
+
if (transposed)
|
|
139
|
+
return { angle: 0, textWidth: Math.max(24, Math.min(120, width * 0.3)) };
|
|
140
|
+
const limit = Math.max(24, Math.min(160, height * 0.5));
|
|
141
|
+
if (labelCount <= 1)
|
|
142
|
+
return { angle: 0, textWidth: limit };
|
|
143
|
+
const slot = Math.max(12, (width - AXIS_HORIZONTAL_PADDING) / labelCount - 6);
|
|
144
|
+
if (preferHorizontal) {
|
|
145
|
+
if (fullWidth <= fontSize * 3 || fullWidth <= slot)
|
|
146
|
+
return { angle: 0, textWidth: limit };
|
|
147
|
+
const marginRight = getDiagonalMarginRight(
|
|
148
|
+
width,
|
|
149
|
+
fullWidth,
|
|
150
|
+
fontSize,
|
|
151
|
+
labelCount,
|
|
152
|
+
xTicksAtEdges
|
|
153
|
+
);
|
|
154
|
+
if (marginRight > MAX_DIAGONAL_MARGIN_RIGHT)
|
|
155
|
+
return { angle: 90, textWidth: limit };
|
|
156
|
+
const fitsDiagonal = fullWidth <= slot * Math.SQRT2 && fullWidth <= limit && (fullWidth + fontSize) / Math.SQRT2 <= height * 0.25;
|
|
157
|
+
return {
|
|
158
|
+
angle: fitsDiagonal ? 45 : 0,
|
|
159
|
+
textWidth: fitsDiagonal ? fullWidth + 1 : limit,
|
|
160
|
+
marginRight: fitsDiagonal ? marginRight : void 0
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const longest = Math.min(limit, fullWidth);
|
|
164
|
+
if (longest <= fontSize * 6 || longest <= slot)
|
|
165
|
+
return { angle: 0, textWidth: limit };
|
|
166
|
+
const diagonalWidth = Math.min(limit, slot / Math.SQRT2);
|
|
167
|
+
return diagonalWidth >= Math.min(longest, fontSize * 3) ? { angle: 45, textWidth: diagonalWidth } : { angle: 90, textWidth: limit };
|
|
168
|
+
}
|
|
169
|
+
function getDiagonalMarginRight(width, textWidth, fontSize, labelCount, ticksAtEdges = false) {
|
|
170
|
+
const projection = (textWidth + fontSize / 2) / Math.SQRT2;
|
|
171
|
+
const edgeFraction = ticksAtEdges ? 0 : 1 / (2 * labelCount);
|
|
172
|
+
return Math.max(
|
|
173
|
+
DEFAULT_MARGIN_RIGHT,
|
|
174
|
+
Math.ceil(
|
|
175
|
+
(projection + 4 - (width - AXIS_HORIZONTAL_PADDING + DEFAULT_MARGIN_RIGHT) * edgeFraction) / (1 - edgeFraction)
|
|
176
|
+
)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
180
|
+
0 && (module.exports = {
|
|
181
|
+
bindCartesianAxisLayout,
|
|
182
|
+
createCartesianAxis,
|
|
183
|
+
getCartesianAxis
|
|
184
|
+
});
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import type { Theme } from '@antv/g2';
|
|
2
2
|
import type { PluginOptions } from '@antv/g6';
|
|
3
3
|
export type ChartLocale = 'en-US' | 'zh-CN';
|
|
4
|
-
export type CartesianXAxisOptions = {
|
|
5
|
-
xLabels?: unknown[];
|
|
6
|
-
chartWidth?: number;
|
|
7
|
-
};
|
|
8
|
-
export type CartesianAxisOptions = CartesianXAxisOptions & {
|
|
9
|
-
axisXTitle?: string | false;
|
|
10
|
-
axisYTitle?: string | false;
|
|
11
|
-
};
|
|
12
4
|
export declare const resolveChartLocale: (locale?: string) => ChartLocale;
|
|
13
|
-
export declare const getCartesianLayout: ({ xLabels, chartWidth, }: CartesianXAxisOptions) => Record<string, number>;
|
|
14
|
-
export declare const getCartesianAxis: ({ axisXTitle, axisYTitle, xLabels, chartWidth, }: CartesianAxisOptions) => Record<'x' | 'y', Record<string, unknown>>;
|
|
15
5
|
export declare const getColorLegend: (visible: boolean) => false | {
|
|
16
6
|
color: Record<string, never>;
|
|
17
7
|
};
|
|
@@ -19,73 +19,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/util/components.ts
|
|
20
20
|
var components_exports = {};
|
|
21
21
|
__export(components_exports, {
|
|
22
|
-
getCartesianAxis: () => getCartesianAxis,
|
|
23
|
-
getCartesianLayout: () => getCartesianLayout,
|
|
24
22
|
getColorLegend: () => getColorLegend,
|
|
25
23
|
getDataLabels: () => getDataLabels,
|
|
26
24
|
getGraphTitle: () => getGraphTitle,
|
|
27
25
|
resolveChartLocale: () => resolveChartLocale
|
|
28
26
|
});
|
|
29
27
|
module.exports = __toCommonJS(components_exports);
|
|
30
|
-
var DEFAULT_CHART_WIDTH = 640;
|
|
31
|
-
var AXIS_HORIZONTAL_PADDING = 96;
|
|
32
|
-
var ANGLED_LABEL_MARGIN_RIGHT_MIN = 32;
|
|
33
|
-
var ANGLED_LABEL_MARGIN_RIGHT_MAX = 64;
|
|
34
|
-
var ANGLED_LABEL_EDGE_GAP = 8;
|
|
35
|
-
var estimateLabelWidth = (value) => Array.from(String(value ?? "")).reduce(
|
|
36
|
-
(width, character) => width + ((character.codePointAt(0) ?? 0) > 255 ? 12 : 7),
|
|
37
|
-
0
|
|
38
|
-
);
|
|
39
|
-
var shouldUseAngledXAxisLabels = (labels, chartWidth = DEFAULT_CHART_WIDTH) => {
|
|
40
|
-
if (!(labels == null ? void 0 : labels.length))
|
|
41
|
-
return false;
|
|
42
|
-
const uniqueLabels = Array.from(new Set(labels.map((label) => String(label ?? ""))));
|
|
43
|
-
if (uniqueLabels.length <= 1)
|
|
44
|
-
return false;
|
|
45
|
-
const availableWidth = Math.max(chartWidth - AXIS_HORIZONTAL_PADDING, 240);
|
|
46
|
-
const estimatedWidth = uniqueLabels.reduce(
|
|
47
|
-
(total, label) => total + Math.max(28, estimateLabelWidth(label) + 16),
|
|
48
|
-
0
|
|
49
|
-
);
|
|
50
|
-
return estimatedWidth > availableWidth;
|
|
51
|
-
};
|
|
52
28
|
var resolveChartLocale = (locale) => (locale == null ? void 0 : locale.toLowerCase().startsWith("zh")) ? "zh-CN" : "en-US";
|
|
53
|
-
var getCartesianLayout = ({
|
|
54
|
-
xLabels,
|
|
55
|
-
chartWidth
|
|
56
|
-
}) => {
|
|
57
|
-
if (!shouldUseAngledXAxisLabels(xLabels, chartWidth))
|
|
58
|
-
return {};
|
|
59
|
-
const tailLabel = xLabels == null ? void 0 : xLabels[xLabels.length - 1];
|
|
60
|
-
const labelWidth = estimateLabelWidth(tailLabel);
|
|
61
|
-
const projectedHalfWidth = (labelWidth + 12) * Math.SQRT1_2 / 2;
|
|
62
|
-
return {
|
|
63
|
-
marginRight: Math.min(
|
|
64
|
-
ANGLED_LABEL_MARGIN_RIGHT_MAX,
|
|
65
|
-
Math.max(
|
|
66
|
-
ANGLED_LABEL_MARGIN_RIGHT_MIN,
|
|
67
|
-
Math.ceil(projectedHalfWidth + ANGLED_LABEL_EDGE_GAP)
|
|
68
|
-
)
|
|
69
|
-
)
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
var getCartesianAxis = ({
|
|
73
|
-
axisXTitle,
|
|
74
|
-
axisYTitle,
|
|
75
|
-
xLabels,
|
|
76
|
-
chartWidth
|
|
77
|
-
}) => {
|
|
78
|
-
const useAngledXAxisLabels = shouldUseAngledXAxisLabels(xLabels, chartWidth);
|
|
79
|
-
return {
|
|
80
|
-
x: {
|
|
81
|
-
title: axisXTitle || false,
|
|
82
|
-
...useAngledXAxisLabels ? { labelTransform: "rotate(45)", labelAutoRotate: false } : {}
|
|
83
|
-
},
|
|
84
|
-
y: {
|
|
85
|
-
title: axisYTitle || false
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
29
|
var getColorLegend = (visible) => visible ? { color: {} } : false;
|
|
90
30
|
function getDataLabels(theme, {
|
|
91
31
|
visible,
|
|
@@ -104,9 +44,16 @@ function getDataLabels(theme, {
|
|
|
104
44
|
const textColor = (_a = theme.label) == null ? void 0 : _a.fill;
|
|
105
45
|
const inverseColor = (_b = theme.innerLabel) == null ? void 0 : _b.fill;
|
|
106
46
|
const contrastTransform = contrast === "inside" && textColor !== inverseColor ? [{ type: "contrastReverse", palette: [textColor, inverseColor] }] : [];
|
|
107
|
-
const
|
|
47
|
+
const strokeTransform = (paint == null ? void 0 : paint.stroke) === void 0 && (style == null ? void 0 : style.stroke) === void 0 ? [{ type: "overflowStroke" }] : [];
|
|
48
|
+
const transforms = [...contrastTransform, ...strokeTransform, ...transform ?? []];
|
|
108
49
|
return [
|
|
109
|
-
{
|
|
50
|
+
{
|
|
51
|
+
...content,
|
|
52
|
+
...strokeTransform.length ? { lineWidth: 1.5, paintFirst: "stroke" } : {},
|
|
53
|
+
...transforms.length ? { transform: transforms } : {},
|
|
54
|
+
...style,
|
|
55
|
+
...paint
|
|
56
|
+
}
|
|
110
57
|
];
|
|
111
58
|
}
|
|
112
59
|
function getGraphTitle(title, subtitle, style = {}) {
|
|
@@ -125,8 +72,6 @@ function getGraphTitle(title, subtitle, style = {}) {
|
|
|
125
72
|
}
|
|
126
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
127
74
|
0 && (module.exports = {
|
|
128
|
-
getCartesianAxis,
|
|
129
|
-
getCartesianLayout,
|
|
130
75
|
getColorLegend,
|
|
131
76
|
getDataLabels,
|
|
132
77
|
getGraphTitle,
|
package/dist/cjs/util/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export { getChartAnimation } from './animation';
|
|
2
|
+
export { bindCartesianAxisLayout, createCartesianAxis, getCartesianAxis } from './axis';
|
|
3
|
+
export { getColorLegend, getDataLabels, getGraphTitle, resolveChartLocale } from './components';
|
|
4
|
+
export { bindCrosshairAxisLabels } from './crosshair-axis-labels';
|
|
5
|
+
export { escapeHtml } from './html';
|
|
6
|
+
export { getCategoryBackgroundHighlightState, getCategoryHighlightInteraction, getElementHoverScaleInteraction, getLineHighlightState, getPointHighlightState, getSeriesHighlightByColorInteraction, getSharedTooltipInteraction, } from './interaction';
|
|
7
|
+
export { CHART_FONT_FAMILY, CHART_STYLE_DEFAULTS, getChartVisualTokens } from './tokens';
|
package/dist/cjs/util/index.js
CHANGED
|
@@ -2,6 +2,10 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
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
|
+
};
|
|
5
9
|
var __copyProps = (to, from, except, desc) => {
|
|
6
10
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
11
|
for (let key of __getOwnPropNames(from))
|
|
@@ -10,20 +14,60 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
10
14
|
}
|
|
11
15
|
return to;
|
|
12
16
|
};
|
|
13
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
18
|
|
|
16
19
|
// src/util/index.ts
|
|
17
20
|
var util_exports = {};
|
|
21
|
+
__export(util_exports, {
|
|
22
|
+
CHART_FONT_FAMILY: () => import_tokens.CHART_FONT_FAMILY,
|
|
23
|
+
CHART_STYLE_DEFAULTS: () => import_tokens.CHART_STYLE_DEFAULTS,
|
|
24
|
+
bindCartesianAxisLayout: () => import_axis.bindCartesianAxisLayout,
|
|
25
|
+
bindCrosshairAxisLabels: () => import_crosshair_axis_labels.bindCrosshairAxisLabels,
|
|
26
|
+
createCartesianAxis: () => import_axis.createCartesianAxis,
|
|
27
|
+
escapeHtml: () => import_html.escapeHtml,
|
|
28
|
+
getCartesianAxis: () => import_axis.getCartesianAxis,
|
|
29
|
+
getCategoryBackgroundHighlightState: () => import_interaction.getCategoryBackgroundHighlightState,
|
|
30
|
+
getCategoryHighlightInteraction: () => import_interaction.getCategoryHighlightInteraction,
|
|
31
|
+
getChartAnimation: () => import_animation.getChartAnimation,
|
|
32
|
+
getChartVisualTokens: () => import_tokens.getChartVisualTokens,
|
|
33
|
+
getColorLegend: () => import_components.getColorLegend,
|
|
34
|
+
getDataLabels: () => import_components.getDataLabels,
|
|
35
|
+
getElementHoverScaleInteraction: () => import_interaction.getElementHoverScaleInteraction,
|
|
36
|
+
getGraphTitle: () => import_components.getGraphTitle,
|
|
37
|
+
getLineHighlightState: () => import_interaction.getLineHighlightState,
|
|
38
|
+
getPointHighlightState: () => import_interaction.getPointHighlightState,
|
|
39
|
+
getSeriesHighlightByColorInteraction: () => import_interaction.getSeriesHighlightByColorInteraction,
|
|
40
|
+
getSharedTooltipInteraction: () => import_interaction.getSharedTooltipInteraction,
|
|
41
|
+
resolveChartLocale: () => import_components.resolveChartLocale
|
|
42
|
+
});
|
|
18
43
|
module.exports = __toCommonJS(util_exports);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
44
|
+
var import_animation = require("./animation");
|
|
45
|
+
var import_axis = require("./axis");
|
|
46
|
+
var import_components = require("./components");
|
|
47
|
+
var import_crosshair_axis_labels = require("./crosshair-axis-labels");
|
|
48
|
+
var import_html = require("./html");
|
|
49
|
+
var import_interaction = require("./interaction");
|
|
50
|
+
var import_tokens = require("./tokens");
|
|
23
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
24
52
|
0 && (module.exports = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
53
|
+
CHART_FONT_FAMILY,
|
|
54
|
+
CHART_STYLE_DEFAULTS,
|
|
55
|
+
bindCartesianAxisLayout,
|
|
56
|
+
bindCrosshairAxisLabels,
|
|
57
|
+
createCartesianAxis,
|
|
58
|
+
escapeHtml,
|
|
59
|
+
getCartesianAxis,
|
|
60
|
+
getCategoryBackgroundHighlightState,
|
|
61
|
+
getCategoryHighlightInteraction,
|
|
62
|
+
getChartAnimation,
|
|
63
|
+
getChartVisualTokens,
|
|
64
|
+
getColorLegend,
|
|
65
|
+
getDataLabels,
|
|
66
|
+
getElementHoverScaleInteraction,
|
|
67
|
+
getGraphTitle,
|
|
68
|
+
getLineHighlightState,
|
|
69
|
+
getPointHighlightState,
|
|
70
|
+
getSeriesHighlightByColorInteraction,
|
|
71
|
+
getSharedTooltipInteraction,
|
|
72
|
+
resolveChartLocale
|
|
29
73
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RendererAnnotation } from '../../annotation/registry';
|
|
1
2
|
import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* AreaDataItem is the type for each data item in the area chart.
|
|
@@ -20,6 +21,7 @@ export interface AreaConfig {
|
|
|
20
21
|
axisYTitle?: string;
|
|
21
22
|
theme?: VisualizationTheme;
|
|
22
23
|
style?: ThemeStyle;
|
|
24
|
+
annotations?: RendererAnnotation<AreaDataItem, 'g2', 'area'>[];
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* AreaInstance represents an area chart instance with render and destroy methods.
|
|
@@ -23,15 +23,15 @@ __export(area_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(area_exports);
|
|
25
25
|
var import_g2 = require("@antv/g2");
|
|
26
|
+
var import_annotation = require("../../annotation");
|
|
26
27
|
var import_g22 = require("../../theme/g2");
|
|
27
28
|
var import_util = require("../../util");
|
|
28
|
-
var import_components = require("../../util/components");
|
|
29
|
-
var import_tokens = require("../../util/tokens");
|
|
30
29
|
var getLinearGradientColor = (color, backgroundColor = "white") => `linear-gradient(-90deg, ${backgroundColor} 0%, ${color} 100%)`;
|
|
31
30
|
var DEFAULT_COLOR = "#3A95FF";
|
|
32
31
|
var Area = (options) => {
|
|
33
32
|
const { container, width, height, theme: chartTheme = "default" } = options;
|
|
34
33
|
let chart = null;
|
|
34
|
+
let cleanupAnnotations;
|
|
35
35
|
let hasRendered = false;
|
|
36
36
|
let cleanupCrosshairAxisLabels = null;
|
|
37
37
|
const render = (config) => {
|
|
@@ -47,6 +47,7 @@ var Area = (options) => {
|
|
|
47
47
|
style: localStyle = {}
|
|
48
48
|
} = config;
|
|
49
49
|
if (chart) {
|
|
50
|
+
cleanupAnnotations == null ? void 0 : cleanupAnnotations();
|
|
50
51
|
cleanupCrosshairAxisLabels == null ? void 0 : cleanupCrosshairAxisLabels();
|
|
51
52
|
cleanupCrosshairAxisLabels = null;
|
|
52
53
|
chart.destroy();
|
|
@@ -55,24 +56,29 @@ var Area = (options) => {
|
|
|
55
56
|
const cartesianAxisOptions = {
|
|
56
57
|
axisXTitle,
|
|
57
58
|
axisYTitle,
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
preferHorizontal: true,
|
|
60
|
+
xTicksAtEdges: true,
|
|
61
|
+
xValues: data.map(({ time }) => time),
|
|
62
|
+
container,
|
|
63
|
+
chartWidth: width,
|
|
64
|
+
chartHeight: height
|
|
60
65
|
};
|
|
61
66
|
const appearance = (0, import_g22.getThemeObject)("area", theme, localStyle);
|
|
62
67
|
const { theme: rendererTheme } = appearance;
|
|
68
|
+
const cartesianAxis = (0, import_util.createCartesianAxis)(cartesianAxisOptions, rendererTheme);
|
|
63
69
|
const areaMark = {
|
|
64
|
-
fillOpacity:
|
|
70
|
+
fillOpacity: import_util.CHART_STYLE_DEFAULTS.areaOpacity,
|
|
65
71
|
...appearance.mark.area
|
|
66
72
|
};
|
|
67
73
|
const lineMark = {
|
|
68
|
-
lineWidth:
|
|
69
|
-
strokeOpacity:
|
|
74
|
+
lineWidth: import_util.CHART_STYLE_DEFAULTS.lineWidth,
|
|
75
|
+
strokeOpacity: import_util.CHART_STYLE_DEFAULTS.lineOpacity,
|
|
70
76
|
...appearance.mark.line
|
|
71
77
|
};
|
|
72
78
|
const pointStyle = {
|
|
73
79
|
shape: "point",
|
|
74
|
-
size:
|
|
75
|
-
lineWidth:
|
|
80
|
+
size: import_util.CHART_STYLE_DEFAULTS.pointSize,
|
|
81
|
+
lineWidth: import_util.CHART_STYLE_DEFAULTS.pointLineWidth,
|
|
76
82
|
stroke: rendererTheme.view.viewFill,
|
|
77
83
|
...appearance.mark.point
|
|
78
84
|
};
|
|
@@ -81,7 +87,7 @@ var Area = (options) => {
|
|
|
81
87
|
const colors = rendererTheme.category10;
|
|
82
88
|
const backgroundColor = rendererTheme.view.viewFill;
|
|
83
89
|
const fillColor = getLinearGradientColor(colors[0] || DEFAULT_COLOR, backgroundColor);
|
|
84
|
-
const areaOpacity = areaMark.fillOpacity ??
|
|
90
|
+
const areaOpacity = areaMark.fillOpacity ?? import_util.CHART_STYLE_DEFAULTS.areaOpacity;
|
|
85
91
|
const tooltip = {
|
|
86
92
|
items: [
|
|
87
93
|
(d) => ({
|
|
@@ -176,9 +182,9 @@ var Area = (options) => {
|
|
|
176
182
|
transform,
|
|
177
183
|
children,
|
|
178
184
|
scale: scaleConfig,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
legend: (0,
|
|
185
|
+
axis: cartesianAxis.axis,
|
|
186
|
+
...cartesianAxis.layout(),
|
|
187
|
+
legend: (0, import_util.getColorLegend)(hasGroupField),
|
|
182
188
|
interaction: {
|
|
183
189
|
tooltip: (0, import_util.getSharedTooltipInteraction)({ crosshairs: true }),
|
|
184
190
|
...hasGroupField ? (0, import_util.getSeriesHighlightByColorInteraction)() : {}
|
|
@@ -186,11 +192,22 @@ var Area = (options) => {
|
|
|
186
192
|
theme: rendererTheme
|
|
187
193
|
};
|
|
188
194
|
chart.options(chartOptions);
|
|
195
|
+
cleanupAnnotations = (0, import_annotation.bindAnnotations)({
|
|
196
|
+
renderer: "g2",
|
|
197
|
+
chartType: "area",
|
|
198
|
+
chart,
|
|
199
|
+
annotations: config.annotations,
|
|
200
|
+
mapping: { x: "time", y: "value", series: hasGroupField ? "group" : void 0, data },
|
|
201
|
+
themeObject: appearance
|
|
202
|
+
});
|
|
203
|
+
(0, import_util.bindCartesianAxisLayout)(chart, cartesianAxis);
|
|
189
204
|
cleanupCrosshairAxisLabels = (0, import_util.bindCrosshairAxisLabels)(chart, baseTheme);
|
|
190
205
|
chart.render();
|
|
191
206
|
hasRendered = true;
|
|
192
207
|
};
|
|
193
208
|
const destroy = () => {
|
|
209
|
+
cleanupAnnotations == null ? void 0 : cleanupAnnotations();
|
|
210
|
+
cleanupAnnotations = void 0;
|
|
194
211
|
if (chart) {
|
|
195
212
|
cleanupCrosshairAxisLabels == null ? void 0 : cleanupCrosshairAxisLabels();
|
|
196
213
|
cleanupCrosshairAxisLabels = null;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RendererAnnotation } from '../../annotation/registry';
|
|
1
2
|
import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* BarDataItem is the type for each data item in the bar chart.
|
|
@@ -23,6 +24,7 @@ export interface BarConfig {
|
|
|
23
24
|
axisYTitle?: string;
|
|
24
25
|
theme?: VisualizationTheme;
|
|
25
26
|
style?: ThemeStyle;
|
|
27
|
+
annotations?: RendererAnnotation<BarDataItem, 'g2', 'bar'>[];
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* BarInstance represents a bar chart instance with render and destroy methods.
|
|
@@ -23,13 +23,13 @@ __export(bar_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(bar_exports);
|
|
25
25
|
var import_g2 = require("@antv/g2");
|
|
26
|
+
var import_annotation = require("../../annotation");
|
|
26
27
|
var import_g22 = require("../../theme/g2");
|
|
27
28
|
var import_util = require("../../util");
|
|
28
|
-
var import_components = require("../../util/components");
|
|
29
|
-
var import_tokens = require("../../util/tokens");
|
|
30
29
|
var Bar = (options) => {
|
|
31
30
|
const { container, width, height, theme: chartTheme = "default" } = options;
|
|
32
31
|
let chart = null;
|
|
32
|
+
let cleanupAnnotations;
|
|
33
33
|
const render = (config) => {
|
|
34
34
|
var _a;
|
|
35
35
|
const {
|
|
@@ -45,6 +45,7 @@ var Bar = (options) => {
|
|
|
45
45
|
style: localStyle = {}
|
|
46
46
|
} = config;
|
|
47
47
|
if (chart) {
|
|
48
|
+
cleanupAnnotations == null ? void 0 : cleanupAnnotations();
|
|
48
49
|
chart.destroy();
|
|
49
50
|
}
|
|
50
51
|
const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
|
|
@@ -52,7 +53,7 @@ var Bar = (options) => {
|
|
|
52
53
|
const { theme: rendererTheme } = appearance;
|
|
53
54
|
const intervalMark = {
|
|
54
55
|
...rendererTheme.type !== "academy" ? { radius: 4 } : {},
|
|
55
|
-
columnWidthRatio:
|
|
56
|
+
columnWidthRatio: import_util.CHART_STYLE_DEFAULTS.intervalWidthRatio,
|
|
56
57
|
...!hasGroupField ? { fill: rendererTheme.category10[0] } : {},
|
|
57
58
|
...appearance.mark.interval
|
|
58
59
|
};
|
|
@@ -93,16 +94,29 @@ var Bar = (options) => {
|
|
|
93
94
|
transform,
|
|
94
95
|
coordinate: { transform: [{ type: "transpose" }] },
|
|
95
96
|
scale: scaleConfig,
|
|
96
|
-
axis: (0, import_util.getCartesianAxis)(
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
axis: (0, import_util.getCartesianAxis)(
|
|
98
|
+
{
|
|
99
|
+
xType: "category",
|
|
100
|
+
xValues: data.map(({ category }) => category),
|
|
101
|
+
container,
|
|
102
|
+
chartWidth: width,
|
|
103
|
+
chartHeight: height,
|
|
104
|
+
axisXTitle,
|
|
105
|
+
axisYTitle,
|
|
106
|
+
transposed: true
|
|
107
|
+
},
|
|
108
|
+
rendererTheme
|
|
109
|
+
),
|
|
110
|
+
legend: (0, import_util.getColorLegend)(hasGroupField),
|
|
111
|
+
labels: (0, import_util.getDataLabels)(rendererTheme, {
|
|
99
112
|
visible: label,
|
|
100
113
|
defaultVisible: true,
|
|
101
114
|
text: "value",
|
|
102
115
|
position: "right",
|
|
103
116
|
contrast: "inside",
|
|
104
117
|
dx: -4,
|
|
105
|
-
dy: 0
|
|
118
|
+
dy: 0,
|
|
119
|
+
transform: [{ type: "overflowHide" }]
|
|
106
120
|
}),
|
|
107
121
|
tooltip: {
|
|
108
122
|
items: [
|
|
@@ -121,9 +135,25 @@ var Bar = (options) => {
|
|
|
121
135
|
theme: rendererTheme
|
|
122
136
|
};
|
|
123
137
|
chart.options(chartOptions);
|
|
138
|
+
cleanupAnnotations = (0, import_annotation.bindAnnotations)({
|
|
139
|
+
renderer: "g2",
|
|
140
|
+
chartType: "bar",
|
|
141
|
+
chart,
|
|
142
|
+
annotations: config.annotations,
|
|
143
|
+
mapping: {
|
|
144
|
+
x: "category",
|
|
145
|
+
y: "value",
|
|
146
|
+
series: hasGroupField ? "group" : void 0,
|
|
147
|
+
data,
|
|
148
|
+
interval: true
|
|
149
|
+
},
|
|
150
|
+
themeObject: appearance
|
|
151
|
+
});
|
|
124
152
|
chart.render();
|
|
125
153
|
};
|
|
126
154
|
const destroy = () => {
|
|
155
|
+
cleanupAnnotations == null ? void 0 : cleanupAnnotations();
|
|
156
|
+
cleanupAnnotations = void 0;
|
|
127
157
|
if (chart) {
|
|
128
158
|
chart.destroy();
|
|
129
159
|
chart = null;
|
|
@@ -24,7 +24,7 @@ __export(boxplot_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(boxplot_exports);
|
|
25
25
|
var import_g2 = require("@antv/g2");
|
|
26
26
|
var import_g22 = require("../../theme/g2");
|
|
27
|
-
var
|
|
27
|
+
var import_util = require("../../util");
|
|
28
28
|
var prefixMarkStyle = (prefix, style) => Object.fromEntries(
|
|
29
29
|
Object.entries(style ?? {}).map(([key, value]) => [
|
|
30
30
|
`${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`,
|
|
@@ -75,7 +75,7 @@ var Boxplot = (options) => {
|
|
|
75
75
|
...prefixMarkStyle("box", boxStyle),
|
|
76
76
|
...prefixMarkStyle("point", resolvedPointStyle)
|
|
77
77
|
} : { ...boxStyle, point: false };
|
|
78
|
-
const legend = (0,
|
|
78
|
+
const legend = (0, import_util.getColorLegend)(hasGroupField);
|
|
79
79
|
chart = new import_g2.Chart({
|
|
80
80
|
container,
|
|
81
81
|
width,
|
|
@@ -88,7 +88,18 @@ var Boxplot = (options) => {
|
|
|
88
88
|
data,
|
|
89
89
|
title: title ? { title, subtitle } : "",
|
|
90
90
|
encode,
|
|
91
|
-
axis: (0,
|
|
91
|
+
axis: (0, import_util.getCartesianAxis)(
|
|
92
|
+
{
|
|
93
|
+
xType: "category",
|
|
94
|
+
xValues: data.map(({ category }) => category),
|
|
95
|
+
container,
|
|
96
|
+
chartWidth: width,
|
|
97
|
+
chartHeight: height,
|
|
98
|
+
axisXTitle,
|
|
99
|
+
axisYTitle
|
|
100
|
+
},
|
|
101
|
+
rendererTheme
|
|
102
|
+
),
|
|
92
103
|
scale: {
|
|
93
104
|
x: { paddingInner: 0.6, paddingOuter: 0.3 },
|
|
94
105
|
series: { paddingInner: 0.3, paddingOuter: 0.1 },
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RendererAnnotation } from '../../annotation/registry';
|
|
1
2
|
import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* ColumnDataItem is the type for each data item in the column chart.
|
|
@@ -23,6 +24,7 @@ export interface ColumnConfig {
|
|
|
23
24
|
axisYTitle?: string;
|
|
24
25
|
theme?: VisualizationTheme;
|
|
25
26
|
style?: ThemeStyle;
|
|
27
|
+
annotations?: RendererAnnotation<ColumnDataItem, 'g2', 'column'>[];
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* ColumnInstance represents a column chart instance with render and destroy methods.
|