pivotkit-react 0.0.0-stage → 0.1.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/CHANGELOG.md +300 -0
- package/LICENSE +21 -0
- package/README.md +327 -2
- package/dist/chunks/chunk-C32TYSHG.js +441 -0
- package/dist/chunks/chunk-ILHFIV2P.js +784 -0
- package/dist/chunks/chunk-KKJO36W5.js +1833 -0
- package/dist/chunks/chunk-XYP47DJ3.js +123 -0
- package/dist/echarts.js +262 -0
- package/dist/index.js +3390 -0
- package/dist/labels.js +12 -0
- package/dist/menus.js +1085 -0
- package/dist/styles.css +2447 -0
- package/package.json +70 -4
- package/types/PivotReport.d.ts +20 -0
- package/types/all-labels.d.ts +5 -0
- package/types/chart-decorate.d.ts +16 -0
- package/types/chart-options.d.ts +23 -0
- package/types/chart-summary.d.ts +12 -0
- package/types/chart-tooltip.d.ts +38 -0
- package/types/chart-types.d.ts +152 -0
- package/types/chart.d.ts +39 -0
- package/types/chip-menus.d.ts +32 -0
- package/types/clear-input.d.ts +20 -0
- package/types/dnd-moves.d.ts +45 -0
- package/types/dnd.d.ts +101 -0
- package/types/dom.d.ts +52 -0
- package/types/drill-export.d.ts +42 -0
- package/types/drill-panel.d.ts +39 -0
- package/types/drill.d.ts +62 -0
- package/types/echarts.d.ts +4 -0
- package/types/export-run.d.ts +59 -0
- package/types/field-info.d.ts +34 -0
- package/types/fields.d.ts +32 -0
- package/types/files.d.ts +27 -0
- package/types/filter.d.ts +21 -0
- package/types/icons.d.ts +76 -0
- package/types/index.d.ts +536 -0
- package/types/info.d.ts +34 -0
- package/types/iso.d.ts +2 -0
- package/types/labels.d.ts +721 -0
- package/types/lazy-menus.d.ts +16 -0
- package/types/menu-labels.d.ts +255 -0
- package/types/menus.d.ts +7 -0
- package/types/names.d.ts +80 -0
- package/types/numbers.d.ts +13 -0
- package/types/overflow.d.ts +59 -0
- package/types/place.d.ts +43 -0
- package/types/popover.d.ts +89 -0
- package/types/rove.d.ts +20 -0
- package/types/section.d.ts +42 -0
- package/types/share.d.ts +123 -0
- package/types/skeleton.d.ts +9 -0
- package/types/storage.d.ts +24 -0
- package/types/table.d.ts +23 -0
- package/types/templates.d.ts +40 -0
- package/types/theme.d.ts +24 -0
- package/types/tip-list.d.ts +20 -0
- package/types/tips.d.ts +298 -0
- package/types/toasts.d.ts +26 -0
- package/types/toolbar-panels.d.ts +90 -0
- package/types/toolbar.d.ts +5 -0
- package/types/use-big-result.d.ts +29 -0
- package/types/use-export.d.ts +7 -0
- package/types/use-theme.d.ts +11 -0
- package/types/use-view-history.d.ts +34 -0
- package/types/version.d.ts +2 -0
- package/types/view-history.d.ts +89 -0
- package/types/view-ops.d.ts +344 -0
- package/types/view-store.d.ts +52 -0
- package/types/virtual.d.ts +44 -0
- package/types/zones.d.ts +42 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// src/chart-types.js
|
|
2
|
+
import { autoChartType } from "pivotkit-core";
|
|
3
|
+
var CHART_TYPES = Object.freeze({
|
|
4
|
+
auto: { chart: { type: "auto", stacked: false, horizontal: false }, icon: "sparkle", axis: true },
|
|
5
|
+
bar: { chart: { type: "bar", stacked: false, horizontal: false }, icon: "chart", axis: true },
|
|
6
|
+
stacked: { chart: { type: "bar", stacked: true, horizontal: false }, icon: "stacked", axis: true },
|
|
7
|
+
horizontal: { chart: { type: "bar", stacked: false, horizontal: true }, icon: "horizontal", axis: true },
|
|
8
|
+
line: { chart: { type: "line", stacked: false, horizontal: false }, icon: "line", axis: true },
|
|
9
|
+
area: { chart: { type: "area", stacked: false, horizontal: false }, icon: "area", axis: true },
|
|
10
|
+
pie: { chart: { type: "pie", stacked: false, horizontal: false }, icon: "pie", axis: false },
|
|
11
|
+
donut: { chart: { type: "donut", stacked: false, horizontal: false }, icon: "donut", axis: false },
|
|
12
|
+
heatmap: { chart: { type: "heatmap", stacked: false, horizontal: false }, icon: "heatmap", axis: false }
|
|
13
|
+
});
|
|
14
|
+
var SLICE_TYPES = Object.freeze(["pie", "donut"]);
|
|
15
|
+
var CHART_TYPE_NAMES = Object.freeze(Object.keys(CHART_TYPES));
|
|
16
|
+
function chartTypeOf(chart) {
|
|
17
|
+
const found = CHART_TYPE_NAMES.find((name) => {
|
|
18
|
+
const c = CHART_TYPES[name].chart;
|
|
19
|
+
return c.type === chart.type && c.stacked === Boolean(chart.stacked) && c.horizontal === Boolean(chart.horizontal);
|
|
20
|
+
});
|
|
21
|
+
if (found) {
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
24
|
+
if (chart.type === "bar") {
|
|
25
|
+
return chart.horizontal ? "horizontal" : "stacked";
|
|
26
|
+
}
|
|
27
|
+
return CHART_TYPE_NAMES.find((name) => CHART_TYPES[name].chart.type === chart.type) ?? "bar";
|
|
28
|
+
}
|
|
29
|
+
function chartPlan(view, encoded) {
|
|
30
|
+
if (view.chart.type !== "auto") {
|
|
31
|
+
const name2 = chartTypeOf(view.chart);
|
|
32
|
+
return { name: name2, auto: false, swap: false, chart: { type: view.chart.type, stacked: Boolean(view.chart.stacked), horizontal: Boolean(view.chart.horizontal) } };
|
|
33
|
+
}
|
|
34
|
+
const own = autoChartType(
|
|
35
|
+
/** @type {any} */
|
|
36
|
+
view,
|
|
37
|
+
encoded
|
|
38
|
+
);
|
|
39
|
+
const swap = own === "bar" && view.cols.length > 0 && autoChartType(
|
|
40
|
+
/** @type {any} */
|
|
41
|
+
{ ...view, rows: view.cols },
|
|
42
|
+
encoded
|
|
43
|
+
) === "line";
|
|
44
|
+
const name = own === "line" || swap ? "line" : "bar";
|
|
45
|
+
return { name, auto: true, swap, chart: { ...CHART_TYPES[name].chart } };
|
|
46
|
+
}
|
|
47
|
+
var MANY_SERIES = 8;
|
|
48
|
+
var MAX_CATEGORIES = 50;
|
|
49
|
+
function pieLabelRoom(height) {
|
|
50
|
+
return Math.round(Math.min(24, Math.max(0, height) * 0.05));
|
|
51
|
+
}
|
|
52
|
+
var SLANTED_LABEL_WIDTH = 120;
|
|
53
|
+
var HEATMAP_FRAME = { x: 80, y: 120 };
|
|
54
|
+
var LABEL_LINE = 16;
|
|
55
|
+
var LABEL_PAD = 4;
|
|
56
|
+
function columnLabelLayout(names, width, fontSize = 12) {
|
|
57
|
+
if (names.length === 0) {
|
|
58
|
+
return { rotate: 0 };
|
|
59
|
+
}
|
|
60
|
+
const slot = Math.max(0, width - HEATMAP_FRAME.x) / names.length;
|
|
61
|
+
const longest = Math.max(...names.map((n) => String(n).length)) * fontSize * 0.55;
|
|
62
|
+
return longest <= slot ? { rotate: 0 } : { rotate: 45, width: SLANTED_LABEL_WIDTH, overflow: "truncate" };
|
|
63
|
+
}
|
|
64
|
+
function heatmapCellLabels(columns, rows, width, height, texts, fontSize = 12) {
|
|
65
|
+
const w = Math.max(0, width - HEATMAP_FRAME.x) / Math.max(1, columns);
|
|
66
|
+
const h = Math.max(0, height - HEATMAP_FRAME.y) / Math.max(1, rows);
|
|
67
|
+
const longest = texts.reduce((m, t) => Math.max(m, String(t).length), 0) * fontSize * 0.55;
|
|
68
|
+
return w >= longest + 2 * LABEL_PAD && h >= LABEL_LINE;
|
|
69
|
+
}
|
|
70
|
+
function rowLabelInterval(rows, height) {
|
|
71
|
+
const h = Math.max(0, height - HEATMAP_FRAME.y) / Math.max(1, rows);
|
|
72
|
+
return h >= LABEL_LINE ? 0 : Math.ceil(LABEL_LINE / Math.max(h, 0.1)) - 1;
|
|
73
|
+
}
|
|
74
|
+
var CATEGORY_LABEL_WIDTH = 120;
|
|
75
|
+
var AXIS_FRAME = { x: 80, y: 60 };
|
|
76
|
+
function categoryLabelLayout(names, { width, height, horizontal = false, mode = "auto", fontSize = 12 }) {
|
|
77
|
+
const n = Math.max(1, names.length);
|
|
78
|
+
const cut = { width: CATEGORY_LABEL_WIDTH, overflow: (
|
|
79
|
+
/** @type {const} */
|
|
80
|
+
"truncate"
|
|
81
|
+
) };
|
|
82
|
+
const every = (slot2, need) => Math.max(1, Math.ceil(need / Math.max(slot2, 0.1)));
|
|
83
|
+
const result = (rotate, step) => ({ rotate, interval: step - 1, every: step, ...cut });
|
|
84
|
+
if (horizontal) {
|
|
85
|
+
const slot2 = Math.max(0, height - AXIS_FRAME.y) / n;
|
|
86
|
+
return result(0, mode === "all" ? 1 : every(slot2, fontSize + 1));
|
|
87
|
+
}
|
|
88
|
+
const slot = Math.max(0, width - AXIS_FRAME.x) / n;
|
|
89
|
+
const longest = Math.min(CATEGORY_LABEL_WIDTH, Math.max(0, ...names.map((t) => String(t).length)) * fontSize * 0.55);
|
|
90
|
+
if (mode === "nth") {
|
|
91
|
+
return result(0, every(slot, longest + 8));
|
|
92
|
+
}
|
|
93
|
+
if (longest + 8 <= slot) {
|
|
94
|
+
return result(0, 1);
|
|
95
|
+
}
|
|
96
|
+
return result(45, mode === "all" ? 1 : every(slot, LABEL_LINE));
|
|
97
|
+
}
|
|
98
|
+
var GROUP_LABEL_ROOM = Object.freeze({ along: 56, across: 28, width: 420, height: 260 });
|
|
99
|
+
function groupLabelsFit(count, groupSize, { width, height, horizontal = false }) {
|
|
100
|
+
if (width < GROUP_LABEL_ROOM.width || height < GROUP_LABEL_ROOM.height) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const n = Math.max(1, count);
|
|
104
|
+
const slot = horizontal ? Math.max(0, height - AXIS_FRAME.y) / n : Math.max(0, width - AXIS_FRAME.x) / n;
|
|
105
|
+
return slot * Math.max(1, groupSize) >= (horizontal ? GROUP_LABEL_ROOM.across : GROUP_LABEL_ROOM.along);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export {
|
|
109
|
+
CHART_TYPES,
|
|
110
|
+
SLICE_TYPES,
|
|
111
|
+
CHART_TYPE_NAMES,
|
|
112
|
+
chartTypeOf,
|
|
113
|
+
chartPlan,
|
|
114
|
+
MANY_SERIES,
|
|
115
|
+
MAX_CATEGORIES,
|
|
116
|
+
pieLabelRoom,
|
|
117
|
+
columnLabelLayout,
|
|
118
|
+
heatmapCellLabels,
|
|
119
|
+
rowLabelInterval,
|
|
120
|
+
CATEGORY_LABEL_WIDTH,
|
|
121
|
+
categoryLabelLayout,
|
|
122
|
+
groupLabelsFit
|
|
123
|
+
};
|
package/dist/echarts.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CATEGORY_LABEL_WIDTH,
|
|
3
|
+
categoryLabelLayout,
|
|
4
|
+
columnLabelLayout,
|
|
5
|
+
groupLabelsFit,
|
|
6
|
+
heatmapCellLabels,
|
|
7
|
+
pieLabelRoom,
|
|
8
|
+
rowLabelInterval
|
|
9
|
+
} from "./chunks/chunk-XYP47DJ3.js";
|
|
10
|
+
|
|
11
|
+
// src/echarts.js
|
|
12
|
+
import { init, use as register } from "echarts/core";
|
|
13
|
+
import { BarChart, HeatmapChart, LineChart, PieChart } from "echarts/charts";
|
|
14
|
+
import { GridComponent, LegendComponent, TitleComponent, TooltipComponent, VisualMapComponent } from "echarts/components";
|
|
15
|
+
import { CanvasRenderer } from "echarts/renderers";
|
|
16
|
+
|
|
17
|
+
// src/chart-options.js
|
|
18
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["rich", "link", "sublink", "target", "subtarget", "linkTarget", "image", "extraCssText", "className", "appendTo", "appendToBody", "renderMode"]);
|
|
19
|
+
var TEMPLATE_KEYS = /* @__PURE__ */ new Set(["formatter", "content"]);
|
|
20
|
+
var CHART_OPTIONS_CAPS = Object.freeze({ depth: 12, entries: 2e3 });
|
|
21
|
+
var FORBIDDEN = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
22
|
+
var isPlain = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
|
|
23
|
+
function cleanChartOptions(value) {
|
|
24
|
+
if (value === void 0 || value === null) {
|
|
25
|
+
return { options: null, problems: [] };
|
|
26
|
+
}
|
|
27
|
+
if (!isPlain(value)) {
|
|
28
|
+
return { options: null, problems: ["chartOptions: not a plain object"] };
|
|
29
|
+
}
|
|
30
|
+
const problems = [];
|
|
31
|
+
let entries = 0;
|
|
32
|
+
const clean = (v, path, depth) => {
|
|
33
|
+
if (typeof v === "string" && /^\s*image:\/\//i.test(v)) {
|
|
34
|
+
problems.push(`${path}: an image address, not allowed`);
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
if (v === null || typeof v === "string" || typeof v === "boolean") {
|
|
38
|
+
return v;
|
|
39
|
+
}
|
|
40
|
+
if (typeof v === "number") {
|
|
41
|
+
if (Number.isFinite(v)) {
|
|
42
|
+
return v;
|
|
43
|
+
}
|
|
44
|
+
problems.push(`${path}: not a finite number`);
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(v) || isPlain(v)) {
|
|
48
|
+
if (depth >= CHART_OPTIONS_CAPS.depth) {
|
|
49
|
+
problems.push(`${path}: nested deeper than ${CHART_OPTIONS_CAPS.depth} levels`);
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(v)) {
|
|
53
|
+
const out2 = [];
|
|
54
|
+
for (let i = 0; i < v.length; i++) {
|
|
55
|
+
if (++entries > CHART_OPTIONS_CAPS.entries) {
|
|
56
|
+
problems.push(`${path}: more than ${CHART_OPTIONS_CAPS.entries} entries in all`);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
const c = clean(v[i], `${path}[${i}]`, depth + 1);
|
|
60
|
+
out2.push(c === void 0 ? null : c);
|
|
61
|
+
}
|
|
62
|
+
return out2;
|
|
63
|
+
}
|
|
64
|
+
const out = {};
|
|
65
|
+
for (const key of Object.keys(v)) {
|
|
66
|
+
if (FORBIDDEN.has(key)) {
|
|
67
|
+
problems.push(`${path}.${key}: not allowed`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (UNSAFE_KEYS.has(key)) {
|
|
71
|
+
problems.push(`${path}.${key}: markup, an address or the tooltip's element, not allowed`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (TEMPLATE_KEYS.has(key) && typeof v[key] === "string") {
|
|
75
|
+
problems.push(`${path}.${key}: a text template (written as markup), not allowed`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (++entries > CHART_OPTIONS_CAPS.entries) {
|
|
79
|
+
problems.push(`${path}: more than ${CHART_OPTIONS_CAPS.entries} entries in all`);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
const c = clean(v[key], `${path}.${key}`, depth + 1);
|
|
83
|
+
if (c !== void 0) {
|
|
84
|
+
out[key] = c;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
problems.push(`${path}: ${typeof v === "function" ? "a function" : typeof v === "object" ? "not plain JSON" : `a ${typeof v}`}, not allowed`);
|
|
90
|
+
return void 0;
|
|
91
|
+
};
|
|
92
|
+
return { options: (
|
|
93
|
+
/** @type {Record<string, unknown>} */
|
|
94
|
+
clean(value, "chartOptions", 0)
|
|
95
|
+
), problems };
|
|
96
|
+
}
|
|
97
|
+
function mergeChartOptions(base, over) {
|
|
98
|
+
if (over === void 0) {
|
|
99
|
+
return base;
|
|
100
|
+
}
|
|
101
|
+
if (Array.isArray(base)) {
|
|
102
|
+
if (Array.isArray(over)) {
|
|
103
|
+
const length = Math.max(base.length, over.length);
|
|
104
|
+
return Array.from({ length }, (_, i) => i < over.length ? mergeChartOptions(base[i], over[i]) : base[i]);
|
|
105
|
+
}
|
|
106
|
+
if (isPlain(over)) {
|
|
107
|
+
return base.map((entry) => mergeChartOptions(entry, over));
|
|
108
|
+
}
|
|
109
|
+
return over;
|
|
110
|
+
}
|
|
111
|
+
if (isPlain(base) && isPlain(over)) {
|
|
112
|
+
const b = (
|
|
113
|
+
/** @type {Record<string, unknown>} */
|
|
114
|
+
base
|
|
115
|
+
);
|
|
116
|
+
const o = (
|
|
117
|
+
/** @type {Record<string, unknown>} */
|
|
118
|
+
over
|
|
119
|
+
);
|
|
120
|
+
const out = { ...b };
|
|
121
|
+
for (const key of Object.keys(o)) {
|
|
122
|
+
out[key] = mergeChartOptions(b[key], o[key]);
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
return over;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/chart-tooltip.js
|
|
130
|
+
function tooltipContent(params, { valueFormatter = (v) => String(v ?? ""), xNames = [], yNames = [], categoryNames = [] } = {}) {
|
|
131
|
+
const color = (p) => typeof p.color === "string" ? p.color : null;
|
|
132
|
+
const text = (v) => v === null || v === void 0 ? "" : String(v);
|
|
133
|
+
if (Array.isArray(params)) {
|
|
134
|
+
const first = params[0];
|
|
135
|
+
return {
|
|
136
|
+
title: first ? text(categoryNames[first.dataIndex] ?? first.axisValueLabel ?? first.name) : "",
|
|
137
|
+
lines: params.map((p) => ({ color: color(p), name: text(p.seriesName), value: valueFormatter(p.value) }))
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (params && params.seriesType === "heatmap" && Array.isArray(params.value)) {
|
|
141
|
+
const [x, y, v] = params.value;
|
|
142
|
+
return {
|
|
143
|
+
title: text(params.seriesName),
|
|
144
|
+
lines: [{ color: color(params), name: [yNames[y], xNames[x]].filter((n) => n !== void 0).map(text).join(", "), value: valueFormatter(v) }]
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
title: text(params?.seriesName),
|
|
149
|
+
lines: params ? [{ color: color(params), name: text(params.name), value: valueFormatter(params.value) }] : []
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function tooltipFormatter(doc, options) {
|
|
153
|
+
return (params) => {
|
|
154
|
+
const { title, lines } = tooltipContent(params, options);
|
|
155
|
+
const box = doc.createElement("div");
|
|
156
|
+
if (title) {
|
|
157
|
+
const head = doc.createElement("div");
|
|
158
|
+
head.textContent = title;
|
|
159
|
+
head.style.fontWeight = "600";
|
|
160
|
+
head.style.marginBottom = "2px";
|
|
161
|
+
box.append(head);
|
|
162
|
+
}
|
|
163
|
+
for (const line of lines) {
|
|
164
|
+
const row = doc.createElement("div");
|
|
165
|
+
row.style.display = "flex";
|
|
166
|
+
row.style.alignItems = "center";
|
|
167
|
+
row.style.gap = "8px";
|
|
168
|
+
const marker = doc.createElement("span");
|
|
169
|
+
marker.style.display = "inline-block";
|
|
170
|
+
marker.style.width = "10px";
|
|
171
|
+
marker.style.height = "10px";
|
|
172
|
+
marker.style.borderRadius = "50%";
|
|
173
|
+
marker.style.flex = "none";
|
|
174
|
+
if (line.color) {
|
|
175
|
+
marker.style.backgroundColor = line.color;
|
|
176
|
+
}
|
|
177
|
+
const name = doc.createElement("span");
|
|
178
|
+
name.textContent = line.name;
|
|
179
|
+
name.style.flex = "1";
|
|
180
|
+
const value = doc.createElement("span");
|
|
181
|
+
value.textContent = line.value;
|
|
182
|
+
value.style.fontWeight = "600";
|
|
183
|
+
value.style.marginLeft = "12px";
|
|
184
|
+
row.append(marker, name, value);
|
|
185
|
+
box.append(row);
|
|
186
|
+
}
|
|
187
|
+
return box;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/chart-decorate.js
|
|
192
|
+
function decorate(option, style, height = 480, doc = void 0, width = 800, extra = {}) {
|
|
193
|
+
const first = (a) => Array.isArray(a) ? a[0] : a;
|
|
194
|
+
const v = (name) => style.getPropertyValue(name).trim();
|
|
195
|
+
const surface = v("--pk-surface") || void 0;
|
|
196
|
+
const tooltip = {
|
|
197
|
+
...option.tooltip,
|
|
198
|
+
backgroundColor: v("--pk-surface-raised") || surface,
|
|
199
|
+
borderColor: v("--pk-border") || void 0,
|
|
200
|
+
textStyle: { color: v("--pk-text") || void 0, fontFamily: style.getPropertyValue("font-family") || void 0 },
|
|
201
|
+
extraCssText: `box-shadow: ${v("--pk-shadow") || "none"}; border-radius: 8px;`,
|
|
202
|
+
...doc ? { formatter: tooltipFormatter(doc, { valueFormatter: option.tooltip?.valueFormatter, xNames: first(option.xAxis)?.data, yNames: first(option.yAxis)?.data, categoryNames: extra.categoryNames }) } : {}
|
|
203
|
+
};
|
|
204
|
+
const series = (option.series || []).map((s) => {
|
|
205
|
+
if (s.type === "bar") {
|
|
206
|
+
const horizontal = first(option.yAxis)?.type === "category";
|
|
207
|
+
const r = horizontal ? [0, 4, 4, 0] : [4, 4, 0, 0];
|
|
208
|
+
return { ...s, barMaxWidth: 48, itemStyle: { borderRadius: s.stack ? 0 : r, borderColor: s.stack ? surface : void 0, borderWidth: s.stack ? 1 : 0 }, emphasis: { focus: "series" } };
|
|
209
|
+
}
|
|
210
|
+
if (s.type === "line") {
|
|
211
|
+
return { ...s, lineStyle: { width: 2 }, symbolSize: 7, smooth: Boolean(s.smooth), areaStyle: s.areaStyle ? { opacity: 0.18 } : void 0, emphasis: { focus: "series" } };
|
|
212
|
+
}
|
|
213
|
+
if (s.type === "pie") {
|
|
214
|
+
const room = pieLabelRoom(height);
|
|
215
|
+
const top = (typeof s.top === "number" ? s.top : 0) + room;
|
|
216
|
+
const bottom = (typeof s.bottom === "number" ? s.bottom : 0) + room;
|
|
217
|
+
return { ...s, top, bottom, itemStyle: { borderColor: surface, borderWidth: 2, borderRadius: 4 }, label: { ...s.label, color: s.label?.position === "inside" ? void 0 : v("--pk-text") || void 0 } };
|
|
218
|
+
}
|
|
219
|
+
if (s.type === "heatmap") {
|
|
220
|
+
const texts = typeof s.label?.formatter === "function" ? s.data.map((d) => s.label.formatter({ value: d })) : [];
|
|
221
|
+
const fits = heatmapCellLabels(option.xAxis?.data?.length ?? 1, option.yAxis?.data?.length ?? 1, width, height, texts);
|
|
222
|
+
return { ...s, itemStyle: { borderColor: surface, borderWidth: 2, borderRadius: 3 }, label: { ...s.label, show: Boolean(s.label?.show) && fits, color: v("--pk-text") || void 0 } };
|
|
223
|
+
}
|
|
224
|
+
return s;
|
|
225
|
+
});
|
|
226
|
+
const legend = option.legend ? { ...option.legend, icon: "roundRect", itemWidth: 12, itemHeight: 12, textStyle: { ...option.legend.textStyle, color: v("--pk-text") || void 0 } } : void 0;
|
|
227
|
+
const grid = option.grid ? { left: 12, right: 24, bottom: option.visualMap ? 64 : 12, containLabel: true, ...option.grid } : void 0;
|
|
228
|
+
const heatmap = series.some((s) => s.type === "heatmap") && option.xAxis?.axisLabel;
|
|
229
|
+
const xAxis = heatmap ? { ...option.xAxis, axisLabel: { ...option.xAxis.axisLabel, ...columnLabelLayout(option.xAxis.data ?? [], width) } } : option.xAxis;
|
|
230
|
+
const yAxis = heatmap && option.yAxis ? { ...option.yAxis, axisLabel: { ...option.yAxis.axisLabel, interval: rowLabelInterval(option.yAxis.data?.length ?? 0, height) } } : option.yAxis;
|
|
231
|
+
const title = option.title ? { title: { ...option.title, textStyle: { ...option.title.textStyle, width: Math.max(40, width - 32), overflow: "truncate" } } } : {};
|
|
232
|
+
let axes = { xAxis, yAxis };
|
|
233
|
+
let axisEvery = 1;
|
|
234
|
+
const along = !heatmap && series.some((s) => s.type === "bar" || s.type === "line") ? first(option.yAxis)?.type === "category" ? "yAxis" : first(option.xAxis)?.type === "category" ? "xAxis" : null : null;
|
|
235
|
+
if (along) {
|
|
236
|
+
let list = Array.isArray(axes[along]) ? axes[along] : [axes[along]];
|
|
237
|
+
const group = list[1]?.groups ? list[1] : null;
|
|
238
|
+
if (group && group.groupsAuto && !groupLabelsFit(list[0].data?.length ?? 0, group.groupSize ?? 1, { width, height, horizontal: along === "yAxis" })) {
|
|
239
|
+
list = [{ ...list[0], data: extra.categoryNames ?? list[0].data }];
|
|
240
|
+
}
|
|
241
|
+
const names = list[0].data ?? [];
|
|
242
|
+
const layout = categoryLabelLayout(names, { width, height, horizontal: along === "yAxis", mode: extra.axisLabels });
|
|
243
|
+
axisEvery = layout.every;
|
|
244
|
+
const longest = Math.min(CATEGORY_LABEL_WIDTH, Math.max(0, ...names.map((t) => String(t).length)) * 12 * 0.55);
|
|
245
|
+
const offset = along === "yAxis" ? Math.round(longest) + 16 : layout.rotate ? Math.round(longest * 0.71) + 14 : 24;
|
|
246
|
+
const main = { ...list[0], axisLabel: { ...list[0].axisLabel, rotate: layout.rotate, interval: layout.interval, width: layout.width, overflow: layout.overflow } };
|
|
247
|
+
const slot = (along === "yAxis" ? Math.max(0, height - 60) : Math.max(0, width - 80)) / Math.max(1, names.length);
|
|
248
|
+
const groupWidth = along === "yAxis" ? CATEGORY_LABEL_WIDTH : Math.max(24, Math.round(slot * (list[1]?.groupSize ?? 1)) - 8);
|
|
249
|
+
const rest = list.slice(1).map((a) => a.groups ? { ...a, offset, axisTick: { ...a.axisTick, length: offset }, axisLabel: { ...a.axisLabel, width: groupWidth, overflow: "truncate" } } : a);
|
|
250
|
+
axes = { ...axes, [along]: rest.length ? [main, ...rest] : main };
|
|
251
|
+
}
|
|
252
|
+
return { ...option, ...title, tooltip, series, ...axes.xAxis ? { xAxis: axes.xAxis } : {}, ...axes.yAxis ? { yAxis: axes.yAxis } : {}, ...legend ? { legend } : {}, ...grid ? { grid } : {}, animationDuration: style.getPropertyValue("--pk-duration").trim() === "0ms" ? 0 : 400, axisEvery };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/echarts.js
|
|
256
|
+
register([BarChart, LineChart, PieChart, HeatmapChart, GridComponent, TooltipComponent, LegendComponent, TitleComponent, VisualMapComponent, CanvasRenderer]);
|
|
257
|
+
export {
|
|
258
|
+
cleanChartOptions,
|
|
259
|
+
decorate,
|
|
260
|
+
init,
|
|
261
|
+
mergeChartOptions
|
|
262
|
+
};
|