@lexaxai/spreadsheet-engine 0.0.0-stage → 0.1.0-dryrun.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.
@@ -0,0 +1,379 @@
1
+ // The extended chart families (waterfall, treemap, histogram, maps ...)
2
+ // written in their own schema, what addChart takes of either kind, a
3
+ // chart's design, and a chart sheet's chart and settings.
4
+
5
+ import type {
6
+ ChartAutoPlacement, ChartOfTable, ChartPalette, ChartProperties, PivotChartProperties,
7
+ } from './chart';
8
+ import type { ChartColor, ChartOutline, ChartShapeFormat } from './chart_format';
9
+ import type { ImagePosition, ImageRange } from './drawings';
10
+ import type { HeaderFooter, Margins, PaperSize } from './page';
11
+ import type { WorksheetState } from './sheet';
12
+ import type { Color } from './styles';
13
+
14
+ /**
15
+ * The extended chart families, written in their own schema (xl/charts/chartExN.xml).
16
+ * `boxAndWhisker` is Excel's name for `boxWhisker`. A `filledMap` is written without
17
+ * its geography, which Excel fetches the first time it opens the file.
18
+ */
19
+ export type ChartExType =
20
+ | 'waterfall' | 'funnel' | 'treemap' | 'sunburst' | 'histogram' | 'pareto' | 'boxWhisker'
21
+ | 'boxAndWhisker' | 'filledMap';
22
+
23
+ /**
24
+ * The fill, outline and effects of an extended chart's element; a chart read from a file
25
+ * carries its formatting as it was written (`spPr`), which is written back as it is.
26
+ */
27
+ export interface ChartExShape extends ChartShapeFormat {
28
+ /**
29
+ * The element's formatting as the file writes it: its fill, outline and effects. A chart read from a file
30
+ * keeps it as it was read.
31
+ */
32
+ spPr?: any;
33
+ }
34
+
35
+ /**
36
+ * An extended chart's data labels; `position` is the file's own code, and null
37
+ * gives none where the family's labels have one.
38
+ */
39
+ export interface ChartExDataLabels {
40
+ /**
41
+ * The place of the labels, as the file codes it: `bestFit`, `b`, `ctr`, `inBase`, `inEnd`, `l`, `outEnd`,
42
+ * `r` or `t`. `null` gives none where the family has one.
43
+ */
44
+ position?: 'bestFit' | 'b' | 'ctr' | 'inBase' | 'inEnd' | 'l' | 'outEnd' | 'r' | 't' | null;
45
+ /**
46
+ * Whether the labels show each point's value.
47
+ */
48
+ value?: boolean;
49
+ /**
50
+ * Whether the labels show each point's category.
51
+ */
52
+ category?: boolean;
53
+ /**
54
+ * Whether the labels show the series' name.
55
+ */
56
+ series?: boolean;
57
+ /**
58
+ * The number format of the values the labels show.
59
+ */
60
+ numFmt?: string;
61
+ /**
62
+ * The text between the parts of a label, such as `, `.
63
+ */
64
+ separator?: string;
65
+ }
66
+
67
+ /**
68
+ * An axis of an extended chart, as `ChartExProperties.categoryAxis` and `valueAxis` take it.
69
+ */
70
+ export interface ChartExAxis {
71
+ /**
72
+ * Whether the axis is hidden.
73
+ */
74
+ hidden?: boolean;
75
+ /** true is Excel's automatic title ("Axis Title") */
76
+ title?: string | boolean;
77
+ /**
78
+ * The lowest value on the axis, Excel's automatic minimum when left out.
79
+ */
80
+ min?: number;
81
+ /**
82
+ * The highest value on the axis, Excel's automatic maximum when left out.
83
+ */
84
+ max?: number;
85
+ /**
86
+ * The interval between the major gridlines and labels, in the axis's units; automatic when left out.
87
+ */
88
+ majorUnit?: number;
89
+ /**
90
+ * The interval between the minor gridlines, in the axis's units; automatic when left out.
91
+ */
92
+ minorUnit?: number;
93
+ /** major gridlines; a value axis has them by default */
94
+ gridlines?: boolean;
95
+ /**
96
+ * Whether minor gridlines are drawn.
97
+ */
98
+ minorGridlines?: boolean;
99
+ /** none unless given; true writes the element without a type, which Excel reads as cross */
100
+ majorTickMarks?: 'in' | 'out' | 'cross' | 'none' | boolean;
101
+ /**
102
+ * The minor tick marks: `in`, `out`, `cross` or `none`. None are drawn unless given; `true` writes the
103
+ * element without a type, which Excel reads as `cross`.
104
+ */
105
+ minorTickMarks?: 'in' | 'out' | 'cross' | 'none' | boolean;
106
+ /** false hides the axis labels */
107
+ tickLabels?: boolean;
108
+ /**
109
+ * The number format of the axis labels.
110
+ */
111
+ numFmt?: string;
112
+ }
113
+
114
+ /**
115
+ * A series of an extended chart, as `ChartExProperties.series` takes it.
116
+ */
117
+ export interface ChartExSeries extends ChartExShape {
118
+ /** a cell (`'Data!$B$1'`), whose text Excel keeps live, or literal text */
119
+ name?: string;
120
+ /**
121
+ * The values the series plots, a range such as `Data!$B$2:$B$7`.
122
+ */
123
+ values: string;
124
+ /** a treemap's or a sunburst's may span several columns, one per level */
125
+ categories?: string;
126
+ /**
127
+ * The colour of the series.
128
+ */
129
+ color?: ChartColor;
130
+ /**
131
+ * The outline of the series' shapes, or `false` for none.
132
+ */
133
+ line?: ChartOutline | false;
134
+ /**
135
+ * Points formatted on their own, each by its `index`, counted from 0, with its colour or other formatting.
136
+ */
137
+ points?: Array<{index: number; color?: ChartColor} & ChartExShape>;
138
+ /**
139
+ * Whether the series' points have data labels, or the labels' options.
140
+ */
141
+ dataLabels?: boolean | ChartExDataLabels;
142
+ }
143
+
144
+ /**
145
+ * `addChart` for the extended chart types. Each type takes the options Excel's
146
+ * Format pane has for it, and refuses the rest by name.
147
+ */
148
+ export interface ChartExProperties {
149
+ /**
150
+ * The family of the chart: `waterfall`, `funnel`, `treemap`, `sunburst`, `histogram`, `pareto`, `boxWhisker`
151
+ * (also `boxAndWhisker`) or `filledMap`.
152
+ */
153
+ type: ChartExType;
154
+ /**
155
+ * Where the chart sits on the sheet, in the forms `ChartProperties.range` takes.
156
+ */
157
+ range: string | 'auto' | {auto: ChartAutoPlacement} | ({editAs?: string} & ImageRange) | ({editAs?: string} & ImagePosition);
158
+ /**
159
+ * The chart's name in the sheet's drawing, which defaults to `Chart N`.
160
+ */
161
+ name?: string;
162
+ /**
163
+ * How the chart moves and sizes with its cells: `moveAndSize`, `move`, `absolute`, or the anchor names
164
+ * `twoCell` and `oneCell`.
165
+ */
166
+ placement?: 'moveAndSize' | 'move' | 'absolute' | 'twoCell' | 'oneCell';
167
+ /**
168
+ * Whether the chart is locked on a protected worksheet; `false` leaves it editable.
169
+ */
170
+ locked?: boolean;
171
+ /**
172
+ * Whether the chart prints with its worksheet; `false` leaves it out when the worksheet is printed.
173
+ */
174
+ print?: boolean;
175
+ /**
176
+ * The alt text: a string is the description, or an object gives a `title` and a `description`.
177
+ */
178
+ altText?: string | {title?: string; description?: string};
179
+ /** a string, or a cell whose text it shows */
180
+ title?: string | {text?: string; ref?: string; position?: 'top' | 'bottom' | 'left' | 'right'; overlay?: boolean};
181
+ /** without a title, true shows Excel's automatic one ("Chart Title") */
182
+ autoTitle?: boolean;
183
+ /** each family has Excel's default; false removes it */
184
+ legend?: boolean | 'top' | 'bottom' | 'left' | 'right' | {position?: 'top' | 'bottom' | 'left' | 'right'; overlay?: boolean};
185
+ /** each family has Excel's default; false removes them */
186
+ dataLabels?: boolean | ChartExDataLabels;
187
+ /** the categories of every series */
188
+ categories?: string;
189
+ /** one series, except a box and whisker chart's */
190
+ series: ChartExSeries[];
191
+ /**
192
+ * The category axis, for a family that has one.
193
+ */
194
+ categoryAxis?: ChartExAxis;
195
+ /**
196
+ * The value axis, for a family that has one.
197
+ */
198
+ valueAxis?: ChartExAxis;
199
+ /** a Pareto chart's cumulative percentage axis */
200
+ percentAxis?: ChartExAxis;
201
+ /** percent of a bar's width */
202
+ gapWidth?: number;
203
+ /**
204
+ * The chart area, the frame the chart is drawn in, with its fill and outline.
205
+ */
206
+ chartArea?: ChartExShape;
207
+ /**
208
+ * The plot area, where the data is drawn, with its fill and outline.
209
+ */
210
+ plotArea?: ChartExShape;
211
+ /**
212
+ * The recipe of one of the type's Chart Styles, which formats the whole
213
+ * chart: Excel writes an extended chart's style into its recipe alone. The
214
+ * family's own when left out (395 for a waterfall, 410 for a treemap ...).
215
+ */
216
+ chartStyle?: number;
217
+ /**
218
+ * An item of Excel's Chart Styles gallery for this type ("Style 4" is 4):
219
+ * its recipe and what choosing it changes besides (the legend, the labels, a
220
+ * treemap's parent labels). Anything set here wins.
221
+ */
222
+ quickStyle?: number;
223
+ /** An item of Excel's Quick Layout gallery for this type ("Layout 3" is 3). */
224
+ quickLayout?: number;
225
+ /** A palette from Excel's Change Colours gallery, by its name there or its colours part's id */
226
+ palette?: ChartPalette | number;
227
+ /** waterfall: the indexes of the points that are totals */
228
+ subtotals?: number[];
229
+ /** waterfall */
230
+ connectorLines?: boolean;
231
+ /** histogram and Pareto without categories: automatic bins unless a width or count is given */
232
+ bins?: {width?: number; count?: number; overflow?: number | 'auto'; underflow?: number | 'auto'; closed?: 'left' | 'right'};
233
+ /** treemap */
234
+ parentLabels?: 'none' | 'banner' | 'overlapping';
235
+ /** box and whisker */
236
+ quartiles?: 'exclusive' | 'inclusive';
237
+ /**
238
+ * Box and whisker charts: whether a line joins the mean of each box.
239
+ */
240
+ meanLine?: boolean;
241
+ /**
242
+ * Box and whisker charts: whether each box shows a marker at its mean.
243
+ */
244
+ meanMarkers?: boolean;
245
+ /**
246
+ * Box and whisker charts: whether the points inside the boxes are drawn.
247
+ */
248
+ innerPoints?: boolean;
249
+ /**
250
+ * Box and whisker charts: whether the outlying points beyond the whiskers are drawn.
251
+ */
252
+ outliers?: boolean;
253
+ /** filled map; `robinson` draws the whole world, so it is refused with `mapArea` `dataOnly` or `countryRegionList` */
254
+ projection?: 'mercator' | 'miller' | 'robinson';
255
+ /** filled map: how much of the world it shows; Excel chooses when left out */
256
+ mapArea?: 'dataOnly' | 'countryRegionList' | 'world';
257
+ /** filled map: which regions are labelled with their names */
258
+ regionLabels?: 'none' | 'bestFit' | 'all';
259
+ /** filled map: the colour of the lowest value, of the highest, and one between if wanted */
260
+ colors?: {min: ChartColor; mid?: ChartColor; max: ChartColor};
261
+ }
262
+
263
+ /**
264
+ * What `Worksheet.addChart` takes: a classic or an extended chart's options, a table's columns in place of its
265
+ * series, or a pivot chart's options with its PivotTable's name.
266
+ */
267
+ export type ChartConfig =
268
+ | ChartProperties
269
+ | ChartExProperties
270
+ | (Omit<ChartProperties, 'series'> & ChartOfTable)
271
+ | (Omit<ChartExProperties, 'series'> & ChartOfTable)
272
+ | (PivotChartProperties & {pivotTable: string});
273
+
274
+ /**
275
+ * The design a chart is drawn in, as `Chart.design` gives it: its gallery entry, and each item of the Quick
276
+ * Styles and Quick Layout galleries whose settings it has.
277
+ */
278
+ export interface ChartDesign {
279
+ /**
280
+ * The gallery entry, such as `clusteredColumn` or `waterfall`.
281
+ */
282
+ type: string;
283
+ /**
284
+ * The Quick Styles items it matches, by number.
285
+ */
286
+ quickStyle: number[];
287
+ /**
288
+ * The Quick Layout items it matches, by number.
289
+ */
290
+ quickLayout: number[];
291
+ }
292
+
293
+ /** A chart sheet's chart: `addChart`'s configuration without a place on a sheet. */
294
+ export type ChartsheetChart = Omit<ChartProperties, 'range'> | Omit<ChartExProperties, 'range'>;
295
+
296
+ /** The settings of a chart sheet's own part, all optional. */
297
+ export interface ChartsheetOptions {
298
+ /** the tab's colour */
299
+ tabColor: Partial<Color>;
300
+ /**
301
+ * Whether the chart sheet is `'visible'`, `'hidden'` or `'veryHidden'`.
302
+ */
303
+ state: WorksheetState;
304
+ /**
305
+ * Whether the chart is zoomed to fit the window, as Excel's new chart
306
+ * sheets are. `false` keeps it at `zoomScale`.
307
+ * @default true
308
+ */
309
+ zoomToFit: boolean;
310
+ /** percent */
311
+ zoomScale: number;
312
+ /**
313
+ * The margins of the printed chart sheet, in inches: `left`, `right`, `top`, `bottom`, `header` and
314
+ * `footer`.
315
+ */
316
+ pageMargins: Partial<Margins>;
317
+ /**
318
+ * The page setup of the printed chart sheet, as `ChartsheetPageSetup` gives it.
319
+ */
320
+ pageSetup: Partial<ChartsheetPageSetup>;
321
+ /**
322
+ * The header and footer of the printed chart sheet, in the form a worksheet's header and footer take.
323
+ */
324
+ headerFooter: Partial<HeaderFooter>;
325
+ /** what protecting the sheet locks: the chart's contents, and its drawing objects */
326
+ protection: {content?: boolean; objects?: boolean};
327
+ }
328
+
329
+ /** A chart sheet's page setup (`CT_CsPageSetup`), a smaller set than a worksheet's. */
330
+ export interface ChartsheetPageSetup {
331
+ /**
332
+ * The paper size, as one of Excel's paper size codes (`PaperSize`).
333
+ */
334
+ paperSize: PaperSize;
335
+ /**
336
+ * The height of a custom paper size, with its unit, such as `297mm`.
337
+ */
338
+ paperHeight: string;
339
+ /**
340
+ * The width of a custom paper size, with its unit, such as `210mm`.
341
+ */
342
+ paperWidth: string;
343
+ /**
344
+ * The orientation of the printed page: `'default'`, `'portrait'` or `'landscape'`.
345
+ */
346
+ orientation: 'default' | 'portrait' | 'landscape';
347
+ /**
348
+ * The number of the first printed page, when `useFirstPageNumber` is set.
349
+ */
350
+ firstPageNumber: number;
351
+ /**
352
+ * Whether the pages are numbered from `firstPageNumber` rather than from 1.
353
+ */
354
+ useFirstPageNumber: boolean;
355
+ /**
356
+ * Whether the printer's own default settings are used for the settings that are not given.
357
+ */
358
+ usePrinterDefaults: boolean;
359
+ /**
360
+ * Whether the chart prints in black and white.
361
+ */
362
+ blackAndWhite: boolean;
363
+ /**
364
+ * Whether the chart prints in draft quality.
365
+ */
366
+ draft: boolean;
367
+ /**
368
+ * The horizontal printing resolution, in dots per inch.
369
+ */
370
+ horizontalDpi: number;
371
+ /**
372
+ * The vertical printing resolution, in dots per inch.
373
+ */
374
+ verticalDpi: number;
375
+ /**
376
+ * The number of copies printed.
377
+ */
378
+ copies: number;
379
+ }