@tetacom/svg-charts 1.4.0 → 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.
- package/chart/chart.module.d.ts +4 -3
- package/chart/core/axis/axis.d.ts +1 -1
- package/chart/core/axis/builders/extremes-builder.d.ts +2 -2
- package/chart/model/enum/scale-type.d.ts +1 -1
- package/chart/stories/bandseries/bandseries.component.d.ts +21 -0
- package/esm2020/chart/chart/chart.component.mjs +8 -1
- package/esm2020/chart/chart-container/plotband/plot-band.component.mjs +4 -2
- package/esm2020/chart/chart.module.mjs +5 -2
- package/esm2020/chart/core/axis/axis.mjs +11 -5
- package/esm2020/chart/core/axis/builders/axis-size-builder.mjs +10 -3
- package/esm2020/chart/core/axis/builders/extremes-builder.mjs +5 -1
- package/esm2020/chart/directives/zoomable.directive.mjs +16 -12
- package/esm2020/chart/model/enum/scale-type.mjs +2 -2
- package/esm2020/chart/service/chart.service.mjs +1 -5
- package/esm2020/chart/service/scale.service.mjs +13 -3
- package/esm2020/chart/stories/bandseries/bandseries.component.mjs +29 -0
- package/fesm2015/tetacom-svg-charts.mjs +81 -25
- package/fesm2015/tetacom-svg-charts.mjs.map +1 -1
- package/fesm2020/tetacom-svg-charts.mjs +81 -25
- package/fesm2020/tetacom-svg-charts.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -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["
|
|
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
|
-
|
|
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);
|
|
@@ -1738,7 +1760,9 @@ class PlotBandComponent {
|
|
|
1738
1760
|
let [min, max] = this.scale.domain();
|
|
1739
1761
|
min = min instanceof Date ? min.getTime() : min;
|
|
1740
1762
|
max = max instanceof Date ? max.getTime() : max;
|
|
1741
|
-
const
|
|
1763
|
+
const from = this.plotBand.from instanceof Date ? this.plotBand.from.getTime() : this.plotBand.from;
|
|
1764
|
+
const to = this.plotBand.to instanceof Date ? this.plotBand.to.getTime() : this.plotBand.to;
|
|
1765
|
+
const position = ((from <= min ? min : from) + (to >= max ? max : to)) / 2;
|
|
1742
1766
|
return this.scale(position);
|
|
1743
1767
|
};
|
|
1744
1768
|
}
|
|
@@ -2081,17 +2105,20 @@ class ZoomableDirective {
|
|
|
2081
2105
|
if (this.config.zoom?.wheelDelta) {
|
|
2082
2106
|
this.zoom.wheelDelta(this.config.zoom?.wheelDelta);
|
|
2083
2107
|
}
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
:
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
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
|
+
}
|
|
2095
2122
|
this.zoom.on('zoom end', this.zoomed);
|
|
2096
2123
|
this._element.call(this.zoom).on('dblclick.zoom', null);
|
|
2097
2124
|
if (this.config?.zoom?.zoomBehavior === ZoomBehaviorType.wheel) {
|
|
@@ -2656,6 +2683,9 @@ class ChartComponent {
|
|
|
2656
2683
|
if (tooltipTracking === TooltipTracking.y) {
|
|
2657
2684
|
const result = new Map();
|
|
2658
2685
|
y.forEach((value, key) => {
|
|
2686
|
+
if (value.options.scaleType.type === ScaleType.band) {
|
|
2687
|
+
return;
|
|
2688
|
+
}
|
|
2659
2689
|
result.set(key, value.scale.invert(event.offsetY));
|
|
2660
2690
|
});
|
|
2661
2691
|
this.pointerMove.emit({
|
|
@@ -2666,6 +2696,9 @@ class ChartComponent {
|
|
|
2666
2696
|
else {
|
|
2667
2697
|
const result = new Map();
|
|
2668
2698
|
x.forEach((value, key) => {
|
|
2699
|
+
if (value.options.scaleType.type === ScaleType.band) {
|
|
2700
|
+
return;
|
|
2701
|
+
}
|
|
2669
2702
|
result.set(key, value.scale.invert(event.offsetX));
|
|
2670
2703
|
});
|
|
2671
2704
|
this.pointerMove.emit({
|
|
@@ -2760,6 +2793,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
|
|
|
2760
2793
|
type: Input
|
|
2761
2794
|
}] } });
|
|
2762
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
|
+
|
|
2763
2817
|
class ChartModule {
|
|
2764
2818
|
}
|
|
2765
2819
|
ChartModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
@@ -2785,7 +2839,8 @@ ChartModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "1
|
|
|
2785
2839
|
BlockAreaSeriesComponent,
|
|
2786
2840
|
AnnotationComponent,
|
|
2787
2841
|
CrosshairComponent,
|
|
2788
|
-
DraggablePointDirective
|
|
2842
|
+
DraggablePointDirective,
|
|
2843
|
+
BandseriesComponent], imports: [CommonModule, LetModule], exports: [ChartComponent,
|
|
2789
2844
|
LegendComponent,
|
|
2790
2845
|
SeriesBaseComponent,
|
|
2791
2846
|
LineSeriesComponent,
|
|
@@ -2822,6 +2877,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
|
|
|
2822
2877
|
AnnotationComponent,
|
|
2823
2878
|
CrosshairComponent,
|
|
2824
2879
|
DraggablePointDirective,
|
|
2880
|
+
BandseriesComponent,
|
|
2825
2881
|
],
|
|
2826
2882
|
exports: [
|
|
2827
2883
|
ChartComponent,
|