@d3plus/core 3.0.12 → 3.0.14

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,5 +1,5 @@
1
1
  /*
2
- @d3plus/core v3.0.12
2
+ @d3plus/core v3.0.14
3
3
  Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.
4
4
  Copyright (c) 2025 D3plus - https://d3plus.org
5
5
  @license MIT
@@ -2711,6 +2711,7 @@
2711
2711
  if (zeroMatch) return +`${zeroMatch[1]}${+zeroMatch[2]}`;
2712
2712
  return d;
2713
2713
  };
2714
+ const maxTimezoneOffset = 1000 * 60 * 60 * 26;
2714
2715
  /**
2715
2716
  * Calculates ticks from a given scale (negative and/or positive)
2716
2717
  * @param {scale} scale A d3-scale object
@@ -2753,9 +2754,15 @@
2753
2754
  * @private
2754
2755
  */ function calculateTicks(scale, minorTicks = false) {
2755
2756
  let ticks = [];
2756
- const step = calculateStep.bind(this)(scale, minorTicks);
2757
- const domain = scale.domain();
2757
+ const scaleClone = scale.copy();
2758
+ if (this._scale === "time" && this._data.length) {
2759
+ const newDomain = d3Array.extent(this._data);
2760
+ const range = newDomain.map(scale);
2761
+ scaleClone.domain(newDomain).range(range);
2762
+ }
2763
+ const domain = scaleClone.domain();
2758
2764
  const inverted = domain[1] < domain[0];
2765
+ const step = calculateStep.bind(this)(scaleClone, minorTicks);
2759
2766
  if (!minorTicks && this._scale === "log") {
2760
2767
  const roundDomain = domain.map((d)=>Math.log10(d) % 1 === 0 ? d : (inverted ? ceilPow : floorPow)(d));
2761
2768
  const invertedRound = roundDomain[1] < roundDomain[0];
@@ -2764,11 +2771,11 @@
2764
2771
  1
2765
2772
  ].includes(d) || Math.abs(d) < 1 ? 1 : Math.log10(Math.abs(d))));
2766
2773
  const powMod = Math.ceil((Math.abs(powers[1] - powers[0]) + 1) / (step * 0.65));
2767
- ticks = powMod <= 1 && powers[0] === powers[1] || invertedRound !== inverted ? scale.ticks(step).filter((d)=>+`${d}`.replace("0.", "") % 2 === 0) : d3Array.range(powers[0], powers[1], powers[1] < powers[0] ? -1 : 1).concat([
2774
+ ticks = powMod <= 1 && powers[0] === powers[1] || invertedRound !== inverted ? scaleClone.ticks(step).filter((d)=>+`${d}`.replace("0.", "") % 2 === 0) : d3Array.range(powers[0], powers[1], powers[1] < powers[0] ? -1 : 1).concat([
2768
2775
  powers[1]
2769
2776
  ]).filter((d)=>Math.abs(d) % powMod === 0).map((d)=>+`${(isNegative(d) ? -1 : 1) * (d ? Math.pow(10, Math.abs(d)) : Math.sign(1 / d) > 0 ? 1 : -1)}`.replace(/9+/g, "1"));
2770
2777
  } else {
2771
- ticks = scale.ticks(step);
2778
+ ticks = scaleClone.ticks(step);
2772
2779
  if (!minorTicks && ![
2773
2780
  "log",
2774
2781
  "time"
@@ -2784,6 +2791,14 @@
2784
2791
  });
2785
2792
  }
2786
2793
  }
2794
+ // for time scale, if data array has been provided, filter out ticks that are not in the array
2795
+ if (this._scale === "time" && this._data.length) {
2796
+ const dataNumbers = this._data.map(Number);
2797
+ ticks = ticks.filter((t)=>{
2798
+ const tn = +t;
2799
+ return dataNumbers.find((n)=>n >= tn - maxTimezoneOffset && n <= tn + maxTimezoneOffset);
2800
+ });
2801
+ }
2787
2802
  // forces min/max into ticks, if not present
2788
2803
  if (!this._d3ScaleNegative || isNegative(domain[inverted ? 1 : 0]) === ticks.some((d)=>isNegative(d))) {
2789
2804
  if (!ticks.map(Number).includes(+domain[0])) {
@@ -2795,11 +2810,6 @@
2795
2810
  ticks.push(domain[1]);
2796
2811
  }
2797
2812
  }
2798
- // for time scale, if data array has been provided, filter out ticks that are not in the array
2799
- if (this._scale === "time" && this._data.length) {
2800
- const dataNumbers = this._data.map(Number);
2801
- ticks = ticks.filter((t)=>dataNumbers.includes(+t));
2802
- }
2803
2813
  return ticks;
2804
2814
  }
2805
2815
  class Axis extends BaseClass {
@@ -3775,7 +3785,7 @@
3775
3785
  super();
3776
3786
  this._align = "middle";
3777
3787
  this._barConfig = {
3778
- "stroke": openColor$1.colors.gray[600],
3788
+ stroke: openColor$1.colors.gray[600],
3779
3789
  "stroke-width": 1
3780
3790
  };
3781
3791
  this._data = [];
@@ -3785,7 +3795,7 @@
3785
3795
  ];
3786
3796
  this._duration = 600;
3787
3797
  this._gridConfig = {
3788
- "stroke": color.colorDefaults.light,
3798
+ stroke: color.colorDefaults.light,
3789
3799
  "stroke-width": 1
3790
3800
  };
3791
3801
  this._gridLog = false;
@@ -11375,19 +11385,7 @@
11375
11385
  @chainable
11376
11386
  */ fitObject(_, f) {
11377
11387
  if (arguments.length) {
11378
- if (typeof _ === "string") {
11379
- const prev = this._queue.find((q)=>q[3] === "fitObject");
11380
- const d = [
11381
- data.load.bind(this),
11382
- _,
11383
- f,
11384
- "fitObject"
11385
- ];
11386
- if (prev) this._queue[this._queue.indexOf(prev)] = d;
11387
- else this._queue.push(d);
11388
- } else {
11389
- this._fitObject = _;
11390
- }
11388
+ data.addToQueue.bind(this)(_, f, "fitObject");
11391
11389
  this._zoomSet = false;
11392
11390
  return this;
11393
11391
  }
@@ -11504,19 +11502,7 @@
11504
11502
  @chainable
11505
11503
  */ topojson(_, f) {
11506
11504
  if (arguments.length) {
11507
- if (typeof _ === "string") {
11508
- const prev = this._queue.find((q)=>q[3] === "topojson");
11509
- const d = [
11510
- data.load.bind(this),
11511
- _,
11512
- f,
11513
- "topojson"
11514
- ];
11515
- if (prev) this._queue[this._queue.indexOf(prev)] = d;
11516
- else this._queue.push(d);
11517
- } else {
11518
- this._topojson = _;
11519
- }
11505
+ data.addToQueue.bind(this)(_, f, "topojson");
11520
11506
  this._zoomSet = false;
11521
11507
  return this;
11522
11508
  }
@@ -11610,9 +11596,9 @@
11610
11596
  return this._topojsonFill(d, i);
11611
11597
  },
11612
11598
  on: {
11613
- "mouseenter": (d, i, x, event)=>!this._coordData.features.includes(d) ? this._on.mouseenter.bind(this)(d, i, x, event) : null,
11599
+ mouseenter: (d, i, x, event)=>!this._coordData.features.includes(d) ? this._on.mouseenter.bind(this)(d, i, x, event) : null,
11614
11600
  "mousemove.shape": (d, i, x, event)=>!this._coordData.features.includes(d) ? this._on["mousemove.shape"].bind(this)(d, i, x, event) : null,
11615
- "mouseleave": (d, i, x, event)=>!this._coordData.features.includes(d) ? this._on.mouseleave.bind(this)(d, i, x, event) : null
11601
+ mouseleave: (d, i, x, event)=>!this._coordData.features.includes(d) ? this._on.mouseleave.bind(this)(d, i, x, event) : null
11616
11602
  },
11617
11603
  stroke: (d, i)=>{
11618
11604
  const c = typeof this._shapeConfig.Path.fill === "function" ? this._shapeConfig.Path.fill(d, i) : this._shapeConfig.Path.fill;