@tetacom/svg-charts 1.1.20 → 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
  }
@@ -2053,30 +2075,28 @@ class ChartContainerComponent {
2053
2075
  this.xAxisMap = this._scaleService.xAxisMap;
2054
2076
  this.yScaleMap = this._scaleService.yScaleMap.pipe(throttleTime(0, animationFrameScheduler, { trailing: true }), tap(() => this._cdr.detectChanges()), shareReplay({
2055
2077
  bufferSize: 1,
2056
- refCount: true
2078
+ refCount: true,
2057
2079
  }));
2058
2080
  this.xScaleMap = this._scaleService.xScaleMap.pipe(throttleTime(0, animationFrameScheduler, { trailing: true }), tap(() => this._cdr.detectChanges()), shareReplay({
2059
2081
  bufferSize: 1,
2060
- refCount: true
2082
+ refCount: true,
2061
2083
  }));
2062
2084
  this.brushScale = combineLatest([
2063
2085
  this._scaleService.xScaleMap,
2064
2086
  this._scaleService.yScaleMap,
2065
2087
  ]).pipe(withLatestFrom(this.config), map((data) => {
2066
2088
  const [[x, y], config] = data;
2067
- return config.brush?.type === BrushType.x
2068
- ? x.get(0)
2069
- : y.get(0);
2089
+ return config.brush?.type === BrushType.x ? x.get(0) : y.get(0);
2070
2090
  }), shareReplay({
2071
2091
  bufferSize: 1,
2072
- refCount: true
2092
+ refCount: true,
2073
2093
  }));
2074
2094
  this.visibleRect = combineLatest([
2075
2095
  this.size,
2076
2096
  this.xAxisMap,
2077
- this.yAxisMap
2078
- ]).pipe(throttleTime(0, animationFrameScheduler, { trailing: true }), map((data) => {
2079
- 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;
2080
2100
  const yAxesArray = [...y.values()];
2081
2101
  const xAxesArray = [...x.values()];
2082
2102
  const left = yAxesArray
@@ -2092,10 +2112,18 @@ class ChartContainerComponent {
2092
2112
  .filter((_) => _.options.opposite && _.options.visible)
2093
2113
  .reduce(this.sumSize, 0);
2094
2114
  return {
2095
- x: left,
2096
- y: top,
2097
- width: size.width - left - right,
2098
- 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,
2099
2127
  };
2100
2128
  }), tap(() => setTimeout(() => this._cdr.detectChanges())));
2101
2129
  }
@@ -2117,8 +2145,8 @@ class ChartContainerComponent {
2117
2145
  this._observer.disconnect();
2118
2146
  }
2119
2147
  getTranslate(axis, size) {
2120
- return combineLatest([this.xAxisMap, this.yAxisMap]).pipe(map((data) => {
2121
- const [x, y] = data;
2148
+ return combineLatest([this.xAxisMap, this.yAxisMap]).pipe(withLatestFrom(this.config), map((data) => {
2149
+ const [[x, y], config] = data;
2122
2150
  const xAxesArray = [...x.values()];
2123
2151
  const yAxesArray = [...y.values()];
2124
2152
  const oppositeFilter = this.filterPositionMap.get(true);
@@ -2133,10 +2161,10 @@ class ChartContainerComponent {
2133
2161
  const nonOppisteTranslateX = nonOppositeOffsetX.reduce((acc, curr) => acc + curr.selfSize, 0);
2134
2162
  const left = yAxesArray
2135
2163
  .filter((_) => _.options.visible && _.options.opposite !== true)
2136
- .reduce((acc, curr) => acc + curr.selfSize, 0);
2164
+ .reduce((acc, curr) => acc + curr.selfSize, config.bounds?.left);
2137
2165
  const top = xAxesArray
2138
2166
  .filter((_) => _.options.visible && _.options.opposite === true)
2139
- .reduce((acc, curr) => acc + curr.selfSize, 0);
2167
+ .reduce((acc, curr) => acc + curr.selfSize, config.bounds?.top);
2140
2168
  if (axis.orientation === AxisOrientation.x) {
2141
2169
  return `translate(${left}, ${axis.options.opposite
2142
2170
  ? oppositeTranslateX
@@ -2160,8 +2188,8 @@ class ChartContainerComponent {
2160
2188
  event: event,
2161
2189
  target: {
2162
2190
  x: x.invert(event.offsetX),
2163
- y: y.invert(event.offsetY)
2164
- }
2191
+ y: y.invert(event.offsetY),
2192
+ },
2165
2193
  });
2166
2194
  }
2167
2195
  contextMenu(event, xScales, yScales) {
@@ -2171,8 +2199,8 @@ class ChartContainerComponent {
2171
2199
  event: event,
2172
2200
  target: {
2173
2201
  x: x.invert(event.offsetX),
2174
- y: y.invert(event.offsetY)
2175
- }
2202
+ y: y.invert(event.offsetY),
2203
+ },
2176
2204
  });
2177
2205
  }
2178
2206
  mouseMove(event) {