@acorex/charts 20.1.28 → 20.1.29

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.
@@ -1,3 +1,4 @@
1
+ import { getEasingFunction, computeTooltipPosition } from '@acorex/charts';
1
2
  import { AXChartTooltipComponent } from '@acorex/charts/chart-tooltip';
2
3
  import * as i0 from '@angular/core';
3
4
  import { InjectionToken, inject, ChangeDetectorRef, input, viewChild, signal, computed, afterNextRender, effect, ChangeDetectionStrategy, ViewEncapsulation, Component } from '@angular/core';
@@ -79,6 +80,8 @@ class AXGaugeChartComponent {
79
80
  ...this.options(),
80
81
  };
81
82
  }, ...(ngDevMode ? [{ debugName: "effectiveOptions" }] : []));
83
+ // Tooltip gap in pixels for precise spacing
84
+ TOOLTIP_GAP = 10;
82
85
  constructor() {
83
86
  // Dynamically load D3 and initialize the chart when the component is ready
84
87
  afterNextRender(() => {
@@ -213,7 +216,7 @@ class AXGaugeChartComponent {
213
216
  const minValue = options.minValue;
214
217
  const maxValue = options.maxValue;
215
218
  const animationDuration = options.animationDuration;
216
- const easingFunction = this.getEasingFunction(options.animationEasing);
219
+ const easingFunction = getEasingFunction(this.d3, options.animationEasing);
217
220
  const currentValue = value;
218
221
  const svg = this.d3.select(this.svgElement);
219
222
  // Update value text
@@ -389,32 +392,14 @@ class AXGaugeChartComponent {
389
392
  * Updates the tooltip position based on the mouse event
390
393
  */
391
394
  updateTooltipPosition(event) {
392
- const container = this.chartContainerEl().nativeElement.getBoundingClientRect();
393
- const x = event.clientX - container.left;
394
- const y = event.clientY - container.top;
395
- // Get container dimensions to check if we're near the edge
396
- const containerWidth = container.width;
397
- // Tooltip dimensions approximation (can't get exact dimensions without rendering)
398
- const tooltipWidth = 150; // Approximate width of tooltip
399
- // Calculate position with edge detection
400
- let tooltipX = x + 8; // fix overlap with cursor
401
- const tooltipY = y - 12; // fix overlap with cursor
402
- // Check if we're too close to the right edge
403
- const rightEdgeDistance = containerWidth - x;
404
- if (rightEdgeDistance < tooltipWidth) {
405
- // Place tooltip to the left of the cursor with no gap
406
- tooltipX = x - tooltipWidth + 70; // Overlap more with cursor position
407
- }
408
- // Check if we're too close to the bottom edge
409
- // const bottomEdgeDistance = containerHeight - y;
410
- // if (bottomEdgeDistance < tooltipHeight + 10) {
411
- // // Move tooltip up if near bottom edge
412
- // tooltipY = y - tooltipHeight;
413
- // }
414
- this._tooltipPosition.set({
415
- x: tooltipX,
416
- y: tooltipY,
417
- });
395
+ const containerEl = this.chartContainerEl()?.nativeElement;
396
+ if (!containerEl)
397
+ return;
398
+ const rect = containerEl.getBoundingClientRect();
399
+ const tooltipEl = containerEl.querySelector('.chart-tooltip');
400
+ const tooltipRect = tooltipEl ? tooltipEl.getBoundingClientRect() : null;
401
+ const pos = computeTooltipPosition(rect, tooltipRect, event.clientX, event.clientY, this.TOOLTIP_GAP);
402
+ this._tooltipPosition.set(pos);
418
403
  this.cdr.detectChanges();
419
404
  }
420
405
  /**
@@ -605,7 +590,7 @@ class AXGaugeChartComponent {
605
590
  .attr('r', radius * 0.03)
606
591
  .attr('fill', '#fff');
607
592
  // Get easing function
608
- const easingFunction = this.getEasingFunction(this.options()?.animationEasing);
593
+ const easingFunction = getEasingFunction(this.d3, this.options()?.animationEasing);
609
594
  // Animate the needle from min to current value
610
595
  needlePath
611
596
  .transition()
@@ -613,33 +598,7 @@ class AXGaugeChartComponent {
613
598
  .ease(easingFunction)
614
599
  .attr('transform', `rotate(${angleInDegrees})`);
615
600
  }
616
- /**
617
- * Gets the appropriate D3 easing function based on the option string
618
- */
619
- getEasingFunction(easing) {
620
- switch (easing) {
621
- case 'linear':
622
- return this.d3.easeLinear;
623
- case 'ease':
624
- return this.d3.easePolyInOut;
625
- case 'ease-in':
626
- return this.d3.easePolyIn;
627
- case 'ease-out':
628
- return this.d3.easePolyOut;
629
- case 'ease-in-out':
630
- return this.d3.easePolyInOut;
631
- case 'cubic':
632
- return this.d3.easeCubic;
633
- case 'cubic-in':
634
- return this.d3.easeCubicIn;
635
- case 'cubic-out':
636
- return this.d3.easeCubicOut;
637
- case 'cubic-in-out':
638
- return this.d3.easeCubicInOut;
639
- default:
640
- return this.d3.easeCubicOut; // Default easing
641
- }
642
- }
601
+ // getEasingFunction moved to shared chart utils
643
602
  /**
644
603
  * Creates a path string for the needle
645
604
  */