@lexaxai/spreadsheet-engine 0.0.0-stage → 0.1.0-dryrun.1

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,479 @@
1
+ // A classic chart as addChart takes it: its type, the gallery's names, the
2
+ // chart's own options, and its placement, protection, printing and palette.
3
+
4
+ import type { ImagePosition, ImageRange } from './drawings';
5
+ import type { ChartAxis, ChartFont, ChartLayout, ChartLegend, ChartLine, ChartShapeFormat, ChartSurface, ChartTitle } from './chart_format';
6
+ import type { ChartDataLabels, ChartSeries } from './chart_series';
7
+
8
+ /**
9
+ * The chart families supported by `Worksheet.addChart`.
10
+ * These map onto the OOXML `<c:*Chart>` plot-group elements.
11
+ */
12
+ export type ChartType =
13
+ | 'bar' | 'bar3D' | 'line' | 'line3D' | 'area' | 'area3D' | 'pie' | 'pie3D' | 'doughnut' | 'ofPie'
14
+ | 'scatter' | 'bubble' | 'radar' | 'stock' | 'surface' | 'surface3D';
15
+
16
+ /**
17
+ * How the series in a plot group relate to one another. Which values are legal depends
18
+ * on the chart type: bar/line/area use the grouping values, scatter and radar carry
19
+ * their own style names.
20
+ */
21
+ export type ChartSubType =
22
+ | 'clustered' | 'stacked' | 'percentStacked' | 'standard' | 'none' | 'line' | 'lineMarker'
23
+ | 'marker' | 'smooth' | 'smoothMarker' | 'filled';
24
+
25
+ /**
26
+ * The entries of Excel's Insert Chart gallery, by the name Excel gives them.
27
+ * Each expands to a family plus the settings that make that entry what it is;
28
+ * options given alongside it win. Excel's plain Line, Pie, Doughnut, Area and
29
+ * Bubble are the family names themselves; its plain Scatter and Radar are
30
+ * `scatterWithOnlyMarkers` and `radarWithoutMarkers`, since the scatter
31
+ * family draws lines and the radar family draws markers.
32
+ */
33
+ export type ChartGalleryName =
34
+ | 'clusteredColumn' | 'stackedColumn' | 'percentStackedColumn'
35
+ | 'threeDClusteredColumn' | 'threeDStackedColumn' | 'threeDPercentStackedColumn' | 'threeDColumn'
36
+ | 'clusteredBar' | 'stackedBar' | 'percentStackedBar'
37
+ | 'threeDClusteredBar' | 'threeDStackedBar' | 'threeDPercentStackedBar'
38
+ | 'stackedLine' | 'percentStackedLine'
39
+ | 'lineWithMarkers' | 'stackedLineWithMarkers' | 'percentStackedLineWithMarkers' | 'threeDLine'
40
+ | 'explodedPie' | 'threeDPie' | 'explodedThreeDPie' | 'pieOfPie' | 'barOfPie' | 'explodedDoughnut'
41
+ | 'stackedArea' | 'percentStackedArea' | 'threeDArea' | 'threeDStackedArea' | 'threeDPercentStackedArea'
42
+ | 'scatterWithOnlyMarkers' | 'scatterWithSmoothLinesAndMarkers' | 'scatterWithSmoothLines'
43
+ | 'scatterWithStraightLinesAndMarkers' | 'scatterWithStraightLines'
44
+ | 'threeDBubble'
45
+ | 'highLowClose' | 'openHighLowClose' | 'volumeHighLowClose' | 'volumeOpenHighLowClose'
46
+ | 'threeDSurface' | 'wireframeThreeDSurface' | 'contour' | 'wireframeContour'
47
+ | 'radarWithoutMarkers' | 'radarWithMarkers' | 'filledRadar'
48
+ | 'clusteredColumnLine' | 'clusteredColumnLineOnSecondaryAxis' | 'stackedAreaClusteredColumn'
49
+ | 'clusteredCylinderColumn' | 'stackedCylinderColumn' | 'percentStackedCylinderColumn'
50
+ | 'clusteredCylinderBar' | 'stackedCylinderBar' | 'percentStackedCylinderBar' | 'threeDCylinderColumn'
51
+ | 'clusteredConeColumn' | 'stackedConeColumn' | 'percentStackedConeColumn'
52
+ | 'clusteredConeBar' | 'stackedConeBar' | 'percentStackedConeBar' | 'threeDConeColumn'
53
+ | 'clusteredPyramidColumn' | 'stackedPyramidColumn' | 'percentStackedPyramidColumn'
54
+ | 'clusteredPyramidBar' | 'stackedPyramidBar' | 'percentStackedPyramidBar' | 'threeDPyramidColumn';
55
+
56
+ /**
57
+ * Where a legend sits: `'top'`, `'bottom'`, `'left'`, `'right'`, or `'topRight'` for Excel's top right
58
+ * position.
59
+ */
60
+ export type ChartLegendPosition = 'top' | 'bottom' | 'left' | 'right' | 'topRight';
61
+
62
+ /**
63
+ * The unit of a date axis's base, major or minor ticks: `days`, `months` or `years`.
64
+ */
65
+ export type ChartTimeUnit = 'days' | 'months' | 'years';
66
+
67
+ /** Where a chart that places itself goes (`range: {auto: ...}`). */
68
+ export interface ChartAutoPlacement {
69
+ /** a range to sit beside, or 'data' (the default) for the chart's own data */
70
+ near?: string | 'data';
71
+ /** in points (Excel's 360 by 216 by default), or in cells */
72
+ size?: {width: number; height: number} | {cols: number; rows: number};
73
+ /** empty cells between it and what it sits beside; 1 by default */
74
+ gap?: number;
75
+ }
76
+
77
+ /** Excel's Change Colours palettes; colorful1 is every chart's by default */
78
+ export type ChartPalette =
79
+ | 'colorful1' | 'colorful2' | 'colorful3' | 'colorful4'
80
+ | 'monochromatic1' | 'monochromatic2' | 'monochromatic3' | 'monochromatic4' | 'monochromatic5'
81
+ | 'monochromatic6' | 'monochromatic7' | 'monochromatic8' | 'monochromatic9' | 'monochromatic10'
82
+ | 'monochromatic11' | 'monochromatic12' | 'monochromatic13';
83
+
84
+ /**
85
+ * What a chart refuses to let a user change once its sheet is protected, as `ChartProperties.protection`
86
+ * takes it.
87
+ */
88
+ export interface ChartProtection {
89
+ /**
90
+ * Whether the chart object is locked on a protected worksheet.
91
+ */
92
+ chartObject?: boolean;
93
+ /**
94
+ * Whether the chart's data is locked on a protected worksheet.
95
+ */
96
+ data?: boolean;
97
+ /**
98
+ * Whether the chart's formatting is locked on a protected worksheet.
99
+ */
100
+ formatting?: boolean;
101
+ selection?: boolean;
102
+ userInterface?: boolean;
103
+ }
104
+
105
+ /**
106
+ * How a chart prints when it is printed on its own: its header and footer, margins and page setup, as
107
+ * `ChartProperties.printSettings` takes them.
108
+ */
109
+ export interface ChartPrintSettings {
110
+ /** texts use the worksheet header codes: &L &C &R, &P, &D and so on */
111
+ headerFooter?: {
112
+ oddHeader?: string;
113
+ oddFooter?: string;
114
+ evenHeader?: string;
115
+ evenFooter?: string;
116
+ firstHeader?: string;
117
+ firstFooter?: string;
118
+ alignWithMargins?: boolean;
119
+ differentOddEven?: boolean;
120
+ differentFirst?: boolean;
121
+ };
122
+ /** inches; any left out take Excel's defaults */
123
+ margins?: {left?: number; right?: number; top?: number; bottom?: number; header?: number; footer?: number};
124
+ /**
125
+ * The paper, orientation, number of copies and the other page options the chart prints with.
126
+ */
127
+ pageSetup?: {
128
+ paperSize?: number;
129
+ paperWidth?: string;
130
+ paperHeight?: string;
131
+ orientation?: 'default' | 'portrait' | 'landscape';
132
+ blackAndWhite?: boolean;
133
+ draft?: boolean;
134
+ firstPageNumber?: number;
135
+ useFirstPageNumber?: boolean;
136
+ horizontalDpi?: number;
137
+ verticalDpi?: number;
138
+ copies?: number;
139
+ };
140
+ }
141
+
142
+ /** How a picture fill is laid on a bar or an area. */
143
+ export interface ChartPictureOptions {
144
+ /** one stretched picture, a stack, or a stack with one picture per `stackUnit` */
145
+ format?: 'stretch' | 'stack' | 'stackScale';
146
+ /**
147
+ * The number of units each picture covers in a `'stackScale'` fill.
148
+ */
149
+ stackUnit?: number;
150
+ /** 3-D charts: which faces of a bar take the picture */
151
+ applyToFront?: boolean;
152
+ /**
153
+ * For 3-D charts, whether the sides of a bar take the picture.
154
+ */
155
+ applyToSides?: boolean;
156
+ /**
157
+ * For 3-D charts, whether the ends of a bar take the picture.
158
+ */
159
+ applyToEnd?: boolean;
160
+ }
161
+
162
+ /**
163
+ * A chart of a table's columns, in place of series: each series plots a
164
+ * column's data rows as a table reference, named from its header cell, and so
165
+ * follows the table as it grows and shrinks.
166
+ */
167
+ export interface ChartOfTable {
168
+ /** the table, by its displayName */
169
+ table: string;
170
+ /** the column of the categories, or of a scatter's or bubble's x values */
171
+ x?: string;
172
+ /** the columns plotted; every column but x and size by default */
173
+ y?: string | string[];
174
+ /** a bubble chart's sizes */
175
+ size?: string;
176
+ }
177
+
178
+ /** One of Excel's Recommended Charts for a block of cells. */
179
+ export interface ChartRecommendation {
180
+ /** the chart type addChart takes, for example 'clusteredColumn' */
181
+ type: string;
182
+ /** the name Excel's list shows, for example 'Clustered Column' */
183
+ name: string;
184
+ /** addChart config over the block: type, categories and series */
185
+ config: ChartProperties;
186
+ /** why the chart suits the data, in words */
187
+ reason: string;
188
+ }
189
+
190
+ /** How `arrangeCharts` lays a sheet's charts out. */
191
+ export interface ChartArrangement {
192
+ /** charts across; 2 by default */
193
+ columns?: number;
194
+ /** each chart's size, in points (Excel's 360 by 216 by default) or in cells */
195
+ size?: {width: number; height: number} | {cols: number; rows: number};
196
+ /** empty cells between charts; 1 by default */
197
+ gap?: number;
198
+ /** the top-left cell of the first chart; below everything on the sheet by default */
199
+ start?: string;
200
+ /** the charts to lay out, by place or name; all of the sheet's by default */
201
+ charts?: Array<number | string>;
202
+ }
203
+
204
+ /**
205
+ * The options of `Worksheet.addChart` for a classic chart: its type, series, axes, labels, layout and
206
+ * formatting.
207
+ */
208
+ export interface ChartProperties {
209
+ /**
210
+ * The chart's type: a family such as `bar` or `line`, or an entry of Excel's Insert Chart gallery such as
211
+ * `clusteredColumn`.
212
+ */
213
+ type: ChartType | ChartGalleryName;
214
+ /**
215
+ * How the series of the plot group relate to one another, such as `clustered`, `stacked` or
216
+ * `percentStacked`; the values allowed depend on the type.
217
+ */
218
+ subType?: ChartSubType;
219
+ /**
220
+ * Where the chart sits on the sheet: the same forms `addImage` accepts, or
221
+ * 'auto' ({auto: {...}}) to leave it to the library: whole cells beside the
222
+ * chart's data, over no cell with a value, merged range, table, image or
223
+ * other chart, worked out when the workbook is written.
224
+ */
225
+ range: string | 'auto' | {auto: ChartAutoPlacement} | ({editAs?: string} & ImageRange) | ({editAs?: string} & ImagePosition);
226
+ /** defaults to `Chart N` */
227
+ name?: string;
228
+ /** true, or a title with no words, shows Excel's own ("Chart Title", or a lone series' name) */
229
+ title?: string | true | ChartTitle;
230
+ /** true is a legend on the right, or where a quickStyle or quickLayout puts it */
231
+ legend?: boolean | ChartLegendPosition | ChartLegend;
232
+ /** default categories for every series */
233
+ categories?: string;
234
+ /**
235
+ * The series the chart plots, one for each set of values.
236
+ */
237
+ series: ChartSeries[];
238
+
239
+ /**
240
+ * The category axis, the one the categories run along.
241
+ */
242
+ categoryAxis?: ChartAxis;
243
+ /**
244
+ * The value axis, the one the values are scaled along.
245
+ */
246
+ valueAxis?: ChartAxis;
247
+ /** only used when a series sets `axis: 'secondary'` */
248
+ secondaryValueAxis?: ChartAxis;
249
+ /**
250
+ * The hidden category axis the secondary value axis crosses. It takes the
251
+ * primary category axis's kind, and its tick marks unless given its own;
252
+ * nothing else about it shows.
253
+ */
254
+ secondaryCategoryAxis?: Pick<ChartAxis, 'majorTickMark'>;
255
+ /**
256
+ * The depth axis of a 3-D chart, along which its series sit.
257
+ */
258
+ seriesAxis?: ChartAxis;
259
+
260
+ /**
261
+ * The data labels of every series; a series can set its own `dataLabels`.
262
+ */
263
+ dataLabels?: ChartDataLabels;
264
+ /**
265
+ * The plot area, where the data is drawn, with its fill, outline and `layout`. The layout's box is the
266
+ * plot's inner area, where the axes are, unless `target` is `outer`.
267
+ */
268
+ plotArea?: ChartShapeFormat & {
269
+ spPr?: any;
270
+ /** the plot's inner box (where the axes are) unless target is 'outer' */
271
+ layout?: ChartLayout & {target?: 'inner' | 'outer'};
272
+ };
273
+ /**
274
+ * The chart area, the frame the whole chart is drawn in, with its fill and outline.
275
+ */
276
+ chartArea?: ChartShapeFormat & {spPr?: any};
277
+ /** the data table under the plot; each switch is on unless turned off */
278
+ dataTable?:
279
+ | boolean
280
+ | (ChartShapeFormat & {
281
+ horizontalBorders?: boolean;
282
+ verticalBorders?: boolean;
283
+ outline?: boolean;
284
+ legendKeys?: boolean;
285
+ font?: ChartFont;
286
+ /** under a chart style, the text's direction written out (rtl="0" for false), as Quick Layout 5 does */
287
+ rightToLeft?: boolean;
288
+ });
289
+ /** 3-D charts: the floor, and the walls (both, or one at a time) */
290
+ floor?: ChartSurface;
291
+ /**
292
+ * The walls of a 3-D chart, both the side and the back wall; `sideWall` and `backWall` set one each.
293
+ */
294
+ walls?: ChartSurface;
295
+ /**
296
+ * The side wall of a 3-D chart. `walls` sets both walls.
297
+ */
298
+ sideWall?: ChartSurface;
299
+ /**
300
+ * The back wall of a 3-D chart. `walls` sets both walls.
301
+ */
302
+ backWall?: ChartSurface;
303
+ /**
304
+ * Whether the corners of the chart area are rounded.
305
+ */
306
+ roundedCorners?: boolean;
307
+ /** what the chart refuses to let a user change once its sheet is protected */
308
+ protection?: ChartProtection;
309
+ /** how the chart prints on its own */
310
+ printSettings?: ChartPrintSettings;
311
+ /**
312
+ * Excel's Properties choices: move and size with cells, move but don't
313
+ * size, or neither. The anchor's own names (twoCell, oneCell) are taken too.
314
+ */
315
+ placement?: 'moveAndSize' | 'move' | 'absolute' | 'twoCell' | 'oneCell';
316
+ /** false leaves the chart editable on a protected sheet */
317
+ locked?: boolean;
318
+ /** false leaves the chart out when the sheet is printed */
319
+ print?: boolean;
320
+ /** a string is the description, which Excel's Alt Text pane edits */
321
+ altText?: string | {title?: string; description?: string};
322
+ /** false plots data in hidden rows and columns too */
323
+ plotVisibleOnly?: boolean;
324
+ /**
325
+ * How empty cells are plotted: `gap` (the default), `zero`, or `span`, which joins the points either side of
326
+ * them.
327
+ */
328
+ displayBlanksAs?: 'gap' | 'zero' | 'span';
329
+ /**
330
+ * Excel's "Show #N/A as an empty cell", which its Insert ribbon switches on;
331
+ * left out, a #N/A is drawn as Excel drew it before the setting existed
332
+ */
333
+ showNaAsBlank?: boolean;
334
+ /** the editing language Excel stamps on the chart, en-US unless given */
335
+ lang?: string;
336
+ /** show labels on values past the value axis maximum */
337
+ showDataLabelsOverMax?: boolean;
338
+ /** built-in chart style, 1..48 */
339
+ style?: number;
340
+ /**
341
+ * A style from Excel's Chart Styles gallery, 201 to 352. It formats every
342
+ * element the chart has (series, markers, axes, gridlines, titles, legend,
343
+ * labels, the data table, trendlines, error bars and the chart and plot
344
+ * areas) as Excel does, and anything set here is laid over it. What a
345
+ * style does besides formatting (turning labels or gridlines on, moving the
346
+ * legend) is left to the other options. Without one, the chart has style
347
+ * 201's look.
348
+ */
349
+ chartStyle?: number;
350
+ /**
351
+ * A palette from Excel's Change Colours gallery, by its name there or its
352
+ * colours part's id (10 to 26). Every series (or, on a pie, every point) is
353
+ * given the palette's colour, as Excel gives it: a monochromatic palette
354
+ * spreads one colour from darker to lighter, by how many series there are.
355
+ * Refused beside `styleColors`, which leaves the series colours to Excel's
356
+ * automatic ones.
357
+ */
358
+ palette?: ChartPalette | number;
359
+ /**
360
+ * An item of Excel's Chart Styles gallery for this type, by the number Excel
361
+ * gives it ("Style 4" is 4): its recipe (chartStyle) and what choosing it
362
+ * changes besides, as Excel does it (labels, where the legend
363
+ * goes, gridlines, an axis deleted, the gap between bars). The type must be
364
+ * a gallery name ('clusteredColumn', 'lineWithMarkers' ...). A style moves
365
+ * a legend the chart has and gives none to a chart without: `legend: true`
366
+ * is one where the style puts it. A chart of one series takes the gallery
367
+ * Excel offers one series (a scatter's Style 8 is then recipe 247).
368
+ * Anything set here wins.
369
+ */
370
+ quickStyle?: number;
371
+ /**
372
+ * An item of Excel's Quick Layout gallery for this type ("Layout 5" is 5):
373
+ * which titles, legend, labels, gridlines and data table the chart has, and
374
+ * where, whatever it had. Laid over quickStyle where both set the same
375
+ * thing; anything set here wins over both (`legend: true` takes the
376
+ * layout's place for it).
377
+ */
378
+ quickLayout?: number;
379
+
380
+ /** bar and bar3D */
381
+ barDirection?: 'col' | 'bar';
382
+ /**
383
+ * The plot group's settings. null leaves one out, even the value the
384
+ * chart's family would write, as Excel leaves overlap out under some of its
385
+ * styles and layouts; a chart read back says null where its file had none.
386
+ */
387
+ gapWidth?: number | null;
388
+ /**
389
+ * The overlap of the bars of a bar or column chart's series, in percent of a bar's width; `null` leaves it
390
+ * out.
391
+ */
392
+ overlap?: number | null;
393
+ /**
394
+ * Whether each point of a single series is given a colour of its own.
395
+ */
396
+ varyColors?: boolean;
397
+ /** doughnut */
398
+ holeSize?: number | null;
399
+ /** pie and doughnut */
400
+ firstSliceAngle?: number;
401
+ /** bubble */
402
+ bubbleScale?: number | null;
403
+ /**
404
+ * What the size of a bubble stands for: its `area` (the default) or its `w` (width). `null` leaves it out.
405
+ */
406
+ sizeRepresents?: 'area' | 'w' | null;
407
+ /** surface */
408
+ wireframe?: boolean;
409
+ /** 3D bar/line/area - depth gap between series, percent; null leaves it out */
410
+ gapDepth?: number | null;
411
+ /** bar3D - default bar shape for the whole group */
412
+ shape?: 'cone' | 'coneToMax' | 'box' | 'cylinder' | 'pyramid' | 'pyramidToMax';
413
+ /** ofPie - whether the secondary plot is a pie or a bar */
414
+ ofPieType?: 'pie' | 'bar';
415
+ /**
416
+ * ofPie - how points are assigned to the secondary plot. 'auto' is rejected
417
+ * at addChart time, because Excel refuses an explicit auto; 'cust' needs
418
+ * `secondPlotPoints`.
419
+ */
420
+ splitType?: 'percent' | 'pos' | 'val' | 'cust';
421
+ /** ofPie - the threshold for splitType ('pos': last N points, 'percent'/'val': cutoff) */
422
+ splitPos?: number;
423
+ /** ofPie - the points drawn in the secondary plot, counted from 0; makes the split custom */
424
+ secondPlotPoints?: number[];
425
+ /** surface - the fill of each height band, by band index */
426
+ bands?: Array<{index: number; fill?: any; line?: any}>;
427
+ /** false deletes the title Excel would draw from a lone series' name */
428
+ autoTitle?: boolean;
429
+ /**
430
+ * Leave the series colours to the chart style, as a chart made through
431
+ * Excel's object model does, so they follow Change Colors in Excel
432
+ */
433
+ styleColors?: boolean;
434
+ /** line - the group's show-markers flag; derived from the series when not set */
435
+ markers?: boolean;
436
+ /** stock and line - the bars between the first and last series, each with a fill of its own */
437
+ upDownBars?: boolean | {gapWidth?: number; up?: ChartShapeFormat; down?: ChartShapeFormat};
438
+ /**
439
+ * stock and line - vertical lines from the highest to the lowest value.
440
+ * Line options draw them with a line of their own; false turns off a
441
+ * stock chart's.
442
+ */
443
+ hiLowLines?: boolean | ChartLine;
444
+ /** line, area and stock - lines from each point down to the category axis */
445
+ dropLines?: boolean | ChartLine;
446
+ /** stacked bar and ofPie - lines joining the series */
447
+ serLines?: boolean | ChartLine;
448
+ /** ofPie - secondary plot size as a percentage of the primary, 5..200 */
449
+ secondPieSize?: number;
450
+ /**
451
+ * 3D families. Laid over the view the family has anyway; null leaves a
452
+ * setting out, as a chart read back says where its file had none.
453
+ */
454
+ view3D?: {
455
+ rotX?: number | null;
456
+ /** the plot's height as a percentage of its width, 5..500 */
457
+ hPercent?: number | null;
458
+ rotY?: number | null;
459
+ depthPercent?: number | null;
460
+ rAngAx?: boolean | null;
461
+ perspective?: number | null;
462
+ };
463
+
464
+ /**
465
+ * `auto` recomputes the cached values from the live cells on every write (the
466
+ * default for charts you create), `preserve` replays the values read from a file,
467
+ * and `none` writes references with no cache at all.
468
+ */
469
+ cache?: 'auto' | 'preserve' | 'none';
470
+
471
+ /**
472
+ * Throw at addChart time instead of silently correcting: any value that would
473
+ * be clamped or dropped at render time (see `Chart.warnings`) becomes an error.
474
+ */
475
+ strict?: boolean;
476
+ }
477
+
478
+ /** a PivotChart's: a chart's but its series and categories, which its PivotTable gives */
479
+ export type PivotChartProperties = Omit<ChartProperties, 'series' | 'categories' | 'range'> & {range?: ChartProperties['range']};