@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
|
@@ -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["
|
|
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
|
-
|
|
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);
|
|
@@ -1751,7 +1773,9 @@ class PlotBandComponent {
|
|
|
1751
1773
|
let [min, max] = this.scale.domain();
|
|
1752
1774
|
min = min instanceof Date ? min.getTime() : min;
|
|
1753
1775
|
max = max instanceof Date ? max.getTime() : max;
|
|
1754
|
-
const
|
|
1776
|
+
const from = this.plotBand.from instanceof Date ? this.plotBand.from.getTime() : this.plotBand.from;
|
|
1777
|
+
const to = this.plotBand.to instanceof Date ? this.plotBand.to.getTime() : this.plotBand.to;
|
|
1778
|
+
const position = ((from <= min ? min : from) + (to >= max ? max : to)) / 2;
|
|
1755
1779
|
return this.scale(position);
|
|
1756
1780
|
};
|
|
1757
1781
|
}
|
|
@@ -2103,17 +2127,20 @@ class ZoomableDirective {
|
|
|
2103
2127
|
if ((_p = this.config.zoom) === null || _p === void 0 ? void 0 : _p.wheelDelta) {
|
|
2104
2128
|
this.zoom.wheelDelta((_q = this.config.zoom) === null || _q === void 0 ? void 0 : _q.wheelDelta);
|
|
2105
2129
|
}
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
: 0
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2130
|
+
if (this.axis.options.scaleType.type === ScaleType.band) {
|
|
2131
|
+
const extremes = this.axis.extremes;
|
|
2132
|
+
const maxZoom = ((_r = this.config.zoom) === null || _r === void 0 ? void 0 : _r.max)
|
|
2133
|
+
? (extremes[1] - extremes[0]) /
|
|
2134
|
+
((_s = this.config.zoom) === null || _s === void 0 ? void 0 : _s.max)
|
|
2135
|
+
: ((_t = this.config.zoom) === null || _t === void 0 ? void 0 : _t.limitZoomByData)
|
|
2136
|
+
? 1
|
|
2137
|
+
: 0;
|
|
2138
|
+
const minZoom = ((_u = this.config.zoom) === null || _u === void 0 ? void 0 : _u.min)
|
|
2139
|
+
? (extremes[1] - extremes[0]) /
|
|
2140
|
+
((_v = this.config.zoom) === null || _v === void 0 ? void 0 : _v.min)
|
|
2141
|
+
: Infinity;
|
|
2142
|
+
this.zoom.scaleExtent([maxZoom, minZoom]);
|
|
2143
|
+
}
|
|
2117
2144
|
this.zoom.on('zoom end', this.zoomed);
|
|
2118
2145
|
this._element.call(this.zoom).on('dblclick.zoom', null);
|
|
2119
2146
|
if (((_x = (_w = this.config) === null || _w === void 0 ? void 0 : _w.zoom) === null || _x === void 0 ? void 0 : _x.zoomBehavior) === ZoomBehaviorType.wheel) {
|
|
@@ -2693,6 +2720,9 @@ class ChartComponent {
|
|
|
2693
2720
|
if (tooltipTracking === TooltipTracking.y) {
|
|
2694
2721
|
const result = new Map();
|
|
2695
2722
|
y.forEach((value, key) => {
|
|
2723
|
+
if (value.options.scaleType.type === ScaleType.band) {
|
|
2724
|
+
return;
|
|
2725
|
+
}
|
|
2696
2726
|
result.set(key, value.scale.invert(event.offsetY));
|
|
2697
2727
|
});
|
|
2698
2728
|
this.pointerMove.emit({
|
|
@@ -2703,6 +2733,9 @@ class ChartComponent {
|
|
|
2703
2733
|
else {
|
|
2704
2734
|
const result = new Map();
|
|
2705
2735
|
x.forEach((value, key) => {
|
|
2736
|
+
if (value.options.scaleType.type === ScaleType.band) {
|
|
2737
|
+
return;
|
|
2738
|
+
}
|
|
2706
2739
|
result.set(key, value.scale.invert(event.offsetX));
|
|
2707
2740
|
});
|
|
2708
2741
|
this.pointerMove.emit({
|
|
@@ -2797,6 +2830,27 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
|
|
|
2797
2830
|
type: Input
|
|
2798
2831
|
}] } });
|
|
2799
2832
|
|
|
2833
|
+
class BandseriesComponent extends SeriesBaseComponent {
|
|
2834
|
+
constructor(svc, cdr, scaleService, zoomService, element) {
|
|
2835
|
+
super(svc, cdr, scaleService, zoomService, element);
|
|
2836
|
+
this.svc = svc;
|
|
2837
|
+
this.cdr = cdr;
|
|
2838
|
+
this.scaleService = scaleService;
|
|
2839
|
+
this.zoomService = zoomService;
|
|
2840
|
+
this.element = element;
|
|
2841
|
+
}
|
|
2842
|
+
ngOnInit() {
|
|
2843
|
+
this.x = this.scaleService.scales.pipe(map(_ => { var _a; return (_a = _.x.get(this.series.xAxisIndex)) === null || _a === void 0 ? void 0 : _a.scale; }));
|
|
2844
|
+
this.y = this.scaleService.scales.pipe(map(_ => { var _a; return (_a = _.y.get(this.series.yAxisIndex)) === null || _a === void 0 ? void 0 : _a.scale; }));
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
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 });
|
|
2848
|
+
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" }] });
|
|
2849
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: BandseriesComponent, decorators: [{
|
|
2850
|
+
type: Component,
|
|
2851
|
+
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" }]
|
|
2852
|
+
}], ctorParameters: function () { return [{ type: ChartService }, { type: i0.ChangeDetectorRef }, { type: ScaleService }, { type: ZoomService }, { type: i0.ElementRef }]; } });
|
|
2853
|
+
|
|
2800
2854
|
class ChartModule {
|
|
2801
2855
|
}
|
|
2802
2856
|
ChartModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
@@ -2822,7 +2876,8 @@ ChartModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "1
|
|
|
2822
2876
|
BlockAreaSeriesComponent,
|
|
2823
2877
|
AnnotationComponent,
|
|
2824
2878
|
CrosshairComponent,
|
|
2825
|
-
DraggablePointDirective
|
|
2879
|
+
DraggablePointDirective,
|
|
2880
|
+
BandseriesComponent], imports: [CommonModule, LetModule], exports: [ChartComponent,
|
|
2826
2881
|
LegendComponent,
|
|
2827
2882
|
SeriesBaseComponent,
|
|
2828
2883
|
LineSeriesComponent,
|
|
@@ -2859,6 +2914,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
|
|
|
2859
2914
|
AnnotationComponent,
|
|
2860
2915
|
CrosshairComponent,
|
|
2861
2916
|
DraggablePointDirective,
|
|
2917
|
+
BandseriesComponent,
|
|
2862
2918
|
],
|
|
2863
2919
|
exports: [
|
|
2864
2920
|
ChartComponent,
|