@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.
@@ -404,21 +404,7 @@ 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
- }
411
407
  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
- }
422
408
  }
423
409
  getD3Transform(targetDomain, originalDomain, scale, orientation, inverted) {
424
410
  const zoomScale = Math.abs(scale(originalDomain[1]) - scale(originalDomain[0])) / Math.abs(scale(targetDomain[1]) - scale(targetDomain[0]));
@@ -441,10 +427,6 @@ class ZoomService {
441
427
  }
442
428
  return transform;
443
429
  }
444
- ngOnDestroy() {
445
- var _a;
446
- (_a = this.broadcastSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
447
- }
448
430
  }
449
431
  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 });
450
432
  ZoomService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomService, providedIn: 'root' });
@@ -2002,37 +1984,41 @@ class BrushMessage {
2002
1984
  }
2003
1985
 
2004
1986
  class ZoomableDirective {
2005
- constructor(elementRef, zoomService, chartService, zone) {
1987
+ constructor(elementRef, zoomService, chartService, broadcast, zone) {
2006
1988
  this.elementRef = elementRef;
2007
1989
  this.zoomService = zoomService;
2008
1990
  this.chartService = chartService;
1991
+ this.broadcast = broadcast;
2009
1992
  this.zone = zone;
2010
1993
  this.zoomable = false;
2011
1994
  this.crosshair = false;
2012
1995
  this.alive = true;
2013
1996
  this.currentTransform = zoomIdentity;
2014
1997
  this.zoomed = (event) => {
2015
- if (event.sourceEvent) {
2016
- if (Object.keys(event.sourceEvent).length !== 0) {
2017
- const origin = this.axis.scale.copy().domain(this.axis.originDomain);
2018
- let domain = this.axis.orientation === AxisOrientation.y
2019
- ? event.transform.rescaleY(origin).domain()
2020
- : event.transform.rescaleX(origin).domain();
2021
- const message = new ZoomMessage({
2022
- eventType: event.type,
2023
- axis: {
2024
- index: this.axis.index,
2025
- orientation: this.axis.orientation,
2026
- },
2027
- element: this.elementRef,
2028
- domain: domain,
2029
- chartId: this.config.id
2030
- });
2031
- this.zoomService.fireZoom(message);
2032
- this.zoomService.broadcastZoom(message);
2033
- }
2034
- this.currentTransform = event.transform;
1998
+ if (!event.sourceEvent)
1999
+ return;
2000
+ const origin = this.axis.scale.copy().domain(this.axis.originDomain);
2001
+ let domain = this.axis.orientation === AxisOrientation.y
2002
+ ? event.transform.rescaleY(origin).domain()
2003
+ : event.transform.rescaleX(origin).domain();
2004
+ const message = new ZoomMessage({
2005
+ eventType: event.type,
2006
+ axis: {
2007
+ index: this.axis.index,
2008
+ orientation: this.axis.orientation,
2009
+ },
2010
+ element: this.elementRef,
2011
+ domain: domain,
2012
+ chartId: this.config.id
2013
+ });
2014
+ if (event.sourceEvent.type === 'broadcast') {
2015
+ this.zoomService.fireZoom(message);
2016
+ }
2017
+ if (event.sourceEvent.type === 'wheeling' || event.sourceEvent instanceof MouseEvent || (window.TouchEvent && event.sourceEvent instanceof TouchEvent)) {
2018
+ this.zoomService.fireZoom(message);
2019
+ this.zoomService.broadcastZoom(message);
2035
2020
  }
2021
+ this.currentTransform = event.transform;
2036
2022
  };
2037
2023
  }
2038
2024
  ngOnInit() {
@@ -2057,7 +2043,7 @@ class ZoomableDirective {
2057
2043
  var _a, _b, _c;
2058
2044
  if (this._element && this.elementRef !== (zoomed === null || zoomed === void 0 ? void 0 : zoomed.element)
2059
2045
  && ((_a = zoomed === null || zoomed === void 0 ? void 0 : zoomed.axis) === null || _a === void 0 ? void 0 : _a.index) === this.axis.index
2060
- && ((_b = zoomed === null || zoomed === void 0 ? void 0 : zoomed.axis) === null || _b === void 0 ? void 0 : _b.orientation) === this.axis.orientation) {
2046
+ && ((_b = zoomed === null || zoomed === void 0 ? void 0 : zoomed.axis) === null || _b === void 0 ? void 0 : _b.orientation) === this.axis.orientation && zoomed.eventType === 'end') {
2061
2047
  const scale = this.axis.scale.copy().domain(this.axis.originDomain);
2062
2048
  let transform;
2063
2049
  if (zoomed.domain === null) {
@@ -2078,7 +2064,7 @@ class ZoomableDirective {
2078
2064
  });
2079
2065
  }
2080
2066
  initZoomListeners() {
2081
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
2067
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
2082
2068
  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) ||
2083
2069
  ((_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.zoom) === null || _e === void 0 ? void 0 : _e.enable);
2084
2070
  if (!enable) {
@@ -2091,41 +2077,53 @@ class ZoomableDirective {
2091
2077
  ]);
2092
2078
  const min = ((_g = (_f = this.config) === null || _f === void 0 ? void 0 : _f.zoom) === null || _g === void 0 ? void 0 : _g.minTranslate)
2093
2079
  ? this.axis.scale((_j = (_h = this.config) === null || _h === void 0 ? void 0 : _h.zoom) === null || _j === void 0 ? void 0 : _j.minTranslate)
2094
- : -Infinity;
2095
- const max = (((_l = (_k = this.config) === null || _k === void 0 ? void 0 : _k.zoom) === null || _l === void 0 ? void 0 : _l.maxTranslate)
2096
- ? 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)
2097
- : Infinity);
2098
- if (this.axis.orientation === AxisOrientation.x && this.config.zoom.type === ZoomType.x) {
2080
+ : 0;
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
+ : this.axis.orientation === AxisOrientation.x ? this.size.width : this.size.height;
2084
+ if (this.axis.orientation === AxisOrientation.x && ((_p = this.config.zoom) === null || _p === void 0 ? void 0 : _p.type) === ZoomType.x) {
2099
2085
  this.zoom.translateExtent([
2100
- [min, -Infinity],
2101
- [max, Infinity],
2086
+ [min, 0],
2087
+ [max, this.size.height],
2102
2088
  ]);
2103
2089
  }
2104
- if (this.axis.orientation === AxisOrientation.y && this.config.zoom.type === ZoomType.y) {
2090
+ if (this.axis.orientation === AxisOrientation.y && ((_q = this.config.zoom) === null || _q === void 0 ? void 0 : _q.type) === ZoomType.y) {
2105
2091
  this.zoom.translateExtent([
2106
- [-Infinity, min],
2107
- [Infinity, max],
2092
+ [0, min],
2093
+ [this.size.width, max],
2108
2094
  ]);
2109
2095
  }
2110
- if ((_p = this.config.zoom) === null || _p === void 0 ? void 0 : _p.wheelDelta) {
2111
- this.zoom.wheelDelta((_q = this.config.zoom) === null || _q === void 0 ? void 0 : _q.wheelDelta);
2096
+ if ((_r = this.config.zoom) === null || _r === void 0 ? void 0 : _r.wheelDelta) {
2097
+ this.zoom.wheelDelta((_s = this.config.zoom) === null || _s === void 0 ? void 0 : _s.wheelDelta);
2112
2098
  }
2113
- const maxZoom = ((_r = this.config.zoom) === null || _r === void 0 ? void 0 : _r.max)
2114
- ? (this.axis.extremes[1] - this.axis.extremes[0]) /
2115
- ((_s = this.config.zoom) === null || _s === void 0 ? void 0 : _s.max)
2116
- : ((_t = this.config.zoom) === null || _t === void 0 ? void 0 : _t.limitZoomByData)
2117
- ? 1
2118
- : 0;
2119
- const minZoom = ((_u = this.config.zoom) === null || _u === void 0 ? void 0 : _u.min)
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
+ }
2104
+ const minZoom = ((_y = this.config.zoom) === null || _y === void 0 ? void 0 : _y.min)
2120
2105
  ? (this.axis.extremes[1] - this.axis.extremes[0]) /
2121
- ((_v = this.config.zoom) === null || _v === void 0 ? void 0 : _v.min)
2106
+ ((_z = this.config.zoom) === null || _z === void 0 ? void 0 : _z.min)
2122
2107
  : Infinity;
2123
2108
  this.zoom.scaleExtent([maxZoom, minZoom]);
2124
2109
  this.zoom.on('zoom end', this.zoomed);
2125
2110
  this._element.call(this.zoom).on('dblclick.zoom', null);
2126
- if (((_x = (_w = this.config) === null || _w === void 0 ? void 0 : _w.zoom) === null || _x === void 0 ? void 0 : _x.zoomBehavior) === ZoomBehaviorType.wheel) {
2111
+ if (((_1 = (_0 = this.config) === null || _0 === void 0 ? void 0 : _0.zoom) === null || _1 === void 0 ? void 0 : _1.zoomBehavior) === ZoomBehaviorType.wheel) {
2127
2112
  this.runWheelTranslate();
2128
2113
  }
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
+ });
2129
2127
  }
2130
2128
  runWheelTranslate() {
2131
2129
  let type = 'start';
@@ -2144,7 +2142,6 @@ class ZoomableDirective {
2144
2142
  });
2145
2143
  const emit = (type, event) => {
2146
2144
  var _a;
2147
- const origin = this.axis.scale.copy().domain(this.axis.originDomain);
2148
2145
  let transform = zoomIdentity;
2149
2146
  const delta = type === 'end'
2150
2147
  ? 0
@@ -2158,22 +2155,7 @@ class ZoomableDirective {
2158
2155
  transform = transform.translate(this.currentTransform.x - delta / 2, 0);
2159
2156
  }
2160
2157
  transform = transform.scale(this.currentTransform.k);
2161
- let domain = this.axis.orientation === AxisOrientation.y
2162
- ? transform.rescaleY(origin).domain()
2163
- : transform.rescaleX(origin).domain();
2164
- const message = new ZoomMessage({
2165
- eventType: type,
2166
- element: this.elementRef,
2167
- axis: {
2168
- index: this.axis.index,
2169
- orientation: this.axis.orientation
2170
- },
2171
- domain,
2172
- chartId: this.config.id,
2173
- });
2174
- (_a = this._element) === null || _a === void 0 ? void 0 : _a.call(this.zoom.transform, transform);
2175
- this.zoomService.fireZoom(message);
2176
- this.zoomService.broadcastZoom(message);
2158
+ (_a = this._element) === null || _a === void 0 ? void 0 : _a.call(this.zoom.transform, transform, null, { type: 'wheeling' });
2177
2159
  this.currentTransform = transform;
2178
2160
  };
2179
2161
  this._element.on('wheel', (event) => {
@@ -2193,14 +2175,14 @@ class ZoomableDirective {
2193
2175
  });
2194
2176
  }
2195
2177
  }
2196
- 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 });
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: BroadcastService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
2197
2179
  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 });
2198
2180
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: ZoomableDirective, decorators: [{
2199
2181
  type: Directive,
2200
2182
  args: [{
2201
2183
  selector: '[tetaZoomable]',
2202
2184
  }]
2203
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type: i0.NgZone }]; }, propDecorators: { config: [{
2185
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: ZoomService }, { type: ChartService }, { type: BroadcastService }, { type: i0.NgZone }]; }, propDecorators: { config: [{
2204
2186
  type: Input
2205
2187
  }], axis: [{
2206
2188
  type: Input
@@ -2238,6 +2220,14 @@ class BrushableDirective {
2238
2220
  this._alive = false;
2239
2221
  }
2240
2222
  ngAfterViewInit() {
2223
+ var _a, _b, _c, _d;
2224
+ if ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.brush) === null || _b === void 0 ? void 0 : _b.enable) {
2225
+ const brushMessage = new BrushMessage({
2226
+ chartId: this.config.id,
2227
+ selection: [(_c = this.config.brush) === null || _c === void 0 ? void 0 : _c.from, (_d = this.config.brush) === null || _d === void 0 ? void 0 : _d.to],
2228
+ });
2229
+ this.brushService.setBrush(brushMessage);
2230
+ }
2241
2231
  }
2242
2232
  ngOnChanges(changes) {
2243
2233
  var _a, _b;
@@ -2331,7 +2321,7 @@ class BrushableDirective {
2331
2321
  }
2332
2322
  this._container.call(this.brush.move, this.selection
2333
2323
  ? this.selection.map(brushScale)
2334
- : domain.map(brushScale), {});
2324
+ : domain.map(brushScale));
2335
2325
  }, 0);
2336
2326
  });
2337
2327
  }