@tetacom/svg-charts 1.3.1 → 1.3.2

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.
@@ -421,7 +421,7 @@ class ZoomService {
421
421
  }
422
422
  }
423
423
  getD3Transform(targetDomain, originalDomain, scale, orientation, inverted) {
424
- const zoomScale = Math.abs(originalDomain[1] - originalDomain[0]) / Math.abs(targetDomain[1] - targetDomain[0]);
424
+ const zoomScale = Math.abs(scale(originalDomain[1]) - scale(originalDomain[0])) / Math.abs(scale(targetDomain[1]) - scale(targetDomain[0]));
425
425
  let transform = zoomIdentity.scale(zoomScale);
426
426
  if (orientation === AxisOrientation.x) {
427
427
  if (!!inverted) {
@@ -864,7 +864,7 @@ class LinearSeriesBase extends SeriesBaseComponent {
864
864
  set series(series) {
865
865
  var _a;
866
866
  this.__series = series;
867
- this.markers = (_a = this.__series.data) === null || _a === void 0 ? void 0 : _a.filter((_) => (_ === null || _ === void 0 ? void 0 : _.marker) && (_ === null || _ === void 0 ? void 0 : _.x) !== undefined && (_ === null || _ === void 0 ? void 0 : _.y) !== undefined);
867
+ this.markers = (_a = this.__series.data) === null || _a === void 0 ? void 0 : _a.filter((_) => (_ === null || _ === void 0 ? void 0 : _.marker) && (_ === null || _ === void 0 ? void 0 : _.x) !== undefined && (_ === null || _ === void 0 ? void 0 : _.y) !== undefined && (_ === null || _ === void 0 ? void 0 : _.x) !== null && (_ === null || _ === void 0 ? void 0 : _.y) !== null);
868
868
  }
869
869
  get series() {
870
870
  return this.__series;
@@ -1599,13 +1599,14 @@ class XAxisComponent {
1599
1599
  constructor(scaleService, _svc) {
1600
1600
  this.scaleService = scaleService;
1601
1601
  this._svc = _svc;
1602
+ this.update$ = new BehaviorSubject(null);
1602
1603
  this._alive = true;
1603
1604
  this.x = this.scaleService.scales.pipe(map((_) => {
1604
1605
  var _a;
1605
1606
  return (_a = _.x.get(this.axis.index)) === null || _a === void 0 ? void 0 : _a.scale;
1606
1607
  }));
1607
- this.ticks = this.x.pipe(withLatestFrom(this._svc.size), map((_) => {
1608
- const [x, size] = _;
1608
+ this.ticks = combineLatest([this.x, this.update$]).pipe(withLatestFrom(this._svc.size), map((_) => {
1609
+ const [[x], size] = _;
1609
1610
  const tickSize = x.ticks().map((_) => getTextWidth(this.axis.options.tickFormat ? this.axis.options.tickFormat(_) : this.axis.defaultFormatter()(_), 0.45, 11));
1610
1611
  return x.ticks(size.width / parseInt(d3.max(tickSize), 10) / 10);
1611
1612
  }));
@@ -1618,9 +1619,14 @@ class XAxisComponent {
1618
1619
  ngOnDestroy() {
1619
1620
  this._alive = false;
1620
1621
  }
1622
+ ngOnChanges(changes) {
1623
+ if (changes.hasOwnProperty('axis')) {
1624
+ this.update$.next();
1625
+ }
1626
+ }
1621
1627
  }
1622
1628
  XAxisComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: XAxisComponent, deps: [{ token: ScaleService }, { token: ChartService }], target: i0.ɵɵFactoryTarget.Component });
1623
- XAxisComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.2", type: XAxisComponent, selector: "[teta-x-axis]", inputs: { axis: "axis", size: "size" }, ngImport: i0, template: "<ng-container *ngIf=\"{x: x | async, ticks: ticks | async} as data\">\n <svg:g text-anchor=\"middle\" *ngFor=\"let tick of data.ticks\" [attr.transform]=\"'translate('+ data.x(tick) +', 0)'\">\n <text fill=\"var(--color-text-70)\" [attr.dy]=\"axis.options.opposite ? '-0.71em' : '0.71em'\" [attr.y]=\"axis.options.opposite ? 0 : 9\">{{ this.axis.options.tickFormat ? this.axis.options.tickFormat(tick) : this.axis.defaultFormatter()(tick) }}</text>\n <line stroke=\"var(--color-text-30)\" [attr.y2]=\"axis.options.opposite ? -6 : 6\"></line>\n </svg:g>\n\n <svg:g class=\"label-axis font-caption\" [attr.transform]=\"getLabelTransform()\">\n <text fill=\"var(--color-text-70)\" text-anchor=\"middle\" dominant-baseline=\"middle\">{{ axis.options.title }}</text>\n </svg:g>\n</ng-container>\n\n", styles: [":host .tick{stroke:var(--color-text-20)}\n"], dependencies: [{ kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1629
+ XAxisComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.2", type: XAxisComponent, selector: "[teta-x-axis]", inputs: { axis: "axis", size: "size" }, usesOnChanges: true, ngImport: i0, template: "<ng-container *ngIf=\"{x: x | async, ticks: ticks | async} as data\">\n <svg:g text-anchor=\"middle\" *ngFor=\"let tick of data.ticks\" [attr.transform]=\"'translate('+ data.x(tick) +', 0)'\">\n <text fill=\"var(--color-text-70)\" [attr.dy]=\"axis.options.opposite ? '-0.71em' : '0.71em'\" [attr.y]=\"axis.options.opposite ? 0 : 9\">{{ this.axis.options.tickFormat ? this.axis.options.tickFormat(tick) : this.axis.defaultFormatter()(tick) }}</text>\n <line stroke=\"var(--color-text-30)\" [attr.y2]=\"axis.options.opposite ? -6 : 6\"></line>\n </svg:g>\n\n <svg:g class=\"label-axis font-caption\" [attr.transform]=\"getLabelTransform()\">\n <text fill=\"var(--color-text-70)\" text-anchor=\"middle\" dominant-baseline=\"middle\">{{ axis.options.title }}</text>\n </svg:g>\n</ng-container>\n\n", styles: [":host .tick{stroke:var(--color-text-20)}\n"], dependencies: [{ kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i4.AsyncPipe, name: "async" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1624
1630
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.2", ngImport: i0, type: XAxisComponent, decorators: [{
1625
1631
  type: Component,
1626
1632
  args: [{ selector: '[teta-x-axis]', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-container *ngIf=\"{x: x | async, ticks: ticks | async} as data\">\n <svg:g text-anchor=\"middle\" *ngFor=\"let tick of data.ticks\" [attr.transform]=\"'translate('+ data.x(tick) +', 0)'\">\n <text fill=\"var(--color-text-70)\" [attr.dy]=\"axis.options.opposite ? '-0.71em' : '0.71em'\" [attr.y]=\"axis.options.opposite ? 0 : 9\">{{ this.axis.options.tickFormat ? this.axis.options.tickFormat(tick) : this.axis.defaultFormatter()(tick) }}</text>\n <line stroke=\"var(--color-text-30)\" [attr.y2]=\"axis.options.opposite ? -6 : 6\"></line>\n </svg:g>\n\n <svg:g class=\"label-axis font-caption\" [attr.transform]=\"getLabelTransform()\">\n <text fill=\"var(--color-text-70)\" text-anchor=\"middle\" dominant-baseline=\"middle\">{{ axis.options.title }}</text>\n </svg:g>\n</ng-container>\n\n", styles: [":host .tick{stroke:var(--color-text-20)}\n"] }]
@@ -2072,7 +2078,7 @@ class ZoomableDirective {
2072
2078
  });
2073
2079
  }
2074
2080
  initZoomListeners() {
2075
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
2081
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
2076
2082
  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) ||
2077
2083
  ((_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.zoom) === null || _e === void 0 ? void 0 : _e.enable);
2078
2084
  if (!enable) {
@@ -2083,29 +2089,41 @@ class ZoomableDirective {
2083
2089
  [0, 0],
2084
2090
  [this.size.width, this.size.height],
2085
2091
  ]);
2086
- if ((_f = this.config.zoom) === null || _f === void 0 ? void 0 : _f.limitTranslateByData) {
2092
+ const min = ((_g = (_f = this.config) === null || _f === void 0 ? void 0 : _f.zoom) === null || _g === void 0 ? void 0 : _g.minTranslate)
2093
+ ? 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) {
2099
+ this.zoom.translateExtent([
2100
+ [min, -Infinity],
2101
+ [max, Infinity],
2102
+ ]);
2103
+ }
2104
+ if (this.axis.orientation === AxisOrientation.y && this.config.zoom.type === ZoomType.y) {
2087
2105
  this.zoom.translateExtent([
2088
- [0, 0],
2089
- [this.size.width, this.size.height],
2106
+ [-Infinity, min],
2107
+ [Infinity, max],
2090
2108
  ]);
2091
2109
  }
2092
- if ((_g = this.config.zoom) === null || _g === void 0 ? void 0 : _g.wheelDelta) {
2093
- this.zoom.wheelDelta((_h = this.config.zoom) === null || _h === void 0 ? void 0 : _h.wheelDelta);
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);
2094
2112
  }
2095
- const maxZoom = ((_j = this.config.zoom) === null || _j === void 0 ? void 0 : _j.max)
2113
+ const maxZoom = ((_r = this.config.zoom) === null || _r === void 0 ? void 0 : _r.max)
2096
2114
  ? (this.axis.extremes[1] - this.axis.extremes[0]) /
2097
- ((_k = this.config.zoom) === null || _k === void 0 ? void 0 : _k.max)
2098
- : ((_l = this.config.zoom) === null || _l === void 0 ? void 0 : _l.limitZoomByData)
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)
2099
2117
  ? 1
2100
2118
  : 0;
2101
- const minZoom = ((_m = this.config.zoom) === null || _m === void 0 ? void 0 : _m.min)
2119
+ const minZoom = ((_u = this.config.zoom) === null || _u === void 0 ? void 0 : _u.min)
2102
2120
  ? (this.axis.extremes[1] - this.axis.extremes[0]) /
2103
- ((_o = this.config.zoom) === null || _o === void 0 ? void 0 : _o.min)
2121
+ ((_v = this.config.zoom) === null || _v === void 0 ? void 0 : _v.min)
2104
2122
  : Infinity;
2105
2123
  this.zoom.scaleExtent([maxZoom, minZoom]);
2106
2124
  this.zoom.on('zoom end', this.zoomed);
2107
- this._element.call(this.zoom).on('dblclick.zoom', null); // Disable dbclick zoom
2108
- if (((_q = (_p = this.config) === null || _p === void 0 ? void 0 : _p.zoom) === null || _q === void 0 ? void 0 : _q.zoomBehavior) === ZoomBehaviorType.wheel) {
2125
+ 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) {
2109
2127
  this.runWheelTranslate();
2110
2128
  }
2111
2129
  }
@@ -2415,8 +2433,6 @@ class CrosshairComponent {
2415
2433
  }
2416
2434
  ngOnInit() {
2417
2435
  this.transform = this.chartService.pointerMove.pipe(map((event) => {
2418
- const composedPath = event.composedPath();
2419
- const classes = composedPath.map((_) => { var _a; return (_a = _.classList) === null || _a === void 0 ? void 0 : _a.contains('crosshair'); }).filter((_) => _);
2420
2436
  return {
2421
2437
  x: event.type === 'mouseleave' ? -9999 : event.offsetX,
2422
2438
  y: event.type === 'mouseleave' ? -9999 : event.offsetY