@tetacom/svg-charts 1.3.3 → 1.4.1
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/directives/zoomable.directive.d.ts +1 -3
- package/chart/service/zoom.service.d.ts +4 -1
- package/esm2020/chart/chart-container/plotband/plot-band.component.mjs +4 -2
- package/esm2020/chart/directives/brushable.directive.mjs +2 -2
- package/esm2020/chart/directives/zoomable.directive.mjs +58 -63
- package/esm2020/chart/service/brush.service.mjs +1 -3
- package/esm2020/chart/service/zoom.service.mjs +17 -2
- package/fesm2015/tetacom-svg-charts.mjs +88 -75
- package/fesm2015/tetacom-svg-charts.mjs.map +1 -1
- package/fesm2020/tetacom-svg-charts.mjs +76 -65
- package/fesm2020/tetacom-svg-charts.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -409,7 +409,19 @@ class ZoomService {
|
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
411
|
setBroadcastChannel(channel) {
|
|
412
|
+
if (this.broadcastSub) {
|
|
413
|
+
this.broadcastSub?.unsubscribe();
|
|
414
|
+
}
|
|
412
415
|
this.broadcastChannel = channel;
|
|
416
|
+
if (this.broadcastChannel?.length) {
|
|
417
|
+
this.broadcastSub = combineLatest([this._broadcast.subscribeToZoom(this.broadcastChannel), this._chart.config])
|
|
418
|
+
.pipe(filter(([zoom, config]) => {
|
|
419
|
+
return zoom.message?.chartId !== config.id;
|
|
420
|
+
}))
|
|
421
|
+
.subscribe(([zoom, config]) => {
|
|
422
|
+
this.fireZoom(zoom.message);
|
|
423
|
+
});
|
|
424
|
+
}
|
|
413
425
|
}
|
|
414
426
|
getD3Transform(targetDomain, originalDomain, scale, orientation, inverted) {
|
|
415
427
|
const zoomScale = Math.abs(scale(originalDomain[1]) - scale(originalDomain[0])) / Math.abs(scale(targetDomain[1]) - scale(targetDomain[0]));
|
|
@@ -432,6 +444,9 @@ class ZoomService {
|
|
|
432
444
|
}
|
|
433
445
|
return transform;
|
|
434
446
|
}
|
|
447
|
+
ngOnDestroy() {
|
|
448
|
+
this.broadcastSub?.unsubscribe();
|
|
449
|
+
}
|
|
435
450
|
}
|
|
436
451
|
ZoomService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomService, deps: [{ token: BroadcastService }, { token: ChartService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
437
452
|
ZoomService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomService, providedIn: 'root' });
|
|
@@ -770,9 +785,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
|
|
|
770
785
|
}], ctorParameters: function () { return [{ type: ChartService }, { type: ZoomService }]; } });
|
|
771
786
|
|
|
772
787
|
class BrushService {
|
|
773
|
-
// private _outBrushDomain = new ReplaySubject<[number, number]>(1);
|
|
774
788
|
constructor() {
|
|
775
|
-
// outBrushDomain: Observable<[number, number]>;
|
|
776
789
|
this._brushDomain = new ReplaySubject(1);
|
|
777
790
|
this.brushDomain = this._brushDomain.asObservable();
|
|
778
791
|
}
|
|
@@ -1725,7 +1738,9 @@ class PlotBandComponent {
|
|
|
1725
1738
|
let [min, max] = this.scale.domain();
|
|
1726
1739
|
min = min instanceof Date ? min.getTime() : min;
|
|
1727
1740
|
max = max instanceof Date ? max.getTime() : max;
|
|
1728
|
-
const
|
|
1741
|
+
const from = this.plotBand.from instanceof Date ? this.plotBand.from.getTime() : this.plotBand.from;
|
|
1742
|
+
const to = this.plotBand.to instanceof Date ? this.plotBand.to.getTime() : this.plotBand.to;
|
|
1743
|
+
const position = ((from <= min ? min : from) + (to >= max ? max : to)) / 2;
|
|
1729
1744
|
return this.scale(position);
|
|
1730
1745
|
};
|
|
1731
1746
|
}
|
|
@@ -1969,41 +1984,37 @@ class BrushMessage {
|
|
|
1969
1984
|
}
|
|
1970
1985
|
|
|
1971
1986
|
class ZoomableDirective {
|
|
1972
|
-
constructor(elementRef, zoomService, chartService,
|
|
1987
|
+
constructor(elementRef, zoomService, chartService, zone) {
|
|
1973
1988
|
this.elementRef = elementRef;
|
|
1974
1989
|
this.zoomService = zoomService;
|
|
1975
1990
|
this.chartService = chartService;
|
|
1976
|
-
this.broadcast = broadcast;
|
|
1977
1991
|
this.zone = zone;
|
|
1978
1992
|
this.zoomable = false;
|
|
1979
1993
|
this.crosshair = false;
|
|
1980
1994
|
this.alive = true;
|
|
1981
1995
|
this.currentTransform = zoomIdentity;
|
|
1982
1996
|
this.zoomed = (event) => {
|
|
1983
|
-
if (
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
this.zoomService.fireZoom(message);
|
|
2004
|
-
this.zoomService.broadcastZoom(message);
|
|
1997
|
+
if (event.sourceEvent) {
|
|
1998
|
+
if (Object.keys(event.sourceEvent).length !== 0) {
|
|
1999
|
+
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2000
|
+
let domain = this.axis.orientation === AxisOrientation.y
|
|
2001
|
+
? event.transform.rescaleY(origin).domain()
|
|
2002
|
+
: event.transform.rescaleX(origin).domain();
|
|
2003
|
+
const message = new ZoomMessage({
|
|
2004
|
+
eventType: event.type,
|
|
2005
|
+
axis: {
|
|
2006
|
+
index: this.axis.index,
|
|
2007
|
+
orientation: this.axis.orientation,
|
|
2008
|
+
},
|
|
2009
|
+
element: this.elementRef,
|
|
2010
|
+
domain: domain,
|
|
2011
|
+
chartId: this.config.id
|
|
2012
|
+
});
|
|
2013
|
+
this.zoomService.fireZoom(message);
|
|
2014
|
+
this.zoomService.broadcastZoom(message);
|
|
2015
|
+
}
|
|
2016
|
+
this.currentTransform = event.transform;
|
|
2005
2017
|
}
|
|
2006
|
-
this.currentTransform = event.transform;
|
|
2007
2018
|
};
|
|
2008
2019
|
}
|
|
2009
2020
|
ngOnInit() {
|
|
@@ -2025,7 +2036,7 @@ class ZoomableDirective {
|
|
|
2025
2036
|
this.zoomService.zoomed.pipe(takeWhile(() => this.alive)).subscribe((zoomed) => {
|
|
2026
2037
|
if (this._element && this.elementRef !== zoomed?.element
|
|
2027
2038
|
&& zoomed?.axis?.index === this.axis.index
|
|
2028
|
-
&& zoomed?.axis?.orientation === this.axis.orientation
|
|
2039
|
+
&& zoomed?.axis?.orientation === this.axis.orientation) {
|
|
2029
2040
|
const scale = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2030
2041
|
let transform;
|
|
2031
2042
|
if (zoomed.domain === null) {
|
|
@@ -2035,12 +2046,7 @@ class ZoomableDirective {
|
|
|
2035
2046
|
transform =
|
|
2036
2047
|
this.zoomService.getD3Transform(zoomed.domain, this.axis.originDomain, scale, this.axis.orientation, this.axis.options.inverted);
|
|
2037
2048
|
}
|
|
2038
|
-
|
|
2039
|
-
this._element.transition().call(this.zoom.transform, transform);
|
|
2040
|
-
}
|
|
2041
|
-
else {
|
|
2042
|
-
this._element.call(this.zoom.transform, transform);
|
|
2043
|
-
}
|
|
2049
|
+
this._element.call(this.zoom.transform, transform);
|
|
2044
2050
|
this.currentTransform = transform;
|
|
2045
2051
|
}
|
|
2046
2052
|
});
|
|
@@ -2058,30 +2064,31 @@ class ZoomableDirective {
|
|
|
2058
2064
|
]);
|
|
2059
2065
|
const min = this.config?.zoom?.minTranslate
|
|
2060
2066
|
? this.axis.scale(this.config?.zoom?.minTranslate)
|
|
2061
|
-
:
|
|
2062
|
-
const max = this.config?.zoom?.maxTranslate
|
|
2063
|
-
? this.axis.scale(this.config?.zoom?.maxTranslate)
|
|
2064
|
-
:
|
|
2065
|
-
if (this.axis.orientation === AxisOrientation.x && this.config.zoom
|
|
2067
|
+
: -Infinity;
|
|
2068
|
+
const max = (this.config?.zoom?.maxTranslate
|
|
2069
|
+
? this.axis.scale(this.config?.zoom?.maxTranslate) - (this.axis.orientation === AxisOrientation.x ? this.size.width : this.size.height)
|
|
2070
|
+
: Infinity);
|
|
2071
|
+
if (this.axis.orientation === AxisOrientation.x && this.config.zoom.type === ZoomType.x) {
|
|
2066
2072
|
this.zoom.translateExtent([
|
|
2067
|
-
[min,
|
|
2068
|
-
[max,
|
|
2073
|
+
[min, -Infinity],
|
|
2074
|
+
[max, Infinity],
|
|
2069
2075
|
]);
|
|
2070
2076
|
}
|
|
2071
|
-
if (this.axis.orientation === AxisOrientation.y && this.config.zoom
|
|
2077
|
+
if (this.axis.orientation === AxisOrientation.y && this.config.zoom.type === ZoomType.y) {
|
|
2072
2078
|
this.zoom.translateExtent([
|
|
2073
|
-
[
|
|
2074
|
-
[
|
|
2079
|
+
[-Infinity, min],
|
|
2080
|
+
[Infinity, max],
|
|
2075
2081
|
]);
|
|
2076
2082
|
}
|
|
2077
2083
|
if (this.config.zoom?.wheelDelta) {
|
|
2078
2084
|
this.zoom.wheelDelta(this.config.zoom?.wheelDelta);
|
|
2079
2085
|
}
|
|
2080
2086
|
const maxZoom = this.config.zoom?.max
|
|
2081
|
-
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2082
|
-
|
|
2083
|
-
this.
|
|
2084
|
-
|
|
2087
|
+
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2088
|
+
this.config.zoom?.max
|
|
2089
|
+
: this.config.zoom?.limitZoomByData
|
|
2090
|
+
? 1
|
|
2091
|
+
: 0;
|
|
2085
2092
|
const minZoom = this.config.zoom?.min
|
|
2086
2093
|
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2087
2094
|
this.config.zoom?.min
|
|
@@ -2092,18 +2099,6 @@ class ZoomableDirective {
|
|
|
2092
2099
|
if (this.config?.zoom?.zoomBehavior === ZoomBehaviorType.wheel) {
|
|
2093
2100
|
this.runWheelTranslate();
|
|
2094
2101
|
}
|
|
2095
|
-
this.broadcast.subscribeToZoom(this.config?.zoom.syncChannel).subscribe((zoom) => {
|
|
2096
|
-
if (zoom.message.chartId !== this.config?.id && zoom.message.axis.orientation === this.axis.orientation && zoom.message.axis.index === this.axis.index) {
|
|
2097
|
-
const scale = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2098
|
-
const transform = this.zoomService.getD3Transform(zoom.message.domain, this.axis.originDomain, scale, this.axis.orientation, this.axis.options.inverted);
|
|
2099
|
-
if (zoom.message.style?.transition) {
|
|
2100
|
-
this._element.transition().duration(300).call(this.zoom.transform, transform, null, { type: 'broadcast' });
|
|
2101
|
-
}
|
|
2102
|
-
else {
|
|
2103
|
-
this._element.call(this.zoom.transform, transform, null, { type: 'broadcast' });
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
});
|
|
2107
2102
|
}
|
|
2108
2103
|
runWheelTranslate() {
|
|
2109
2104
|
let type = 'start';
|
|
@@ -2120,6 +2115,7 @@ class ZoomableDirective {
|
|
|
2120
2115
|
return delta * 0.002;
|
|
2121
2116
|
});
|
|
2122
2117
|
const emit = (type, event) => {
|
|
2118
|
+
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2123
2119
|
let transform = zoomIdentity;
|
|
2124
2120
|
const delta = type === 'end'
|
|
2125
2121
|
? 0
|
|
@@ -2133,7 +2129,22 @@ class ZoomableDirective {
|
|
|
2133
2129
|
transform = transform.translate(this.currentTransform.x - delta / 2, 0);
|
|
2134
2130
|
}
|
|
2135
2131
|
transform = transform.scale(this.currentTransform.k);
|
|
2136
|
-
this.
|
|
2132
|
+
let domain = this.axis.orientation === AxisOrientation.y
|
|
2133
|
+
? transform.rescaleY(origin).domain()
|
|
2134
|
+
: transform.rescaleX(origin).domain();
|
|
2135
|
+
const message = new ZoomMessage({
|
|
2136
|
+
eventType: type,
|
|
2137
|
+
element: this.elementRef,
|
|
2138
|
+
axis: {
|
|
2139
|
+
index: this.axis.index,
|
|
2140
|
+
orientation: this.axis.orientation
|
|
2141
|
+
},
|
|
2142
|
+
domain,
|
|
2143
|
+
chartId: this.config.id,
|
|
2144
|
+
});
|
|
2145
|
+
this._element?.call(this.zoom.transform, transform);
|
|
2146
|
+
this.zoomService.fireZoom(message);
|
|
2147
|
+
this.zoomService.broadcastZoom(message);
|
|
2137
2148
|
this.currentTransform = transform;
|
|
2138
2149
|
};
|
|
2139
2150
|
this._element.on('wheel', (event) => {
|
|
@@ -2153,14 +2164,14 @@ class ZoomableDirective {
|
|
|
2153
2164
|
});
|
|
2154
2165
|
}
|
|
2155
2166
|
}
|
|
2156
|
-
ZoomableDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomableDirective, deps: [{ token: i0.ElementRef }, { token: ZoomService }, { token: ChartService }, { token:
|
|
2167
|
+
ZoomableDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomableDirective, deps: [{ token: i0.ElementRef }, { token: ZoomService }, { token: ChartService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
|
|
2157
2168
|
ZoomableDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.2", type: ZoomableDirective, selector: "[tetaZoomable]", inputs: { config: "config", axis: "axis", size: "size" }, host: { properties: { "class.zoomable": "this.zoomable", "class.crosshair": "this.crosshair" } }, ngImport: i0 });
|
|
2158
2169
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomableDirective, decorators: [{
|
|
2159
2170
|
type: Directive,
|
|
2160
2171
|
args: [{
|
|
2161
2172
|
selector: '[tetaZoomable]',
|
|
2162
2173
|
}]
|
|
2163
|
-
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type:
|
|
2174
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type: i0.NgZone }]; }, propDecorators: { config: [{
|
|
2164
2175
|
type: Input
|
|
2165
2176
|
}], axis: [{
|
|
2166
2177
|
type: Input
|
|
@@ -2201,7 +2212,7 @@ class BrushableDirective {
|
|
|
2201
2212
|
if (this.config?.brush?.enable) {
|
|
2202
2213
|
const brushMessage = new BrushMessage({
|
|
2203
2214
|
chartId: this.config.id,
|
|
2204
|
-
selection: [this.config
|
|
2215
|
+
selection: [this.config?.brush?.from, this.config?.brush?.to],
|
|
2205
2216
|
});
|
|
2206
2217
|
this.brushService.setBrush(brushMessage);
|
|
2207
2218
|
}
|