@tetacom/svg-charts 1.3.3 → 1.4.0
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/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 +85 -74
- package/fesm2015/tetacom-svg-charts.mjs.map +1 -1
- package/fesm2020/tetacom-svg-charts.mjs +73 -64
- 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
|
}
|
|
@@ -1969,41 +1982,37 @@ class BrushMessage {
|
|
|
1969
1982
|
}
|
|
1970
1983
|
|
|
1971
1984
|
class ZoomableDirective {
|
|
1972
|
-
constructor(elementRef, zoomService, chartService,
|
|
1985
|
+
constructor(elementRef, zoomService, chartService, zone) {
|
|
1973
1986
|
this.elementRef = elementRef;
|
|
1974
1987
|
this.zoomService = zoomService;
|
|
1975
1988
|
this.chartService = chartService;
|
|
1976
|
-
this.broadcast = broadcast;
|
|
1977
1989
|
this.zone = zone;
|
|
1978
1990
|
this.zoomable = false;
|
|
1979
1991
|
this.crosshair = false;
|
|
1980
1992
|
this.alive = true;
|
|
1981
1993
|
this.currentTransform = zoomIdentity;
|
|
1982
1994
|
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);
|
|
1995
|
+
if (event.sourceEvent) {
|
|
1996
|
+
if (Object.keys(event.sourceEvent).length !== 0) {
|
|
1997
|
+
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
1998
|
+
let domain = this.axis.orientation === AxisOrientation.y
|
|
1999
|
+
? event.transform.rescaleY(origin).domain()
|
|
2000
|
+
: event.transform.rescaleX(origin).domain();
|
|
2001
|
+
const message = new ZoomMessage({
|
|
2002
|
+
eventType: event.type,
|
|
2003
|
+
axis: {
|
|
2004
|
+
index: this.axis.index,
|
|
2005
|
+
orientation: this.axis.orientation,
|
|
2006
|
+
},
|
|
2007
|
+
element: this.elementRef,
|
|
2008
|
+
domain: domain,
|
|
2009
|
+
chartId: this.config.id
|
|
2010
|
+
});
|
|
2011
|
+
this.zoomService.fireZoom(message);
|
|
2012
|
+
this.zoomService.broadcastZoom(message);
|
|
2013
|
+
}
|
|
2014
|
+
this.currentTransform = event.transform;
|
|
2005
2015
|
}
|
|
2006
|
-
this.currentTransform = event.transform;
|
|
2007
2016
|
};
|
|
2008
2017
|
}
|
|
2009
2018
|
ngOnInit() {
|
|
@@ -2025,7 +2034,7 @@ class ZoomableDirective {
|
|
|
2025
2034
|
this.zoomService.zoomed.pipe(takeWhile(() => this.alive)).subscribe((zoomed) => {
|
|
2026
2035
|
if (this._element && this.elementRef !== zoomed?.element
|
|
2027
2036
|
&& zoomed?.axis?.index === this.axis.index
|
|
2028
|
-
&& zoomed?.axis?.orientation === this.axis.orientation
|
|
2037
|
+
&& zoomed?.axis?.orientation === this.axis.orientation) {
|
|
2029
2038
|
const scale = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2030
2039
|
let transform;
|
|
2031
2040
|
if (zoomed.domain === null) {
|
|
@@ -2035,12 +2044,7 @@ class ZoomableDirective {
|
|
|
2035
2044
|
transform =
|
|
2036
2045
|
this.zoomService.getD3Transform(zoomed.domain, this.axis.originDomain, scale, this.axis.orientation, this.axis.options.inverted);
|
|
2037
2046
|
}
|
|
2038
|
-
|
|
2039
|
-
this._element.transition().call(this.zoom.transform, transform);
|
|
2040
|
-
}
|
|
2041
|
-
else {
|
|
2042
|
-
this._element.call(this.zoom.transform, transform);
|
|
2043
|
-
}
|
|
2047
|
+
this._element.call(this.zoom.transform, transform);
|
|
2044
2048
|
this.currentTransform = transform;
|
|
2045
2049
|
}
|
|
2046
2050
|
});
|
|
@@ -2058,30 +2062,31 @@ class ZoomableDirective {
|
|
|
2058
2062
|
]);
|
|
2059
2063
|
const min = this.config?.zoom?.minTranslate
|
|
2060
2064
|
? 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
|
|
2065
|
+
: -Infinity;
|
|
2066
|
+
const max = (this.config?.zoom?.maxTranslate
|
|
2067
|
+
? this.axis.scale(this.config?.zoom?.maxTranslate) - (this.axis.orientation === AxisOrientation.x ? this.size.width : this.size.height)
|
|
2068
|
+
: Infinity);
|
|
2069
|
+
if (this.axis.orientation === AxisOrientation.x && this.config.zoom.type === ZoomType.x) {
|
|
2066
2070
|
this.zoom.translateExtent([
|
|
2067
|
-
[min,
|
|
2068
|
-
[max,
|
|
2071
|
+
[min, -Infinity],
|
|
2072
|
+
[max, Infinity],
|
|
2069
2073
|
]);
|
|
2070
2074
|
}
|
|
2071
|
-
if (this.axis.orientation === AxisOrientation.y && this.config.zoom
|
|
2075
|
+
if (this.axis.orientation === AxisOrientation.y && this.config.zoom.type === ZoomType.y) {
|
|
2072
2076
|
this.zoom.translateExtent([
|
|
2073
|
-
[
|
|
2074
|
-
[
|
|
2077
|
+
[-Infinity, min],
|
|
2078
|
+
[Infinity, max],
|
|
2075
2079
|
]);
|
|
2076
2080
|
}
|
|
2077
2081
|
if (this.config.zoom?.wheelDelta) {
|
|
2078
2082
|
this.zoom.wheelDelta(this.config.zoom?.wheelDelta);
|
|
2079
2083
|
}
|
|
2080
2084
|
const maxZoom = this.config.zoom?.max
|
|
2081
|
-
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2082
|
-
|
|
2083
|
-
this.
|
|
2084
|
-
|
|
2085
|
+
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2086
|
+
this.config.zoom?.max
|
|
2087
|
+
: this.config.zoom?.limitZoomByData
|
|
2088
|
+
? 1
|
|
2089
|
+
: 0;
|
|
2085
2090
|
const minZoom = this.config.zoom?.min
|
|
2086
2091
|
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2087
2092
|
this.config.zoom?.min
|
|
@@ -2092,18 +2097,6 @@ class ZoomableDirective {
|
|
|
2092
2097
|
if (this.config?.zoom?.zoomBehavior === ZoomBehaviorType.wheel) {
|
|
2093
2098
|
this.runWheelTranslate();
|
|
2094
2099
|
}
|
|
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
2100
|
}
|
|
2108
2101
|
runWheelTranslate() {
|
|
2109
2102
|
let type = 'start';
|
|
@@ -2120,6 +2113,7 @@ class ZoomableDirective {
|
|
|
2120
2113
|
return delta * 0.002;
|
|
2121
2114
|
});
|
|
2122
2115
|
const emit = (type, event) => {
|
|
2116
|
+
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2123
2117
|
let transform = zoomIdentity;
|
|
2124
2118
|
const delta = type === 'end'
|
|
2125
2119
|
? 0
|
|
@@ -2133,7 +2127,22 @@ class ZoomableDirective {
|
|
|
2133
2127
|
transform = transform.translate(this.currentTransform.x - delta / 2, 0);
|
|
2134
2128
|
}
|
|
2135
2129
|
transform = transform.scale(this.currentTransform.k);
|
|
2136
|
-
this.
|
|
2130
|
+
let domain = this.axis.orientation === AxisOrientation.y
|
|
2131
|
+
? transform.rescaleY(origin).domain()
|
|
2132
|
+
: transform.rescaleX(origin).domain();
|
|
2133
|
+
const message = new ZoomMessage({
|
|
2134
|
+
eventType: type,
|
|
2135
|
+
element: this.elementRef,
|
|
2136
|
+
axis: {
|
|
2137
|
+
index: this.axis.index,
|
|
2138
|
+
orientation: this.axis.orientation
|
|
2139
|
+
},
|
|
2140
|
+
domain,
|
|
2141
|
+
chartId: this.config.id,
|
|
2142
|
+
});
|
|
2143
|
+
this._element?.call(this.zoom.transform, transform);
|
|
2144
|
+
this.zoomService.fireZoom(message);
|
|
2145
|
+
this.zoomService.broadcastZoom(message);
|
|
2137
2146
|
this.currentTransform = transform;
|
|
2138
2147
|
};
|
|
2139
2148
|
this._element.on('wheel', (event) => {
|
|
@@ -2153,14 +2162,14 @@ class ZoomableDirective {
|
|
|
2153
2162
|
});
|
|
2154
2163
|
}
|
|
2155
2164
|
}
|
|
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:
|
|
2165
|
+
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
2166
|
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
2167
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomableDirective, decorators: [{
|
|
2159
2168
|
type: Directive,
|
|
2160
2169
|
args: [{
|
|
2161
2170
|
selector: '[tetaZoomable]',
|
|
2162
2171
|
}]
|
|
2163
|
-
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type:
|
|
2172
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type: i0.NgZone }]; }, propDecorators: { config: [{
|
|
2164
2173
|
type: Input
|
|
2165
2174
|
}], axis: [{
|
|
2166
2175
|
type: Input
|
|
@@ -2201,7 +2210,7 @@ class BrushableDirective {
|
|
|
2201
2210
|
if (this.config?.brush?.enable) {
|
|
2202
2211
|
const brushMessage = new BrushMessage({
|
|
2203
2212
|
chartId: this.config.id,
|
|
2204
|
-
selection: [this.config
|
|
2213
|
+
selection: [this.config?.brush?.from, this.config?.brush?.to],
|
|
2205
2214
|
});
|
|
2206
2215
|
this.brushService.setBrush(brushMessage);
|
|
2207
2216
|
}
|