@tetacom/svg-charts 1.1.18 → 1.1.21

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.
@@ -20,14 +20,14 @@ var ZoomType;
20
20
 
21
21
  class ChartBounds {
22
22
  constructor(options) {
23
- this.top = 30;
24
- this.right = 30;
23
+ this.top = 0;
24
+ this.right = 0;
25
25
  this.bottom = 0;
26
26
  this.left = 0;
27
- this.top = options?.top || this.top;
28
- this.right = options?.right || this.right;
29
- this.bottom = options?.bottom || this.bottom;
30
- this.left = options?.left || this.left;
27
+ this.top = options?.top || 0;
28
+ this.right = options?.right || 0;
29
+ this.bottom = options?.bottom || 0;
30
+ this.left = options?.left || 0;
31
31
  }
32
32
  }
33
33
 
@@ -133,11 +133,9 @@ class ChartService {
133
133
  this.annotationEvent$ = new Subject();
134
134
  this.annotationMove$ = new Subject();
135
135
  this.id = of((Date.now() + Math.random()).toString(36));
136
- this.config = this.config$
137
- .asObservable()
138
- .pipe(withLatestFrom(this.id), map(this.setDefaults), map(this.setPreparationData), shareReplay({
136
+ this.config = this.config$.asObservable().pipe(withLatestFrom(this.id), map(this.setDefaults), map(this.setPreparationData), shareReplay({
139
137
  bufferSize: 1,
140
- refCount: true
138
+ refCount: true,
141
139
  }));
142
140
  this.size = this.size$.asObservable();
143
141
  this.pointerMove = this.pointerMove$.asObservable();
@@ -147,8 +145,12 @@ class ChartService {
147
145
  this.pointMove = this.pointMove$.asObservable();
148
146
  this.chartClick = this.chartClick$.asObservable();
149
147
  this.chartContextMenu = this.chartContextMenu$.asObservable();
150
- this.annotationClick = this.annotationEvent$.asObservable().pipe(filter((_) => _?.event?.type === 'click'));
151
- this.annotationContextMenu = this.annotationEvent$.asObservable().pipe(filter((_) => _?.event?.type === 'contextmenu'));
148
+ this.annotationClick = this.annotationEvent$
149
+ .asObservable()
150
+ .pipe(filter((_) => _?.event?.type === 'click'));
151
+ this.annotationContextMenu = this.annotationEvent$
152
+ .asObservable()
153
+ .pipe(filter((_) => _?.event?.type === 'contextmenu'));
152
154
  this.annotationMove = this.annotationMove$.asObservable();
153
155
  this.plotBandClick = this.plotBandEvent$
154
156
  .asObservable()
@@ -219,6 +221,22 @@ class ChartService {
219
221
  id: _.id ?? index,
220
222
  };
221
223
  });
224
+ const oppositeYCount = config.yAxis?.filter((_) => _.opposite);
225
+ const oppositeXCount = config.xAxis?.filter((_) => _.opposite);
226
+ const nonOppositeYCount = config.yAxis?.filter((_) => !_.opposite);
227
+ const nonOppositeXCount = config.xAxis?.filter((_) => !_.opposite);
228
+ if (nonOppositeXCount?.length > 1) {
229
+ config.bounds.bottom = 0;
230
+ }
231
+ if (oppositeXCount?.length > 1) {
232
+ config.bounds.top = 0;
233
+ }
234
+ if (nonOppositeYCount?.length > 1) {
235
+ config.bounds.left = 0;
236
+ }
237
+ if (oppositeYCount?.length > 1) {
238
+ config.bounds.right = 0;
239
+ }
222
240
  config.tooltip = Object.assign({}, defaultChartConfig().tooltip, config.tooltip);
223
241
  config.zoom.syncChannel = config.zoom?.syncChannel ?? id;
224
242
  return config;
@@ -483,7 +501,7 @@ class ScaleService {
483
501
  return map;
484
502
  }), shareReplay({
485
503
  bufferSize: 1,
486
- refCount: true
504
+ refCount: true,
487
505
  }));
488
506
  this.yAxisMap = combineLatest([
489
507
  this.chartService.size,
@@ -497,7 +515,7 @@ class ScaleService {
497
515
  return map;
498
516
  }), shareReplay({
499
517
  bufferSize: 1,
500
- refCount: true
518
+ refCount: true,
501
519
  }));
502
520
  this.xScaleMap = combineLatest([
503
521
  this.chartService.size,
@@ -521,7 +539,7 @@ class ScaleService {
521
539
  let scale = this.scaleMapping
522
540
  .get(axis.options.scaleType.type)()
523
541
  .domain(domain)
524
- .range([0, finalWidth]);
542
+ .range([0, finalWidth - config.bounds.right]);
525
543
  if (axis.options.niceTicks) {
526
544
  scale.nice();
527
545
  }
@@ -550,7 +568,7 @@ class ScaleService {
550
568
  return map;
551
569
  }), shareReplay({
552
570
  bufferSize: 1,
553
- refCount: true
571
+ refCount: true,
554
572
  }));
555
573
  this.yScaleMap = combineLatest([
556
574
  this.chartService.size,
@@ -565,7 +583,11 @@ class ScaleService {
565
583
  const bottom = [...xAxes.values()]
566
584
  .filter((_) => _.options?.visible && _.options?.opposite !== true)
567
585
  .reduce((acc, cur) => acc + cur.selfSize, 0);
568
- const finalHeight = (size.height || 0) - top - bottom;
586
+ const finalHeight = (size.height || 0) -
587
+ top -
588
+ bottom -
589
+ config?.bounds?.top -
590
+ config.bounds?.bottom;
569
591
  yAxes.forEach((axis) => {
570
592
  let domain = axis.extremes;
571
593
  if (axis.orientation === AxisOrientation.y) {
@@ -577,7 +599,7 @@ class ScaleService {
577
599
  const scale = this.scaleMapping
578
600
  .get(axis.options.scaleType.type)()
579
601
  .domain(domain)
580
- .range([0, finalHeight]);
602
+ .range([config.bounds.top, finalHeight]);
581
603
  if (axis.options.niceTicks) {
582
604
  scale.nice();
583
605
  }
@@ -606,7 +628,7 @@ class ScaleService {
606
628
  return map;
607
629
  }), shareReplay({
608
630
  bufferSize: 1,
609
- refCount: true
631
+ refCount: true,
610
632
  }));
611
633
  }
612
634
  }
@@ -1846,7 +1868,7 @@ class ZoomableDirective {
1846
1868
  }
1847
1869
  ngOnInit() {
1848
1870
  if (this.axis?.options?.zoom || this.config?.zoom?.enable) {
1849
- this.zoomable = true;
1871
+ this.zoomable = this.config?.zoom?.zoomBehavior === ZoomBehaviorType.move;
1850
1872
  }
1851
1873
  }
1852
1874
  ngAfterViewInit() {
@@ -1871,14 +1893,13 @@ class ZoomableDirective {
1871
1893
  const minZoom = this.config.zoom?.min ? (this.zoomAxis.extremes[1] - this.zoomAxis.extremes[0]) / this.config.zoom?.min : Infinity;
1872
1894
  this.zoom.scaleExtent([maxZoom, minZoom]);
1873
1895
  this.zoom.on('start zoom end', this.zoomed);
1874
- this._element.call(this.zoom)
1875
- .on('dblclick.zoom', null);
1896
+ this._element.call(this.zoom).on('dblclick.zoom', null);
1876
1897
  if (this.config?.zoom?.zoomBehavior === ZoomBehaviorType.wheel) {
1877
1898
  let wheeling;
1878
1899
  let type = 'start';
1879
1900
  const origin = this.brushScale.copy().domain(this.zoomAxis.extremes);
1880
1901
  this.zoom
1881
- .filter((event) => event.ctrlKey)
1902
+ .filter((event) => event.ctrlKey && event.type === 'wheel')
1882
1903
  .wheelDelta((event) => {
1883
1904
  const delta = this.config?.zoom.type === ZoomType.x ? -event.deltaX : -event.deltaY;
1884
1905
  return delta * 0.002;
@@ -1892,10 +1913,10 @@ class ZoomableDirective {
1892
1913
  let transform = zoomIdentity;
1893
1914
  const delta = type === 'end' ? 0 : this.config.zoom?.type === ZoomType.y ? event.deltaY : event.deltaX;
1894
1915
  if (this.config.zoom?.type === ZoomType.y) {
1895
- transform = transform.translate(0, this.currentTransform.y - delta);
1916
+ transform = transform.translate(0, this.currentTransform.y - delta / 2);
1896
1917
  }
1897
1918
  if (this.config.zoom?.type === ZoomType.x) {
1898
- transform = transform.translate(this.currentTransform.x - delta, 0);
1919
+ transform = transform.translate(this.currentTransform.x - delta / 2, 0);
1899
1920
  }
1900
1921
  transform = transform.scale(this.currentTransform.k);
1901
1922
  let domain = this.config.zoom?.type === ZoomType.y ?
@@ -1934,7 +1955,7 @@ class ZoomableDirective {
1934
1955
  type = 'end';
1935
1956
  emit(type);
1936
1957
  type = 'start';
1937
- }, 400);
1958
+ }, 300);
1938
1959
  });
1939
1960
  });
1940
1961
  }
@@ -1983,7 +2004,7 @@ class ZoomableDirective {
1983
2004
  if (m.message?.brushType === BrushType.y) {
1984
2005
  transform = transform.translate(0, -this.brushScale(s[0]));
1985
2006
  }
1986
- this._element.transition().duration(150).call(this.zoom.transform, transform, null, {});
2007
+ this._element.call(this.zoom.transform, transform, null, {});
1987
2008
  }
1988
2009
  }
1989
2010
  ZoomableDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: ZoomableDirective, deps: [{ token: i0.ElementRef }, { token: ZoomService }, { token: BroadcastService }, { token: ChartService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
@@ -2054,30 +2075,28 @@ class ChartContainerComponent {
2054
2075
  this.xAxisMap = this._scaleService.xAxisMap;
2055
2076
  this.yScaleMap = this._scaleService.yScaleMap.pipe(throttleTime(0, animationFrameScheduler, { trailing: true }), tap(() => this._cdr.detectChanges()), shareReplay({
2056
2077
  bufferSize: 1,
2057
- refCount: true
2078
+ refCount: true,
2058
2079
  }));
2059
2080
  this.xScaleMap = this._scaleService.xScaleMap.pipe(throttleTime(0, animationFrameScheduler, { trailing: true }), tap(() => this._cdr.detectChanges()), shareReplay({
2060
2081
  bufferSize: 1,
2061
- refCount: true
2082
+ refCount: true,
2062
2083
  }));
2063
2084
  this.brushScale = combineLatest([
2064
2085
  this._scaleService.xScaleMap,
2065
2086
  this._scaleService.yScaleMap,
2066
2087
  ]).pipe(withLatestFrom(this.config), map((data) => {
2067
2088
  const [[x, y], config] = data;
2068
- return config.brush?.type === BrushType.x
2069
- ? x.get(0)
2070
- : y.get(0);
2089
+ return config.brush?.type === BrushType.x ? x.get(0) : y.get(0);
2071
2090
  }), shareReplay({
2072
2091
  bufferSize: 1,
2073
- refCount: true
2092
+ refCount: true,
2074
2093
  }));
2075
2094
  this.visibleRect = combineLatest([
2076
2095
  this.size,
2077
2096
  this.xAxisMap,
2078
- this.yAxisMap
2079
- ]).pipe(throttleTime(0, animationFrameScheduler, { trailing: true }), map((data) => {
2080
- const [size, x, y] = data;
2097
+ this.yAxisMap,
2098
+ ]).pipe(throttleTime(0, animationFrameScheduler, { trailing: true }), withLatestFrom(this.config), map((data) => {
2099
+ const [[size, x, y], config] = data;
2081
2100
  const yAxesArray = [...y.values()];
2082
2101
  const xAxesArray = [...x.values()];
2083
2102
  const left = yAxesArray
@@ -2093,10 +2112,18 @@ class ChartContainerComponent {
2093
2112
  .filter((_) => _.options.opposite && _.options.visible)
2094
2113
  .reduce(this.sumSize, 0);
2095
2114
  return {
2096
- x: left,
2097
- y: top,
2098
- width: size.width - left - right,
2099
- height: size.height - top - bottom,
2115
+ x: left + config.bounds?.left,
2116
+ y: top + config.bounds?.top,
2117
+ width: size.width -
2118
+ left -
2119
+ right -
2120
+ config.bounds?.left -
2121
+ config.bounds?.right,
2122
+ height: size.height -
2123
+ top -
2124
+ bottom -
2125
+ config.bounds?.top -
2126
+ config.bounds?.bottom,
2100
2127
  };
2101
2128
  }), tap(() => setTimeout(() => this._cdr.detectChanges())));
2102
2129
  }
@@ -2118,8 +2145,8 @@ class ChartContainerComponent {
2118
2145
  this._observer.disconnect();
2119
2146
  }
2120
2147
  getTranslate(axis, size) {
2121
- return combineLatest([this.xAxisMap, this.yAxisMap]).pipe(map((data) => {
2122
- const [x, y] = data;
2148
+ return combineLatest([this.xAxisMap, this.yAxisMap]).pipe(withLatestFrom(this.config), map((data) => {
2149
+ const [[x, y], config] = data;
2123
2150
  const xAxesArray = [...x.values()];
2124
2151
  const yAxesArray = [...y.values()];
2125
2152
  const oppositeFilter = this.filterPositionMap.get(true);
@@ -2134,10 +2161,10 @@ class ChartContainerComponent {
2134
2161
  const nonOppisteTranslateX = nonOppositeOffsetX.reduce((acc, curr) => acc + curr.selfSize, 0);
2135
2162
  const left = yAxesArray
2136
2163
  .filter((_) => _.options.visible && _.options.opposite !== true)
2137
- .reduce((acc, curr) => acc + curr.selfSize, 0);
2164
+ .reduce((acc, curr) => acc + curr.selfSize, config.bounds?.left);
2138
2165
  const top = xAxesArray
2139
2166
  .filter((_) => _.options.visible && _.options.opposite === true)
2140
- .reduce((acc, curr) => acc + curr.selfSize, 0);
2167
+ .reduce((acc, curr) => acc + curr.selfSize, config.bounds?.top);
2141
2168
  if (axis.orientation === AxisOrientation.x) {
2142
2169
  return `translate(${left}, ${axis.options.opposite
2143
2170
  ? oppositeTranslateX
@@ -2161,8 +2188,8 @@ class ChartContainerComponent {
2161
2188
  event: event,
2162
2189
  target: {
2163
2190
  x: x.invert(event.offsetX),
2164
- y: y.invert(event.offsetY)
2165
- }
2191
+ y: y.invert(event.offsetY),
2192
+ },
2166
2193
  });
2167
2194
  }
2168
2195
  contextMenu(event, xScales, yScales) {
@@ -2172,8 +2199,8 @@ class ChartContainerComponent {
2172
2199
  event: event,
2173
2200
  target: {
2174
2201
  x: x.invert(event.offsetX),
2175
- y: y.invert(event.offsetY)
2176
- }
2202
+ y: y.invert(event.offsetY),
2203
+ },
2177
2204
  });
2178
2205
  }
2179
2206
  mouseMove(event) {