@aseity/igrid-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 +17 -0
- package/LICENSE +21 -0
- package/README.md +34 -2
- package/dist/cells.d.ts +7 -0
- package/dist/cells.js +98 -0
- package/dist/charts.d.ts +14 -0
- package/dist/charts.js +51 -0
- package/dist/column-resize.d.ts +15 -0
- package/dist/column-resize.js +75 -0
- package/dist/echarts-adapter.d.ts +2 -0
- package/dist/echarts-adapter.js +128 -0
- package/dist/formula-value.d.ts +4 -0
- package/dist/formula-value.js +21 -0
- package/dist/grid.d.ts +6 -0
- package/dist/grid.js +192 -0
- package/dist/images.d.ts +13 -0
- package/dist/images.js +56 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +75 -0
- package/dist/paint-grid.d.ts +19 -0
- package/dist/paint-grid.js +75 -0
- package/dist/presentation.d.ts +39 -0
- package/dist/presentation.js +23 -0
- package/dist/selection.d.ts +47 -0
- package/dist/selection.js +148 -0
- package/dist/style.css +150 -0
- package/dist/text.d.ts +2 -0
- package/dist/text.js +202 -0
- package/package.json +33 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @aseity/igrid-react
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Initial release of the read-only XLSX engine and React viewer.
|
|
8
|
+
|
|
9
|
+
Includes Rust/WASM workbook loading, typed viewport data, Canvas2D rendering,
|
|
10
|
+
worksheet navigation, frozen panes, selection and copying, supported styles,
|
|
11
|
+
images and charts, and rendering-loss reporting. Formula cells retain cached
|
|
12
|
+
values; supported formulas with missing caches are calculated in Rust.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @aseity/igrid-engine@0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 iGrid contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# React viewer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
```sh
|
|
4
|
+
npm install @aseity/igrid-react react@^19 react-dom@^19
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { IGrid } from "@aseity/igrid-react";
|
|
9
|
+
|
|
10
|
+
export function Viewer({ bytes }: { bytes: Uint8Array }) {
|
|
11
|
+
return <div style={{ height: 600 }}><IGrid bytes={bytes} /></div>;
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Use a bundler with CSS and WASM asset support, such as Vite. Styles are imported
|
|
16
|
+
by the component; `@aseity/igrid-react/styles.css` is also exported for explicit
|
|
17
|
+
stylesheet imports. The engine is installed as a dependency. Supply a new
|
|
18
|
+
`Uint8Array` when opening another file. Licensed under MIT; the source repository
|
|
19
|
+
is currently private.
|
|
20
|
+
|
|
21
|
+
The package contains compiled JavaScript, declarations and styles. `labels` overrides control and accessibility text. `loadingFallback` replaces the opening state. `renderError(error, kind)` replaces caught workbook, chart and image errors; `kind` is `workbook`, `chart` or `image`. The demo's Host messages checkbox demonstrates these options. A host error boundary should handle render failures separately.
|
|
22
|
+
|
|
23
|
+
`<IGrid bytes={xlsxBytes} />` opens the saved active visible worksheet and uses each sheet's saved zoom. Hidden and veryHidden sheets stay out of the tab bar. Frozen rows and columns remain fixed while the rest of the sheet scrolls.
|
|
24
|
+
|
|
25
|
+
Pass `zoom` as a ratio (for example `1.5`) to override saved zoom. `onZoomChange` receives changes from the viewer's percentage control; a controlled host should update `zoom` in response. Without `zoom`, the viewer retains each sheet's chosen zoom while switching tabs. The supported range is 10–400%.
|
|
26
|
+
|
|
27
|
+
The light interface uses CSS custom properties on `.igrid`: `--igrid-background`, `--igrid-text`, `--igrid-header-background`, `--igrid-header-text`, `--igrid-grid-line`, `--igrid-border`, `--igrid-active-background`, and `--igrid-active-border`. Hosts can override these with a more specific `.host .igrid` selector. Workbook cell styles and chart colors still come from the file.
|
|
28
|
+
|
|
29
|
+
Cell text follows the workbook's vertical alignment using font bounds measured from a fixed sample. Top alignment keeps two CSS pixels above the font box. Bottom alignment leaves one CSS pixel below it, matching the cell's clipping inset. Centered text uses the font block's midpoint. Text with the same font and size shares a stable baseline, including when only some values contain descenders such as `g`. Available system fonts can still differ from Excel's web fonts.
|
|
30
|
+
|
|
31
|
+
A single selected cell, including a merged cell, has an outline without a fill. Multi-cell, row and column selections use a 10% black overlay inside the outline, darkening the cells without whitening their text.
|
|
32
|
+
|
|
33
|
+
The read-only formula bar uses a decorative stroked SVG for its function marker, keeping its shape independent of the available text fonts.
|
|
34
|
+
|
|
35
|
+
Worksheets parse on first access. The engine's `workbook.losses` getter contains losses from sheets accessed so far, including required formula/chart dependencies. Read it again after opening another sheet; the React `onLosses` callback updates on sheet changes. A malformed deferred worksheet raises an error when accessed and the demo displays it explicitly.
|
package/dist/cells.d.ts
ADDED
package/dist/cells.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { drawText } from "./text.js";
|
|
2
|
+
export function drawCells(context, list, view, gridColor = "#dedede") {
|
|
3
|
+
context.strokeStyle = gridColor;
|
|
4
|
+
context.lineWidth = 1;
|
|
5
|
+
context.beginPath();
|
|
6
|
+
for (let i = 0; i < list.columns.length; i += 3) {
|
|
7
|
+
const x = list.columns[i + 1] + list.columns[i + 2] + 0.5;
|
|
8
|
+
context.moveTo(x, view.y);
|
|
9
|
+
context.lineTo(x, view.y + view.height);
|
|
10
|
+
}
|
|
11
|
+
for (let i = 0; i < list.rows.length; i += 3) {
|
|
12
|
+
const y = list.rows[i + 1] + list.rows[i + 2] + 0.5;
|
|
13
|
+
context.moveTo(view.x, y);
|
|
14
|
+
context.lineTo(view.x + view.width, y);
|
|
15
|
+
}
|
|
16
|
+
if (list.show_grid_lines)
|
|
17
|
+
context.stroke();
|
|
18
|
+
for (let i = 0; i < list.merges.length; i += 4) {
|
|
19
|
+
const [x, y, width, height] = list.merges.subarray(i, i + 4);
|
|
20
|
+
context.fillStyle = "white";
|
|
21
|
+
context.fillRect(x + 0.5, y + 0.5, width, height);
|
|
22
|
+
if (list.show_grid_lines)
|
|
23
|
+
context.strokeRect(x + 0.5, y + 0.5, width, height);
|
|
24
|
+
}
|
|
25
|
+
for (let i = 0; i < list.text_indices.length; i++) {
|
|
26
|
+
const fill = list.cell_styles[i * 5 + 3];
|
|
27
|
+
if (!fill)
|
|
28
|
+
continue;
|
|
29
|
+
const [x, y, width, height] = list.rectangles.subarray(i * 4, i * 4 + 4);
|
|
30
|
+
context.fillStyle = color(fill);
|
|
31
|
+
context.fillRect(x + 0.5, y + 0.5, width, height);
|
|
32
|
+
}
|
|
33
|
+
drawDataBars(context, list);
|
|
34
|
+
drawBorders(context, list.borders);
|
|
35
|
+
for (let i = 0; i < list.text_indices.length; i++) {
|
|
36
|
+
const [x, y, width] = list.rectangles.subarray(i * 4, i * 4 + 4);
|
|
37
|
+
drawText(context, list, i);
|
|
38
|
+
if (list.cell_styles[i * 5 + 4]) {
|
|
39
|
+
context.fillStyle = "#ff0000";
|
|
40
|
+
context.beginPath();
|
|
41
|
+
context.moveTo(x + width - 7, y + 1);
|
|
42
|
+
context.lineTo(x + width - 1, y + 1);
|
|
43
|
+
context.lineTo(x + width - 1, y + 7);
|
|
44
|
+
context.fill();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function drawDataBars(context, list) {
|
|
49
|
+
context.save();
|
|
50
|
+
for (let i = 0; i < list.data_bars.length; i += 7) {
|
|
51
|
+
const [index, start, end, axis, rgba, gradient, axisColor] = list.data_bars.subarray(i, i + 7);
|
|
52
|
+
const [x, y, width, height] = list.rectangles.subarray(index * 4, index * 4 + 4);
|
|
53
|
+
const left = x + 1;
|
|
54
|
+
const available = Math.max(0, width - 2);
|
|
55
|
+
const from = left + start * available;
|
|
56
|
+
const to = left + end * available;
|
|
57
|
+
context.fillStyle = color(rgba);
|
|
58
|
+
if (gradient && from !== to) {
|
|
59
|
+
const fill = context.createLinearGradient(from, 0, to, 0);
|
|
60
|
+
fill.addColorStop(0, color(rgba));
|
|
61
|
+
fill.addColorStop(1, "white");
|
|
62
|
+
context.fillStyle = fill;
|
|
63
|
+
}
|
|
64
|
+
context.fillRect(Math.min(from, to), y + 2, Math.abs(to - from), Math.max(0, height - 4));
|
|
65
|
+
if (axis >= 0) {
|
|
66
|
+
context.strokeStyle = color(axisColor);
|
|
67
|
+
context.lineWidth = 1;
|
|
68
|
+
context.setLineDash([1, 1]);
|
|
69
|
+
context.beginPath();
|
|
70
|
+
context.moveTo(left + axis * available, y + 1);
|
|
71
|
+
context.lineTo(left + axis * available, y + height - 1);
|
|
72
|
+
context.stroke();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
context.restore();
|
|
76
|
+
}
|
|
77
|
+
function color(value) {
|
|
78
|
+
return `#${value.toString(16).padStart(8, "0")}`;
|
|
79
|
+
}
|
|
80
|
+
function drawBorders(context, borders) {
|
|
81
|
+
context.save();
|
|
82
|
+
for (let i = 0; i < borders.length; i += 6) {
|
|
83
|
+
const [x1, y1, x2, y2, style, rgba] = borders.subarray(i, i + 6);
|
|
84
|
+
context.strokeStyle = color(rgba);
|
|
85
|
+
context.lineWidth =
|
|
86
|
+
style === 2 ? 2 : style === 3 ? 3 : style === 7 ? 0.5 : 1;
|
|
87
|
+
context.setLineDash(style === 4 ? [3, 2] : style === 5 || style === 7 ? [1, 1] : []);
|
|
88
|
+
for (const offset of style === 6 ? [-1, 1] : [0]) {
|
|
89
|
+
const dx = x1 === x2 ? offset : 0;
|
|
90
|
+
const dy = y1 === y2 ? offset : 0;
|
|
91
|
+
context.beginPath();
|
|
92
|
+
context.moveTo(x1 + dx + 0.5, y1 + dy + 0.5);
|
|
93
|
+
context.lineTo(x2 + dx + 0.5, y2 + dy + 0.5);
|
|
94
|
+
context.stroke();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
context.restore();
|
|
98
|
+
}
|
package/dist/charts.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Chart, Workbook } from "@aseity/igrid-engine";
|
|
2
|
+
export declare function Charts({ workbook, charts, view, headerWidth, headerHeight, pixelRatio, }: {
|
|
3
|
+
workbook: Workbook;
|
|
4
|
+
charts: Chart[];
|
|
5
|
+
view: {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
headerWidth: number;
|
|
12
|
+
headerHeight: number;
|
|
13
|
+
pixelRatio: number;
|
|
14
|
+
}): import("react/jsx-runtime").JSX.Element;
|
package/dist/charts.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { GridError, useGridPresentation } from "./presentation.js";
|
|
4
|
+
export function Charts({ workbook, charts, view, headerWidth, headerHeight, pixelRatio, }) {
|
|
5
|
+
const { labels } = useGridPresentation();
|
|
6
|
+
return (_jsx("div", { style: {
|
|
7
|
+
position: "absolute",
|
|
8
|
+
left: headerWidth,
|
|
9
|
+
top: headerHeight,
|
|
10
|
+
width: Math.max(0, view.width - headerWidth),
|
|
11
|
+
height: Math.max(0, view.height - headerHeight),
|
|
12
|
+
overflow: "hidden",
|
|
13
|
+
pointerEvents: "none",
|
|
14
|
+
}, children: charts.map((chart, index) => (_jsxs("div", { style: {
|
|
15
|
+
position: "absolute",
|
|
16
|
+
left: chart.rectangle.x - view.x,
|
|
17
|
+
top: chart.rectangle.y - view.y,
|
|
18
|
+
width: chart.rectangle.width,
|
|
19
|
+
height: chart.rectangle.height,
|
|
20
|
+
background: "white",
|
|
21
|
+
}, children: [chart.kind === "unsupported" ? (_jsx("div", { role: "img", "aria-label": labels.unsupportedChart, style: { height: "100%", display: "grid", placeItems: "center" }, children: labels.unsupportedChart })) : (_jsx(ChartCanvas, { workbook: workbook, chart: chart, pixelRatio: pixelRatio })), _jsx("div", { "aria-hidden": "true", style: {
|
|
22
|
+
position: "absolute",
|
|
23
|
+
inset: 0,
|
|
24
|
+
boxShadow: "inset 0 0 0 1px #d9d9d9",
|
|
25
|
+
} })] }, `${index}-${chart.kind}`))) }));
|
|
26
|
+
}
|
|
27
|
+
function ChartCanvas({ workbook, chart, pixelRatio, }) {
|
|
28
|
+
const { labels } = useGridPresentation();
|
|
29
|
+
const element = useRef(null);
|
|
30
|
+
const [error, setError] = useState("");
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
let cancelled = false;
|
|
33
|
+
let dispose;
|
|
34
|
+
import("./echarts-adapter.js")
|
|
35
|
+
.then(({ renderChart }) => {
|
|
36
|
+
if (!cancelled && element.current)
|
|
37
|
+
dispose = renderChart(element.current, chart, (value, format) => workbook.formatNumber(value, format), pixelRatio);
|
|
38
|
+
})
|
|
39
|
+
.catch((cause) => {
|
|
40
|
+
if (!cancelled)
|
|
41
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
cancelled = true;
|
|
45
|
+
dispose?.();
|
|
46
|
+
};
|
|
47
|
+
}, [workbook, chart, pixelRatio]);
|
|
48
|
+
if (error)
|
|
49
|
+
return _jsx(GridError, { error: error, kind: "chart" });
|
|
50
|
+
return (_jsx("div", { ref: element, role: "img", "aria-label": `${labels.chart} ${chart.series.map((series) => series.name).join(", ")}`, style: { width: "100%", height: "100%" } }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DrawList } from "@aseity/igrid-engine";
|
|
2
|
+
export declare function ColumnResize({ lists, panes, zoom, headerWidth, headerHeight, height, onResize, }: {
|
|
3
|
+
lists: DrawList[];
|
|
4
|
+
panes: {
|
|
5
|
+
top: number;
|
|
6
|
+
left: number;
|
|
7
|
+
x: number;
|
|
8
|
+
width: number;
|
|
9
|
+
}[];
|
|
10
|
+
zoom: number;
|
|
11
|
+
headerWidth: number;
|
|
12
|
+
headerHeight: number;
|
|
13
|
+
height: number;
|
|
14
|
+
onResize: (column: number, width: number) => void;
|
|
15
|
+
}): import("react/jsx-runtime").JSX.Element[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { columnName } from "./paint-grid.js";
|
|
4
|
+
import { useGridPresentation } from "./presentation.js";
|
|
5
|
+
export function ColumnResize({ lists, panes, zoom, headerWidth, headerHeight, height, onResize, }) {
|
|
6
|
+
const boundaries = [];
|
|
7
|
+
for (const [index, pane] of panes.entries()) {
|
|
8
|
+
if (pane.top !== 0)
|
|
9
|
+
continue;
|
|
10
|
+
const columns = lists[index].columns;
|
|
11
|
+
for (let i = 0; i < columns.length; i += 3) {
|
|
12
|
+
const [column, position, width] = columns.subarray(i, i + 3);
|
|
13
|
+
const edge = position + width - pane.x;
|
|
14
|
+
if (width <= 0 || edge <= 0 || edge > pane.width)
|
|
15
|
+
continue;
|
|
16
|
+
boundaries.push({
|
|
17
|
+
column,
|
|
18
|
+
width,
|
|
19
|
+
left: (headerWidth + pane.left + edge) * zoom,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return boundaries.map((boundary) => (_jsx(ResizeHandle, { boundary: boundary, zoom: zoom, headerHeight: headerHeight, height: height, onResize: onResize }, boundary.column)));
|
|
24
|
+
}
|
|
25
|
+
function ResizeHandle({ boundary, zoom, headerHeight, height, onResize, }) {
|
|
26
|
+
const { labels } = useGridPresentation();
|
|
27
|
+
const [drag, setDrag] = useState();
|
|
28
|
+
const widthAt = (clientX) => Math.max(8, boundary.width + (clientX - (drag?.start ?? clientX)) / zoom);
|
|
29
|
+
return (_jsx("button", { type: "button", "aria-label": `${labels.resizeColumn} ${columnName(boundary.column)}`, style: {
|
|
30
|
+
position: "absolute",
|
|
31
|
+
left: boundary.left - 4,
|
|
32
|
+
top: 0,
|
|
33
|
+
width: 8,
|
|
34
|
+
height: headerHeight * zoom,
|
|
35
|
+
padding: 0,
|
|
36
|
+
margin: 0,
|
|
37
|
+
border: 0,
|
|
38
|
+
borderRadius: 0,
|
|
39
|
+
background: "transparent",
|
|
40
|
+
cursor: "col-resize",
|
|
41
|
+
touchAction: "none",
|
|
42
|
+
zIndex: 2,
|
|
43
|
+
}, onPointerDown: (event) => {
|
|
44
|
+
if (event.button !== 0)
|
|
45
|
+
return;
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
48
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
49
|
+
setDrag({ start: event.clientX, width: boundary.width });
|
|
50
|
+
}, onPointerMove: (event) => {
|
|
51
|
+
if (drag)
|
|
52
|
+
setDrag({ ...drag, width: widthAt(event.clientX) });
|
|
53
|
+
}, onPointerUp: (event) => {
|
|
54
|
+
if (!drag)
|
|
55
|
+
return;
|
|
56
|
+
const width = widthAt(event.clientX);
|
|
57
|
+
setDrag(undefined);
|
|
58
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
59
|
+
onResize(boundary.column, width);
|
|
60
|
+
}, onLostPointerCapture: () => setDrag(undefined), onPointerCancel: () => setDrag(undefined), onKeyDown: (event) => {
|
|
61
|
+
if (event.key === "Escape")
|
|
62
|
+
setDrag(undefined);
|
|
63
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight")
|
|
64
|
+
return;
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
onResize(boundary.column, Math.max(8, boundary.width + (event.key === "ArrowLeft" ? -8 : 8)));
|
|
67
|
+
}, children: drag && (_jsx("span", { "aria-hidden": "true", style: {
|
|
68
|
+
position: "absolute",
|
|
69
|
+
top: 0,
|
|
70
|
+
left: 4 + (drag.width - boundary.width) * zoom,
|
|
71
|
+
height,
|
|
72
|
+
borderLeft: "1px dashed var(--igrid-active-border)",
|
|
73
|
+
pointerEvents: "none",
|
|
74
|
+
} })) }));
|
|
75
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { BarChart, LineChart, PieChart } from "echarts/charts";
|
|
2
|
+
import { GridComponent, LegendComponent } from "echarts/components";
|
|
3
|
+
import { init, use } from "echarts/core";
|
|
4
|
+
import { CanvasRenderer } from "echarts/renderers";
|
|
5
|
+
use([
|
|
6
|
+
BarChart,
|
|
7
|
+
LineChart,
|
|
8
|
+
PieChart,
|
|
9
|
+
GridComponent,
|
|
10
|
+
LegendComponent,
|
|
11
|
+
CanvasRenderer,
|
|
12
|
+
]);
|
|
13
|
+
export function renderChart(element, chart, formatNumber, pixelRatio) {
|
|
14
|
+
const instance = init(element, undefined, {
|
|
15
|
+
renderer: "canvas",
|
|
16
|
+
devicePixelRatio: pixelRatio,
|
|
17
|
+
});
|
|
18
|
+
instance.setOption(options(chart, formatNumber));
|
|
19
|
+
return () => instance.dispose();
|
|
20
|
+
}
|
|
21
|
+
function options(chart, formatNumber) {
|
|
22
|
+
const position = chart.legend;
|
|
23
|
+
const verticalLegend = position === "left" || position === "right";
|
|
24
|
+
const pie = chart.kind === "pie";
|
|
25
|
+
const horizontal = chart.kind === "bar";
|
|
26
|
+
const isHorizontal = (kind) => (kind === "category") !== horizontal;
|
|
27
|
+
const axis = (direction) => chart.axes
|
|
28
|
+
.filter((axis) => isHorizontal(axis.kind) === (direction === "x"))
|
|
29
|
+
.map((axis) => ({
|
|
30
|
+
type: axis.kind === "category" ? "category" : "value",
|
|
31
|
+
position: isHorizontal(axis.kind)
|
|
32
|
+
? axis.position === "top"
|
|
33
|
+
? "top"
|
|
34
|
+
: "bottom"
|
|
35
|
+
: axis.position === "right"
|
|
36
|
+
? "right"
|
|
37
|
+
: "left",
|
|
38
|
+
data: axis.kind === "category" ? chart.series[0]?.categories : undefined,
|
|
39
|
+
boundaryGap: axis.kind === "category" ? true : undefined,
|
|
40
|
+
splitNumber: 10,
|
|
41
|
+
axisLabel: {
|
|
42
|
+
color: "#595959",
|
|
43
|
+
fontSize: 12,
|
|
44
|
+
formatter: axis.kind === "value"
|
|
45
|
+
? (value) => formatNumber(value, axis.display_num_fmt)
|
|
46
|
+
: undefined,
|
|
47
|
+
},
|
|
48
|
+
axisTick: { show: false },
|
|
49
|
+
axisLine: {
|
|
50
|
+
show: true,
|
|
51
|
+
onZero: false,
|
|
52
|
+
lineStyle: { color: "#000000", width: 1 },
|
|
53
|
+
},
|
|
54
|
+
splitLine: {
|
|
55
|
+
show: axis.gridlines,
|
|
56
|
+
lineStyle: {
|
|
57
|
+
color: axis.line_color,
|
|
58
|
+
width: axis.line_width,
|
|
59
|
+
type: axis.line_style === "dash"
|
|
60
|
+
? "dashed"
|
|
61
|
+
: axis.line_style === "dot"
|
|
62
|
+
? "dotted"
|
|
63
|
+
: "solid",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}));
|
|
67
|
+
return {
|
|
68
|
+
animation: false,
|
|
69
|
+
backgroundColor: "#ffffff",
|
|
70
|
+
textStyle: { fontFamily: "Calibri, Arial, sans-serif", color: "#595959" },
|
|
71
|
+
legend: {
|
|
72
|
+
show: position !== "",
|
|
73
|
+
selectedMode: false,
|
|
74
|
+
orient: verticalLegend ? "vertical" : "horizontal",
|
|
75
|
+
data: pie
|
|
76
|
+
? chart.series[0]?.categories
|
|
77
|
+
: chart.series.map((series) => series.name),
|
|
78
|
+
[position || "right"]: 6,
|
|
79
|
+
...(position === "top" ? { top: 6 } : {}),
|
|
80
|
+
...(verticalLegend ? { top: "middle" } : { left: "center" }),
|
|
81
|
+
textStyle: { color: "#595959", fontSize: 12 },
|
|
82
|
+
itemWidth: 24,
|
|
83
|
+
itemHeight: chart.kind === "line" ? 3 : 8,
|
|
84
|
+
icon: "rect",
|
|
85
|
+
},
|
|
86
|
+
grid: {
|
|
87
|
+
left: position === "left" ? Math.min(chart.rectangle.width * 0.3, 120) : 12,
|
|
88
|
+
right: position === "right" ? Math.min(chart.rectangle.width * 0.3, 120) : 18,
|
|
89
|
+
top: 12 + (position === "top" ? 25 : 0),
|
|
90
|
+
bottom: position === "bottom" ? 36 : 12,
|
|
91
|
+
outerBoundsMode: "same",
|
|
92
|
+
outerBoundsContain: "axisLabel",
|
|
93
|
+
outerBoundsClampWidth: 0,
|
|
94
|
+
outerBoundsClampHeight: 0,
|
|
95
|
+
},
|
|
96
|
+
xAxis: pie ? undefined : axis("x"),
|
|
97
|
+
yAxis: pie ? undefined : axis("y"),
|
|
98
|
+
series: chart.series.map((series) => pie
|
|
99
|
+
? {
|
|
100
|
+
name: series.name,
|
|
101
|
+
type: "pie",
|
|
102
|
+
radius: "70%",
|
|
103
|
+
center: [position === "right" ? "42%" : "50%", "50%"],
|
|
104
|
+
clockwise: true,
|
|
105
|
+
startAngle: 90,
|
|
106
|
+
label: { show: false },
|
|
107
|
+
silent: true,
|
|
108
|
+
data: series.values.map((value, index) => ({
|
|
109
|
+
name: series.categories[index],
|
|
110
|
+
value,
|
|
111
|
+
itemStyle: { color: chart.palette[index % chart.palette.length] },
|
|
112
|
+
})),
|
|
113
|
+
}
|
|
114
|
+
: {
|
|
115
|
+
name: series.name,
|
|
116
|
+
type: chart.kind === "line" ? "line" : "bar",
|
|
117
|
+
silent: true,
|
|
118
|
+
emphasis: { disabled: true },
|
|
119
|
+
showSymbol: false,
|
|
120
|
+
symbol: "none",
|
|
121
|
+
lineStyle: { color: series.color, width: 3, type: "solid" },
|
|
122
|
+
itemStyle: { color: series.color },
|
|
123
|
+
data: series.values.map((value, index) => horizontal
|
|
124
|
+
? [value, series.categories[index]]
|
|
125
|
+
: [series.categories[index], value]),
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
const tokens = /(?<string>"(?:[^"]|"")*")|(?<reference>(?:'(?:[^']|'')*'|[\p{L}_][\p{L}\p{N}_.]*)!)|(?<function>[\p{L}_][\p{L}\p{N}_.]*(?=\s*\())|(?<cell>\$?[A-Za-z]{1,3}\$?\d+\b)|(?<number>(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?%?)|(?<name>[\p{L}_][\p{L}\p{N}_.]*)/gu;
|
|
4
|
+
export function FormulaValue({ value, label, }) {
|
|
5
|
+
const highlight = useRef(null);
|
|
6
|
+
const parts = [];
|
|
7
|
+
let start = 0;
|
|
8
|
+
if (value.startsWith("=")) {
|
|
9
|
+
for (const match of value.matchAll(tokens)) {
|
|
10
|
+
parts.push(value.slice(start, match.index));
|
|
11
|
+
const kind = Object.keys(match.groups ?? {}).find((key) => match.groups?.[key] !== undefined);
|
|
12
|
+
parts.push(_jsx("span", { className: `igrid-formula-${kind}`, children: match[0] }, match.index));
|
|
13
|
+
start = match.index + match[0].length;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
parts.push(value.slice(start));
|
|
17
|
+
return (_jsxs("div", { className: "igrid-formula-value", children: [_jsx("div", { className: "igrid-formula-highlight", "aria-hidden": "true", children: _jsx("span", { ref: highlight, children: parts }) }), _jsx("input", { "aria-label": label, readOnly: true, value: value, onScroll: (event) => {
|
|
18
|
+
if (highlight.current)
|
|
19
|
+
highlight.current.style.transform = `translateX(${-event.currentTarget.scrollLeft}px)`;
|
|
20
|
+
} })] }, value));
|
|
21
|
+
}
|