@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
|
@@ -404,7 +404,21 @@ class ZoomService {
|
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
setBroadcastChannel(channel) {
|
|
407
|
+
var _a, _b;
|
|
408
|
+
if (this.broadcastSub) {
|
|
409
|
+
(_a = this.broadcastSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
410
|
+
}
|
|
407
411
|
this.broadcastChannel = channel;
|
|
412
|
+
if ((_b = this.broadcastChannel) === null || _b === void 0 ? void 0 : _b.length) {
|
|
413
|
+
this.broadcastSub = combineLatest([this._broadcast.subscribeToZoom(this.broadcastChannel), this._chart.config])
|
|
414
|
+
.pipe(filter(([zoom, config]) => {
|
|
415
|
+
var _a;
|
|
416
|
+
return ((_a = zoom.message) === null || _a === void 0 ? void 0 : _a.chartId) !== config.id;
|
|
417
|
+
}))
|
|
418
|
+
.subscribe(([zoom, config]) => {
|
|
419
|
+
this.fireZoom(zoom.message);
|
|
420
|
+
});
|
|
421
|
+
}
|
|
408
422
|
}
|
|
409
423
|
getD3Transform(targetDomain, originalDomain, scale, orientation, inverted) {
|
|
410
424
|
const zoomScale = Math.abs(scale(originalDomain[1]) - scale(originalDomain[0])) / Math.abs(scale(targetDomain[1]) - scale(targetDomain[0]));
|
|
@@ -427,6 +441,10 @@ class ZoomService {
|
|
|
427
441
|
}
|
|
428
442
|
return transform;
|
|
429
443
|
}
|
|
444
|
+
ngOnDestroy() {
|
|
445
|
+
var _a;
|
|
446
|
+
(_a = this.broadcastSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
447
|
+
}
|
|
430
448
|
}
|
|
431
449
|
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 });
|
|
432
450
|
ZoomService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomService, providedIn: 'root' });
|
|
@@ -769,9 +787,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImpor
|
|
|
769
787
|
}], ctorParameters: function () { return [{ type: ChartService }, { type: ZoomService }]; } });
|
|
770
788
|
|
|
771
789
|
class BrushService {
|
|
772
|
-
// private _outBrushDomain = new ReplaySubject<[number, number]>(1);
|
|
773
790
|
constructor() {
|
|
774
|
-
// outBrushDomain: Observable<[number, number]>;
|
|
775
791
|
this._brushDomain = new ReplaySubject(1);
|
|
776
792
|
this.brushDomain = this._brushDomain.asObservable();
|
|
777
793
|
}
|
|
@@ -1984,41 +2000,37 @@ class BrushMessage {
|
|
|
1984
2000
|
}
|
|
1985
2001
|
|
|
1986
2002
|
class ZoomableDirective {
|
|
1987
|
-
constructor(elementRef, zoomService, chartService,
|
|
2003
|
+
constructor(elementRef, zoomService, chartService, zone) {
|
|
1988
2004
|
this.elementRef = elementRef;
|
|
1989
2005
|
this.zoomService = zoomService;
|
|
1990
2006
|
this.chartService = chartService;
|
|
1991
|
-
this.broadcast = broadcast;
|
|
1992
2007
|
this.zone = zone;
|
|
1993
2008
|
this.zoomable = false;
|
|
1994
2009
|
this.crosshair = false;
|
|
1995
2010
|
this.alive = true;
|
|
1996
2011
|
this.currentTransform = zoomIdentity;
|
|
1997
2012
|
this.zoomed = (event) => {
|
|
1998
|
-
if (
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
this.zoomService.fireZoom(message);
|
|
2019
|
-
this.zoomService.broadcastZoom(message);
|
|
2013
|
+
if (event.sourceEvent) {
|
|
2014
|
+
if (Object.keys(event.sourceEvent).length !== 0) {
|
|
2015
|
+
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2016
|
+
let domain = this.axis.orientation === AxisOrientation.y
|
|
2017
|
+
? event.transform.rescaleY(origin).domain()
|
|
2018
|
+
: event.transform.rescaleX(origin).domain();
|
|
2019
|
+
const message = new ZoomMessage({
|
|
2020
|
+
eventType: event.type,
|
|
2021
|
+
axis: {
|
|
2022
|
+
index: this.axis.index,
|
|
2023
|
+
orientation: this.axis.orientation,
|
|
2024
|
+
},
|
|
2025
|
+
element: this.elementRef,
|
|
2026
|
+
domain: domain,
|
|
2027
|
+
chartId: this.config.id
|
|
2028
|
+
});
|
|
2029
|
+
this.zoomService.fireZoom(message);
|
|
2030
|
+
this.zoomService.broadcastZoom(message);
|
|
2031
|
+
}
|
|
2032
|
+
this.currentTransform = event.transform;
|
|
2020
2033
|
}
|
|
2021
|
-
this.currentTransform = event.transform;
|
|
2022
2034
|
};
|
|
2023
2035
|
}
|
|
2024
2036
|
ngOnInit() {
|
|
@@ -2040,10 +2052,10 @@ class ZoomableDirective {
|
|
|
2040
2052
|
}
|
|
2041
2053
|
initZoomSync() {
|
|
2042
2054
|
this.zoomService.zoomed.pipe(takeWhile(() => this.alive)).subscribe((zoomed) => {
|
|
2043
|
-
var _a, _b
|
|
2055
|
+
var _a, _b;
|
|
2044
2056
|
if (this._element && this.elementRef !== (zoomed === null || zoomed === void 0 ? void 0 : zoomed.element)
|
|
2045
2057
|
&& ((_a = zoomed === null || zoomed === void 0 ? void 0 : zoomed.axis) === null || _a === void 0 ? void 0 : _a.index) === this.axis.index
|
|
2046
|
-
&& ((_b = zoomed === null || zoomed === void 0 ? void 0 : zoomed.axis) === null || _b === void 0 ? void 0 : _b.orientation) === this.axis.orientation
|
|
2058
|
+
&& ((_b = zoomed === null || zoomed === void 0 ? void 0 : zoomed.axis) === null || _b === void 0 ? void 0 : _b.orientation) === this.axis.orientation) {
|
|
2047
2059
|
const scale = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2048
2060
|
let transform;
|
|
2049
2061
|
if (zoomed.domain === null) {
|
|
@@ -2053,18 +2065,13 @@ class ZoomableDirective {
|
|
|
2053
2065
|
transform =
|
|
2054
2066
|
this.zoomService.getD3Transform(zoomed.domain, this.axis.originDomain, scale, this.axis.orientation, this.axis.options.inverted);
|
|
2055
2067
|
}
|
|
2056
|
-
|
|
2057
|
-
this._element.transition().call(this.zoom.transform, transform);
|
|
2058
|
-
}
|
|
2059
|
-
else {
|
|
2060
|
-
this._element.call(this.zoom.transform, transform);
|
|
2061
|
-
}
|
|
2068
|
+
this._element.call(this.zoom.transform, transform);
|
|
2062
2069
|
this.currentTransform = transform;
|
|
2063
2070
|
}
|
|
2064
2071
|
});
|
|
2065
2072
|
}
|
|
2066
2073
|
initZoomListeners() {
|
|
2067
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x
|
|
2074
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
2068
2075
|
const enable = (((_b = (_a = this.axis) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.zoom) && ((_c = this.axis) === null || _c === void 0 ? void 0 : _c.options.visible) !== false) ||
|
|
2069
2076
|
((_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.zoom) === null || _e === void 0 ? void 0 : _e.enable);
|
|
2070
2077
|
if (!enable) {
|
|
@@ -2077,53 +2084,41 @@ class ZoomableDirective {
|
|
|
2077
2084
|
]);
|
|
2078
2085
|
const min = ((_g = (_f = this.config) === null || _f === void 0 ? void 0 : _f.zoom) === null || _g === void 0 ? void 0 : _g.minTranslate)
|
|
2079
2086
|
? this.axis.scale((_j = (_h = this.config) === null || _h === void 0 ? void 0 : _h.zoom) === null || _j === void 0 ? void 0 : _j.minTranslate)
|
|
2080
|
-
:
|
|
2081
|
-
const max = ((_l = (_k = this.config) === null || _k === void 0 ? void 0 : _k.zoom) === null || _l === void 0 ? void 0 : _l.maxTranslate)
|
|
2082
|
-
? this.axis.scale((_o = (_m = this.config) === null || _m === void 0 ? void 0 : _m.zoom) === null || _o === void 0 ? void 0 : _o.maxTranslate)
|
|
2083
|
-
:
|
|
2084
|
-
if (this.axis.orientation === AxisOrientation.x &&
|
|
2087
|
+
: -Infinity;
|
|
2088
|
+
const max = (((_l = (_k = this.config) === null || _k === void 0 ? void 0 : _k.zoom) === null || _l === void 0 ? void 0 : _l.maxTranslate)
|
|
2089
|
+
? this.axis.scale((_o = (_m = this.config) === null || _m === void 0 ? void 0 : _m.zoom) === null || _o === void 0 ? void 0 : _o.maxTranslate) - (this.axis.orientation === AxisOrientation.x ? this.size.width : this.size.height)
|
|
2090
|
+
: Infinity);
|
|
2091
|
+
if (this.axis.orientation === AxisOrientation.x && this.config.zoom.type === ZoomType.x) {
|
|
2085
2092
|
this.zoom.translateExtent([
|
|
2086
|
-
[min,
|
|
2087
|
-
[max,
|
|
2093
|
+
[min, -Infinity],
|
|
2094
|
+
[max, Infinity],
|
|
2088
2095
|
]);
|
|
2089
2096
|
}
|
|
2090
|
-
if (this.axis.orientation === AxisOrientation.y &&
|
|
2097
|
+
if (this.axis.orientation === AxisOrientation.y && this.config.zoom.type === ZoomType.y) {
|
|
2091
2098
|
this.zoom.translateExtent([
|
|
2092
|
-
[
|
|
2093
|
-
[
|
|
2099
|
+
[-Infinity, min],
|
|
2100
|
+
[Infinity, max],
|
|
2094
2101
|
]);
|
|
2095
2102
|
}
|
|
2096
|
-
if ((
|
|
2097
|
-
this.zoom.wheelDelta((
|
|
2098
|
-
}
|
|
2099
|
-
const maxZoom = ((_t = this.config.zoom) === null || _t === void 0 ? void 0 : _t.max)
|
|
2100
|
-
? (this.axis.extremes[1] - this.axis.extremes[0]) / ((_u = this.config.zoom) === null || _u === void 0 ? void 0 : _u.max) : ((_v = this.config.zoom) === null || _v === void 0 ? void 0 : _v.limitZoomByData) ? 1 : 0;
|
|
2101
|
-
if ((_w = this.config.zoom) === null || _w === void 0 ? void 0 : _w.wheelDelta) {
|
|
2102
|
-
this.zoom.wheelDelta((_x = this.config.zoom) === null || _x === void 0 ? void 0 : _x.wheelDelta);
|
|
2103
|
+
if ((_p = this.config.zoom) === null || _p === void 0 ? void 0 : _p.wheelDelta) {
|
|
2104
|
+
this.zoom.wheelDelta((_q = this.config.zoom) === null || _q === void 0 ? void 0 : _q.wheelDelta);
|
|
2103
2105
|
}
|
|
2104
|
-
const
|
|
2106
|
+
const maxZoom = ((_r = this.config.zoom) === null || _r === void 0 ? void 0 : _r.max)
|
|
2105
2107
|
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2106
|
-
((
|
|
2108
|
+
((_s = this.config.zoom) === null || _s === void 0 ? void 0 : _s.max)
|
|
2109
|
+
: ((_t = this.config.zoom) === null || _t === void 0 ? void 0 : _t.limitZoomByData)
|
|
2110
|
+
? 1
|
|
2111
|
+
: 0;
|
|
2112
|
+
const minZoom = ((_u = this.config.zoom) === null || _u === void 0 ? void 0 : _u.min)
|
|
2113
|
+
? (this.axis.extremes[1] - this.axis.extremes[0]) /
|
|
2114
|
+
((_v = this.config.zoom) === null || _v === void 0 ? void 0 : _v.min)
|
|
2107
2115
|
: Infinity;
|
|
2108
2116
|
this.zoom.scaleExtent([maxZoom, minZoom]);
|
|
2109
2117
|
this.zoom.on('zoom end', this.zoomed);
|
|
2110
2118
|
this._element.call(this.zoom).on('dblclick.zoom', null);
|
|
2111
|
-
if (((
|
|
2119
|
+
if (((_x = (_w = this.config) === null || _w === void 0 ? void 0 : _w.zoom) === null || _x === void 0 ? void 0 : _x.zoomBehavior) === ZoomBehaviorType.wheel) {
|
|
2112
2120
|
this.runWheelTranslate();
|
|
2113
2121
|
}
|
|
2114
|
-
this.broadcast.subscribeToZoom((_2 = this.config) === null || _2 === void 0 ? void 0 : _2.zoom.syncChannel).subscribe((zoom) => {
|
|
2115
|
-
var _a, _b;
|
|
2116
|
-
if (zoom.message.chartId !== ((_a = this.config) === null || _a === void 0 ? void 0 : _a.id) && zoom.message.axis.orientation === this.axis.orientation && zoom.message.axis.index === this.axis.index) {
|
|
2117
|
-
const scale = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2118
|
-
const transform = this.zoomService.getD3Transform(zoom.message.domain, this.axis.originDomain, scale, this.axis.orientation, this.axis.options.inverted);
|
|
2119
|
-
if ((_b = zoom.message.style) === null || _b === void 0 ? void 0 : _b.transition) {
|
|
2120
|
-
this._element.transition().duration(300).call(this.zoom.transform, transform, null, { type: 'broadcast' });
|
|
2121
|
-
}
|
|
2122
|
-
else {
|
|
2123
|
-
this._element.call(this.zoom.transform, transform, null, { type: 'broadcast' });
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
});
|
|
2127
2122
|
}
|
|
2128
2123
|
runWheelTranslate() {
|
|
2129
2124
|
let type = 'start';
|
|
@@ -2142,6 +2137,7 @@ class ZoomableDirective {
|
|
|
2142
2137
|
});
|
|
2143
2138
|
const emit = (type, event) => {
|
|
2144
2139
|
var _a;
|
|
2140
|
+
const origin = this.axis.scale.copy().domain(this.axis.originDomain);
|
|
2145
2141
|
let transform = zoomIdentity;
|
|
2146
2142
|
const delta = type === 'end'
|
|
2147
2143
|
? 0
|
|
@@ -2155,7 +2151,22 @@ class ZoomableDirective {
|
|
|
2155
2151
|
transform = transform.translate(this.currentTransform.x - delta / 2, 0);
|
|
2156
2152
|
}
|
|
2157
2153
|
transform = transform.scale(this.currentTransform.k);
|
|
2158
|
-
|
|
2154
|
+
let domain = this.axis.orientation === AxisOrientation.y
|
|
2155
|
+
? transform.rescaleY(origin).domain()
|
|
2156
|
+
: transform.rescaleX(origin).domain();
|
|
2157
|
+
const message = new ZoomMessage({
|
|
2158
|
+
eventType: type,
|
|
2159
|
+
element: this.elementRef,
|
|
2160
|
+
axis: {
|
|
2161
|
+
index: this.axis.index,
|
|
2162
|
+
orientation: this.axis.orientation
|
|
2163
|
+
},
|
|
2164
|
+
domain,
|
|
2165
|
+
chartId: this.config.id,
|
|
2166
|
+
});
|
|
2167
|
+
(_a = this._element) === null || _a === void 0 ? void 0 : _a.call(this.zoom.transform, transform);
|
|
2168
|
+
this.zoomService.fireZoom(message);
|
|
2169
|
+
this.zoomService.broadcastZoom(message);
|
|
2159
2170
|
this.currentTransform = transform;
|
|
2160
2171
|
};
|
|
2161
2172
|
this._element.on('wheel', (event) => {
|
|
@@ -2175,14 +2186,14 @@ class ZoomableDirective {
|
|
|
2175
2186
|
});
|
|
2176
2187
|
}
|
|
2177
2188
|
}
|
|
2178
|
-
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:
|
|
2189
|
+
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 });
|
|
2179
2190
|
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 });
|
|
2180
2191
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomableDirective, decorators: [{
|
|
2181
2192
|
type: Directive,
|
|
2182
2193
|
args: [{
|
|
2183
2194
|
selector: '[tetaZoomable]',
|
|
2184
2195
|
}]
|
|
2185
|
-
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type:
|
|
2196
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type: i0.NgZone }]; }, propDecorators: { config: [{
|
|
2186
2197
|
type: Input
|
|
2187
2198
|
}], axis: [{
|
|
2188
2199
|
type: Input
|
|
@@ -2220,11 +2231,11 @@ class BrushableDirective {
|
|
|
2220
2231
|
this._alive = false;
|
|
2221
2232
|
}
|
|
2222
2233
|
ngAfterViewInit() {
|
|
2223
|
-
var _a, _b, _c, _d;
|
|
2234
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2224
2235
|
if ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.brush) === null || _b === void 0 ? void 0 : _b.enable) {
|
|
2225
2236
|
const brushMessage = new BrushMessage({
|
|
2226
2237
|
chartId: this.config.id,
|
|
2227
|
-
selection: [(_c = this.config
|
|
2238
|
+
selection: [(_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.brush) === null || _d === void 0 ? void 0 : _d.from, (_f = (_e = this.config) === null || _e === void 0 ? void 0 : _e.brush) === null || _f === void 0 ? void 0 : _f.to],
|
|
2228
2239
|
});
|
|
2229
2240
|
this.brushService.setBrush(brushMessage);
|
|
2230
2241
|
}
|