pivotkit-react 0.3.0 → 0.5.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 +339 -1
- package/README.md +2 -2
- package/dist/chunks/{chunk-IOPAM4JD.js → chunk-2AT72SLA.js} +635 -980
- package/dist/chunks/chunk-3E4NB5RZ.js +215 -0
- package/dist/chunks/{chunk-32Z33U6S.js → chunk-3WUGQPWV.js} +106 -9
- package/dist/chunks/{chunk-7CC4JHDY.js → chunk-4RS72AAA.js} +27 -8
- package/dist/chunks/{chunk-EM23V5GH.js → chunk-E6M57YLL.js} +19 -8
- package/dist/chunks/{chunk-RWYHJRQO.js → chunk-JMRTIOX4.js} +17 -7
- package/dist/chunks/chunk-RIOSIYGC.js +665 -0
- package/dist/chunks/{chunk-APB4NW4O.js → chunk-U5Q5I2D5.js} +36 -10
- package/dist/chunks/report-run-BZBFOMPF.js +12 -0
- package/dist/chunks/{unused-texts-K3VFH65P.js → unused-texts-Y4R67XSN.js} +1 -1
- package/dist/chunks/{unused-texts-de-OW4TGIVX.js → unused-texts-de-6YVPTNVS.js} +1 -1
- package/dist/echarts.js +38 -156
- package/dist/import-ui.js +765 -0
- package/dist/import-worker.js +20 -0
- package/dist/index.js +683 -244
- package/dist/labels.js +14 -10
- package/dist/menu-texts-de.js +1 -1
- package/dist/menus.js +768 -299
- package/dist/styles.css +322 -100
- package/package.json +9 -4
- package/types/chart-decorate.d.ts +28 -4
- package/types/chart-types.d.ts +2 -4
- package/types/data-history.d.ts +85 -0
- package/types/data-keep.d.ts +51 -0
- package/types/data-menu.d.ts +11 -0
- package/types/dom.d.ts +40 -7
- package/types/echarts.d.ts +1 -1
- package/types/export-run.d.ts +37 -3
- package/types/field-info.d.ts +32 -0
- package/types/filter.d.ts +1 -1
- package/types/icons.d.ts +1 -0
- package/types/import-host.d.ts +53 -0
- package/types/import-labels.d.ts +401 -0
- package/types/import-limits.d.ts +6 -0
- package/types/import-module.d.ts +2 -0
- package/types/import-run.d.ts +73 -0
- package/types/import-source.d.ts +32 -0
- package/types/import-steps.d.ts +121 -0
- package/types/import-ui.d.ts +108 -0
- package/types/import-worker.d.ts +1 -0
- package/types/index.d.ts +81 -11
- package/types/labels.d.ts +224 -4
- package/types/lazy-import.d.ts +4 -0
- package/types/lazy-menus.d.ts +2 -2
- package/types/levels.d.ts +3 -2
- package/types/light-tokens.d.ts +16 -0
- package/types/menu-labels.d.ts +37 -17
- package/types/menu-ops.d.ts +161 -40
- package/types/menu-topics.d.ts +9 -8
- package/types/menus.d.ts +1 -0
- package/types/names.d.ts +47 -19
- package/types/overflow.d.ts +29 -17
- package/types/place.d.ts +24 -0
- package/types/popover.d.ts +47 -5
- package/types/print-frame.d.ts +24 -0
- package/types/report-run.d.ts +14 -0
- package/types/section.d.ts +2 -2
- package/types/share-actions.d.ts +3 -3
- package/types/share.d.ts +13 -17
- package/types/theme.d.ts +2 -16
- package/types/tips.d.ts +5 -0
- package/types/toasts.d.ts +1 -1
- package/types/toolbar-panels.d.ts +11 -9
- package/types/unused-keep.d.ts +20 -0
- package/types/unused-texts.d.ts +13 -3
- package/types/unused.d.ts +1 -0
- package/types/use-export.d.ts +2 -2
- package/types/use-view-history.d.ts +12 -4
- package/types/view-ops.d.ts +65 -6
- package/types/virtual.d.ts +15 -0
- package/types/chart-layout.d.ts +0 -111
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MENU_TEXTS,
|
|
3
3
|
mergeLabels
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3WUGQPWV.js";
|
|
5
5
|
|
|
6
6
|
// src/menu-labels.js
|
|
7
7
|
var en = {
|
|
@@ -10,12 +10,14 @@ var en = {
|
|
|
10
10
|
settingInfo: {
|
|
11
11
|
grandTotalRow: "A last row with the total of every column.",
|
|
12
12
|
grandTotalColumn: "A last column with the total of every row.",
|
|
13
|
-
rowSubtotals: "With two or more fields in Rows: a
|
|
14
|
-
colSubtotals: "With two or more fields in Columns: a
|
|
13
|
+
rowSubtotals: "With two or more fields in Rows: a subtotal row (\u201CNorth Total\u201D) under each group of the outer field that has more than one item.",
|
|
14
|
+
colSubtotals: "With two or more fields in Columns: a subtotal column (\u201CNorth Total\u201D) after each group of the outer field that has more than one item.",
|
|
15
15
|
along: "The direction the calculation walks: Rows goes down the rows of each column, Columns across the columns of each row. A running total adds up along it, a difference compares with the item before it.",
|
|
16
16
|
showAs: "Shows each value as a share, a difference, a running total or a rank instead of the number itself. For percentages, a tip above the result says what 100% is.",
|
|
17
17
|
exportXlsx: "Every number with all its decimals, formats kept, ready to calculate with.",
|
|
18
18
|
exportCsv: "Percentages and calculations as the table shows them, as plain text.",
|
|
19
|
+
exportHtml: "A page with the table as it is shown, the chart when the chart is shown, and the filters: opens in any browser, prints well.",
|
|
20
|
+
exportPrint: "The same report in the browser's print dialog: print it, or pick Save as PDF there.",
|
|
19
21
|
copyTable: "The table as it is shown, headers and totals included: tab-separated, pastes into Excel or Google Sheets as columns.",
|
|
20
22
|
copyDataJson: "The table's numbers with their labels as JSON, for a program. Not the view itself: that is Views \u2192 Copy view as JSON.",
|
|
21
23
|
drillCopy: "The rows as the panel shows them, with a header row: tab-separated, pastes into Excel or Google Sheets as columns.",
|
|
@@ -23,7 +25,6 @@ var en = {
|
|
|
23
25
|
groupLabels: "With two or more fields in Rows: the outer field's items written once under the axis, below their categories.",
|
|
24
26
|
labelPosition: "Outside: each slice's name and number next to it. Inside: the number on the slice, the names in the legend; outside when a donut's ring is too thin for it.",
|
|
25
27
|
sharedView: "Only admins can change shared views.",
|
|
26
|
-
newReport: "Takes every field out, to start over. Undo brings them back; saved views stay.",
|
|
27
28
|
valuesFilter: "Values are not filtered here: filter a field on Rows or Columns through its menu, or move a field to Filters."
|
|
28
29
|
},
|
|
29
30
|
// a menu in levels: the way back, a level's title, the search of a menu
|
|
@@ -96,13 +97,27 @@ var en = {
|
|
|
96
97
|
// the Filter level of a date field: its quick choices ("Last [5] years" around the number typed),
|
|
97
98
|
// each with the data's share and the rows it keeps, the ones not offered, the reference date
|
|
98
99
|
quickTitle: "Quick choices",
|
|
99
|
-
quickCount: { year: "Number of years", month: "Number of months", day: "Number of days" },
|
|
100
|
-
quickLast: { year: { one: "Last {count} year", other: "Last {count} years" }, month: { one: "Last {count} month", other: "Last {count} months" }, day: { one: "Last {count} day", other: "Last {count} days" } },
|
|
100
|
+
quickCount: { year: "Number of years", quarter: "Number of quarters", month: "Number of months", week: "Number of weeks", day: "Number of days" },
|
|
101
101
|
quickRows: "{rows} rows",
|
|
102
102
|
quickHidden: { one: "{choices} is not offered: the data end {latest}.", other: "{choices} are not offered: the data end {latest}." },
|
|
103
|
+
// under the choice that is set: whether its periods take the current one ("Last 3 months" with November)
|
|
104
|
+
quickCurrent: { year: "Include the current year", quarter: "Include the current quarter", month: "Include the current month", week: "Include the current week", day: "Include today" },
|
|
105
|
+
// the rare choices, folded: Next N, Before the last N, rolling periods
|
|
106
|
+
quickMore: "More choices",
|
|
107
|
+
quickRolling: "Rolling instead of whole calendar periods",
|
|
108
|
+
// the names of the unit selects, after their choice: "Unit of “Last …”"; This's select picks the period
|
|
109
|
+
quickUnitOf: "Unit of \u201C{choice} \u2026\u201D",
|
|
110
|
+
quickThisUnit: "Current period",
|
|
103
111
|
anchorLabel: "Counted back from",
|
|
104
112
|
anchorToday: "today ({date})",
|
|
105
113
|
anchorLatest: "the latest record ({date})",
|
|
114
|
+
anchorFirst: "the first record ({date})",
|
|
115
|
+
anchorDate: "a date\u2026",
|
|
116
|
+
anchorDay: "The date counted from",
|
|
117
|
+
// the date field without a whole date: the range keeps the one before
|
|
118
|
+
anchorDayIncomplete: "Enter a whole date; the ranges still count from {date}.",
|
|
119
|
+
// under a choice whose current period has no data (the data end before it)
|
|
120
|
+
anchorUseLatest: "Count back from the latest record ({date}) instead",
|
|
106
121
|
quickLine: "Quick choice: {text}",
|
|
107
122
|
changeAbove: "change it above",
|
|
108
123
|
// a cyclic grouping ("month of the year") combines the years: the ones ticked
|
|
@@ -159,7 +174,10 @@ var en = {
|
|
|
159
174
|
ruleUnits: { year: { one: "year", other: "years" }, month: { one: "month", other: "months" }, day: { one: "day", other: "days" } },
|
|
160
175
|
// a rule on the total, as a sentence: "Product items whose / Count of Cycle / is greater than / 3"
|
|
161
176
|
ruleWhose: "{field} items whose total",
|
|
177
|
+
ruleFixed: "Kept as the view has it; the rules here cannot change it yet.",
|
|
162
178
|
blanksOut: "Blank items are not kept.",
|
|
179
|
+
// under the rules on the items: the field's blank items kept with them
|
|
180
|
+
rulesBlanks: { one: "Also keep items without a value ({rows} row)", other: "Also keep items without a value ({rows} rows)" },
|
|
163
181
|
ruleUnit: "Unit",
|
|
164
182
|
moveLeft: "Move left",
|
|
165
183
|
moveRight: "Move right",
|
|
@@ -206,7 +224,6 @@ var en = {
|
|
|
206
224
|
replaceConfirm: "\u201C{name}\u201D exists. Replace it?",
|
|
207
225
|
replaceAction: "Replace",
|
|
208
226
|
replaceSharedConfirm: "Replace the shared view \u201C{name}\u201D for everyone?",
|
|
209
|
-
newAlready: "The report is empty already.",
|
|
210
227
|
save: "Save",
|
|
211
228
|
cancel: "Cancel",
|
|
212
229
|
expandAll: "Expand all",
|
|
@@ -278,6 +295,10 @@ var en = {
|
|
|
278
295
|
topCount: "Count",
|
|
279
296
|
bottom: "Bottom",
|
|
280
297
|
topBy: "by",
|
|
298
|
+
topTies: "Also show items with the same value as the last one",
|
|
299
|
+
// under it: how many items the top shows (the field first on its axis), else that a group can show more
|
|
300
|
+
topShown: { one: "{count} item shown", other: "{count} items shown" },
|
|
301
|
+
topTiesGroups: "A group can show more than {count} items.",
|
|
281
302
|
searchValues: "Search values",
|
|
282
303
|
selectAll: "Select all",
|
|
283
304
|
selectNone: "Select none",
|
|
@@ -293,6 +314,10 @@ var en = {
|
|
|
293
314
|
exportXlsx: "Excel workbook (.xlsx)",
|
|
294
315
|
exportCsv: "CSV file (.csv)",
|
|
295
316
|
exportPng: "Chart image (.png)",
|
|
317
|
+
exportSvg: "Chart image (.svg)",
|
|
318
|
+
exportHtml: "HTML report (.html)",
|
|
319
|
+
exportPrintGroup: "Print",
|
|
320
|
+
exportPrint: "Print or save as PDF\u2026",
|
|
296
321
|
exportPngNeedsChart: "Switch to Chart first.",
|
|
297
322
|
exportNeedsField: "Add a field first.",
|
|
298
323
|
copyTable: "Copy table",
|
|
@@ -300,6 +325,7 @@ var en = {
|
|
|
300
325
|
toastTableCopied: "Table copied: tab-separated, pastes into Excel or Google Sheets as columns",
|
|
301
326
|
toastDataCopied: "Data copied as JSON",
|
|
302
327
|
toastCopyBlocked: "This page does not allow copying. Download a file instead.",
|
|
328
|
+
toastPrintBlocked: "This page does not allow printing the report. Download the HTML report instead.",
|
|
303
329
|
// drill-down
|
|
304
330
|
drillTitle: "Rows behind this value",
|
|
305
331
|
drillCount: { one: "{count} row", other: "{count} rows" },
|
|
@@ -348,15 +374,14 @@ var en = {
|
|
|
348
374
|
groupLabels: "Group labels under the axis",
|
|
349
375
|
groupLabelNames: { auto: "Automatic", on: "On", off: "Off" },
|
|
350
376
|
defaultName: "Use the default name",
|
|
351
|
-
// sharing a view (the Views menu): the group
|
|
377
|
+
// sharing a view (the Views menu): the group's title
|
|
352
378
|
shareThisView: "Share this view",
|
|
353
|
-
share: "Share",
|
|
354
379
|
copyLink: "Copy link",
|
|
355
380
|
copyJson: "Copy view as JSON",
|
|
356
381
|
downloadView: "Download view (.pivotkit.json)",
|
|
357
382
|
// said where a view leaves the report as a file, as JSON or as a link
|
|
358
383
|
sharePrivacy: "A view holds the names of fields and, in its filters, the values chosen there: share it only where those may be seen.",
|
|
359
|
-
loadView: "
|
|
384
|
+
loadView: "Open view file\u2026",
|
|
360
385
|
loadViewHint: "Paste a view file, a view as JSON or a link, or choose a .pivotkit.json file.",
|
|
361
386
|
loadViewText: "View as JSON or link",
|
|
362
387
|
chooseFile: "Choose file\u2026",
|
|
@@ -388,6 +413,7 @@ var en = {
|
|
|
388
413
|
needsColField: "Needs a field in Columns.",
|
|
389
414
|
needsRowFields: "Needs two or more fields in Rows.",
|
|
390
415
|
needsColFields: "Needs two or more fields in Columns.",
|
|
416
|
+
needsValue: "Needs a field in Values.",
|
|
391
417
|
expandNothing: "Nothing is collapsed.",
|
|
392
418
|
collapseNeedsRows: "Needs two or more fields in Rows.",
|
|
393
419
|
collapseAllDone: "Every group is collapsed already.",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/report-run.js
|
|
2
|
+
import { use as register } from "echarts/core";
|
|
3
|
+
import { SVGRenderer } from "echarts/renderers";
|
|
4
|
+
import { LIGHT_TOKENS, SHAPE_TOKENS, SIZE_TOKENS, WEIGHT_TOKENS, render } from "pivotkit-report";
|
|
5
|
+
register([SVGRenderer]);
|
|
6
|
+
var REPORT_TOKENS = Object.freeze([...Object.keys(WEIGHT_TOKENS), ...Object.keys(SHAPE_TOKENS), ...Object.keys(LIGHT_TOKENS), "--pk-scale-mid"]);
|
|
7
|
+
var REPORT_LENGTHS = Object.freeze(Object.keys(SIZE_TOKENS));
|
|
8
|
+
export {
|
|
9
|
+
REPORT_LENGTHS,
|
|
10
|
+
REPORT_TOKENS,
|
|
11
|
+
render
|
|
12
|
+
};
|
package/dist/echarts.js
CHANGED
|
@@ -116,6 +116,9 @@ function mergeChartOptions(base, over) {
|
|
|
116
116
|
return over;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
// src/chart-decorate.js
|
|
120
|
+
import { decorateOption } from "pivotkit-core/chart";
|
|
121
|
+
|
|
119
122
|
// src/chart-tooltip.js
|
|
120
123
|
function tooltipContent(params, { valueFormatter = (v) => String(v ?? ""), xNames = [], yNames = [], categoryNames = [] } = {}) {
|
|
121
124
|
const color = (p) => typeof p.color === "string" ? p.color : null;
|
|
@@ -146,7 +149,7 @@ function tooltipFormatter(doc, options) {
|
|
|
146
149
|
if (title) {
|
|
147
150
|
const head = doc.createElement("div");
|
|
148
151
|
head.textContent = title;
|
|
149
|
-
head.style.fontWeight = "
|
|
152
|
+
head.style.fontWeight = "var(--pk-weight-strong)";
|
|
150
153
|
head.style.marginBottom = "2px";
|
|
151
154
|
box.append(head);
|
|
152
155
|
}
|
|
@@ -169,7 +172,7 @@ function tooltipFormatter(doc, options) {
|
|
|
169
172
|
name.style.flex = "1";
|
|
170
173
|
const value = doc.createElement("span");
|
|
171
174
|
value.textContent = line.value;
|
|
172
|
-
value.style.fontWeight = "
|
|
175
|
+
value.style.fontWeight = "var(--pk-weight-strong)";
|
|
173
176
|
value.style.marginLeft = "12px";
|
|
174
177
|
row.append(marker, name, value);
|
|
175
178
|
box.append(row);
|
|
@@ -178,170 +181,49 @@ function tooltipFormatter(doc, options) {
|
|
|
178
181
|
};
|
|
179
182
|
}
|
|
180
183
|
|
|
181
|
-
// src/chart-layout.js
|
|
182
|
-
function pieLabelRoom(height) {
|
|
183
|
-
return Math.round(Math.min(24, Math.max(0, height) * 0.05));
|
|
184
|
-
}
|
|
185
|
-
var RIGHT_LEGEND_MIN_WIDTH = 480;
|
|
186
|
-
var BOTTOM_LEGEND_ROOM = 32;
|
|
187
|
-
var labelWidth = (text) => String(text).length * 7;
|
|
188
|
-
function ringLabelsFit(radius, box, texts) {
|
|
189
|
-
const half = Math.max(0, Math.min(box.width, box.height)) / 2;
|
|
190
|
-
const px = (r) => typeof r === "number" ? r : /%$/.test(String(r)) ? parseFloat(String(r)) / 100 * half : parseFloat(String(r)) || 0;
|
|
191
|
-
const inner = px(radius[0]);
|
|
192
|
-
if (inner <= 0) {
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
const ring = px(radius[1]) - inner;
|
|
196
|
-
return texts.every((t) => labelWidth(t) + 6 <= ring);
|
|
197
|
-
}
|
|
198
|
-
var SLANTED_LABEL_WIDTH = 120;
|
|
199
|
-
var HEATMAP_FRAME = { x: 80, y: 120 };
|
|
200
|
-
var LABEL_LINE = 16;
|
|
201
|
-
var LABEL_PAD = 4;
|
|
202
|
-
function columnLabelLayout(names, width, fontSize = 12) {
|
|
203
|
-
if (names.length === 0) {
|
|
204
|
-
return { rotate: 0 };
|
|
205
|
-
}
|
|
206
|
-
const slot = Math.max(0, width - HEATMAP_FRAME.x) / names.length;
|
|
207
|
-
const longest = Math.max(...names.map((n) => String(n).length)) * fontSize * 0.55;
|
|
208
|
-
return longest <= slot ? { rotate: 0 } : { rotate: 45, width: SLANTED_LABEL_WIDTH, overflow: "truncate" };
|
|
209
|
-
}
|
|
210
|
-
function heatmapCellLabels(columns, rows, width, height, texts, fontSize = 12) {
|
|
211
|
-
const w = Math.max(0, width - HEATMAP_FRAME.x) / Math.max(1, columns);
|
|
212
|
-
const h = Math.max(0, height - HEATMAP_FRAME.y) / Math.max(1, rows);
|
|
213
|
-
const longest = texts.reduce((m, t) => Math.max(m, String(t).length), 0) * fontSize * 0.55;
|
|
214
|
-
return w >= longest + 2 * LABEL_PAD && h >= LABEL_LINE;
|
|
215
|
-
}
|
|
216
|
-
function rowLabelInterval(rows, height) {
|
|
217
|
-
const h = Math.max(0, height - HEATMAP_FRAME.y) / Math.max(1, rows);
|
|
218
|
-
return h >= LABEL_LINE ? 0 : Math.ceil(LABEL_LINE / Math.max(h, 0.1)) - 1;
|
|
219
|
-
}
|
|
220
|
-
var CATEGORY_LABEL_WIDTH = 120;
|
|
221
|
-
var AXIS_FRAME = { x: 80, y: 60 };
|
|
222
|
-
function categoryLabelLayout(names, { width, height, horizontal = false, mode = "auto", fontSize = 12 }) {
|
|
223
|
-
const n = Math.max(1, names.length);
|
|
224
|
-
const cut = { width: CATEGORY_LABEL_WIDTH, overflow: (
|
|
225
|
-
/** @type {const} */
|
|
226
|
-
"truncate"
|
|
227
|
-
) };
|
|
228
|
-
const every = (slot2, need) => Math.max(1, Math.ceil(need / Math.max(slot2, 0.1)));
|
|
229
|
-
const result = (rotate, step) => ({ rotate, interval: step - 1, every: step, ...cut });
|
|
230
|
-
if (horizontal) {
|
|
231
|
-
const slot2 = Math.max(0, height - AXIS_FRAME.y) / n;
|
|
232
|
-
return result(0, mode === "all" ? 1 : every(slot2, fontSize + 1));
|
|
233
|
-
}
|
|
234
|
-
const slot = Math.max(0, width - AXIS_FRAME.x) / n;
|
|
235
|
-
const longest = Math.min(CATEGORY_LABEL_WIDTH, Math.max(0, ...names.map((t) => String(t).length)) * fontSize * 0.55);
|
|
236
|
-
if (mode === "nth") {
|
|
237
|
-
return result(0, every(slot, longest + 8));
|
|
238
|
-
}
|
|
239
|
-
if (longest + 8 <= slot) {
|
|
240
|
-
return result(0, 1);
|
|
241
|
-
}
|
|
242
|
-
return result(45, mode === "all" ? 1 : every(slot, LABEL_LINE));
|
|
243
|
-
}
|
|
244
|
-
var GROUP_LABEL_ROOM = Object.freeze({ along: 56, across: 28, width: 420, height: 260 });
|
|
245
|
-
function groupLabelsFit(count, groupSize, { width, height, horizontal = false }) {
|
|
246
|
-
if (width < GROUP_LABEL_ROOM.width || height < GROUP_LABEL_ROOM.height) {
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
const n = Math.max(1, count);
|
|
250
|
-
const slot = horizontal ? Math.max(0, height - AXIS_FRAME.y) / n : Math.max(0, width - AXIS_FRAME.x) / n;
|
|
251
|
-
return slot * Math.max(1, groupSize) >= (horizontal ? GROUP_LABEL_ROOM.across : GROUP_LABEL_ROOM.along);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
184
|
// src/chart-decorate.js
|
|
255
|
-
var without = (obj, keys) => Object.fromEntries(Object.entries(obj).filter(([k]) => !keys.includes(k)));
|
|
256
185
|
function decorate(option, style, height = 480, doc = void 0, width = 800, extra = {}) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
};
|
|
186
|
+
return decorateOption(option, style, { height, width, ...extra, tooltipFormatter: doc ? (context) => tooltipFormatter(doc, context) : void 0 });
|
|
187
|
+
}
|
|
188
|
+
var LENGTH_TOKENS = Object.freeze(["--pk-chart-title-size", "--pk-chart-text-size", "--pk-radius-chart"]);
|
|
189
|
+
function tokenLengths(root, names = LENGTH_TOKENS) {
|
|
190
|
+
const view = root.ownerDocument.defaultView;
|
|
191
|
+
const style = view?.getComputedStyle(root);
|
|
192
|
+
const lengthy = (value) => Boolean(value) && (typeof CSS === "undefined" || CSS.supports("margin-left", value));
|
|
193
|
+
const set = style ? names.filter((name) => lengthy(style.getPropertyValue(name).trim())) : [];
|
|
194
|
+
if (!view || !set.length) {
|
|
195
|
+
return {};
|
|
268
196
|
}
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
if (s.type === "line") {
|
|
285
|
-
return { ...s, lineStyle: { width: 2 }, symbolSize: 7, smooth: Boolean(s.smooth), areaStyle: s.areaStyle ? { opacity: 0.18 } : void 0, emphasis: { focus: "series" } };
|
|
286
|
-
}
|
|
287
|
-
if (s.type === "pie") {
|
|
288
|
-
const room = pieLabelRoom(height);
|
|
289
|
-
const top = (typeof s.top === "number" ? s.top : 0) + room;
|
|
290
|
-
const bottom = (typeof s.bottom === "number" ? s.bottom : 0) + room;
|
|
291
|
-
let label = s.label;
|
|
292
|
-
let line = s.labelLine;
|
|
293
|
-
if (label?.position === "inside" && label.show !== false && Array.isArray(s.radius)) {
|
|
294
|
-
const box = { width: width - (typeof s.right === "number" ? s.right : 0), height: height - top - bottom };
|
|
295
|
-
const total = (s.data || []).reduce((sum, d) => sum + (typeof d.value === "number" ? d.value : 0), 0);
|
|
296
|
-
const texts = typeof label.formatter === "function" ? (s.data || []).map((d) => label.formatter({ name: d.name, value: d.value, percent: total ? d.value / total * 100 : 0 })) : [];
|
|
297
|
-
if (!ringLabelsFit(s.radius, box, texts)) {
|
|
298
|
-
label = without(label, ["position"]);
|
|
299
|
-
line = { show: true };
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
return { ...s, top, bottom, labelLine: line, itemStyle: { borderColor: surface, borderWidth: 2, borderRadius: 4 }, label: { ...label, color: label?.position === "inside" ? void 0 : v("--pk-text") || void 0 } };
|
|
303
|
-
}
|
|
304
|
-
if (s.type === "heatmap") {
|
|
305
|
-
const texts = typeof s.label?.formatter === "function" ? s.data.map((d) => s.label.formatter({ value: d })) : [];
|
|
306
|
-
const fits = heatmapCellLabels(option.xAxis?.data?.length ?? 1, option.yAxis?.data?.length ?? 1, width, height, texts);
|
|
307
|
-
return { ...s, itemStyle: { borderColor: surface, borderWidth: 2, borderRadius: 3 }, label: { ...s.label, show: Boolean(s.label?.show) && fits, color: v("--pk-text") || void 0 } };
|
|
308
|
-
}
|
|
309
|
-
return s;
|
|
310
|
-
});
|
|
311
|
-
const legend = option.legend ? { ...option.legend, icon: "roundRect", itemWidth: 12, itemHeight: 12, textStyle: { ...option.legend.textStyle, color: v("--pk-text") || void 0 } } : void 0;
|
|
312
|
-
const grid = option.grid ? { left: 12, right: 24, bottom: option.visualMap ? 64 : 12, containLabel: true, ...option.grid } : void 0;
|
|
313
|
-
const heatmap = series.some((s) => s.type === "heatmap") && option.xAxis?.axisLabel;
|
|
314
|
-
const xAxis = heatmap ? { ...option.xAxis, axisLabel: { ...option.xAxis.axisLabel, ...columnLabelLayout(option.xAxis.data ?? [], width) } } : option.xAxis;
|
|
315
|
-
const yAxis = heatmap && option.yAxis ? { ...option.yAxis, axisLabel: { ...option.yAxis.axisLabel, interval: rowLabelInterval(option.yAxis.data?.length ?? 0, height) } } : option.yAxis;
|
|
316
|
-
const title = option.title ? { title: { ...option.title, textStyle: { ...option.title.textStyle, width: Math.max(40, width - 32), overflow: "truncate" } } } : {};
|
|
317
|
-
let axes = { xAxis, yAxis };
|
|
318
|
-
let axisEvery = 1;
|
|
319
|
-
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;
|
|
320
|
-
if (along) {
|
|
321
|
-
let list = Array.isArray(axes[along]) ? axes[along] : [axes[along]];
|
|
322
|
-
const group = list[1]?.groups ? list[1] : null;
|
|
323
|
-
if (group && group.groupsAuto && !groupLabelsFit(list[0].data?.length ?? 0, group.groupSize ?? 1, { width, height, horizontal: along === "yAxis" })) {
|
|
324
|
-
list = [{ ...list[0], data: extra.categoryNames ?? list[0].data }];
|
|
325
|
-
}
|
|
326
|
-
const names = list[0].data ?? [];
|
|
327
|
-
const layout = categoryLabelLayout(names, { width, height, horizontal: along === "yAxis", mode: extra.axisLabels });
|
|
328
|
-
axisEvery = layout.every;
|
|
329
|
-
const longest = Math.min(CATEGORY_LABEL_WIDTH, Math.max(0, ...names.map((t) => String(t).length)) * 12 * 0.55);
|
|
330
|
-
const offset = along === "yAxis" ? Math.round(longest) + 16 : layout.rotate ? Math.round(longest * 0.71) + 14 : 24;
|
|
331
|
-
const main = { ...list[0], axisLabel: { ...list[0].axisLabel, rotate: layout.rotate, interval: layout.interval, width: layout.width, overflow: layout.overflow } };
|
|
332
|
-
const slot = (along === "yAxis" ? Math.max(0, height - 60) : Math.max(0, width - 80)) / Math.max(1, names.length);
|
|
333
|
-
const groupWidth = along === "yAxis" ? CATEGORY_LABEL_WIDTH : Math.max(24, Math.round(slot * (list[1]?.groupSize ?? 1)) - 8);
|
|
334
|
-
const rest = list.slice(1).map((a) => a.groups ? { ...a, offset, axisTick: { ...a.axisTick, length: offset }, axisLabel: { ...a.axisLabel, width: groupWidth, overflow: "truncate" } } : a);
|
|
335
|
-
axes = { ...axes, [along]: rest.length ? [main, ...rest] : main };
|
|
197
|
+
const probe = root.ownerDocument.createElement("span");
|
|
198
|
+
probe.setAttribute("aria-hidden", "true");
|
|
199
|
+
probe.style.setProperty("position", "absolute");
|
|
200
|
+
probe.style.setProperty("visibility", "hidden");
|
|
201
|
+
root.append(probe);
|
|
202
|
+
try {
|
|
203
|
+
return Object.fromEntries(
|
|
204
|
+
set.map((name) => {
|
|
205
|
+
probe.style.setProperty("margin-left", `var(${name})`);
|
|
206
|
+
return [name, view.getComputedStyle(probe).marginLeft];
|
|
207
|
+
}).filter(([, value]) => /px$/.test(value))
|
|
208
|
+
);
|
|
209
|
+
} finally {
|
|
210
|
+
probe.remove();
|
|
336
211
|
}
|
|
337
|
-
|
|
212
|
+
}
|
|
213
|
+
function chartStyle(root) {
|
|
214
|
+
const style = getComputedStyle(root);
|
|
215
|
+
const lengths = tokenLengths(root);
|
|
216
|
+
return { getPropertyValue: (name) => lengths[name] ?? style.getPropertyValue(name) };
|
|
338
217
|
}
|
|
339
218
|
|
|
340
219
|
// src/echarts.js
|
|
341
220
|
register([BarChart, LineChart, PieChart, HeatmapChart, GridComponent, TooltipComponent, LegendComponent, TitleComponent, VisualMapComponent, CanvasRenderer]);
|
|
342
221
|
export {
|
|
222
|
+
LENGTH_TOKENS,
|
|
223
|
+
chartStyle,
|
|
343
224
|
cleanChartOptions,
|
|
344
225
|
decorate,
|
|
345
226
|
init,
|
|
346
|
-
mergeChartOptions
|
|
227
|
+
mergeChartOptions,
|
|
228
|
+
tokenLengths
|
|
347
229
|
};
|