@trebco/treb 30.12.0 → 30.16.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.
@@ -61,8 +61,10 @@ export const ArrayMinMax = (data: number[]) => {
61
61
 
62
62
  export const ReadSeries = (data: ReferenceSeries['value']): SeriesType => {
63
63
 
64
- const [label, x, y, z, index, subtype, data_labels] = data;
64
+ // const label, x, y, z, index, subtype, data_labels] = data;
65
65
 
66
+ const { label, x, y, z, index, subtype, data_labels, axis } = data;
67
+
66
68
  // series type is (now)
67
69
  //
68
70
  // [0] label, string
@@ -79,6 +81,10 @@ export const ReadSeries = (data: ReferenceSeries['value']): SeriesType => {
79
81
  y: { data: [] },
80
82
  };
81
83
 
84
+ if (typeof axis === 'number') {
85
+ series.axis = axis;
86
+ }
87
+
82
88
  if (typeof index === 'number') {
83
89
  series.index = index;
84
90
  }
@@ -431,10 +437,22 @@ export const CommonData = (series: SeriesType[], y_floor?: number, y_ceiling?: n
431
437
 
432
438
  let x_format = '';
433
439
  let y_format = '';
440
+ let y2_format = '';
434
441
 
435
442
  for (const entry of series) {
436
- if (entry.y.format && !y_format) { y_format = entry.y.format; }
437
- if (entry.x.format && !x_format) { x_format = entry.x.format; }
443
+ if (entry.axis) {
444
+ if (entry.y.format && !y2_format) {
445
+ y2_format = entry.y.format;
446
+ }
447
+ }
448
+ else {
449
+ if (entry.y.format && !y_format) {
450
+ y_format = entry.y.format;
451
+ }
452
+ }
453
+ if (entry.x.format && !x_format) {
454
+ x_format = entry.x.format;
455
+ }
438
456
  }
439
457
 
440
458
  let legend: Array<{ label: string, index?: number }> | undefined; // string[]|undefined;
@@ -449,13 +467,25 @@ export const CommonData = (series: SeriesType[], y_floor?: number, y_ceiling?: n
449
467
  let x_min = Math.min.apply(0, x.map(test => test.x.range?.min || 0));
450
468
  let x_max = Math.max.apply(0, x.map(test => test.x.range?.max || 0));
451
469
 
452
- // const y = series.filter(test => test.y.range);
453
- let y_min = Math.min.apply(0, x.map(test => test.y.range?.min || 0));
454
- let y_max = Math.max.apply(0, x.map(test => test.y.range?.max || 0));
470
+ const x1 = x.filter(test => !test.axis);
471
+ const x2 = x.filter(test => test.axis);
472
+
473
+ let y_min = Math.min.apply(0, x1.map(test => test.y.range?.min || 0));
474
+ let y_max = Math.max.apply(0, x1.map(test => test.y.range?.max || 0));
475
+
476
+ let y2_min = -1;
477
+ let y2_max = -1;
478
+
479
+ if (x2.length) {
480
+ y2_min = Math.min.apply(0, x2.map(test => test.y.range?.min || 0));
481
+ y2_max = Math.max.apply(0, x2.map(test => test.y.range?.max || 0));
482
+ }
455
483
 
456
484
  // if there's z data (used for bubble size), adjust x/y min/max to
457
485
  // account for the z size so bubbles are contained within the grid
458
486
 
487
+ // this can't be used with axis (atm)
488
+
459
489
  for (const subseries of series) {
460
490
  if (subseries.z) {
461
491
  for (const [index, z] of subseries.z.data.entries()) {
@@ -496,9 +526,29 @@ export const CommonData = (series: SeriesType[], y_floor?: number, y_ceiling?: n
496
526
 
497
527
  const x_scale = Util.Scale(x_min, x_max, 7);
498
528
  const y_scale = Util.Scale(y_min, y_max, 7);
529
+ const y2_scale = Util.Scale(y2_min, y2_max, 7);
530
+
531
+ if (y2_min !== y2_max && y_scale && y2_scale) {
532
+ if (y_scale.count !== y2_scale.count) {
533
+ const max = Math.max(y_scale.count, y2_scale.count);
534
+ const target = y_scale.count < max ? y_scale : y2_scale;
535
+ for (let i = target.count; i < max; i += 2) {
536
+ // add high
537
+ target.max += target.step;
538
+ target.count++;
539
+
540
+ if (target.count < max) {
541
+ // add low
542
+ target.min -= target.step;
543
+ target.count++;
544
+ }
545
+ }
546
+ }
547
+ }
499
548
 
500
549
  let x_labels: string[] | undefined;
501
550
  let y_labels: string[] | undefined;
551
+ let y2_labels: string[] | undefined;
502
552
 
503
553
  if (x_format) {
504
554
  x_labels = [];
@@ -509,10 +559,13 @@ export const CommonData = (series: SeriesType[], y_floor?: number, y_ceiling?: n
509
559
  }
510
560
 
511
561
  if (!y_format && auto_number_format) {
512
- // y_format = default_number_format;
513
562
  y_format = AutoFormat(y_scale);
514
563
  }
515
564
 
565
+ if (!y2_format && auto_number_format) {
566
+ y2_format = AutoFormat(y2_scale);
567
+ }
568
+
516
569
  if (y_format) {
517
570
  y_labels = [];
518
571
  const format = NumberFormatCache.Get(y_format);
@@ -520,8 +573,20 @@ export const CommonData = (series: SeriesType[], y_floor?: number, y_ceiling?: n
520
573
  y_labels.push(format.Format(y_scale.min + i * y_scale.step));
521
574
  }
522
575
  }
576
+ if (y2_format) {
577
+ y2_labels = [];
578
+ const format = NumberFormatCache.Get(y2_format);
579
+ for (let i = 0; i <= y2_scale.count; i++) {
580
+ y2_labels.push(format.Format(y2_scale.min + i * y2_scale.step));
581
+ }
582
+ }
523
583
 
524
- return {
584
+ const result: {
585
+ legend?: { label: string, index?: number }[],
586
+ x: { format: string, scale: RangeScale, labels?: string[] },
587
+ y: { format: string, scale: RangeScale, labels?: string[] },
588
+ y2?: { format: string, scale: RangeScale, labels?: string[] },
589
+ } = {
525
590
  x: {
526
591
  format: x_format,
527
592
  scale: x_scale,
@@ -535,6 +600,16 @@ export const CommonData = (series: SeriesType[], y_floor?: number, y_ceiling?: n
535
600
  legend,
536
601
  };
537
602
 
603
+ if (y2_min !== y2_max) {
604
+ result.y2 = {
605
+ format: y2_format,
606
+ scale: y2_scale,
607
+ labels: y2_labels,
608
+ };
609
+ }
610
+
611
+ return result;
612
+
538
613
  };
539
614
 
540
615
  const ApplyLabels = (series_list: SeriesType[], pattern: string, category_labels?: string[]): void => {
@@ -859,7 +934,6 @@ export const CreateScatterChart = (args: [UnionValue, string, string], style: 'p
859
934
  // transform).
860
935
 
861
936
  const series: SeriesType[] = TransformSeriesData(args[0]);
862
-
863
937
  const common = CommonData(series);
864
938
 
865
939
  const title = args[1]?.toString() || undefined;
@@ -878,6 +952,9 @@ export const CreateScatterChart = (args: [UnionValue, string, string], style: 'p
878
952
  y_scale: common.y.scale,
879
953
  y_labels: common.y.labels,
880
954
 
955
+ y2_scale: common.y2?.scale,
956
+ y2_labels: common.y2?.labels,
957
+
881
958
  lines: style === 'line', // true,
882
959
  points: style === 'plot',
883
960
 
@@ -175,6 +175,44 @@ export class DefaultChartRenderer implements ChartRendererType {
175
175
 
176
176
  }
177
177
 
178
+ if (chart_data.type === 'scatter2' && chart_data.y2_labels && chart_data.y2_labels.length && chart_data.y2_scale) {
179
+
180
+ const y2_labels: Array<{label: string; metrics: Metrics}> = [];
181
+ let max_width = 0;
182
+ let max_height = 0;
183
+
184
+ const scale = chart_data.y2_scale;
185
+
186
+ const count = scale.count + 1;
187
+
188
+ for (let i = 0; i < count; i++ ){
189
+ const metrics = this.renderer.MeasureText(chart_data.y2_labels[i], ['axis-label', 'y-axis-label']);
190
+ y2_labels.push({ label: chart_data.y2_labels[i], metrics });
191
+ max_width = Math.max(max_width, metrics.width);
192
+ max_height = Math.max(max_height, metrics.height);
193
+ }
194
+
195
+ /*
196
+ area.bottom = Math.round(area.bottom - max_height / 2);
197
+ area.top = Math.round(area.top + max_height / 2);
198
+
199
+ if (x_metrics.length) {
200
+ area.bottom -= (max_x_height + chart_margin.bottom);
201
+ }
202
+ if (x_metrics2.length) {
203
+ area.bottom -= (max_x_height2 + chart_margin.bottom);
204
+ }
205
+ if (extra_padding) {
206
+ area.bottom -= extra_padding;
207
+ }
208
+ */
209
+
210
+ this.renderer.RenderYAxis(area, area.right - max_width, y2_labels, ['axis-label', 'y-axis-label'], 'left');
211
+ area.right -= (max_width + chart_margin.left);
212
+ // area.left += (max_width + chart_margin.left);
213
+
214
+ }
215
+
178
216
  // now render x axis
179
217
 
180
218
  if (x_metrics.length && chart_data.x_labels?.length) {
@@ -318,11 +356,12 @@ export class DefaultChartRenderer implements ChartRendererType {
318
356
  }
319
357
 
320
358
  const index = typeof series.index === 'number' ? series.index : i + 1;
359
+
321
360
  this.renderer.RenderScatterSeries(area,
322
361
  series.x.data,
323
362
  series.y.data,
324
363
  chart_data.x_scale,
325
- chart_data.y_scale,
364
+ (series.axis && chart_data.y2_scale) ? chart_data.y2_scale : chart_data.y_scale,
326
365
  lines,
327
366
  points,
328
367
  !!chart_data.filled,
@@ -577,11 +577,11 @@ export class ChartRenderer {
577
577
  /**
578
578
  * render y axis labels; skips over labels to prevent overlap
579
579
  */
580
- public RenderYAxis(area: Area, left: number,
580
+ public RenderYAxis(area: Area, x: number,
581
581
  labels: Array<{
582
582
  label: string;
583
583
  metrics: Metrics;
584
- }>, classes?: string | string[]) {
584
+ }>, classes?: string | string[], align:'left'|'right' = 'right') {
585
585
 
586
586
  const count = labels.length;
587
587
  if (!count) return;
@@ -612,7 +612,7 @@ export class ChartRenderer {
612
612
  for (let i = 0; i < count; i += increment) {
613
613
  const label = labels[i];
614
614
  const y = Math.round(area.bottom - step * i + label.metrics.height / 4);
615
- this.RenderText(this.axis_group, label.label, 'right', { x: left, y }, classes);
615
+ this.RenderText(this.axis_group, label.label, align, { x, y }, classes);
616
616
  }
617
617
 
618
618
  }
@@ -2611,6 +2611,19 @@ export class EmbeddedSpreadsheet<USER_DATA_TYPE = unknown> {
2611
2611
  this.grid.ShowSheet(index, !hide);
2612
2612
  }
2613
2613
 
2614
+ /** list sheets in the model */
2615
+ public ListSheets() {
2616
+ return this.model.sheets.list.map(sheet => {
2617
+ const entry: { name: string, hidden?: boolean } = {
2618
+ name: sheet.name,
2619
+ };
2620
+ if (!sheet.visible) {
2621
+ entry.hidden = true;
2622
+ }
2623
+ return entry;
2624
+ });
2625
+ }
2626
+
2614
2627
  /**
2615
2628
  * Show or hide sheet. This method is deprecated because it's ambiguous.
2616
2629
  * To set a sheet's visibility, use `HideSheet`. To activate a sheet, use
@@ -7524,7 +7524,7 @@ export class Grid extends GridBase {
7524
7524
  if (typeof column === 'number') column = [column];
7525
7525
 
7526
7526
  const auto = typeof command.width !== 'number';
7527
- const width = Math.round(command.width || 0 / this.scale)
7527
+ const width = Math.round((command.width || 0) / this.scale);
7528
7528
 
7529
7529
  if (auto) {
7530
7530
  for (const entry of column) {