@tetacom/svg-charts 1.4.1 → 1.4.3

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.
@@ -84,7 +84,7 @@ var ScaleType;
84
84
  ScaleType[ScaleType["pow"] = 3] = "pow";
85
85
  ScaleType[ScaleType["sqrt"] = 4] = "sqrt";
86
86
  ScaleType[ScaleType["time"] = 5] = "time";
87
- ScaleType[ScaleType["category"] = 6] = "category";
87
+ ScaleType[ScaleType["band"] = 6] = "band";
88
88
  })(ScaleType || (ScaleType = {}));
89
89
 
90
90
  const defaultAxisConfig = {
@@ -137,8 +137,6 @@ const defaultSeriesConfig = () => ({
137
137
 
138
138
  class ChartService {
139
139
  constructor() {
140
- // public zoomInstance: Observable<ZoomService>;
141
- // public brushInstance: Observable<BrushService>;
142
140
  this.config$ = new BehaviorSubject(defaultChartConfig());
143
141
  this.size$ = new BehaviorSubject(null);
144
142
  this.pointerMove$ = new Subject();
@@ -349,8 +347,6 @@ class ChartService {
349
347
  return config;
350
348
  }
351
349
  }
352
- // private zoomInstance$ = new Subject<ZoomService>();
353
- // private brushInstance$ = new Subject<BrushService>();
354
350
  ChartService._hiddenSeriesPostfix = 'hidden_series';
355
351
  ChartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ChartService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
356
352
  ChartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ChartService, providedIn: 'root' });
@@ -484,8 +480,14 @@ class AxisSizeBuilder {
484
480
  if (settings.orientation === AxisOrientation.y) {
485
481
  const formatter = settings.options.tickFormat || settings.defaultFormatter();
486
482
  finalPadding += settings.options.title ? this.titlePadding : 0;
487
- const scale = settings.defaultScale();
488
- const ticks = scale().domain(settings.extremes).ticks(20);
483
+ const scale = settings.defaultScale()();
484
+ scale.domain(settings.extremes);
485
+ if (settings.options.scaleType.type === ScaleType.band) {
486
+ scale.ticks = (ticks) => {
487
+ return scale.domain();
488
+ };
489
+ }
490
+ const ticks = scale.ticks(20);
489
491
  const maxElementLengthIndex = maxIndex(ticks, (_) => formatter(_).length);
490
492
  finalPadding += getTextWidth(formatter(ticks[maxElementLengthIndex]), this.backupRatio);
491
493
  }
@@ -514,6 +516,9 @@ class ExtremesBuilder {
514
516
  }, []);
515
517
  const accessor = this.extentAccessorMap.get(settings.orientation);
516
518
  this.extremes = data.length > 1 ? d3.extent(data, accessor) : [0, 0];
519
+ if (settings.options.scaleType.type === ScaleType.band) {
520
+ this.extremes = data.map(accessor);
521
+ }
517
522
  }
518
523
  if (hasMin) {
519
524
  this.extremes[0] = options?.min;
@@ -535,14 +540,16 @@ class Axis {
535
540
  .set(ScaleType.log, d3.format('~s'))
536
541
  .set(ScaleType.symlog, d3.format('~s'))
537
542
  .set(ScaleType.pow, d3.format('~s'))
538
- .set(ScaleType.sqrt, d3.format('~s'));
543
+ .set(ScaleType.sqrt, d3.format('~s'))
544
+ .set(ScaleType.band, (_) => { return _; });
539
545
  this.defaultScales = new Map()
540
546
  .set(ScaleType.linear, d3.scaleLinear)
541
547
  .set(ScaleType.log, d3.scaleLog)
542
548
  .set(ScaleType.symlog, d3.scaleSymlog)
543
549
  .set(ScaleType.pow, d3.scalePow)
544
550
  .set(ScaleType.sqrt, d3.scaleSqrt)
545
- .set(ScaleType.time, d3.scaleTime);
551
+ .set(ScaleType.time, d3.scaleTime)
552
+ .set(ScaleType.band, d3.scaleBand);
546
553
  this.chartConfig = config;
547
554
  }
548
555
  /**
@@ -597,12 +604,17 @@ class Axis {
597
604
  }
598
605
  setScale(scale) {
599
606
  this._scale = scale;
607
+ if (this.options.scaleType.type === ScaleType.band) {
608
+ this._scale.ticks = () => {
609
+ return this._scale.domain();
610
+ };
611
+ }
600
612
  }
601
613
  setSelfSize() {
602
614
  this._selfSize = new AxisSizeBuilder().build(this);
603
615
  }
604
616
  setTicksValues() {
605
- this._ticksValues = generateTicks(this._extremes);
617
+ //this._ticksValues = generateTicks(this._extremes);
606
618
  }
607
619
  setOptions() {
608
620
  const options = this.orientation === AxisOrientation.x
@@ -651,11 +663,11 @@ class ScaleService {
651
663
  this.scaleMapping = new Map()
652
664
  .set(ScaleType.linear, d3.scaleLinear)
653
665
  .set(ScaleType.time, d3.scaleTime)
654
- .set(ScaleType.category, d3.scaleOrdinal)
655
666
  .set(ScaleType.log, d3.scaleLog)
656
667
  .set(ScaleType.symlog, d3.scaleSymlog)
657
668
  .set(ScaleType.pow, d3.scalePow)
658
- .set(ScaleType.sqrt, d3.scaleSqrt);
669
+ .set(ScaleType.sqrt, d3.scaleSqrt)
670
+ .set(ScaleType.band, d3.scaleBand);
659
671
  this.scales = combineLatest([
660
672
  this.chartService.size,
661
673
  this.chartService.config,
@@ -693,6 +705,11 @@ class ScaleService {
693
705
  if (axis.options.scaleType.type === ScaleType.log) {
694
706
  scale.base(axis.options.scaleType.base);
695
707
  }
708
+ if (axis.options.scaleType.type === ScaleType.band) {
709
+ scale.paddingInner(0.1);
710
+ scale.paddingOuter(0.1);
711
+ scale.align(0.1);
712
+ }
696
713
  axis.setScale(scale);
697
714
  axis.setOriginDomain(scale.domain());
698
715
  const hasCache = this.transformCacheX.has(axis.index);
@@ -744,6 +761,11 @@ class ScaleService {
744
761
  if (axis.options.scaleType.type === ScaleType.log) {
745
762
  scale.base(axis.options.scaleType.base);
746
763
  }
764
+ if (axis.options.scaleType.type === ScaleType.band) {
765
+ scale.paddingInner(0.1);
766
+ scale.paddingOuter(0.1);
767
+ scale.align(0.1);
768
+ }
747
769
  axis.setScale(scale);
748
770
  axis.setOriginDomain(scale.domain());
749
771
  const hasCache = this.transformCacheY.has(axis.index);
@@ -1980,6 +2002,7 @@ class BrushMessage {
1980
2002
  constructor(options) {
1981
2003
  this.chartId = options?.chartId;
1982
2004
  this.selection = options?.selection;
2005
+ this.mode = options?.mode;
1983
2006
  }
1984
2007
  }
1985
2008
 
@@ -2083,17 +2106,20 @@ class ZoomableDirective {
2083
2106
  if (this.config.zoom?.wheelDelta) {
2084
2107
  this.zoom.wheelDelta(this.config.zoom?.wheelDelta);
2085
2108
  }
2086
- const maxZoom = this.config.zoom?.max
2087
- ? (this.axis.extremes[1] - this.axis.extremes[0]) /
2088
- this.config.zoom?.max
2089
- : this.config.zoom?.limitZoomByData
2090
- ? 1
2091
- : 0;
2092
- const minZoom = this.config.zoom?.min
2093
- ? (this.axis.extremes[1] - this.axis.extremes[0]) /
2094
- this.config.zoom?.min
2095
- : Infinity;
2096
- this.zoom.scaleExtent([maxZoom, minZoom]);
2109
+ if (this.axis.options.scaleType.type === ScaleType.band) {
2110
+ const extremes = this.axis.extremes;
2111
+ const maxZoom = this.config.zoom?.max
2112
+ ? (extremes[1] - extremes[0]) /
2113
+ this.config.zoom?.max
2114
+ : this.config.zoom?.limitZoomByData
2115
+ ? 1
2116
+ : 0;
2117
+ const minZoom = this.config.zoom?.min
2118
+ ? (extremes[1] - extremes[0]) /
2119
+ this.config.zoom?.min
2120
+ : Infinity;
2121
+ this.zoom.scaleExtent([maxZoom, minZoom]);
2122
+ }
2097
2123
  this.zoom.on('zoom end', this.zoomed);
2098
2124
  this._element.call(this.zoom).on('dblclick.zoom', null);
2099
2125
  if (this.config?.zoom?.zoomBehavior === ZoomBehaviorType.wheel) {
@@ -2213,6 +2239,7 @@ class BrushableDirective {
2213
2239
  const brushMessage = new BrushMessage({
2214
2240
  chartId: this.config.id,
2215
2241
  selection: [this.config?.brush?.from, this.config?.brush?.to],
2242
+ mode: 'init'
2216
2243
  });
2217
2244
  this.brushService.setBrush(brushMessage);
2218
2245
  }
@@ -2290,6 +2317,7 @@ class BrushableDirective {
2290
2317
  const brushMessage = new BrushMessage({
2291
2318
  chartId: this.config.id,
2292
2319
  selection: [brushScale.invert(from), brushScale.invert(to)],
2320
+ mode: _.mode
2293
2321
  });
2294
2322
  this.brushService.setBrush(brushMessage);
2295
2323
  }
@@ -2306,7 +2334,7 @@ class BrushableDirective {
2306
2334
  }
2307
2335
  this._container.call(this.brush.move, this.selection
2308
2336
  ? this.selection.map(brushScale)
2309
- : domain.map(brushScale));
2337
+ : domain.map(brushScale), {});
2310
2338
  }, 0);
2311
2339
  });
2312
2340
  }
@@ -2658,6 +2686,9 @@ class ChartComponent {
2658
2686
  if (tooltipTracking === TooltipTracking.y) {
2659
2687
  const result = new Map();
2660
2688
  y.forEach((value, key) => {
2689
+ if (value.options.scaleType.type === ScaleType.band) {
2690
+ return;
2691
+ }
2661
2692
  result.set(key, value.scale.invert(event.offsetY));
2662
2693
  });
2663
2694
  this.pointerMove.emit({
@@ -2668,6 +2699,9 @@ class ChartComponent {
2668
2699
  else {
2669
2700
  const result = new Map();
2670
2701
  x.forEach((value, key) => {
2702
+ if (value.options.scaleType.type === ScaleType.band) {
2703
+ return;
2704
+ }
2671
2705
  result.set(key, value.scale.invert(event.offsetX));
2672
2706
  });
2673
2707
  this.pointerMove.emit({
@@ -2762,6 +2796,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
2762
2796
  type: Input
2763
2797
  }] } });
2764
2798
 
2799
+ class BandseriesComponent extends SeriesBaseComponent {
2800
+ constructor(svc, cdr, scaleService, zoomService, element) {
2801
+ super(svc, cdr, scaleService, zoomService, element);
2802
+ this.svc = svc;
2803
+ this.cdr = cdr;
2804
+ this.scaleService = scaleService;
2805
+ this.zoomService = zoomService;
2806
+ this.element = element;
2807
+ }
2808
+ ngOnInit() {
2809
+ this.x = this.scaleService.scales.pipe(map(_ => _.x.get(this.series.xAxisIndex)?.scale));
2810
+ this.y = this.scaleService.scales.pipe(map(_ => _.y.get(this.series.yAxisIndex)?.scale));
2811
+ }
2812
+ }
2813
+ BandseriesComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: BandseriesComponent, deps: [{ token: ChartService }, { token: i0.ChangeDetectorRef }, { token: ScaleService }, { token: ZoomService }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
2814
+ BandseriesComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.2", type: BandseriesComponent, selector: "svg:svg[teta-bandseries]", usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"{x: x | async, y: y | async} as scales\">\n <ng-container *ngFor=\"let band of _series.data\">\n <svg:rect [attr.x]=\"scales.x(band.x)\"\n [attr.y]=\"scales.y(band.y) - scales.y.bandwidth() / 2\"\n [attr.width]=\"scales.x(band.x1) - scales.x(band.x)\"\n fill=\"red\"\n [attr.height]=\"scales.y.bandwidth()\">\n </svg:rect>\n <svg:text\n text-anchor=\"middle\"\n dominant-baseline=\"middle\"\n class=\"label font-caption fill-text-90\"\n [attr.x]=\"scales.x(band.x) + (scales.x(band.x1) - scales.x(band.x)) / 2\"\n [attr.y]=\"scales.y(band.y)\">{{band.y}}\n </svg:text>\n </ng-container>\n\n</ng-container>\n", styles: [""], dependencies: [{ kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }] });
2815
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: BandseriesComponent, decorators: [{
2816
+ type: Component,
2817
+ args: [{ selector: 'svg:svg[teta-bandseries]', template: "<ng-container *ngIf=\"{x: x | async, y: y | async} as scales\">\n <ng-container *ngFor=\"let band of _series.data\">\n <svg:rect [attr.x]=\"scales.x(band.x)\"\n [attr.y]=\"scales.y(band.y) - scales.y.bandwidth() / 2\"\n [attr.width]=\"scales.x(band.x1) - scales.x(band.x)\"\n fill=\"red\"\n [attr.height]=\"scales.y.bandwidth()\">\n </svg:rect>\n <svg:text\n text-anchor=\"middle\"\n dominant-baseline=\"middle\"\n class=\"label font-caption fill-text-90\"\n [attr.x]=\"scales.x(band.x) + (scales.x(band.x1) - scales.x(band.x)) / 2\"\n [attr.y]=\"scales.y(band.y)\">{{band.y}}\n </svg:text>\n </ng-container>\n\n</ng-container>\n" }]
2818
+ }], ctorParameters: function () { return [{ type: ChartService }, { type: i0.ChangeDetectorRef }, { type: ScaleService }, { type: ZoomService }, { type: i0.ElementRef }]; } });
2819
+
2765
2820
  class ChartModule {
2766
2821
  }
2767
2822
  ChartModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
@@ -2787,7 +2842,8 @@ ChartModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "1
2787
2842
  BlockAreaSeriesComponent,
2788
2843
  AnnotationComponent,
2789
2844
  CrosshairComponent,
2790
- DraggablePointDirective], imports: [CommonModule, LetModule], exports: [ChartComponent,
2845
+ DraggablePointDirective,
2846
+ BandseriesComponent], imports: [CommonModule, LetModule], exports: [ChartComponent,
2791
2847
  LegendComponent,
2792
2848
  SeriesBaseComponent,
2793
2849
  LineSeriesComponent,
@@ -2824,6 +2880,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
2824
2880
  AnnotationComponent,
2825
2881
  CrosshairComponent,
2826
2882
  DraggablePointDirective,
2883
+ BandseriesComponent,
2827
2884
  ],
2828
2885
  exports: [
2829
2886
  ChartComponent,