@tetacom/svg-charts 1.1.12 → 1.1.13

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.
@@ -676,11 +676,24 @@ class BrushService {
676
676
  if (to - from === 0) {
677
677
  const selection = this.selection?.map(brushScale) ?? [config.brush?.from, config.brush?.to].map(brushScale);
678
678
  const halfBrushHeight = (selection[1] - selection[0]) / 2;
679
+ const invertedSelection = [from - halfBrushHeight, to + halfBrushHeight].map(brushScale.invert);
680
+ if (invertedSelection[1] - invertedSelection[0] > config.brush?.max) {
681
+ container.call(this.brush.move, [invertedSelection[0], invertedSelection[0] + config.brush?.max].map(brushScale));
682
+ return;
683
+ }
684
+ if (invertedSelection[1] - invertedSelection[0] < config.brush?.min) {
685
+ container.call(this.brush.move, [invertedSelection[0], invertedSelection[0] + config.brush?.min].map(brushScale));
686
+ return;
687
+ }
679
688
  container.call(this.brush.move, [from - halfBrushHeight, to + halfBrushHeight]);
680
689
  return;
681
690
  }
682
- if (brushScale.invert(to) - brushScale.invert(from) > config.brush?.limit) {
683
- container.call(this.brush.move, this.selection ? this.selection.map(brushScale) : [config.brush?.from, config.brush?.to].map(brushScale));
691
+ if (brushScale.invert(to) - brushScale.invert(from) > config.brush?.max) {
692
+ container.call(this.brush.move, this.selection ? [this.selection[0], this.selection[0] + config.brush?.max].map(brushScale) : [config.brush?.from, config.brush?.to].map(brushScale));
693
+ return;
694
+ }
695
+ if (brushScale.invert(to) - brushScale.invert(from) < config.brush?.min) {
696
+ container.call(this.brush.move, this.selection ? [this.selection[0], this.selection[0] + config.brush?.min].map(brushScale) : [config.brush?.from, config.brush?.to].map(brushScale));
684
697
  return;
685
698
  }
686
699
  if (_.sourceEvent instanceof MouseEvent) {
@@ -690,7 +703,7 @@ class BrushService {
690
703
  event: _,
691
704
  selection: [brushScale.invert(from), brushScale.invert(to)],
692
705
  brushType: config?.brush?.type ?? BrushType.x,
693
- brushScale,
706
+ brushScale
694
707
  });
695
708
  this.broadcastService.broadcastBrush({
696
709
  channel: config?.zoom?.syncChannel,
@@ -1814,8 +1827,6 @@ class ZoomableDirective {
1814
1827
  this.zoomable = true;
1815
1828
  }
1816
1829
  }
1817
- ngOnChanges(changes) {
1818
- }
1819
1830
  ngAfterViewInit() {
1820
1831
  const enable = this.axis?.options?.zoom && this.axis?.options.visible || this.config?.zoom?.enable;
1821
1832
  if (!enable) {
@@ -1824,7 +1835,6 @@ class ZoomableDirective {
1824
1835
  this._element = d3.select(this.elementRef.nativeElement);
1825
1836
  this.zoom = d3
1826
1837
  .zoom()
1827
- .scaleExtent([0, Infinity])
1828
1838
  .extent([
1829
1839
  [0, 0],
1830
1840
  [this.size.width, this.size.height],
@@ -1832,26 +1842,26 @@ class ZoomableDirective {
1832
1842
  const commonZoomAxis = Axis.createAxis(this.config?.zoom.type === ZoomType.x ? AxisOrientation.x : AxisOrientation.y, this.config, 0, true);
1833
1843
  this.zoomAxis = this.axis ?? commonZoomAxis;
1834
1844
  if (enable) {
1845
+ const maxZoom = this.config.zoom?.max ? (this.zoomAxis.extremes[1] - this.zoomAxis.extremes[0]) / this.config.zoom?.max : 0;
1846
+ const minZoom = this.config.zoom?.min ? (this.zoomAxis.extremes[1] - this.zoomAxis.extremes[0]) / this.config.zoom?.min : Infinity;
1847
+ this.zoom.scaleExtent([maxZoom, minZoom]);
1848
+ console.log(this.zoom.scaleExtent());
1835
1849
  this.zoom.on('start zoom end', this.zoomed);
1836
1850
  this._element.call(this.zoom);
1837
1851
  }
1838
1852
  // Subscribe to zoom events
1839
- this.broadcastService.subscribeToZoom(this.config?.zoom.syncChannel).pipe(filter((m) => m.message.event.sourceEvent instanceof MouseEvent || m.message.event.sourceEvent instanceof WheelEvent), debounceTime(50), filter((m) => {
1853
+ this.broadcastService.subscribeToZoom(this.config?.zoom.syncChannel).pipe(filter((m) => m.message.event.sourceEvent instanceof MouseEvent || m.message.event.sourceEvent instanceof WheelEvent), debounceTime(30), filter((m) => {
1840
1854
  return this.zoomAxis.index === m.message?.axis?.index && this.zoomAxis.orientation === m.message?.axis?.orientation;
1841
1855
  }), tap$1((m) => {
1842
1856
  const currentTransform = d3.zoomTransform(this.elementRef.nativeElement);
1843
1857
  if (currentTransform !== m.message.event.transform) {
1844
- if (this.zoomAxis.isFake && !m.message.axis.isFake || !this.zoomAxis.isFake && m.message.axis.isFake) {
1845
- this._element.call(this.zoom.transform, m.message.event.transform, null, {});
1846
- return;
1847
- }
1848
- this._element.transition().call(this.zoom.transform, m.message.event.transform, null, {});
1858
+ this._element.call(this.zoom.transform, m.message.event.transform, null, {});
1849
1859
  }
1850
1860
  }), takeWhile((_) => this.alive)).subscribe();
1851
1861
  // Subscribe to brush events x or y
1852
1862
  if ((this.config.brush?.type === BrushType.x && this.zoomAxis.orientation === AxisOrientation.x) ||
1853
1863
  (this.config.brush?.type === BrushType.y && this.zoomAxis.orientation === AxisOrientation.y)) {
1854
- this.broadcastService.subscribeToBrush(this.config?.zoom.syncChannel).pipe(throttleTime(0, animationFrameScheduler, { leading: false, trailing: true }), filter((m) => Boolean(m.message.selection)), tap$1((m) => {
1864
+ this.broadcastService.subscribeToBrush(this.config?.zoom.syncChannel).pipe(debounceTime(30), filter((m) => Boolean(m.message.selection)), tap$1((m) => {
1855
1865
  const currentTransform = d3.zoomTransform(this.elementRef.nativeElement);
1856
1866
  if (!m.message.event && this.currentSelection && currentTransform.k !== 1) {
1857
1867
  return;
@@ -1885,7 +1895,7 @@ class ZoomableDirective {
1885
1895
  }
1886
1896
  }
1887
1897
  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: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
1888
- ZoomableDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.0.1", type: ZoomableDirective, selector: "[tetaZoomable]", inputs: { config: "config", axis: "axis", size: "size", brushScale: "brushScale" }, host: { properties: { "class.zoomable": "this.zoomable" } }, usesOnChanges: true, ngImport: i0 });
1898
+ ZoomableDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.0.1", type: ZoomableDirective, selector: "[tetaZoomable]", inputs: { config: "config", axis: "axis", size: "size", brushScale: "brushScale" }, host: { properties: { "class.zoomable": "this.zoomable" } }, ngImport: i0 });
1889
1899
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.1", ngImport: i0, type: ZoomableDirective, decorators: [{
1890
1900
  type: Directive,
1891
1901
  args: [{