@tetacom/svg-charts 1.3.2 → 1.3.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.
- package/chart/directives/zoomable.directive.d.ts +3 -1
- package/chart/service/zoom.service.d.ts +1 -4
- package/esm2020/chart/directives/brushable.directive.mjs +9 -2
- package/esm2020/chart/directives/zoomable.directive.mjs +57 -57
- package/esm2020/chart/service/zoom.service.mjs +2 -17
- package/fesm2015/tetacom-svg-charts.mjs +72 -82
- package/fesm2015/tetacom-svg-charts.mjs.map +1 -1
- package/fesm2020/tetacom-svg-charts.mjs +63 -72
- package/fesm2020/tetacom-svg-charts.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -409,19 +409,7 @@ class ZoomService {
|
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
411
|
setBroadcastChannel(channel) {
|
|
412
|
-
if (this.broadcastSub) {
|
|
413
|
-
this.broadcastSub?.unsubscribe();
|
|
414
|
-
}
|
|
415
412
|
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
|
-
}
|
|
425
413
|
}
|
|
426
414
|
getD3Transform(targetDomain, originalDomain, scale, orientation, inverted) {
|
|
427
415
|
const zoomScale = Math.abs(scale(originalDomain[1]) - scale(originalDomain[0])) / Math.abs(scale(targetDomain[1]) - scale(targetDomain[0]));
|
|
@@ -444,9 +432,6 @@ class ZoomService {
|
|
|
444
432
|
}
|
|
445
433
|
return transform;
|
|
446
434
|
}
|
|
447
|
-
ngOnDestroy() {
|
|
448
|
-
this.broadcastSub?.unsubscribe();
|
|
449
|
-
}
|
|
450
435
|
}
|
|
451
436
|
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 });
|
|
452
437
|
ZoomService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomService, providedIn: 'root' });
|
|
@@ -1984,37 +1969,41 @@ class BrushMessage {
|
|
|
1984
1969
|
}
|
|
1985
1970
|
|
|
1986
1971
|
class ZoomableDirective {
|
|
1987
|
-
constructor(elementRef, zoomService, chartService, zone) {
|
|
1972
|
+
constructor(elementRef, zoomService, chartService, broadcast, zone) {
|
|
1988
1973
|
this.elementRef = elementRef;
|
|
1989
1974
|
this.zoomService = zoomService;
|
|
1990
1975
|
this.chartService = chartService;
|
|
1976
|
+
this.broadcast = broadcast;
|
|
1991
1977
|
this.zone = zone;
|
|
1992
1978
|
this.zoomable = false;
|
|
1993
1979
|
this.crosshair = false;
|
|
1994
1980
|
this.alive = true;
|
|
1995
1981
|
this.currentTransform = zoomIdentity;
|
|
1996
1982
|
this.zoomed = (event) => {
|
|
1997
|
-
if (event.sourceEvent)
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
1983
|
+
if (!event.sourceEvent)
|
|
1984
|
+
return;
|
|
1985
|
+
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
1986
|
+
let domain = this.axis.orientation === AxisOrientation.y
|
|
1987
|
+
? event.transform.rescaleY(origin).domain()
|
|
1988
|
+
: event.transform.rescaleX(origin).domain();
|
|
1989
|
+
const message = new ZoomMessage({
|
|
1990
|
+
eventType: event.type,
|
|
1991
|
+
axis: {
|
|
1992
|
+
index: this.axis.index,
|
|
1993
|
+
orientation: this.axis.orientation,
|
|
1994
|
+
},
|
|
1995
|
+
element: this.elementRef,
|
|
1996
|
+
domain: domain,
|
|
1997
|
+
chartId: this.config.id
|
|
1998
|
+
});
|
|
1999
|
+
if (event.sourceEvent.type === 'broadcast') {
|
|
2000
|
+
this.zoomService.fireZoom(message);
|
|
2001
|
+
}
|
|
2002
|
+
if (event.sourceEvent.type === 'wheeling' || event.sourceEvent instanceof MouseEvent || (window.TouchEvent && event.sourceEvent instanceof TouchEvent)) {
|
|
2003
|
+
this.zoomService.fireZoom(message);
|
|
2004
|
+
this.zoomService.broadcastZoom(message);
|
|
2017
2005
|
}
|
|
2006
|
+
this.currentTransform = event.transform;
|
|
2018
2007
|
};
|
|
2019
2008
|
}
|
|
2020
2009
|
ngOnInit() {
|
|
@@ -2036,7 +2025,7 @@ class ZoomableDirective {
|
|
|
2036
2025
|
this.zoomService.zoomed.pipe(takeWhile(() => this.alive)).subscribe((zoomed) => {
|
|
2037
2026
|
if (this._element && this.elementRef !== zoomed?.element
|
|
2038
2027
|
&& zoomed?.axis?.index === this.axis.index
|
|
2039
|
-
&& zoomed?.axis?.orientation === this.axis.orientation) {
|
|
2028
|
+
&& zoomed?.axis?.orientation === this.axis.orientation && zoomed.eventType === 'end') {
|
|
2040
2029
|
const scale = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2041
2030
|
let transform;
|
|
2042
2031
|
if (zoomed.domain === null) {
|
|
@@ -2069,31 +2058,30 @@ class ZoomableDirective {
|
|
|
2069
2058
|
]);
|
|
2070
2059
|
const min = this.config?.zoom?.minTranslate
|
|
2071
2060
|
? this.axis.scale(this.config?.zoom?.minTranslate)
|
|
2072
|
-
:
|
|
2073
|
-
const max =
|
|
2074
|
-
? this.axis.scale(this.config?.zoom?.maxTranslate)
|
|
2075
|
-
:
|
|
2076
|
-
if (this.axis.orientation === AxisOrientation.x && this.config.zoom
|
|
2061
|
+
: 0;
|
|
2062
|
+
const max = this.config?.zoom?.maxTranslate
|
|
2063
|
+
? this.axis.scale(this.config?.zoom?.maxTranslate)
|
|
2064
|
+
: this.axis.orientation === AxisOrientation.x ? this.size.width : this.size.height;
|
|
2065
|
+
if (this.axis.orientation === AxisOrientation.x && this.config.zoom?.type === ZoomType.x) {
|
|
2077
2066
|
this.zoom.translateExtent([
|
|
2078
|
-
[min,
|
|
2079
|
-
[max,
|
|
2067
|
+
[min, 0],
|
|
2068
|
+
[max, this.size.height],
|
|
2080
2069
|
]);
|
|
2081
2070
|
}
|
|
2082
|
-
if (this.axis.orientation === AxisOrientation.y && this.config.zoom
|
|
2071
|
+
if (this.axis.orientation === AxisOrientation.y && this.config.zoom?.type === ZoomType.y) {
|
|
2083
2072
|
this.zoom.translateExtent([
|
|
2084
|
-
[
|
|
2085
|
-
[
|
|
2073
|
+
[0, min],
|
|
2074
|
+
[this.size.width, max],
|
|
2086
2075
|
]);
|
|
2087
2076
|
}
|
|
2088
2077
|
if (this.config.zoom?.wheelDelta) {
|
|
2089
2078
|
this.zoom.wheelDelta(this.config.zoom?.wheelDelta);
|
|
2090
2079
|
}
|
|
2091
2080
|
const maxZoom = this.config.zoom?.max
|
|
2092
|
-
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
: 0;
|
|
2081
|
+
? (this.axis.extremes[1] - this.axis.extremes[0]) / this.config.zoom?.max : this.config.zoom?.limitZoomByData ? 1 : 0;
|
|
2082
|
+
if (this.config.zoom?.wheelDelta) {
|
|
2083
|
+
this.zoom.wheelDelta(this.config.zoom?.wheelDelta);
|
|
2084
|
+
}
|
|
2097
2085
|
const minZoom = this.config.zoom?.min
|
|
2098
2086
|
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2099
2087
|
this.config.zoom?.min
|
|
@@ -2104,6 +2092,18 @@ class ZoomableDirective {
|
|
|
2104
2092
|
if (this.config?.zoom?.zoomBehavior === ZoomBehaviorType.wheel) {
|
|
2105
2093
|
this.runWheelTranslate();
|
|
2106
2094
|
}
|
|
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
2107
|
}
|
|
2108
2108
|
runWheelTranslate() {
|
|
2109
2109
|
let type = 'start';
|
|
@@ -2120,7 +2120,6 @@ class ZoomableDirective {
|
|
|
2120
2120
|
return delta * 0.002;
|
|
2121
2121
|
});
|
|
2122
2122
|
const emit = (type, event) => {
|
|
2123
|
-
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2124
2123
|
let transform = zoomIdentity;
|
|
2125
2124
|
const delta = type === 'end'
|
|
2126
2125
|
? 0
|
|
@@ -2134,22 +2133,7 @@ class ZoomableDirective {
|
|
|
2134
2133
|
transform = transform.translate(this.currentTransform.x - delta / 2, 0);
|
|
2135
2134
|
}
|
|
2136
2135
|
transform = transform.scale(this.currentTransform.k);
|
|
2137
|
-
|
|
2138
|
-
? transform.rescaleY(origin).domain()
|
|
2139
|
-
: transform.rescaleX(origin).domain();
|
|
2140
|
-
const message = new ZoomMessage({
|
|
2141
|
-
eventType: type,
|
|
2142
|
-
element: this.elementRef,
|
|
2143
|
-
axis: {
|
|
2144
|
-
index: this.axis.index,
|
|
2145
|
-
orientation: this.axis.orientation
|
|
2146
|
-
},
|
|
2147
|
-
domain,
|
|
2148
|
-
chartId: this.config.id,
|
|
2149
|
-
});
|
|
2150
|
-
this._element?.call(this.zoom.transform, transform);
|
|
2151
|
-
this.zoomService.fireZoom(message);
|
|
2152
|
-
this.zoomService.broadcastZoom(message);
|
|
2136
|
+
this._element?.call(this.zoom.transform, transform, null, { type: 'wheeling' });
|
|
2153
2137
|
this.currentTransform = transform;
|
|
2154
2138
|
};
|
|
2155
2139
|
this._element.on('wheel', (event) => {
|
|
@@ -2169,14 +2153,14 @@ class ZoomableDirective {
|
|
|
2169
2153
|
});
|
|
2170
2154
|
}
|
|
2171
2155
|
}
|
|
2172
|
-
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 });
|
|
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: BroadcastService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
|
|
2173
2157
|
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 });
|
|
2174
2158
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomableDirective, decorators: [{
|
|
2175
2159
|
type: Directive,
|
|
2176
2160
|
args: [{
|
|
2177
2161
|
selector: '[tetaZoomable]',
|
|
2178
2162
|
}]
|
|
2179
|
-
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type: i0.NgZone }]; }, propDecorators: { config: [{
|
|
2163
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type: BroadcastService }, { type: i0.NgZone }]; }, propDecorators: { config: [{
|
|
2180
2164
|
type: Input
|
|
2181
2165
|
}], axis: [{
|
|
2182
2166
|
type: Input
|
|
@@ -2214,6 +2198,13 @@ class BrushableDirective {
|
|
|
2214
2198
|
this._alive = false;
|
|
2215
2199
|
}
|
|
2216
2200
|
ngAfterViewInit() {
|
|
2201
|
+
if (this.config?.brush?.enable) {
|
|
2202
|
+
const brushMessage = new BrushMessage({
|
|
2203
|
+
chartId: this.config.id,
|
|
2204
|
+
selection: [this.config.brush?.from, this.config.brush?.to],
|
|
2205
|
+
});
|
|
2206
|
+
this.brushService.setBrush(brushMessage);
|
|
2207
|
+
}
|
|
2217
2208
|
}
|
|
2218
2209
|
ngOnChanges(changes) {
|
|
2219
2210
|
if (changes.hasOwnProperty('config')) {
|
|
@@ -2304,7 +2295,7 @@ class BrushableDirective {
|
|
|
2304
2295
|
}
|
|
2305
2296
|
this._container.call(this.brush.move, this.selection
|
|
2306
2297
|
? this.selection.map(brushScale)
|
|
2307
|
-
: domain.map(brushScale)
|
|
2298
|
+
: domain.map(brushScale));
|
|
2308
2299
|
}, 0);
|
|
2309
2300
|
});
|
|
2310
2301
|
}
|