pivotkit-react 0.6.1 → 0.8.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 +212 -1
- package/README.md +33 -15
- package/dist/chunks/{chunk-JMRTIOX4.js → chunk-2N2UGSIG.js} +7 -0
- package/dist/chunks/{chunk-ZK5RVCHP.js → chunk-BHHIZHUE.js} +1 -1
- package/dist/chunks/{chunk-YXLANLGL.js → chunk-GUSQWPTH.js} +56 -3
- package/dist/chunks/{chunk-JOWAEZAD.js → chunk-JAOOFDNR.js} +21 -1
- package/dist/chunks/{chunk-E6M57YLL.js → chunk-MU5BTKSY.js} +7 -0
- package/dist/chunks/{chunk-TR2HROIK.js → chunk-RNQ32FCN.js} +66 -5
- package/dist/chunks/{chunk-XN5HNKJ2.js → chunk-SJCG4I57.js} +98 -33
- package/dist/chunks/{chunk-3LDE2GPG.js → chunk-VMJMDP7C.js} +372 -33
- package/dist/chunks/{report-run-BZBFOMPF.js → report-run-HU4WPOB7.js} +3 -1
- package/dist/chunks/{unused-texts-Y4R67XSN.js → unused-texts-LRYVWFFN.js} +1 -1
- package/dist/chunks/{unused-texts-de-6YVPTNVS.js → unused-texts-de-GB3IWWEM.js} +1 -1
- package/dist/echarts.js +426 -35
- package/dist/import-ui.js +3 -3
- package/dist/index.js +769 -435
- package/dist/labels.js +6 -6
- package/dist/menu-texts-de.js +1 -1
- package/dist/menus.js +1133 -542
- package/dist/styles.css +271 -158
- package/package.json +8 -4
- package/styles.css.d.ts +3 -0
- package/types/PivotReport.d.ts +6 -0
- package/types/add-menu.d.ts +48 -0
- package/types/chart-colors.d.ts +8 -0
- package/types/chart-decorate.d.ts +66 -3
- package/types/chart-legend.d.ts +176 -0
- package/types/chart-summary.d.ts +8 -3
- package/types/chart-tooltip.d.ts +159 -17
- package/types/chart.d.ts +21 -3
- package/types/date-context.d.ts +30 -0
- package/types/drill-panel.d.ts +4 -2
- package/types/echarts.d.ts +7 -3
- package/types/export-run.d.ts +19 -14
- package/types/export-scope.d.ts +13 -2
- package/types/field-info.d.ts +12 -0
- package/types/files.d.ts +14 -0
- package/types/filter.d.ts +18 -0
- package/types/group-context.d.ts +20 -0
- package/types/index.d.ts +35 -6
- package/types/label-room.d.ts +13 -0
- package/types/labels.d.ts +85 -16
- package/types/lazy-menus.d.ts +2 -2
- package/types/levels.d.ts +16 -7
- package/types/menu-labels.d.ts +67 -1
- package/types/menu-ops.d.ts +10 -0
- package/types/menu-topics.d.ts +110 -21
- package/types/menus.d.ts +3 -2
- package/types/names.d.ts +32 -3
- package/types/overflow.d.ts +18 -30
- package/types/print-frame.d.ts +32 -3
- package/types/report-run.d.ts +5 -0
- package/types/rove.d.ts +10 -0
- package/types/theme-tokens.d.ts +17 -0
- package/types/toolbar-panels.d.ts +43 -15
- package/types/unused-texts.d.ts +7 -0
- package/types/use-big-result.d.ts +24 -9
- package/types/use-export.d.ts +8 -4
- package/types/view-ops.d.ts +19 -8
- package/types/view-tabs.d.ts +12 -0
- package/types/zones.d.ts +41 -9
- package/types/light-tokens.d.ts +0 -16
package/dist/echarts.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// src/echarts.js
|
|
2
|
-
import { init, use as register } from "echarts/core";
|
|
2
|
+
import { color, init, use as register } from "echarts/core";
|
|
3
3
|
import { BarChart, HeatmapChart, LineChart, PieChart } from "echarts/charts";
|
|
4
|
-
import { GridComponent, LegendComponent, TitleComponent, TooltipComponent, VisualMapComponent } from "echarts/components";
|
|
4
|
+
import { DataZoomSliderComponent, GridComponent, LegendComponent, MarkLineComponent, TitleComponent, TooltipComponent, VisualMapComponent } from "echarts/components";
|
|
5
5
|
import { CanvasRenderer } from "echarts/renderers";
|
|
6
|
+
import { toEChartsOption } from "pivotkit-core/chart";
|
|
6
7
|
|
|
7
8
|
// src/chart-options.js
|
|
8
9
|
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["rich", "link", "sublink", "target", "subtarget", "linkTarget", "image", "extraCssText", "className", "appendTo", "appendToBody", "renderMode"]);
|
|
@@ -116,35 +117,199 @@ function mergeChartOptions(base, over) {
|
|
|
116
117
|
return over;
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
// src/chart-colors.js
|
|
121
|
+
function colorMapFor(map, theme) {
|
|
122
|
+
if (map === null || typeof map !== "object" || Array.isArray(map)) {
|
|
123
|
+
return void 0;
|
|
124
|
+
}
|
|
125
|
+
const entries = [];
|
|
126
|
+
for (const name of Object.keys(map)) {
|
|
127
|
+
const value = (
|
|
128
|
+
/** @type {Record<string, unknown>} */
|
|
129
|
+
map[name]
|
|
130
|
+
);
|
|
131
|
+
const color2 = Array.isArray(value) && value.length === 2 ? value[theme === "dark" ? 1 : 0] : value;
|
|
132
|
+
if (typeof color2 === "string") {
|
|
133
|
+
entries.push([name, color2]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return Object.fromEntries(entries);
|
|
137
|
+
}
|
|
138
|
+
|
|
119
139
|
// src/chart-decorate.js
|
|
140
|
+
import { DEFAULT_THEME } from "pivotkit-core";
|
|
120
141
|
import { decorateOption } from "pivotkit-core/chart";
|
|
121
142
|
|
|
122
143
|
// src/chart-tooltip.js
|
|
123
|
-
|
|
124
|
-
|
|
144
|
+
import { referenceLineChecks, referenceLines } from "pivotkit-core/chart";
|
|
145
|
+
import { valueAddsUp } from "pivotkit-core";
|
|
146
|
+
var lineName = (line, seriesNames) => line.series !== null && seriesNames.length > 1 ? `${line.name} (${seriesNames[line.series]})` : line.name;
|
|
147
|
+
function linesSummary(lines, seriesNames, labels) {
|
|
148
|
+
const value = (l) => l.kind === "trend" ? labels.chartTrendSpan.replace("{from}", () => l.format(
|
|
149
|
+
/** @type {number} */
|
|
150
|
+
l.from
|
|
151
|
+
)).replace("{to}", () => l.format(
|
|
152
|
+
/** @type {number} */
|
|
153
|
+
l.to
|
|
154
|
+
)) : l.format(
|
|
155
|
+
/** @type {number} */
|
|
156
|
+
l.value
|
|
157
|
+
);
|
|
158
|
+
return lines.length ? labels.chartLines.replace("{lines}", () => lines.map((l) => `${lineName(l, seriesNames)} ${value(l)}`).join("; ")) : "";
|
|
159
|
+
}
|
|
160
|
+
function chartLines(result, { series, chart, labels, locale }) {
|
|
161
|
+
const drawn = chart ? { chart } : {};
|
|
162
|
+
const lines = referenceLines(result, { series, words: labels.core.referenceLines, locale, ...drawn });
|
|
163
|
+
return {
|
|
164
|
+
lines,
|
|
165
|
+
text: linesSummary(lines, series.series.map((x) => x.name), labels),
|
|
166
|
+
// the format of the first series the legend shows
|
|
167
|
+
checks: { ...referenceLineChecks(result, { series, ...drawn }), format: series.series.find((x) => !/** @type {any} */
|
|
168
|
+
(result.view.chart.hidden ?? []).includes(x.name))?.format }
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function tooltipReferences(lines, seriesNames, color2) {
|
|
172
|
+
return lines.map((line) => ({
|
|
173
|
+
name: lineName(line, seriesNames),
|
|
174
|
+
series: line.series,
|
|
175
|
+
color: line.series === null ? color2 : null,
|
|
176
|
+
value: (i) => {
|
|
177
|
+
if (line.kind !== "trend") {
|
|
178
|
+
return line.format(
|
|
179
|
+
/** @type {number} */
|
|
180
|
+
line.value
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return i >= /** @type {number} */
|
|
184
|
+
line.first && i <= /** @type {number} */
|
|
185
|
+
line.last && line.at ? line.format(line.at(i)) : null;
|
|
186
|
+
}
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
var hasValue = (v) => typeof v === "number" && Number.isFinite(v);
|
|
190
|
+
var isShare = (p) => p.data !== null && typeof p.data === "object" && typeof p.data.raw === "number";
|
|
191
|
+
var rawOf = (p) => isShare(p) ? p.data.raw : p.value;
|
|
192
|
+
function sharesOf(items, { series = [], seriesTotals = [] }) {
|
|
193
|
+
const parts = items.filter((p) => hasValue(p.value));
|
|
194
|
+
if (!parts.length || parts.some((p) => rawOf(p) < 0 || series[p.seriesIndex]?.additive !== true)) {
|
|
195
|
+
return /* @__PURE__ */ new Map();
|
|
196
|
+
}
|
|
197
|
+
if (series.length > 1 && parts.length < 2) {
|
|
198
|
+
return /* @__PURE__ */ new Map();
|
|
199
|
+
}
|
|
200
|
+
const total = series.length > 1 ? parts.reduce((sum, p) => sum + rawOf(p), 0) : seriesTotals[parts[0].seriesIndex];
|
|
201
|
+
return typeof total === "number" && total > 0 ? new Map(parts.map((p) => [p, rawOf(p) / total * 100])) : /* @__PURE__ */ new Map();
|
|
202
|
+
}
|
|
203
|
+
function axisItems(params, { valueFormatter, mode, series, hover, totalLabel }) {
|
|
204
|
+
const items = params.filter(Boolean);
|
|
205
|
+
const stackOf = (p) => series[p.seriesIndex]?.stack;
|
|
206
|
+
const hit = hover ? items.find((p) => p.seriesIndex === hover.seriesIndex && p.dataIndex === hover.dataIndex) : void 0;
|
|
207
|
+
const auto = mode !== "axis";
|
|
208
|
+
const stack = (hit ? [hit] : items).map(stackOf).find(Boolean);
|
|
209
|
+
const parts = stack ? items.filter((p) => stackOf(p) === stack) : [];
|
|
210
|
+
const sums = parts.length > 0 && parts.every((p) => series[p.seriesIndex]?.additive !== false);
|
|
211
|
+
const counted = sums ? parts.filter((p) => hasValue(p.value)) : [];
|
|
212
|
+
const gap = auto && !hit && counted.length > 0 && items.length > 1 && items.every((p) => series[p.seriesIndex]?.type === "bar" && stackOf(p));
|
|
213
|
+
const shown = auto && hit ? [hit] : gap ? [] : hit ? [hit, ...items.filter((p) => p !== hit)] : items;
|
|
214
|
+
const lines = shown.filter((p) => hasValue(p.value));
|
|
215
|
+
return {
|
|
216
|
+
lines: lines.map((p) => ({ p, hovered: p === hit && lines.length > 1 })),
|
|
217
|
+
total: counted.length ? { name: totalLabel, value: valueFormatter(counted.reduce((sum, p) => sum + rawOf(p), 0)) } : null
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function referenceItems(params, references, mode, hover) {
|
|
221
|
+
const at = params.find(Boolean);
|
|
222
|
+
if (!at || !references.length) {
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
const hit = mode !== "axis" && hover ? params.find((p) => p && p.seriesIndex === hover.seriesIndex && p.dataIndex === hover.dataIndex) : void 0;
|
|
226
|
+
const colorOf = (i) => params.find((p) => p && p.seriesIndex === i)?.color;
|
|
227
|
+
return references.flatMap((r) => {
|
|
228
|
+
const value = r.value(at.dataIndex);
|
|
229
|
+
if (value === null || hit && r.series !== null && r.series !== hit.seriesIndex) {
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
const color2 = r.series === null ? r.color : colorOf(r.series);
|
|
233
|
+
return [{ color: typeof color2 === "string" ? color2 : null, name: r.name, value }];
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
function tooltipContent(params, { valueFormatter = (v) => String(v ?? ""), shareFormatter, share = false, seriesTotals, xNames = [], yNames = [], categoryNames = [], mode = "auto", series = [], hover = null, totalLabel = "Total", maxLines = Infinity, moreLabel = "+{count}", moreInTotalLabel = moreLabel, references = [] } = {}) {
|
|
237
|
+
const color2 = (p) => typeof p.color === "string" ? p.color : null;
|
|
125
238
|
const text = (v) => v === null || v === void 0 ? "" : String(v);
|
|
126
239
|
if (Array.isArray(params)) {
|
|
127
240
|
const first = params[0];
|
|
241
|
+
const { lines, total } = axisItems(params, { valueFormatter, mode, series, hover, totalLabel });
|
|
242
|
+
const shares = share && shareFormatter ? sharesOf(params.filter(Boolean), { series, seriesTotals }) : /* @__PURE__ */ new Map();
|
|
243
|
+
const cut = lines.length > maxLines ? lines.length - Math.max(1, maxLines - 1) : 0;
|
|
244
|
+
const kept = cut ? lines.slice(0, lines.length - cut) : lines;
|
|
245
|
+
const refs = referenceItems(params, references, mode, hover);
|
|
128
246
|
return {
|
|
129
247
|
title: first ? text(categoryNames[first.dataIndex] ?? first.axisValueLabel ?? first.name) : "",
|
|
130
|
-
|
|
248
|
+
// a share of the total (chart.tooltipShare), else a 100 % stack's part its share of the stack as drawn
|
|
249
|
+
lines: kept.map(({ p, hovered }) => {
|
|
250
|
+
const part = shares.get(p) ?? (shareFormatter && isShare(p) ? p.value : void 0);
|
|
251
|
+
return { color: color2(p), name: text(p.seriesName), value: valueFormatter(rawOf(p)), ...part !== void 0 && shareFormatter ? { share: shareFormatter(part) } : {}, ...hovered ? { hovered } : {} };
|
|
252
|
+
}),
|
|
253
|
+
...cut ? { more: (total ? moreInTotalLabel : moreLabel).replace("{count}", String(cut)) } : {},
|
|
254
|
+
...total ? { total } : {},
|
|
255
|
+
...refs.length ? { references: refs } : {}
|
|
131
256
|
};
|
|
132
257
|
}
|
|
133
258
|
if (params && params.seriesType === "heatmap" && Array.isArray(params.value)) {
|
|
134
259
|
const [x, y, v] = params.value;
|
|
135
260
|
return {
|
|
136
261
|
title: text(params.seriesName),
|
|
137
|
-
lines: [{ color:
|
|
262
|
+
lines: [{ color: color2(params), name: [yNames[y], xNames[x]].filter((n) => n !== void 0).map(text).join(", "), value: valueFormatter(v) }]
|
|
138
263
|
};
|
|
139
264
|
}
|
|
140
265
|
return {
|
|
141
266
|
title: text(params?.seriesName),
|
|
142
|
-
|
|
267
|
+
// a slice's share: ECharts' percent of the slices shown
|
|
268
|
+
// a slice's share only where its values add up, as a stack's (an average has none)
|
|
269
|
+
lines: params ? [{ color: color2(params), name: text(params.name), value: valueFormatter(params.value), ...share && shareFormatter && hasValue(params.percent) && series[params.seriesIndex ?? 0]?.additive === true ? { share: shareFormatter(params.percent) } : {} }] : []
|
|
143
270
|
};
|
|
144
271
|
}
|
|
145
|
-
function tooltipFormatter(doc, options) {
|
|
272
|
+
function tooltipFormatter(doc, { hoverOf, ...options }) {
|
|
273
|
+
const row = (line) => {
|
|
274
|
+
const el = doc.createElement("div");
|
|
275
|
+
el.style.display = "flex";
|
|
276
|
+
el.style.alignItems = "center";
|
|
277
|
+
el.style.gap = "8px";
|
|
278
|
+
const marker = doc.createElement("span");
|
|
279
|
+
marker.style.display = "inline-block";
|
|
280
|
+
marker.style.width = "10px";
|
|
281
|
+
marker.style.height = "10px";
|
|
282
|
+
marker.style.borderRadius = "50%";
|
|
283
|
+
marker.style.flex = "none";
|
|
284
|
+
if (line.color) {
|
|
285
|
+
marker.style.backgroundColor = line.color;
|
|
286
|
+
}
|
|
287
|
+
const name = doc.createElement("span");
|
|
288
|
+
name.textContent = line.name;
|
|
289
|
+
name.style.flex = "1";
|
|
290
|
+
name.style.maxWidth = "var(--pk-tooltip-name-w)";
|
|
291
|
+
name.style.overflow = "hidden";
|
|
292
|
+
name.style.textOverflow = "ellipsis";
|
|
293
|
+
name.style.whiteSpace = "nowrap";
|
|
294
|
+
if (line.hovered) {
|
|
295
|
+
name.style.fontWeight = "var(--pk-weight-strong)";
|
|
296
|
+
}
|
|
297
|
+
const value = doc.createElement("span");
|
|
298
|
+
value.textContent = line.value;
|
|
299
|
+
value.style.fontWeight = "var(--pk-weight-strong)";
|
|
300
|
+
value.style.marginLeft = "12px";
|
|
301
|
+
el.append(marker, name, value);
|
|
302
|
+
if (line.share) {
|
|
303
|
+
const share = doc.createElement("span");
|
|
304
|
+
share.textContent = line.share;
|
|
305
|
+
share.style.color = "var(--pk-muted)";
|
|
306
|
+
share.style.marginLeft = "8px";
|
|
307
|
+
el.append(share);
|
|
308
|
+
}
|
|
309
|
+
return el;
|
|
310
|
+
};
|
|
146
311
|
return (params) => {
|
|
147
|
-
const { title, lines } = tooltipContent(params, options);
|
|
312
|
+
const { title, lines, more, total, references } = tooltipContent(params, hoverOf ? { ...options, hover: hoverOf() } : options);
|
|
148
313
|
const box = doc.createElement("div");
|
|
149
314
|
if (title) {
|
|
150
315
|
const head = doc.createElement("div");
|
|
@@ -154,38 +319,98 @@ function tooltipFormatter(doc, options) {
|
|
|
154
319
|
box.append(head);
|
|
155
320
|
}
|
|
156
321
|
for (const line of lines) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
value.style.fontWeight = "var(--pk-weight-strong)";
|
|
176
|
-
value.style.marginLeft = "12px";
|
|
177
|
-
row.append(marker, name, value);
|
|
178
|
-
box.append(row);
|
|
322
|
+
box.append(row(line));
|
|
323
|
+
}
|
|
324
|
+
if (more) {
|
|
325
|
+
const rest = doc.createElement("div");
|
|
326
|
+
rest.textContent = more;
|
|
327
|
+
rest.style.color = "var(--pk-muted)";
|
|
328
|
+
box.append(rest);
|
|
329
|
+
}
|
|
330
|
+
const ruled = (el) => {
|
|
331
|
+
el.style.borderTop = "1px solid var(--pk-border)";
|
|
332
|
+
el.style.marginTop = "4px";
|
|
333
|
+
el.style.paddingTop = "4px";
|
|
334
|
+
return el;
|
|
335
|
+
};
|
|
336
|
+
if (total) {
|
|
337
|
+
const sum = ruled(row(total));
|
|
338
|
+
sum.style.fontWeight = "var(--pk-weight-strong)";
|
|
339
|
+
box.append(sum);
|
|
179
340
|
}
|
|
341
|
+
(references ?? []).forEach((line, i) => box.append(i === 0 ? ruled(row(line)) : row(line)));
|
|
180
342
|
return box;
|
|
181
343
|
};
|
|
182
344
|
}
|
|
183
345
|
|
|
184
346
|
// src/chart-decorate.js
|
|
347
|
+
var TOOLTIP_LINE = 1.5;
|
|
348
|
+
var TOOLTIP_PADDING = 24;
|
|
349
|
+
var TOOLTIP_OTHER_LINES = 3;
|
|
185
350
|
function decorate(option, style, height = 480, doc = void 0, width = 800, extra = {}) {
|
|
186
|
-
|
|
351
|
+
const { tooltip = {}, parseColor, ...rest } = extra;
|
|
352
|
+
const series = (option.series || []).map((s, i) => ({ type: s.type, stack: s.stack, additive: tooltip.values ? valueAddsUp(tooltip.values[i]) : void 0 }));
|
|
353
|
+
const hover = tooltip.hover;
|
|
354
|
+
const line = Math.round((typeof option.textStyle?.fontSize === "number" ? option.textStyle.fontSize : DEFAULT_THEME.textSize) * TOOLTIP_LINE);
|
|
355
|
+
const maxLines = Math.max(2, Math.floor((height - TOOLTIP_PADDING) / line) - TOOLTIP_OTHER_LINES);
|
|
356
|
+
const seriesTotals = (option.series || []).map((s) => {
|
|
357
|
+
const values = (Array.isArray(s.data) ? s.data : []).filter((v) => typeof v === "number");
|
|
358
|
+
return values.some((v) => v < 0) ? NaN : values.reduce((a, b) => a + b, 0);
|
|
359
|
+
});
|
|
360
|
+
const reference = style.getPropertyValue("--pk-chart-reference").trim() || style.getPropertyValue("--pk-muted").trim() || null;
|
|
361
|
+
const references = tooltip.lines?.length ? tooltipReferences(tooltip.lines, (option.series || []).map((s) => String(s.name ?? "")), reference) : [];
|
|
362
|
+
const options = { series, share: Boolean(tooltip.share), seriesTotals, mode: tooltip.mode, totalLabel: tooltip.totalLabel, moreLabel: tooltip.moreLabel, moreInTotalLabel: tooltip.moreInTotalLabel, maxLines, references, hoverOf: () => hover?.current ?? null };
|
|
363
|
+
const readColor = doc && parseColor ? screenColor(doc, parseColor) : void 0;
|
|
364
|
+
const drawn = decorateOption(option, style, { height, width, ...rest, readColor, tooltipFormatter: doc ? (context) => tooltipFormatter(doc, { ...context, ...options }) : void 0 });
|
|
365
|
+
return doc ? { ...drawn, tooltip: { ...drawn.tooltip, confine: true } } : drawn;
|
|
366
|
+
}
|
|
367
|
+
function drawOption(instance, option, style, doc, extra, hostOptions) {
|
|
368
|
+
let own = null;
|
|
369
|
+
const marked = (pixelOf) => {
|
|
370
|
+
const drawn = decorate(option, style, instance.getHeight(), doc, instance.getWidth(), { ...extra, pixelOf });
|
|
371
|
+
own ??= drawn;
|
|
372
|
+
const { axisEvery, ...rest } = drawn;
|
|
373
|
+
void axisEvery;
|
|
374
|
+
return hostOptions ? mergeChartOptions(rest, hostOptions) : rest;
|
|
375
|
+
};
|
|
376
|
+
const first = marked(void 0);
|
|
377
|
+
instance.setOption(first, { notMerge: true });
|
|
378
|
+
const lying = !Array.isArray(first.yAxis) && first.yAxis?.type === "value";
|
|
379
|
+
if (lying && (first.series ?? []).some((s) => s.markLine)) {
|
|
380
|
+
instance.setOption({ series: marked((value) => instance.convertToPixel({ yAxisIndex: 0 }, value)).series });
|
|
381
|
+
}
|
|
382
|
+
return own;
|
|
383
|
+
}
|
|
384
|
+
function screenColor(doc, parse) {
|
|
385
|
+
let ctx;
|
|
386
|
+
return (text) => {
|
|
387
|
+
if (parse(text.trim())) {
|
|
388
|
+
return text;
|
|
389
|
+
}
|
|
390
|
+
if (typeof CSS === "undefined" || !CSS.supports("color", text)) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
if (ctx === void 0) {
|
|
394
|
+
const canvas = doc.createElement("canvas");
|
|
395
|
+
canvas.width = 1;
|
|
396
|
+
canvas.height = 1;
|
|
397
|
+
ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
398
|
+
}
|
|
399
|
+
if (!ctx) {
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
ctx.fillStyle = "transparent";
|
|
403
|
+
const sentinel = String(ctx.fillStyle);
|
|
404
|
+
ctx.fillStyle = text;
|
|
405
|
+
if (String(ctx.fillStyle) === sentinel) {
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
409
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
410
|
+
return `#${[...ctx.getImageData(0, 0, 1, 1).data.slice(0, 3)].map((n) => n.toString(16).padStart(2, "0")).join("")}`;
|
|
411
|
+
};
|
|
187
412
|
}
|
|
188
|
-
var LENGTH_TOKENS = Object.freeze(["--pk-chart-title-size", "--pk-chart-text-size", "--pk-radius-chart"]);
|
|
413
|
+
var LENGTH_TOKENS = Object.freeze(["--pk-chart-title-size", "--pk-chart-text-size", "--pk-radius-chart", "--pk-target", "--pk-target-touch"]);
|
|
189
414
|
function tokenLengths(root, names = LENGTH_TOKENS) {
|
|
190
415
|
const view = root.ownerDocument.defaultView;
|
|
191
416
|
const style = view?.getComputedStyle(root);
|
|
@@ -216,14 +441,180 @@ function chartStyle(root) {
|
|
|
216
441
|
return { getPropertyValue: (name) => lengths[name] ?? style.getPropertyValue(name) };
|
|
217
442
|
}
|
|
218
443
|
|
|
444
|
+
// src/chart-legend.js
|
|
445
|
+
import { autoChartType } from "pivotkit-core";
|
|
446
|
+
var RELAYOUT_WAIT = 250;
|
|
447
|
+
function keptWindow(kept, names) {
|
|
448
|
+
if (!kept || kept.names.length !== names.length || kept.names.some((n, i) => n !== names[i])) {
|
|
449
|
+
return void 0;
|
|
450
|
+
}
|
|
451
|
+
return { start: kept.start, end: kept.end };
|
|
452
|
+
}
|
|
453
|
+
function followChart(instance, { onLegend, onZoom }) {
|
|
454
|
+
instance.on("legendselectchanged", (e) => onLegend({ name: e.name, shown: Boolean(e.selected?.[e.name]) }));
|
|
455
|
+
instance.on("datazoom", () => {
|
|
456
|
+
const z = instance.getOption().dataZoom?.[0];
|
|
457
|
+
if (z && typeof z.startValue === "number" && typeof z.endValue === "number") {
|
|
458
|
+
onZoom(z.startValue, z.endValue);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
function chartKeeper(instance, { categories, onLegend, redraw, onWindow }) {
|
|
463
|
+
let kept = null;
|
|
464
|
+
let span = -1;
|
|
465
|
+
let control = null;
|
|
466
|
+
const move = (start, end) => instance.dispatchAction({ type: "dataZoom", dataZoomIndex: 0, startValue: start, endValue: end });
|
|
467
|
+
let wait;
|
|
468
|
+
followChart(instance, {
|
|
469
|
+
onLegend,
|
|
470
|
+
onZoom: (start, end) => {
|
|
471
|
+
const names = categories();
|
|
472
|
+
if (!names) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
kept = { names, start, end };
|
|
476
|
+
if (control && (control.start !== start || control.end !== end)) {
|
|
477
|
+
control = { ...control, start, end };
|
|
478
|
+
onWindow(control);
|
|
479
|
+
}
|
|
480
|
+
if (end - start !== span) {
|
|
481
|
+
clearTimeout(wait);
|
|
482
|
+
wait = setTimeout(redraw, RELAYOUT_WAIT);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
return {
|
|
487
|
+
/**
|
|
488
|
+
* decorateOption's zoom settings: the view's chart.zoom, the window kept, the latest categories
|
|
489
|
+
* first over dates (a date on Rows), a finger's slider on a touch screen
|
|
490
|
+
* @param {import("pivotkit-core").PivotResult} result
|
|
491
|
+
* @param {readonly string[]} names
|
|
492
|
+
* @param {Document} doc
|
|
493
|
+
*/
|
|
494
|
+
zoomOf: (result, names, doc) => ({
|
|
495
|
+
zoom: result.view.chart.zoom,
|
|
496
|
+
zoomAt: keptWindow(kept, names),
|
|
497
|
+
timeline: autoChartType(result.view, result.encoded) === "line",
|
|
498
|
+
touch: Boolean(doc.defaultView?.matchMedia?.("(pointer: coarse)").matches)
|
|
499
|
+
}),
|
|
500
|
+
/**
|
|
501
|
+
* The slider drawn: its window's size, to tell a move from a new size, and its keyboard control.
|
|
502
|
+
* @param {any[] | undefined} dataZoom decorateOption's
|
|
503
|
+
*/
|
|
504
|
+
drawn: (dataZoom) => {
|
|
505
|
+
const z = dataZoom?.[0];
|
|
506
|
+
span = z ? z.endValue - z.startValue : -1;
|
|
507
|
+
const beside = z?.orient === "vertical";
|
|
508
|
+
const next = z ? { start: z.startValue, end: z.endValue, count: categories()?.length ?? z.endValue + 1, beside, offset: beside ? z.right : z.bottom, size: beside ? z.width : z.height, move } : null;
|
|
509
|
+
const same = next && control && ["start", "end", "count", "beside", "offset", "size"].every((k) => next[
|
|
510
|
+
/** @type {keyof ZoomControl} */
|
|
511
|
+
k
|
|
512
|
+
] === control?.[
|
|
513
|
+
/** @type {keyof ZoomControl} */
|
|
514
|
+
k
|
|
515
|
+
]);
|
|
516
|
+
if (!same && (next || control)) {
|
|
517
|
+
control = next;
|
|
518
|
+
onWindow(control);
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
dispose: () => clearTimeout(wait)
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function shownOf(s, option, hidden, slices) {
|
|
525
|
+
const shares = (option.series ?? []).some((x) => Array.isArray(x.data) && x.data.some((d) => d !== null && typeof d === "object" && typeof d.raw === "number"));
|
|
526
|
+
return { series: shownOnly(s, hidden ?? [], slices), shares };
|
|
527
|
+
}
|
|
528
|
+
function shownOnly(s, hidden, slices) {
|
|
529
|
+
const out = new Set(hidden);
|
|
530
|
+
if (!out.size) {
|
|
531
|
+
return s;
|
|
532
|
+
}
|
|
533
|
+
if (!slices) {
|
|
534
|
+
return { ...s, series: s.series.filter((x) => !out.has(x.name)) };
|
|
535
|
+
}
|
|
536
|
+
const keep = s.categories.map((name, i) => out.has(name) ? -1 : i).filter((i) => i >= 0);
|
|
537
|
+
return {
|
|
538
|
+
...s,
|
|
539
|
+
categories: keep.map((i) => s.categories[i]),
|
|
540
|
+
categoryCount: (s.categoryCount ?? s.categories.length) - (s.categories.length - keep.length),
|
|
541
|
+
series: s.series.map((x) => ({ ...x, data: keep.map((i) => x.data[i]) }))
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
var FORWARD = /* @__PURE__ */ new Set(["ArrowRight", "ArrowDown"]);
|
|
545
|
+
var BACK = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowUp"]);
|
|
546
|
+
function nextWindow({ start, end }, count, key, shift) {
|
|
547
|
+
const span = end - start;
|
|
548
|
+
const last = count - 1;
|
|
549
|
+
let next = null;
|
|
550
|
+
if (shift && FORWARD.has(key)) {
|
|
551
|
+
next = { start, end: Math.min(last, end + 1) };
|
|
552
|
+
} else if (shift && BACK.has(key)) {
|
|
553
|
+
next = { start, end: Math.max(start + 1, end - 1) };
|
|
554
|
+
} else {
|
|
555
|
+
const by = FORWARD.has(key) ? 1 : BACK.has(key) ? -1 : key === "PageDown" ? span + 1 : key === "PageUp" ? -(span + 1) : key === "Home" ? -count : key === "End" ? count : 0;
|
|
556
|
+
if (by) {
|
|
557
|
+
const from = Math.min(Math.max(0, start + by), last - span);
|
|
558
|
+
next = { start: from, end: from + span };
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return next && (next.start !== start || next.end !== end) ? next : null;
|
|
562
|
+
}
|
|
563
|
+
function zoomKeyProps({ start, end, count, beside, offset, size, move }, labels, fill, locale) {
|
|
564
|
+
const n = (x) => x.toLocaleString(locale);
|
|
565
|
+
return {
|
|
566
|
+
// its place, through the CSSOM, which a strict Content-Security-Policy allows
|
|
567
|
+
// the pair of the other orientation is cleared: the same element may have been the other one
|
|
568
|
+
ref: (el) => {
|
|
569
|
+
const set = (props) => Object.entries(props).forEach(([k, v]) => el?.style.setProperty(k, v));
|
|
570
|
+
set({ position: "absolute", "pointer-events": "none" });
|
|
571
|
+
set(beside ? { top: "0", bottom: "0", right: `${offset}px`, width: `${size}px`, left: "auto", height: "auto" } : { left: "0", right: "0", bottom: `${offset}px`, height: `${size}px`, top: "auto", width: "auto" });
|
|
572
|
+
},
|
|
573
|
+
role: "slider",
|
|
574
|
+
tabIndex: 0,
|
|
575
|
+
className: "pk-zoom-keys",
|
|
576
|
+
"aria-label": labels.chartZoom,
|
|
577
|
+
"aria-orientation": (
|
|
578
|
+
/** @type {"vertical" | "horizontal"} */
|
|
579
|
+
beside ? "vertical" : "horizontal"
|
|
580
|
+
),
|
|
581
|
+
"aria-valuemin": 1,
|
|
582
|
+
"aria-valuemax": count - (end - start),
|
|
583
|
+
"aria-valuenow": start + 1,
|
|
584
|
+
"aria-valuetext": fill(labels.chartZoomWindow, { from: n(start + 1), to: n(end + 1), count: n(count) }),
|
|
585
|
+
"data-testid": "chart-zoom-keys",
|
|
586
|
+
onKeyDown: (e) => {
|
|
587
|
+
if (e.altKey || e.ctrlKey || e.metaKey) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
const next = nextWindow({ start, end }, count, e.key, e.shiftKey);
|
|
591
|
+
if (next || FORWARD.has(e.key) || BACK.has(e.key) || ["Home", "End", "PageUp", "PageDown"].includes(e.key)) {
|
|
592
|
+
e.preventDefault();
|
|
593
|
+
}
|
|
594
|
+
if (next) {
|
|
595
|
+
move(next.start, next.end);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
|
|
219
601
|
// src/echarts.js
|
|
220
|
-
register([BarChart, LineChart, PieChart, HeatmapChart, GridComponent, TooltipComponent, LegendComponent, TitleComponent, VisualMapComponent, CanvasRenderer]);
|
|
602
|
+
register([BarChart, LineChart, PieChart, HeatmapChart, GridComponent, TooltipComponent, LegendComponent, TitleComponent, VisualMapComponent, DataZoomSliderComponent, MarkLineComponent, CanvasRenderer]);
|
|
221
603
|
export {
|
|
222
604
|
LENGTH_TOKENS,
|
|
605
|
+
chartKeeper,
|
|
606
|
+
chartLines,
|
|
223
607
|
chartStyle,
|
|
224
608
|
cleanChartOptions,
|
|
609
|
+
color,
|
|
610
|
+
colorMapFor,
|
|
225
611
|
decorate,
|
|
612
|
+
drawOption,
|
|
226
613
|
init,
|
|
227
614
|
mergeChartOptions,
|
|
228
|
-
|
|
615
|
+
screenColor,
|
|
616
|
+
shownOf,
|
|
617
|
+
toEChartsOption,
|
|
618
|
+
tokenLengths,
|
|
619
|
+
zoomKeyProps
|
|
229
620
|
};
|
package/dist/import-ui.js
CHANGED
|
@@ -10,17 +10,17 @@ import {
|
|
|
10
10
|
useFormName,
|
|
11
11
|
useModal,
|
|
12
12
|
useTopLayer
|
|
13
|
-
} from "./chunks/chunk-
|
|
13
|
+
} from "./chunks/chunk-JAOOFDNR.js";
|
|
14
14
|
import {
|
|
15
15
|
errorText,
|
|
16
16
|
importLabels,
|
|
17
17
|
noteText
|
|
18
|
-
} from "./chunks/chunk-
|
|
18
|
+
} from "./chunks/chunk-BHHIZHUE.js";
|
|
19
19
|
import {
|
|
20
20
|
fill,
|
|
21
21
|
messageOf,
|
|
22
22
|
plural
|
|
23
|
-
} from "./chunks/chunk-
|
|
23
|
+
} from "./chunks/chunk-SJCG4I57.js";
|
|
24
24
|
|
|
25
25
|
// src/import-host.jsx
|
|
26
26
|
import React2 from "react";
|