@trebco/treb 32.4.1 → 32.6.4

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.
Files changed (31) hide show
  1. package/README.md +0 -6
  2. package/dist/treb-spreadsheet.mjs +12 -12
  3. package/package.json +2 -2
  4. package/treb-base-types/src/import.ts +14 -10
  5. package/treb-calculator/src/calculator.ts +5 -0
  6. package/treb-charts/src/chart-types.ts +2 -0
  7. package/treb-charts/src/chart-utils.ts +45 -4
  8. package/treb-charts/src/default-chart-renderer.ts +84 -24
  9. package/treb-data-model/src/sheet.ts +9 -0
  10. package/treb-embed/src/embedded-spreadsheet.ts +2 -2
  11. package/treb-embed/style/tab-bar.scss +1 -0
  12. package/treb-export/src/{drawing2/drawing2.ts → drawing/drawing.ts} +2 -2
  13. package/treb-export/src/export.ts +11 -11
  14. package/treb-export/src/import.ts +216 -20
  15. package/treb-export/src/metadata.ts +187 -0
  16. package/treb-export/src/{workbook-sheet2.ts → workbook-sheet.ts} +2 -2
  17. package/treb-export/src/{workbook-style2.ts → workbook-style.ts} +1 -1
  18. package/treb-export/src/{workbook-theme2.ts → workbook-theme.ts} +0 -2
  19. package/treb-export/src/{workbook2.ts → workbook.ts} +157 -11
  20. package/treb-grid/src/types/grid.ts +9 -9
  21. package/treb-grid/src/types/grid_base.ts +2 -1
  22. package/treb-grid/src/types/grid_command.ts +3 -0
  23. package/treb-grid/src/types/tab_bar.ts +36 -7
  24. /package/treb-export/src/{drawing2 → drawing}/bubble-chart-template.ts +0 -0
  25. /package/treb-export/src/{drawing2 → drawing}/chart-template-components2.ts +0 -0
  26. /package/treb-export/src/{drawing2/chart2.ts → drawing/chart.ts} +0 -0
  27. /package/treb-export/src/{drawing2 → drawing}/column-chart-template2.ts +0 -0
  28. /package/treb-export/src/{drawing2 → drawing}/donut-chart-template2.ts +0 -0
  29. /package/treb-export/src/{drawing2 → drawing}/embedded-image.ts +0 -0
  30. /package/treb-export/src/{drawing2 → drawing}/scatter-chart-template2.ts +0 -0
  31. /package/treb-export/src/{shared-strings2.ts → shared-strings.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trebco/treb",
3
- "version": "32.4.1",
3
+ "version": "32.6.4",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "homepage": "https://treb.app",
6
6
  "repository": {
@@ -16,7 +16,7 @@
16
16
  "@types/uzip": "^0.20201231.0",
17
17
  "base64-js": "^1.5.1",
18
18
  "cssnano": "^7.0.4",
19
- "esbuild": "^0.24.0",
19
+ "esbuild": "^0.25.0",
20
20
  "eslint": "^9.9.1",
21
21
  "fast-xml-parser": "^4.0.7",
22
22
  "html-minifier-terser": "^7.2.0",
@@ -27,18 +27,22 @@ import type { Table } from './table';
27
27
  import type { DataValidation, AnnotationType, ConditionalFormat } from 'treb-data-model';
28
28
 
29
29
  export interface CellParseResult {
30
- row: number,
31
- column: number,
30
+ row: number;
31
+ column: number;
32
32
  type: SerializedValueType; // ValueType,
33
- value: number|string|undefined|boolean,
34
- calculated?: number|string|undefined|boolean,
33
+ value: number|string|undefined|boolean;
34
+ calculated?: number|string|undefined|boolean;
35
35
  calculated_type?: SerializedValueType; // ValueType,
36
- style_ref?: number,
37
- hyperlink?: string,
38
- validation?: DataValidation,
39
- merge_area?: IArea,
40
- area?: IArea,
41
- table?: Table,
36
+ style_ref?: number;
37
+ hyperlink?: string;
38
+ validation?: DataValidation;
39
+ merge_area?: IArea;
40
+ area?: IArea;
41
+
42
+ /** dynamic arrays */
43
+ spill?: IArea;
44
+
45
+ table?: Table;
42
46
  }
43
47
 
44
48
  export interface AnchoredAnnotation {
@@ -1221,11 +1221,16 @@ export class Calculator extends Graph {
1221
1221
  public AttachSpillData(area: Area, cells?: Cells) {
1222
1222
 
1223
1223
  if (!cells) {
1224
+
1225
+ // can we assume active sheet here? actually I guess not, we'll
1226
+ // need to set that...
1227
+
1224
1228
  const sheet = area.start.sheet_id ? this.model.sheets.Find(area.start.sheet_id) : undefined;
1225
1229
  cells = sheet?.cells;
1226
1230
  }
1227
1231
 
1228
1232
  if (!cells) {
1233
+ console.info({area, cells});
1229
1234
  throw new Error('invalid sheet ID in attach spill data');
1230
1235
  }
1231
1236
 
@@ -207,6 +207,7 @@ export interface HistogramData extends ColumnDataBaseType {
207
207
  export interface LineBaseData extends ChartDataBaseType {
208
208
  series?: NumberOrUndefinedArray[];
209
209
  series2?: SeriesType[];
210
+ stacked_series?: SeriesType[];
210
211
  scale: RangeScale;
211
212
  x_scale?: RangeScale;
212
213
  titles?: string[];
@@ -262,6 +263,7 @@ export interface BarData extends LineBaseData {
262
263
  type: 'bar';
263
264
  round?: boolean;
264
265
  space?: number;
266
+ stacked?: boolean;
265
267
  }
266
268
 
267
269
  export interface DonutDataBaseType extends ChartDataBaseType {
@@ -1001,8 +1001,11 @@ export const CreateColumnChart = (
1001
1001
 
1002
1002
  const [data, labels, args_title, args_options] = args;
1003
1003
 
1004
- const series: SeriesType[] = TransformSeriesData(data);
1005
- const common = CommonData(series);
1004
+ const options = args_options?.toString() || undefined;
1005
+ const stacked = /stacked/i.test(options || '');
1006
+
1007
+ let series: SeriesType[] = TransformSeriesData(data);
1008
+ let common = CommonData(series);
1006
1009
 
1007
1010
  let category_labels: string[] | undefined;
1008
1011
 
@@ -1041,15 +1044,50 @@ export const CreateColumnChart = (
1041
1044
 
1042
1045
  }
1043
1046
 
1047
+ let stacked_series: SeriesType[]|undefined = undefined;
1048
+ const legend = common.legend; // in case we munge it
1049
+
1050
+ if (stacked) {
1051
+ stacked_series = series;
1052
+
1053
+ const map: Map<number, number> = new Map();
1054
+ // const label_map: Map<number, string> = new Map();
1055
+
1056
+ for (const entry of series) {
1057
+ for (const [index, key] of entry.x.data.entries()) {
1058
+ if (key !== undefined) {
1059
+ const value = entry.y.data[index] || 0;
1060
+ map.set(key, value + (map.get(key) || 0));
1061
+ }
1062
+ }
1063
+ }
1064
+
1065
+ const x_data = Array.from(map.keys()).sort((a, b) => a - b);
1066
+ const y_data = x_data.map(key => map.get(key) || 0);
1067
+
1068
+ // console.info({stacked_series, map, x_data, y_data});
1069
+
1070
+ series = [{
1071
+ x: { data: x_data, format: stacked_series[0]?.x?.format },
1072
+ y: { data: y_data, format: stacked_series[0]?.y?.format },
1073
+ }];
1074
+
1075
+ series[0].x.range = ArrayMinMax(x_data);
1076
+ series[0].y.range = ArrayMinMax(y_data);
1077
+
1078
+ common = CommonData(series, Math.min(0, ...y_data));
1079
+
1080
+ }
1081
+
1044
1082
  const title = args_title?.toString() || undefined;
1045
- const options = args_options?.toString() || undefined;
1046
1083
 
1047
1084
  const chart_data = {
1048
1085
  type,
1049
- legend: common.legend,
1086
+ legend, // legend: common.legend,
1050
1087
  // legend_position: LegendPosition.right,
1051
1088
  legend_style: LegendStyle.marker,
1052
1089
  series2: series,
1090
+ stacked_series,
1053
1091
  scale: common.y.scale,
1054
1092
  title,
1055
1093
  y_labels: type === 'bar' ? category_labels : common.y.labels, // swapped
@@ -1057,6 +1095,9 @@ export const CreateColumnChart = (
1057
1095
  };
1058
1096
 
1059
1097
  if (options) {
1098
+
1099
+ (chart_data as BarData).stacked = stacked;
1100
+
1060
1101
  (chart_data as BarData).round = /round/i.test(options);
1061
1102
  (chart_data as ChartDataBaseType).data_labels = /labels/i.test(options);
1062
1103
 
@@ -599,23 +599,33 @@ export class DefaultChartRenderer implements ChartRendererType {
599
599
  corners = [half_width, half_width, 0, 0];
600
600
  }
601
601
 
602
- for (let s = 0; s < series_count; s++) {
603
- const series = chart_data.series2[s];
604
- const color_index = typeof series.index === 'number' ? series.index : s + 1;
602
+ if (chart_data.stacked_series) {
605
603
 
606
- for (let i = 0; i < series.y.data.length; i++ ){
607
- const value = series.y.data[i];
608
- // const format = NumberFormatCache.Get(series.y.format || '0.00');
604
+ // step by group (stacked series)
605
+ for (let s = 0; s < chart_data.stacked_series[0].y.data.length; s++ ){
609
606
 
610
- if (typeof value === 'number') {
607
+ const x = (area.left + s * column_width + space) ; // + s * width;
608
+ let y = 0;
609
+
610
+ // now check each series, grab s-th value
611
+ for (let t = 0; t < chart_data.stacked_series.length; t++) {
612
+
613
+ const series = chart_data.stacked_series[t];
614
+ const color_index = typeof series.index === 'number' ? series.index : t + 1;
611
615
 
612
- // const x = Math.round(area.left + i * column_width + space) + s * width;
613
- const x = (area.left + i * column_width + space) + s * width;
614
-
615
616
  let height = 0;
616
- let y = 0;
617
617
  // let negative = false;
618
618
 
619
+ const value = (series.y.data[s] || 0);
620
+
621
+ if (t === 0) {
622
+ y = Math.min(chart_data.scale.min || 0, value);
623
+ }
624
+
625
+ height = Util.ApplyScale(value, area.height, chart_data.scale);
626
+ const base = area.bottom - height - Util.ApplyScale(y, area.height, chart_data.scale);
627
+
628
+ /*
619
629
  if (zero) {
620
630
  if (value > 0) {
621
631
  height = Util.ApplyScale(value + chart_data.scale.min, area.height, chart_data.scale);
@@ -631,27 +641,77 @@ export class DefaultChartRenderer implements ChartRendererType {
631
641
  height = Util.ApplyScale(value, area.height, chart_data.scale);
632
642
  y = area.bottom - height;
633
643
  }
644
+ */
634
645
 
635
- // const bar_title = chart_data.titles ? chart_data.titles[i] : undefined;
636
- const bar_title = undefined;
646
+ let bar_title = undefined;
647
+ let label = undefined;
648
+ let label_point = undefined;
637
649
 
638
- if (height) {
650
+ this.renderer.RenderRectangle(new Area(
651
+ x, base, x + width, base + height,
652
+ ), corners, ['chart-column', `series-${color_index}`], bar_title || undefined, label, label_point);
639
653
 
640
- const label = (chart_data.data_labels && !!series.y.labels) ? series.y.labels[i] : '';
641
- const label_point = {
642
- x: Math.round(x + width / 2),
643
- y: Math.round(y - 10),
644
- };
654
+ y += value;
645
655
 
646
- this.renderer.RenderRectangle(new Area(
647
- x, y, x + width, y + height,
648
- ), corners, ['chart-column', `series-${color_index}`], bar_title || undefined, label, label_point);
649
- }
650
656
  }
657
+
658
+
651
659
  }
660
+ }
661
+ else {
662
+ for (let s = 0; s < series_count; s++) {
663
+ const series = chart_data.series2[s];
664
+ const color_index = typeof series.index === 'number' ? series.index : s + 1;
665
+
666
+ for (let i = 0; i < series.y.data.length; i++ ){
667
+ const value = series.y.data[i];
668
+
669
+ if (typeof value === 'number') {
670
+
671
+ // const x = Math.round(area.left + i * column_width + space) + s * width;
672
+ const x = (area.left + i * column_width + space) + s * width;
673
+
674
+ let height = 0;
675
+ let y = 0;
676
+ // let negative = false;
677
+
678
+ if (zero) {
679
+ if (value > 0) {
680
+ height = Util.ApplyScale(value + chart_data.scale.min, area.height, chart_data.scale);
681
+ y = area.bottom - height - zero;
682
+ }
683
+ else {
684
+ height = Util.ApplyScale(chart_data.scale.min - value, area.height, chart_data.scale);
685
+ y = area.bottom - zero; // // area.bottom - height - zero;
686
+ // negative = true;
687
+ }
688
+ }
689
+ else {
690
+ height = Util.ApplyScale(value, area.height, chart_data.scale);
691
+ y = area.bottom - height;
692
+ }
693
+
694
+ // const bar_title = chart_data.titles ? chart_data.titles[i] : undefined;
695
+ const bar_title = undefined;
696
+
697
+ if (height) {
652
698
 
699
+ const label = (chart_data.data_labels && !!series.y.labels) ? series.y.labels[i] : '';
700
+ const label_point = {
701
+ x: Math.round(x + width / 2),
702
+ y: Math.round(y - 10),
703
+ };
704
+
705
+ this.renderer.RenderRectangle(new Area(
706
+ x, y, x + width, y + height,
707
+ ), corners, ['chart-column', `series-${color_index}`], bar_title || undefined, label, label_point);
708
+ }
709
+ }
710
+ }
711
+
712
+ }
653
713
  }
654
-
714
+
655
715
  }
656
716
 
657
717
  }
@@ -3011,6 +3011,15 @@ export class Sheet {
3011
3011
  this.name = data.name || ''; // wtf is this?
3012
3012
  }
3013
3013
 
3014
+ // patching from import
3015
+ for (const cell of this.cells.Iterate()) {
3016
+ if (cell.spill) {
3017
+ if (!cell.spill.start.sheet_id) {
3018
+ cell.spill.SetSheetID(this.id);
3019
+ }
3020
+ }
3021
+ }
3022
+
3014
3023
  if (data.tab_color) {
3015
3024
  this.tab_color = data.tab_color;
3016
3025
  }
@@ -1532,9 +1532,9 @@ export class EmbeddedSpreadsheet<USER_DATA_TYPE = unknown> {
1532
1532
  }
1533
1533
 
1534
1534
  /**
1535
- * @internal
1535
+ *
1536
1536
  */
1537
- public ConditionalFormatDataBar(range: RangeReference|undefined, options?: ConditionalFormatDataBarOptions): ConditionalFormat {
1537
+ public ConditionalFormatDataBars(range: RangeReference|undefined, options?: ConditionalFormatDataBarOptions): ConditionalFormat {
1538
1538
 
1539
1539
  const area = this.RangeOrSelection(range, 'invalid range (no selection)');
1540
1540
 
@@ -68,6 +68,7 @@
68
68
  & .treb-spreadsheet-tabs>li {
69
69
  display: inline-block;
70
70
  position: relative;
71
+ margin: 0;
71
72
  }
72
73
 
73
74
  & .treb-spreadsheet-tabs>li,
@@ -21,8 +21,8 @@
21
21
 
22
22
  import type { ImageOptions } from './embedded-image';
23
23
  import { EmbeddedImage } from './embedded-image';
24
- import type { ChartOptions} from './chart2';
25
- import { Chart} from './chart2';
24
+ import type { ChartOptions} from './chart';
25
+ import { Chart} from './chart';
26
26
  import type { RelationshipMap} from '../relationship';
27
27
  import { AddRel } from '../relationship';
28
28
  import type { DOMContent } from '../xml-utils';
@@ -44,10 +44,10 @@ import { Area, Cells, ValueType, Style, IsHTMLColor, IsThemeColor, ThemeColorInd
44
44
  import type { XmlBuilderOptions} from 'fast-xml-parser';
45
45
  import { XMLParser } from 'fast-xml-parser';
46
46
 
47
- import { SharedStrings } from './shared-strings2';
48
- import type { XlColor, BorderEdge } from './workbook-style2';
49
- import { StyleCache } from './workbook-style2';
50
- import { Theme } from './workbook-theme2';
47
+ import { SharedStrings } from './shared-strings';
48
+ import type { XlColor, BorderEdge } from './workbook-style';
49
+ import { StyleCache } from './workbook-style';
50
+ import { Theme } from './workbook-theme';
51
51
 
52
52
  import type { RelationshipMap} from './relationship';
53
53
  import { AddRel } from './relationship';
@@ -57,12 +57,12 @@ import type { UnitAddress, UnitRange, ExpressionUnit} from 'treb-parser';
57
57
  import { Parser } from 'treb-parser';
58
58
 
59
59
  // FIXME: move
60
- import type { ChartOptions } from './drawing2/chart2';
61
- import { Chart } from './drawing2/chart2';
62
- import type { ImageOptions } from './drawing2/embedded-image';
63
- import type { TwoCellAnchor } from './drawing2/drawing2';
64
- import { Drawing } from './drawing2/drawing2';
65
- import { ConditionalFormatOperators, type TableDescription, type TableFooterType } from './workbook2';
60
+ import type { ChartOptions } from './drawing/chart';
61
+ import { Chart } from './drawing/chart';
62
+ import type { ImageOptions } from './drawing/embedded-image';
63
+ import type { TwoCellAnchor } from './drawing/drawing';
64
+ import { Drawing } from './drawing/drawing';
65
+ import { ConditionalFormatOperators, type TableDescription, type TableFooterType } from './workbook';
66
66
  import type { AnnotationData } from 'treb-data-model/src/annotation';
67
67
  import { ZipWrapper } from './zip-wrapper';
68
68
 
@@ -179,7 +179,7 @@ export class Exporter {
179
179
  }
180
180
 
181
181
  const parsed = Base64JS.toByteArray(template);
182
- this.zip = new ZipWrapper(parsed);
182
+ this.zip = new ZipWrapper(parsed.buffer as ArrayBuffer);
183
183
 
184
184
  }
185
185