@rowsncolumns/charts 27.0.34 → 28.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/dist/cjs/atoms/pivot-chart.atom.d.ts +14 -0
- package/dist/cjs/atoms/pivot-chart.atom.d.ts.map +1 -0
- package/dist/cjs/atoms/pivot-chart.atom.js +9 -0
- package/dist/cjs/basic-chart/basic-chart.d.ts +1 -1
- package/dist/cjs/basic-chart/basic-chart.d.ts.map +1 -1
- package/dist/cjs/basic-chart/basic-chart.js +863 -371
- package/dist/cjs/components/dialogs/pivot-chart-dialog.d.ts +39 -0
- package/dist/cjs/components/dialogs/pivot-chart-dialog.d.ts.map +1 -0
- package/dist/cjs/components/dialogs/pivot-chart-dialog.js +100 -0
- package/dist/cjs/components/editors/chart-editor.d.ts +13 -1
- package/dist/cjs/components/editors/chart-editor.d.ts.map +1 -1
- package/dist/cjs/components/editors/chart-editor.js +225 -59
- package/dist/cjs/config.d.ts.map +1 -1
- package/dist/cjs/config.js +149 -12
- package/dist/cjs/hooks/use-charts.d.ts +21 -6
- package/dist/cjs/hooks/use-charts.d.ts.map +1 -1
- package/dist/cjs/hooks/use-charts.js +13 -1
- package/dist/cjs/hooks/use-on-create-chart.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-create-chart.js +7 -1
- package/dist/cjs/hooks/use-on-move-chart-to-sheet.d.ts +12 -0
- package/dist/cjs/hooks/use-on-move-chart-to-sheet.d.ts.map +1 -0
- package/dist/cjs/hooks/use-on-move-chart-to-sheet.js +26 -0
- package/dist/cjs/hooks/use-on-move-chart.d.ts +1 -1
- package/dist/cjs/hooks/use-on-move-chart.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-move-chart.js +2 -2
- package/dist/cjs/hooks/use-on-resize-chart.d.ts +1 -1
- package/dist/cjs/hooks/use-on-resize-chart.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-resize-chart.js +2 -2
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +34 -1
- package/dist/cjs/interface/create-chart.d.ts.map +1 -1
- package/dist/cjs/interface/create-chart.js +33 -42
- package/dist/cjs/interface/delete-chart.d.ts.map +1 -1
- package/dist/cjs/interface/delete-chart.js +4 -0
- package/dist/cjs/interface/move-chart-to-sheet.d.ts +13 -0
- package/dist/cjs/interface/move-chart-to-sheet.d.ts.map +1 -0
- package/dist/cjs/interface/move-chart-to-sheet.js +136 -0
- package/dist/cjs/interface/move-chart.d.ts +2 -2
- package/dist/cjs/interface/move-chart.d.ts.map +1 -1
- package/dist/cjs/interface/move-chart.js +7 -1
- package/dist/cjs/interface/resize-chart.d.ts +2 -2
- package/dist/cjs/interface/resize-chart.d.ts.map +1 -1
- package/dist/cjs/interface/resize-chart.js +7 -1
- package/dist/cjs/interface/update-chart.d.ts.map +1 -1
- package/dist/cjs/interface/update-chart.js +4 -0
- package/dist/cjs/plotly/basic-chart/basic-chart.d.ts +1 -1
- package/dist/cjs/plotly/basic-chart/basic-chart.d.ts.map +1 -1
- package/dist/cjs/plotly/basic-chart/basic-chart.js +970 -585
- package/dist/cjs/plotly/basic-chart/helpers.d.ts.map +1 -1
- package/dist/cjs/plotly/basic-chart/helpers.js +3 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/cjs/types.d.ts +7 -0
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/utils/axis-number-format.d.ts +69 -0
- package/dist/cjs/utils/axis-number-format.d.ts.map +1 -0
- package/dist/cjs/utils/axis-number-format.js +217 -0
- package/dist/cjs/utils/category-levels.d.ts +27 -0
- package/dist/cjs/utils/category-levels.d.ts.map +1 -0
- package/dist/cjs/utils/category-levels.js +80 -0
- package/dist/cjs/utils/chart-image.d.ts +8 -0
- package/dist/cjs/utils/chart-image.d.ts.map +1 -0
- package/dist/cjs/utils/chart-image.js +28 -0
- package/dist/cjs/utils/chart-orientation.d.ts +67 -0
- package/dist/cjs/utils/chart-orientation.d.ts.map +1 -0
- package/dist/cjs/utils/chart-orientation.js +265 -0
- package/dist/cjs/utils/chart-spec-utils.d.ts +3 -0
- package/dist/cjs/utils/chart-spec-utils.d.ts.map +1 -1
- package/dist/cjs/utils/chart-spec-utils.js +12 -4
- package/dist/cjs/utils/chart-styles.d.ts +75 -0
- package/dist/cjs/utils/chart-styles.d.ts.map +1 -0
- package/dist/cjs/utils/chart-styles.js +283 -0
- package/dist/cjs/utils/empty-cells.d.ts +30 -0
- package/dist/cjs/utils/empty-cells.d.ts.map +1 -0
- package/dist/cjs/utils/empty-cells.js +91 -0
- package/dist/cjs/utils/overrides.d.ts +6 -1
- package/dist/cjs/utils/overrides.d.ts.map +1 -1
- package/dist/cjs/utils/overrides.js +19 -7
- package/dist/cjs/utils/pie-explosion.d.ts +30 -0
- package/dist/cjs/utils/pie-explosion.d.ts.map +1 -0
- package/dist/cjs/utils/pie-explosion.js +55 -0
- package/dist/cjs/utils/plotly-click.d.ts +34 -0
- package/dist/cjs/utils/plotly-click.d.ts.map +1 -0
- package/dist/cjs/utils/plotly-click.js +49 -0
- package/dist/cjs/utils/plotly-surface.d.ts +14 -0
- package/dist/cjs/utils/plotly-surface.d.ts.map +1 -0
- package/dist/cjs/utils/plotly-surface.js +64 -0
- package/dist/cjs/utils/plotly-title.d.ts +12 -0
- package/dist/cjs/utils/plotly-title.d.ts.map +1 -0
- package/dist/cjs/utils/plotly-title.js +24 -0
- package/dist/cjs/utils/series-click.d.ts +39 -0
- package/dist/cjs/utils/series-click.d.ts.map +1 -0
- package/dist/cjs/utils/series-click.js +75 -0
- package/dist/cjs/utils/three-d.d.ts +17 -1
- package/dist/cjs/utils/three-d.d.ts.map +1 -1
- package/dist/cjs/utils/three-d.js +32 -4
- package/dist/esm/atoms/pivot-chart.atom.d.ts +14 -0
- package/dist/esm/atoms/pivot-chart.atom.d.ts.map +1 -0
- package/dist/esm/atoms/pivot-chart.atom.js +4 -0
- package/dist/esm/basic-chart/basic-chart.d.ts +1 -1
- package/dist/esm/basic-chart/basic-chart.d.ts.map +1 -1
- package/dist/esm/basic-chart/basic-chart.js +680 -178
- package/dist/esm/components/dialogs/pivot-chart-dialog.d.ts +39 -0
- package/dist/esm/components/dialogs/pivot-chart-dialog.d.ts.map +1 -0
- package/dist/esm/components/dialogs/pivot-chart-dialog.js +89 -0
- package/dist/esm/components/editors/chart-editor.d.ts +13 -1
- package/dist/esm/components/editors/chart-editor.d.ts.map +1 -1
- package/dist/esm/components/editors/chart-editor.js +164 -20
- package/dist/esm/config.d.ts.map +1 -1
- package/dist/esm/config.js +149 -12
- package/dist/esm/hooks/use-charts.d.ts +21 -6
- package/dist/esm/hooks/use-charts.d.ts.map +1 -1
- package/dist/esm/hooks/use-charts.js +13 -1
- package/dist/esm/hooks/use-on-create-chart.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-create-chart.js +7 -1
- package/dist/esm/hooks/use-on-move-chart-to-sheet.d.ts +12 -0
- package/dist/esm/hooks/use-on-move-chart-to-sheet.d.ts.map +1 -0
- package/dist/esm/hooks/use-on-move-chart-to-sheet.js +19 -0
- package/dist/esm/hooks/use-on-move-chart.d.ts +1 -1
- package/dist/esm/hooks/use-on-move-chart.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-move-chart.js +2 -2
- package/dist/esm/hooks/use-on-resize-chart.d.ts +1 -1
- package/dist/esm/hooks/use-on-resize-chart.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-resize-chart.js +2 -2
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +14 -0
- package/dist/esm/interface/create-chart.d.ts.map +1 -1
- package/dist/esm/interface/create-chart.js +36 -58
- package/dist/esm/interface/delete-chart.d.ts.map +1 -1
- package/dist/esm/interface/delete-chart.js +4 -0
- package/dist/esm/interface/move-chart-to-sheet.d.ts +13 -0
- package/dist/esm/interface/move-chart-to-sheet.d.ts.map +1 -0
- package/dist/esm/interface/move-chart-to-sheet.js +126 -0
- package/dist/esm/interface/move-chart.d.ts +2 -2
- package/dist/esm/interface/move-chart.d.ts.map +1 -1
- package/dist/esm/interface/move-chart.js +7 -1
- package/dist/esm/interface/resize-chart.d.ts +2 -2
- package/dist/esm/interface/resize-chart.d.ts.map +1 -1
- package/dist/esm/interface/resize-chart.js +7 -1
- package/dist/esm/interface/update-chart.d.ts.map +1 -1
- package/dist/esm/interface/update-chart.js +4 -0
- package/dist/esm/plotly/basic-chart/basic-chart.d.ts +1 -1
- package/dist/esm/plotly/basic-chart/basic-chart.d.ts.map +1 -1
- package/dist/esm/plotly/basic-chart/basic-chart.js +858 -463
- package/dist/esm/plotly/basic-chart/helpers.d.ts.map +1 -1
- package/dist/esm/plotly/basic-chart/helpers.js +3 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +7 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/utils/axis-number-format.d.ts +69 -0
- package/dist/esm/utils/axis-number-format.d.ts.map +1 -0
- package/dist/esm/utils/axis-number-format.js +170 -0
- package/dist/esm/utils/category-levels.d.ts +27 -0
- package/dist/esm/utils/category-levels.d.ts.map +1 -0
- package/dist/esm/utils/category-levels.js +65 -0
- package/dist/esm/utils/chart-image.d.ts +8 -0
- package/dist/esm/utils/chart-image.d.ts.map +1 -0
- package/dist/esm/utils/chart-image.js +24 -0
- package/dist/esm/utils/chart-orientation.d.ts +67 -0
- package/dist/esm/utils/chart-orientation.d.ts.map +1 -0
- package/dist/esm/utils/chart-orientation.js +234 -0
- package/dist/esm/utils/chart-spec-utils.d.ts +3 -0
- package/dist/esm/utils/chart-spec-utils.d.ts.map +1 -1
- package/dist/esm/utils/chart-spec-utils.js +10 -2
- package/dist/esm/utils/chart-styles.d.ts +75 -0
- package/dist/esm/utils/chart-styles.d.ts.map +1 -0
- package/dist/esm/utils/chart-styles.js +357 -0
- package/dist/esm/utils/empty-cells.d.ts +30 -0
- package/dist/esm/utils/empty-cells.d.ts.map +1 -0
- package/dist/esm/utils/empty-cells.js +67 -0
- package/dist/esm/utils/overrides.d.ts +6 -1
- package/dist/esm/utils/overrides.d.ts.map +1 -1
- package/dist/esm/utils/overrides.js +14 -2
- package/dist/esm/utils/pie-explosion.d.ts +30 -0
- package/dist/esm/utils/pie-explosion.d.ts.map +1 -0
- package/dist/esm/utils/pie-explosion.js +43 -0
- package/dist/esm/utils/plotly-click.d.ts +34 -0
- package/dist/esm/utils/plotly-click.d.ts.map +1 -0
- package/dist/esm/utils/plotly-click.js +44 -0
- package/dist/esm/utils/plotly-surface.d.ts +14 -0
- package/dist/esm/utils/plotly-surface.d.ts.map +1 -0
- package/dist/esm/utils/plotly-surface.js +45 -0
- package/dist/esm/utils/plotly-title.d.ts +12 -0
- package/dist/esm/utils/plotly-title.d.ts.map +1 -0
- package/dist/esm/utils/plotly-title.js +20 -0
- package/dist/esm/utils/series-click.d.ts +39 -0
- package/dist/esm/utils/series-click.d.ts.map +1 -0
- package/dist/esm/utils/series-click.js +66 -0
- package/dist/esm/utils/three-d.d.ts +17 -1
- package/dist/esm/utils/three-d.d.ts.map +1 -1
- package/dist/esm/utils/three-d.js +29 -3
- package/package.json +16 -12
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { isBasicChartSpec } from "./chart-spec-utils";
|
|
2
|
+
/**
|
|
3
|
+
* Adapt a range reader (the renderers' `getDomainValuesFromRange`) into
|
|
4
|
+
* the single-cell label getter the orientation helpers take.
|
|
5
|
+
*/
|
|
6
|
+
export const cellLabelGetterFromRangeReader = (readRange) => (sheetId, rowIndex, columnIndex) => {
|
|
7
|
+
const [value] = readRange({
|
|
8
|
+
sheetId,
|
|
9
|
+
startRowIndex: rowIndex,
|
|
10
|
+
endRowIndex: rowIndex,
|
|
11
|
+
startColumnIndex: columnIndex,
|
|
12
|
+
endColumnIndex: columnIndex,
|
|
13
|
+
}, "SHOW_ALL");
|
|
14
|
+
return value == null ? undefined : String(value);
|
|
15
|
+
};
|
|
16
|
+
const isSingleRow = (range) => range.startRowIndex === range.endRowIndex;
|
|
17
|
+
const isSingleColumn = (range) => range.startColumnIndex === range.endColumnIndex;
|
|
18
|
+
/**
|
|
19
|
+
* Which way a chart's series run. The explicit flag wins; otherwise a
|
|
20
|
+
* chart whose every series is a single row spanning several columns is
|
|
21
|
+
* Excel's series-in-rows shape (OOXML carries no flag — each `<c:ser>` is
|
|
22
|
+
* its own reference — so imported charts are read this way).
|
|
23
|
+
*/
|
|
24
|
+
export const inferSeriesOrientation = (spec) => {
|
|
25
|
+
if (spec.seriesOrientation)
|
|
26
|
+
return spec.seriesOrientation;
|
|
27
|
+
if (!isBasicChartSpec(spec))
|
|
28
|
+
return "columns";
|
|
29
|
+
const sources = spec.series.flatMap((entry) => entry.sources ?? []);
|
|
30
|
+
if (sources.length === 0)
|
|
31
|
+
return "columns";
|
|
32
|
+
return sources.every((range) => isSingleRow(range) && !isSingleColumn(range))
|
|
33
|
+
? "rows"
|
|
34
|
+
: "columns";
|
|
35
|
+
};
|
|
36
|
+
export const flipSeriesOrientation = (orientation) => (orientation === "rows" ? "columns" : "rows");
|
|
37
|
+
/**
|
|
38
|
+
* Excel's chart wizard picks series-in-rows when the selection is wider
|
|
39
|
+
* than it is tall.
|
|
40
|
+
*/
|
|
41
|
+
export const pickSeriesOrientationForRange = (range) => range.endColumnIndex - range.startColumnIndex >
|
|
42
|
+
range.endRowIndex - range.startRowIndex
|
|
43
|
+
? "rows"
|
|
44
|
+
: "columns";
|
|
45
|
+
/**
|
|
46
|
+
* Split a data range the way Excel's chart wizard does. Series in
|
|
47
|
+
* columns: the first column (beneath the header row) is the category
|
|
48
|
+
* axis and every further column is one series named by its header cell.
|
|
49
|
+
* Series in rows is the transpose: the first row (right of the header
|
|
50
|
+
* column) is the category axis and every further row is a series named
|
|
51
|
+
* by its first cell. A range only one row (column) tall still yields a
|
|
52
|
+
* one-cell-deep axis so the chart has something to plot.
|
|
53
|
+
*/
|
|
54
|
+
export const deriveChartSeriesFromRange = ({ range, orientation, getFormattedValue, }) => {
|
|
55
|
+
const { sheetId, startRowIndex, startColumnIndex } = range;
|
|
56
|
+
const endRowIndex = Math.max(range.endRowIndex, startRowIndex);
|
|
57
|
+
const endColumnIndex = Math.max(range.endColumnIndex, startColumnIndex);
|
|
58
|
+
const label = (rowIndex, columnIndex) => getFormattedValue?.(sheetId, rowIndex, columnIndex) ?? undefined;
|
|
59
|
+
if (orientation === "rows") {
|
|
60
|
+
const categoryAxis = {
|
|
61
|
+
sheetId,
|
|
62
|
+
startRowIndex,
|
|
63
|
+
endRowIndex: startRowIndex,
|
|
64
|
+
startColumnIndex: startColumnIndex + 1,
|
|
65
|
+
endColumnIndex: Math.max(endColumnIndex, startColumnIndex + 1),
|
|
66
|
+
};
|
|
67
|
+
const series = [];
|
|
68
|
+
for (let rowIndex = startRowIndex + 1; rowIndex <= endRowIndex; rowIndex++) {
|
|
69
|
+
series.push({
|
|
70
|
+
dataLabel: label(rowIndex, startColumnIndex),
|
|
71
|
+
sources: [
|
|
72
|
+
{
|
|
73
|
+
sheetId,
|
|
74
|
+
startRowIndex: rowIndex,
|
|
75
|
+
endRowIndex: rowIndex,
|
|
76
|
+
startColumnIndex: categoryAxis.startColumnIndex,
|
|
77
|
+
endColumnIndex: categoryAxis.endColumnIndex,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return { domains: [{ sources: [categoryAxis] }], series };
|
|
83
|
+
}
|
|
84
|
+
const categoryAxis = {
|
|
85
|
+
sheetId,
|
|
86
|
+
startRowIndex: startRowIndex + 1,
|
|
87
|
+
endRowIndex: Math.max(endRowIndex, startRowIndex + 1),
|
|
88
|
+
startColumnIndex,
|
|
89
|
+
endColumnIndex: startColumnIndex,
|
|
90
|
+
};
|
|
91
|
+
const series = [];
|
|
92
|
+
for (let columnIndex = startColumnIndex + 1; columnIndex <= endColumnIndex; columnIndex++) {
|
|
93
|
+
series.push({
|
|
94
|
+
dataLabel: label(startRowIndex, columnIndex),
|
|
95
|
+
sources: [
|
|
96
|
+
{
|
|
97
|
+
sheetId,
|
|
98
|
+
startRowIndex: categoryAxis.startRowIndex,
|
|
99
|
+
endRowIndex: categoryAxis.endRowIndex,
|
|
100
|
+
startColumnIndex: columnIndex,
|
|
101
|
+
endColumnIndex: columnIndex,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return { domains: [{ sources: [categoryAxis] }], series };
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* The block the series tile when they form one rectangle: every series
|
|
110
|
+
* is a single source on the same sheet, all single columns sharing one
|
|
111
|
+
* row span (series in columns) or all single rows sharing one column
|
|
112
|
+
* span (series in rows), and adjacent to each other in order. Undefined
|
|
113
|
+
* for anything else — there is no meaningful transpose of scattered
|
|
114
|
+
* sources.
|
|
115
|
+
*/
|
|
116
|
+
export const rectangularSeriesBounds = (spec, orientation) => {
|
|
117
|
+
if (!isBasicChartSpec(spec) || spec.series.length === 0)
|
|
118
|
+
return undefined;
|
|
119
|
+
const sources = [];
|
|
120
|
+
for (const entry of spec.series) {
|
|
121
|
+
if (!entry.sources || entry.sources.length !== 1)
|
|
122
|
+
return undefined;
|
|
123
|
+
sources.push(entry.sources[0]);
|
|
124
|
+
}
|
|
125
|
+
const [first] = sources;
|
|
126
|
+
const alongRows = orientation === "columns";
|
|
127
|
+
for (let i = 0; i < sources.length; i++) {
|
|
128
|
+
const range = sources[i];
|
|
129
|
+
if (range.sheetId !== first.sheetId)
|
|
130
|
+
return undefined;
|
|
131
|
+
if (alongRows) {
|
|
132
|
+
if (!isSingleColumn(range) ||
|
|
133
|
+
range.startRowIndex !== first.startRowIndex ||
|
|
134
|
+
range.endRowIndex !== first.endRowIndex ||
|
|
135
|
+
range.startColumnIndex !== first.startColumnIndex + i) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (!isSingleRow(range) ||
|
|
140
|
+
range.startColumnIndex !== first.startColumnIndex ||
|
|
141
|
+
range.endColumnIndex !== first.endColumnIndex ||
|
|
142
|
+
range.startRowIndex !== first.startRowIndex + i) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const last = sources[sources.length - 1];
|
|
147
|
+
return {
|
|
148
|
+
sheetId: first.sheetId,
|
|
149
|
+
startRowIndex: first.startRowIndex,
|
|
150
|
+
endRowIndex: last.endRowIndex,
|
|
151
|
+
startColumnIndex: first.startColumnIndex,
|
|
152
|
+
endColumnIndex: last.endColumnIndex,
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
/** Whether `switchRowColumn` has a transpose to offer for this chart. */
|
|
156
|
+
export const canSwitchRowColumn = (spec) => isBasicChartSpec(spec) &&
|
|
157
|
+
(!!spec.dataRange ||
|
|
158
|
+
rectangularSeriesBounds(spec, inferSeriesOrientation(spec)) !==
|
|
159
|
+
undefined);
|
|
160
|
+
/**
|
|
161
|
+
* Excel's "Switch Row/Column". With a `dataRange` the series and
|
|
162
|
+
* category axis are re-derived from it the other way round. Without one,
|
|
163
|
+
* rectangular series sources are transposed: each row (column) of the
|
|
164
|
+
* block becomes a series, named after the old category cell beside it,
|
|
165
|
+
* and the old series names become the categories (Excel's behaviour —
|
|
166
|
+
* the names are carried as inline values because the spec stores them
|
|
167
|
+
* as text, not as a cell reference). Per-series presentation (colours,
|
|
168
|
+
* trendlines, …) does not survive the transpose, as in Excel. Returns
|
|
169
|
+
* undefined when the sources cannot be transposed.
|
|
170
|
+
*/
|
|
171
|
+
export const switchRowColumn = (spec, { getFormattedValue } = {}) => {
|
|
172
|
+
if (!isBasicChartSpec(spec))
|
|
173
|
+
return undefined;
|
|
174
|
+
const current = inferSeriesOrientation(spec);
|
|
175
|
+
const next = flipSeriesOrientation(current);
|
|
176
|
+
if (spec.dataRange) {
|
|
177
|
+
const { domains, series } = deriveChartSeriesFromRange({
|
|
178
|
+
range: spec.dataRange,
|
|
179
|
+
orientation: next,
|
|
180
|
+
getFormattedValue,
|
|
181
|
+
});
|
|
182
|
+
return { ...spec, seriesOrientation: next, domains, series };
|
|
183
|
+
}
|
|
184
|
+
const block = rectangularSeriesBounds(spec, current);
|
|
185
|
+
if (!block)
|
|
186
|
+
return undefined;
|
|
187
|
+
const categorySource = spec.domains?.[0]?.sources?.[0];
|
|
188
|
+
const series = [];
|
|
189
|
+
if (next === "rows") {
|
|
190
|
+
for (let rowIndex = block.startRowIndex; rowIndex <= block.endRowIndex; rowIndex++) {
|
|
191
|
+
const offset = rowIndex - block.startRowIndex;
|
|
192
|
+
series.push({
|
|
193
|
+
dataLabel: categorySource && getFormattedValue
|
|
194
|
+
? getFormattedValue(categorySource.sheetId, categorySource.startRowIndex + offset, categorySource.startColumnIndex) ?? undefined
|
|
195
|
+
: undefined,
|
|
196
|
+
sources: [
|
|
197
|
+
{
|
|
198
|
+
sheetId: block.sheetId,
|
|
199
|
+
startRowIndex: rowIndex,
|
|
200
|
+
endRowIndex: rowIndex,
|
|
201
|
+
startColumnIndex: block.startColumnIndex,
|
|
202
|
+
endColumnIndex: block.endColumnIndex,
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
for (let columnIndex = block.startColumnIndex; columnIndex <= block.endColumnIndex; columnIndex++) {
|
|
210
|
+
const offset = columnIndex - block.startColumnIndex;
|
|
211
|
+
series.push({
|
|
212
|
+
dataLabel: categorySource && getFormattedValue
|
|
213
|
+
? getFormattedValue(categorySource.sheetId, categorySource.startRowIndex, categorySource.startColumnIndex + offset) ?? undefined
|
|
214
|
+
: undefined,
|
|
215
|
+
sources: [
|
|
216
|
+
{
|
|
217
|
+
sheetId: block.sheetId,
|
|
218
|
+
startRowIndex: block.startRowIndex,
|
|
219
|
+
endRowIndex: block.endRowIndex,
|
|
220
|
+
startColumnIndex: columnIndex,
|
|
221
|
+
endColumnIndex: columnIndex,
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const categories = spec.series.map((entry, index) => entry.dataLabel ?? `Series ${index + 1}`);
|
|
228
|
+
return {
|
|
229
|
+
...spec,
|
|
230
|
+
seriesOrientation: next,
|
|
231
|
+
domains: [{ sources: [], inlineValues: categories }],
|
|
232
|
+
series,
|
|
233
|
+
};
|
|
234
|
+
};
|
|
@@ -39,6 +39,9 @@ export declare const getDefaultChartTypeSpec: (chartType: ChartType) => Partial<
|
|
|
39
39
|
export declare const getPropertiesToRemove: (fromType: ChartType, toType: ChartType) => string[];
|
|
40
40
|
/**
|
|
41
41
|
* Checks if chart data array is empty or contains only placeholder entries.
|
|
42
|
+
* An entry carrying inline values (`<c:strLit>` / `<c:numLit>` categories,
|
|
43
|
+
* or the series names Switch Row/Column turns into categories) is real
|
|
44
|
+
* data even though it references no cells.
|
|
42
45
|
*/
|
|
43
46
|
export declare const isPlaceholderChartData: (data?: ChartData[]) => boolean;
|
|
44
47
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-spec-utils.d.ts","sourceRoot":"","sources":["../../../utils/chart-spec-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,UAAU,EACV,YAAY,EACb,MAAM,2BAA2B,CAAC;AAEnC,KAAK,SAAS,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC;AACpD,KAAK,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;AACtD,KAAK,SAAS,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;AAEvC,eAAO,MAAM,iBAAiB,6MAe5B,CAAC;AAEH,eAAO,MAAM,kBAAkB,6MAA4C,CAAC;AAE5E,eAAO,MAAM,qBAAqB,6MAGhC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB,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AAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,SAAS,EAAE,KAAG,OAO3D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,UAAU,SAAS,EAAE,EACrB,WAAW,SAAS,EAAE,KACrB,SAAS,EAKX,CAAC;AA+BF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACzB,cAAc,SAAS,EACvB,cAAc,OAAO,CAAC,SAAS,CAAC,KAC/B,SA0EF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,SAAS,KAAG,UAAU,EAsB9D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,OAAO,KAAG,MAQvD,CAAC"}
|
|
@@ -84,12 +84,13 @@ export const getDefaultChartTypeSpec = (chartType) => {
|
|
|
84
84
|
* These should be cleared when switching between chart types within basic charts.
|
|
85
85
|
*/
|
|
86
86
|
const BASIC_CHART_TYPE_PROPERTIES = {
|
|
87
|
-
line: ["smooth"],
|
|
87
|
+
line: ["smooth", "showMarkers"],
|
|
88
88
|
// `doughnutHoleSize` is deliberately NOT cleared when leaving pie so
|
|
89
89
|
// upgrading a legacy pie-based doughnut (pie + doughnutHoleSize) to
|
|
90
90
|
// the first-class doughnut token keeps the authored hole size.
|
|
91
91
|
pie: [
|
|
92
92
|
"radius",
|
|
93
|
+
"explosion",
|
|
93
94
|
// Of-pie composite fields (pie-of-pie / bar-of-pie) — meaningless
|
|
94
95
|
// on any other chart type, so drop them on transition.
|
|
95
96
|
"sourceChartType",
|
|
@@ -98,7 +99,7 @@ const BASIC_CHART_TYPE_PROPERTIES = {
|
|
|
98
99
|
"splitPos",
|
|
99
100
|
"secondPieSize",
|
|
100
101
|
],
|
|
101
|
-
doughnut: ["doughnutHoleSize"],
|
|
102
|
+
doughnut: ["doughnutHoleSize", "explosion"],
|
|
102
103
|
waterfall: ["totalIndices"],
|
|
103
104
|
boxplot: ["quartileMethod", "showOutliers", "showMeanMarker"],
|
|
104
105
|
// Region map (filled map / choropleth) — the geo scope and the
|
|
@@ -112,7 +113,9 @@ const BASIC_CHART_TYPE_PROPERTIES = {
|
|
|
112
113
|
const CATEGORY_SPECIFIC_PROPERTIES = {
|
|
113
114
|
basic: [
|
|
114
115
|
"smooth",
|
|
116
|
+
"showMarkers",
|
|
115
117
|
"radius",
|
|
118
|
+
"explosion",
|
|
116
119
|
"stackedType",
|
|
117
120
|
"doughnutHoleSize",
|
|
118
121
|
"totalIndices",
|
|
@@ -174,11 +177,16 @@ export const getPropertiesToRemove = (fromType, toType) => {
|
|
|
174
177
|
};
|
|
175
178
|
/**
|
|
176
179
|
* Checks if chart data array is empty or contains only placeholder entries.
|
|
180
|
+
* An entry carrying inline values (`<c:strLit>` / `<c:numLit>` categories,
|
|
181
|
+
* or the series names Switch Row/Column turns into categories) is real
|
|
182
|
+
* data even though it references no cells.
|
|
177
183
|
*/
|
|
178
184
|
export const isPlaceholderChartData = (data) => {
|
|
179
185
|
if (!data || data.length === 0)
|
|
180
186
|
return true;
|
|
181
187
|
return data.every((entry) => {
|
|
188
|
+
if (entry?.inlineValues?.length)
|
|
189
|
+
return false;
|
|
182
190
|
const sources = entry?.sources ?? [];
|
|
183
191
|
return sources.length === 0 || sources.every((source) => !source);
|
|
184
192
|
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ChartSpec } from "@rowsncolumns/spreadsheet";
|
|
2
|
+
/**
|
|
3
|
+
* Excel's Chart Design tab as pure spec transforms: Chart Styles, Change
|
|
4
|
+
* Colors, Quick Layouts and Reset to Match Style. Every transform returns
|
|
5
|
+
* a new spec and writes only the fields the gallery entry defines, so the
|
|
6
|
+
* result renders identically on both renderers (they read the same spec)
|
|
7
|
+
* and survives the XLSX round-trip field by field.
|
|
8
|
+
*/
|
|
9
|
+
/** A "Change Colors" gallery entry. `colors` omitted = the workbook theme's accents. */
|
|
10
|
+
export type ChartColorPalette = {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
kind: "colorful" | "monochromatic";
|
|
14
|
+
colors?: string[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Office's Change Colors gallery. Colorful 1 is the theme itself (no
|
|
18
|
+
* `colors` — the renderer keeps its accent fallback); the rest are the
|
|
19
|
+
* default Office theme's derived palettes.
|
|
20
|
+
*/
|
|
21
|
+
export declare const CHART_COLOR_PALETTES: readonly ChartColorPalette[];
|
|
22
|
+
/**
|
|
23
|
+
* Change Colors: set the palette and clear every series' own colour so the
|
|
24
|
+
* palette applies (a series colour always wins over the palette).
|
|
25
|
+
*/
|
|
26
|
+
export declare const applyChartColorPalette: (spec: ChartSpec, palette: ChartColorPalette) => ChartSpec;
|
|
27
|
+
/**
|
|
28
|
+
* Reset to Match Style: drop the per-series formatting overrides so the
|
|
29
|
+
* series follow the chart style's palette again. Chart-level fields are
|
|
30
|
+
* untouched — they *are* the style.
|
|
31
|
+
*/
|
|
32
|
+
export declare const resetChartToMatchStyle: (spec: ChartSpec) => ChartSpec;
|
|
33
|
+
/**
|
|
34
|
+
* The series colour cycle a renderer should use: the spec's palette when
|
|
35
|
+
* one is set, else the caller's theme accents.
|
|
36
|
+
*/
|
|
37
|
+
export declare const getChartPalette: (spec: Pick<ChartSpec, "palette"> | undefined, fallback: readonly string[]) => string[];
|
|
38
|
+
/**
|
|
39
|
+
* A Chart Styles gallery entry. `id` is the OOXML `<c:style>` value the
|
|
40
|
+
* style is written as (§21.2.3.46 ST_Style: 1 grayscale, 2 colourful, 3
|
|
41
|
+
* monochromatic accent 1, +8 per row of increasing emphasis, 33-40 on a
|
|
42
|
+
* dark-gray frame, 41-48 on black).
|
|
43
|
+
*/
|
|
44
|
+
export type ChartStylePreset = {
|
|
45
|
+
id: number;
|
|
46
|
+
label: string;
|
|
47
|
+
/** Swatch colours for the gallery tile. */
|
|
48
|
+
preview: {
|
|
49
|
+
background: string;
|
|
50
|
+
bars: string[];
|
|
51
|
+
};
|
|
52
|
+
apply(spec: ChartSpec): ChartSpec;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The Chart Styles gallery. Each entry pins the look Excel's style of that
|
|
56
|
+
* id implies onto the spec fields both renderers read: chart-area fill,
|
|
57
|
+
* gridlines, data labels, legend placement, title font and — for the
|
|
58
|
+
* grayscale / monochromatic rows — the palette. Per-series colours are
|
|
59
|
+
* left alone (Reset to Match Style clears them).
|
|
60
|
+
*/
|
|
61
|
+
export declare const CHART_STYLES: readonly ChartStylePreset[];
|
|
62
|
+
export declare const applyChartStyle: (spec: ChartSpec, style: ChartStylePreset) => ChartSpec;
|
|
63
|
+
/** A Quick Layouts gallery entry — where the title, legend, labels and axis titles go. */
|
|
64
|
+
export type ChartQuickLayout = {
|
|
65
|
+
id: number;
|
|
66
|
+
label: string;
|
|
67
|
+
apply(spec: ChartSpec): ChartSpec;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Excel's Quick Layout gallery (the first six of the column-chart set).
|
|
71
|
+
* Layouts arrange the existing elements; they never touch colours.
|
|
72
|
+
*/
|
|
73
|
+
export declare const CHART_QUICK_LAYOUTS: readonly ChartQuickLayout[];
|
|
74
|
+
export declare const applyChartQuickLayout: (spec: ChartSpec, layout: ChartQuickLayout) => ChartSpec;
|
|
75
|
+
//# sourceMappingURL=chart-styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-styles.d.ts","sourceRoot":"","sources":["../../../utils/chart-styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAEV,MAAM,2BAA2B,CAAC;AAEnC;;;;;;GAMG;AAEH,wFAAwF;AACxF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,UAAU,GAAG,eAAe,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACn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