@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.
@@ -85,7 +85,7 @@ var ScaleType;
85
85
  ScaleType[ScaleType["pow"] = 3] = "pow";
86
86
  ScaleType[ScaleType["sqrt"] = 4] = "sqrt";
87
87
  ScaleType[ScaleType["time"] = 5] = "time";
88
- ScaleType[ScaleType["category"] = 6] = "category";
88
+ ScaleType[ScaleType["band"] = 6] = "band";
89
89
  })(ScaleType || (ScaleType = {}));
90
90
 
91
91
  const defaultAxisConfig = {
@@ -138,8 +138,6 @@ const defaultSeriesConfig = () => ({
138
138
 
139
139
  class ChartService {
140
140
  constructor() {
141
- // public zoomInstance: Observable<ZoomService>;
142
- // public brushInstance: Observable<BrushService>;
143
141
  this.config$ = new BehaviorSubject(defaultChartConfig());
144
142
  this.size$ = new BehaviorSubject(null);
145
143
  this.pointerMove$ = new Subject();
@@ -343,8 +341,6 @@ class ChartService {
343
341
  return config;
344
342
  }
345
343
  }
346
- // private zoomInstance$ = new Subject<ZoomService>();
347
- // private brushInstance$ = new Subject<BrushService>();
348
344
  ChartService._hiddenSeriesPostfix = 'hidden_series';
349
345
  ChartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ChartService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
350
346
  ChartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ChartService, providedIn: 'root' });
@@ -482,8 +478,14 @@ class AxisSizeBuilder {
482
478
  if (settings.orientation === AxisOrientation.y) {
483
479
  const formatter = settings.options.tickFormat || settings.defaultFormatter();
484
480
  finalPadding += settings.options.title ? this.titlePadding : 0;
485
- const scale = settings.defaultScale();
486
- const ticks = scale().domain(settings.extremes).ticks(20);
481
+ const scale = settings.defaultScale()();
482
+ scale.domain(settings.extremes);
483
+ if (settings.options.scaleType.type === ScaleType.band) {
484
+ scale.ticks = (ticks) => {
485
+ return scale.domain();
486
+ };
487
+ }
488
+ const ticks = scale.ticks(20);
487
489
  const maxElementLengthIndex = maxIndex(ticks, (_) => formatter(_).length);
488
490
  finalPadding += getTextWidth(formatter(ticks[maxElementLengthIndex]), this.backupRatio);
489
491
  }
@@ -512,6 +514,9 @@ class ExtremesBuilder {
512
514
  }, []);
513
515
  const accessor = this.extentAccessorMap.get(settings.orientation);
514
516
  this.extremes = data.length > 1 ? d3.extent(data, accessor) : [0, 0];
517
+ if (settings.options.scaleType.type === ScaleType.band) {
518
+ this.extremes = data.map(accessor);
519
+ }
515
520
  }
516
521
  if (hasMin) {
517
522
  this.extremes[0] = options === null || options === void 0 ? void 0 : options.min;
@@ -533,14 +538,16 @@ class Axis {
533
538
  .set(ScaleType.log, d3.format('~s'))
534
539
  .set(ScaleType.symlog, d3.format('~s'))
535
540
  .set(ScaleType.pow, d3.format('~s'))
536
- .set(ScaleType.sqrt, d3.format('~s'));
541
+ .set(ScaleType.sqrt, d3.format('~s'))
542
+ .set(ScaleType.band, (_) => { return _; });
537
543
  this.defaultScales = new Map()
538
544
  .set(ScaleType.linear, d3.scaleLinear)
539
545
  .set(ScaleType.log, d3.scaleLog)
540
546
  .set(ScaleType.symlog, d3.scaleSymlog)
541
547
  .set(ScaleType.pow, d3.scalePow)
542
548
  .set(ScaleType.sqrt, d3.scaleSqrt)
543
- .set(ScaleType.time, d3.scaleTime);
549
+ .set(ScaleType.time, d3.scaleTime)
550
+ .set(ScaleType.band, d3.scaleBand);
544
551
  this.chartConfig = config;
545
552
  }
546
553
  /**
@@ -596,12 +603,17 @@ class Axis {
596
603
  }
597
604
  setScale(scale) {
598
605
  this._scale = scale;
606
+ if (this.options.scaleType.type === ScaleType.band) {
607
+ this._scale.ticks = () => {
608
+ return this._scale.domain();
609
+ };
610
+ }
599
611
  }
600
612
  setSelfSize() {
601
613
  this._selfSize = new AxisSizeBuilder().build(this);
602
614
  }
603
615
  setTicksValues() {
604
- this._ticksValues = generateTicks(this._extremes);
616
+ //this._ticksValues = generateTicks(this._extremes);
605
617
  }
606
618
  setOptions() {
607
619
  const options = this.orientation === AxisOrientation.x
@@ -650,11 +662,11 @@ class ScaleService {
650
662
  this.scaleMapping = new Map()
651
663
  .set(ScaleType.linear, d3.scaleLinear)
652
664
  .set(ScaleType.time, d3.scaleTime)
653
- .set(ScaleType.category, d3.scaleOrdinal)
654
665
  .set(ScaleType.log, d3.scaleLog)
655
666
  .set(ScaleType.symlog, d3.scaleSymlog)
656
667
  .set(ScaleType.pow, d3.scalePow)
657
- .set(ScaleType.sqrt, d3.scaleSqrt);
668
+ .set(ScaleType.sqrt, d3.scaleSqrt)
669
+ .set(ScaleType.band, d3.scaleBand);
658
670
  this.scales = combineLatest([
659
671
  this.chartService.size,
660
672
  this.chartService.config,
@@ -694,6 +706,11 @@ class ScaleService {
694
706
  if (axis.options.scaleType.type === ScaleType.log) {
695
707
  scale.base(axis.options.scaleType.base);
696
708
  }
709
+ if (axis.options.scaleType.type === ScaleType.band) {
710
+ scale.paddingInner(0.1);
711
+ scale.paddingOuter(0.1);
712
+ scale.align(0.1);
713
+ }
697
714
  axis.setScale(scale);
698
715
  axis.setOriginDomain(scale.domain());
699
716
  const hasCache = this.transformCacheX.has(axis.index);
@@ -746,6 +763,11 @@ class ScaleService {
746
763
  if (axis.options.scaleType.type === ScaleType.log) {
747
764
  scale.base(axis.options.scaleType.base);
748
765
  }
766
+ if (axis.options.scaleType.type === ScaleType.band) {
767
+ scale.paddingInner(0.1);
768
+ scale.paddingOuter(0.1);
769
+ scale.align(0.1);
770
+ }
749
771
  axis.setScale(scale);
750
772
  axis.setOriginDomain(scale.domain());
751
773
  const hasCache = this.transformCacheY.has(axis.index);
@@ -1998,6 +2020,7 @@ class BrushMessage {
1998
2020
  constructor(options) {
1999
2021
  this.chartId = options === null || options === void 0 ? void 0 : options.chartId;
2000
2022
  this.selection = options === null || options === void 0 ? void 0 : options.selection;
2023
+ this.mode = options === null || options === void 0 ? void 0 : options.mode;
2001
2024
  }
2002
2025
  }
2003
2026
 
@@ -2105,17 +2128,20 @@ class ZoomableDirective {
2105
2128
  if ((_p = this.config.zoom) === null || _p === void 0 ? void 0 : _p.wheelDelta) {
2106
2129
  this.zoom.wheelDelta((_q = this.config.zoom) === null || _q === void 0 ? void 0 : _q.wheelDelta);
2107
2130
  }
2108
- const maxZoom = ((_r = this.config.zoom) === null || _r === void 0 ? void 0 : _r.max)
2109
- ? (this.axis.extremes[1] - this.axis.extremes[0]) /
2110
- ((_s = this.config.zoom) === null || _s === void 0 ? void 0 : _s.max)
2111
- : ((_t = this.config.zoom) === null || _t === void 0 ? void 0 : _t.limitZoomByData)
2112
- ? 1
2113
- : 0;
2114
- const minZoom = ((_u = this.config.zoom) === null || _u === void 0 ? void 0 : _u.min)
2115
- ? (this.axis.extremes[1] - this.axis.extremes[0]) /
2116
- ((_v = this.config.zoom) === null || _v === void 0 ? void 0 : _v.min)
2117
- : Infinity;
2118
- this.zoom.scaleExtent([maxZoom, minZoom]);
2131
+ if (this.axis.options.scaleType.type === ScaleType.band) {
2132
+ const extremes = this.axis.extremes;
2133
+ const maxZoom = ((_r = this.config.zoom) === null || _r === void 0 ? void 0 : _r.max)
2134
+ ? (extremes[1] - extremes[0]) /
2135
+ ((_s = this.config.zoom) === null || _s === void 0 ? void 0 : _s.max)
2136
+ : ((_t = this.config.zoom) === null || _t === void 0 ? void 0 : _t.limitZoomByData)
2137
+ ? 1
2138
+ : 0;
2139
+ const minZoom = ((_u = this.config.zoom) === null || _u === void 0 ? void 0 : _u.min)
2140
+ ? (extremes[1] - extremes[0]) /
2141
+ ((_v = this.config.zoom) === null || _v === void 0 ? void 0 : _v.min)
2142
+ : Infinity;
2143
+ this.zoom.scaleExtent([maxZoom, minZoom]);
2144
+ }
2119
2145
  this.zoom.on('zoom end', this.zoomed);
2120
2146
  this._element.call(this.zoom).on('dblclick.zoom', null);
2121
2147
  if (((_x = (_w = this.config) === null || _w === void 0 ? void 0 : _w.zoom) === null || _x === void 0 ? void 0 : _x.zoomBehavior) === ZoomBehaviorType.wheel) {
@@ -2238,6 +2264,7 @@ class BrushableDirective {
2238
2264
  const brushMessage = new BrushMessage({
2239
2265
  chartId: this.config.id,
2240
2266
  selection: [(_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.brush) === null || _d === void 0 ? void 0 : _d.from, (_f = (_e = this.config) === null || _e === void 0 ? void 0 : _e.brush) === null || _f === void 0 ? void 0 : _f.to],
2267
+ mode: 'init'
2241
2268
  });
2242
2269
  this.brushService.setBrush(brushMessage);
2243
2270
  }
@@ -2317,6 +2344,7 @@ class BrushableDirective {
2317
2344
  const brushMessage = new BrushMessage({
2318
2345
  chartId: this.config.id,
2319
2346
  selection: [brushScale.invert(from), brushScale.invert(to)],
2347
+ mode: _.mode
2320
2348
  });
2321
2349
  this.brushService.setBrush(brushMessage);
2322
2350
  }
@@ -2334,7 +2362,7 @@ class BrushableDirective {
2334
2362
  }
2335
2363
  this._container.call(this.brush.move, this.selection
2336
2364
  ? this.selection.map(brushScale)
2337
- : domain.map(brushScale));
2365
+ : domain.map(brushScale), {});
2338
2366
  }, 0);
2339
2367
  });
2340
2368
  }
@@ -2695,6 +2723,9 @@ class ChartComponent {
2695
2723
  if (tooltipTracking === TooltipTracking.y) {
2696
2724
  const result = new Map();
2697
2725
  y.forEach((value, key) => {
2726
+ if (value.options.scaleType.type === ScaleType.band) {
2727
+ return;
2728
+ }
2698
2729
  result.set(key, value.scale.invert(event.offsetY));
2699
2730
  });
2700
2731
  this.pointerMove.emit({
@@ -2705,6 +2736,9 @@ class ChartComponent {
2705
2736
  else {
2706
2737
  const result = new Map();
2707
2738
  x.forEach((value, key) => {
2739
+ if (value.options.scaleType.type === ScaleType.band) {
2740
+ return;
2741
+ }
2708
2742
  result.set(key, value.scale.invert(event.offsetX));
2709
2743
  });
2710
2744
  this.pointerMove.emit({
@@ -2799,6 +2833,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
2799
2833
  type: Input
2800
2834
  }] } });
2801
2835
 
2836
+ class BandseriesComponent extends SeriesBaseComponent {
2837
+ constructor(svc, cdr, scaleService, zoomService, element) {
2838
+ super(svc, cdr, scaleService, zoomService, element);
2839
+ this.svc = svc;
2840
+ this.cdr = cdr;
2841
+ this.scaleService = scaleService;
2842
+ this.zoomService = zoomService;
2843
+ this.element = element;
2844
+ }
2845
+ ngOnInit() {
2846
+ this.x = this.scaleService.scales.pipe(map(_ => { var _a; return (_a = _.x.get(this.series.xAxisIndex)) === null || _a === void 0 ? void 0 : _a.scale; }));
2847
+ this.y = this.scaleService.scales.pipe(map(_ => { var _a; return (_a = _.y.get(this.series.yAxisIndex)) === null || _a === void 0 ? void 0 : _a.scale; }));
2848
+ }
2849
+ }
2850
+ 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 });
2851
+ 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" }] });
2852
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: BandseriesComponent, decorators: [{
2853
+ type: Component,
2854
+ 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" }]
2855
+ }], ctorParameters: function () { return [{ type: ChartService }, { type: i0.ChangeDetectorRef }, { type: ScaleService }, { type: ZoomService }, { type: i0.ElementRef }]; } });
2856
+
2802
2857
  class ChartModule {
2803
2858
  }
2804
2859
  ChartModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
@@ -2824,7 +2879,8 @@ ChartModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "1
2824
2879
  BlockAreaSeriesComponent,
2825
2880
  AnnotationComponent,
2826
2881
  CrosshairComponent,
2827
- DraggablePointDirective], imports: [CommonModule, LetModule], exports: [ChartComponent,
2882
+ DraggablePointDirective,
2883
+ BandseriesComponent], imports: [CommonModule, LetModule], exports: [ChartComponent,
2828
2884
  LegendComponent,
2829
2885
  SeriesBaseComponent,
2830
2886
  LineSeriesComponent,
@@ -2861,6 +2917,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
2861
2917
  AnnotationComponent,
2862
2918
  CrosshairComponent,
2863
2919
  DraggablePointDirective,
2920
+ BandseriesComponent,
2864
2921
  ],
2865
2922
  exports: [
2866
2923
  ChartComponent,