@tetacom/svg-charts 1.4.1 → 1.4.2

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);
@@ -2083,17 +2105,20 @@ class ZoomableDirective {
2083
2105
  if (this.config.zoom?.wheelDelta) {
2084
2106
  this.zoom.wheelDelta(this.config.zoom?.wheelDelta);
2085
2107
  }
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]);
2108
+ if (this.axis.options.scaleType.type === ScaleType.band) {
2109
+ const extremes = this.axis.extremes;
2110
+ const maxZoom = this.config.zoom?.max
2111
+ ? (extremes[1] - extremes[0]) /
2112
+ this.config.zoom?.max
2113
+ : this.config.zoom?.limitZoomByData
2114
+ ? 1
2115
+ : 0;
2116
+ const minZoom = this.config.zoom?.min
2117
+ ? (extremes[1] - extremes[0]) /
2118
+ this.config.zoom?.min
2119
+ : Infinity;
2120
+ this.zoom.scaleExtent([maxZoom, minZoom]);
2121
+ }
2097
2122
  this.zoom.on('zoom end', this.zoomed);
2098
2123
  this._element.call(this.zoom).on('dblclick.zoom', null);
2099
2124
  if (this.config?.zoom?.zoomBehavior === ZoomBehaviorType.wheel) {
@@ -2658,6 +2683,9 @@ class ChartComponent {
2658
2683
  if (tooltipTracking === TooltipTracking.y) {
2659
2684
  const result = new Map();
2660
2685
  y.forEach((value, key) => {
2686
+ if (value.options.scaleType.type === ScaleType.band) {
2687
+ return;
2688
+ }
2661
2689
  result.set(key, value.scale.invert(event.offsetY));
2662
2690
  });
2663
2691
  this.pointerMove.emit({
@@ -2668,6 +2696,9 @@ class ChartComponent {
2668
2696
  else {
2669
2697
  const result = new Map();
2670
2698
  x.forEach((value, key) => {
2699
+ if (value.options.scaleType.type === ScaleType.band) {
2700
+ return;
2701
+ }
2671
2702
  result.set(key, value.scale.invert(event.offsetX));
2672
2703
  });
2673
2704
  this.pointerMove.emit({
@@ -2762,6 +2793,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
2762
2793
  type: Input
2763
2794
  }] } });
2764
2795
 
2796
+ class BandseriesComponent extends SeriesBaseComponent {
2797
+ constructor(svc, cdr, scaleService, zoomService, element) {
2798
+ super(svc, cdr, scaleService, zoomService, element);
2799
+ this.svc = svc;
2800
+ this.cdr = cdr;
2801
+ this.scaleService = scaleService;
2802
+ this.zoomService = zoomService;
2803
+ this.element = element;
2804
+ }
2805
+ ngOnInit() {
2806
+ this.x = this.scaleService.scales.pipe(map(_ => _.x.get(this.series.xAxisIndex)?.scale));
2807
+ this.y = this.scaleService.scales.pipe(map(_ => _.y.get(this.series.yAxisIndex)?.scale));
2808
+ }
2809
+ }
2810
+ 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 });
2811
+ 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" }] });
2812
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: BandseriesComponent, decorators: [{
2813
+ type: Component,
2814
+ 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" }]
2815
+ }], ctorParameters: function () { return [{ type: ChartService }, { type: i0.ChangeDetectorRef }, { type: ScaleService }, { type: ZoomService }, { type: i0.ElementRef }]; } });
2816
+
2765
2817
  class ChartModule {
2766
2818
  }
2767
2819
  ChartModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
@@ -2787,7 +2839,8 @@ ChartModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "1
2787
2839
  BlockAreaSeriesComponent,
2788
2840
  AnnotationComponent,
2789
2841
  CrosshairComponent,
2790
- DraggablePointDirective], imports: [CommonModule, LetModule], exports: [ChartComponent,
2842
+ DraggablePointDirective,
2843
+ BandseriesComponent], imports: [CommonModule, LetModule], exports: [ChartComponent,
2791
2844
  LegendComponent,
2792
2845
  SeriesBaseComponent,
2793
2846
  LineSeriesComponent,
@@ -2824,6 +2877,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
2824
2877
  AnnotationComponent,
2825
2878
  CrosshairComponent,
2826
2879
  DraggablePointDirective,
2880
+ BandseriesComponent,
2827
2881
  ],
2828
2882
  exports: [
2829
2883
  ChartComponent,