@d3plus/core 3.0.13 → 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.13
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
@@ -2411,14 +2411,16 @@ this._whiskerEndpoint=[],ca().key(t=>t.outlier).entries(r).forEach(t=>{var n=t.k
2411
2411
  * Calculates ticks from a given scale (negative and/or positive)
2412
2412
  * @param {scale} scale A d3-scale object
2413
2413
  * @private
2414
- */function Ec(t,e=!1){let i=[];var a=
2414
+ */function Ec(t,e=!1){let i=[];var a=t.copy(),r=("time"===this._scale&&this._data.length&&(t=(r=Hi(this._data)).map(t),a.domain(r).range(t)),a.domain());let o=r[1]<r[0];t=
2415
2415
  /**
2416
2416
  * Calculates ticks from a given scale (negative and/or positive)
2417
2417
  * @param {scale} scale A d3-scale object
2418
2418
  * @private
2419
- */function(t,n=!1){var e=$a().domain([200,1200]).range([8,28]),t=t.range(),t=Math.abs(t[1]-t[0]);let i=Math.floor(e(t));return"time"===this._scale&&(i=this._data&&this._data.length?(e=Hi(this._data),t=this._data.reduce((t,n,e,i)=>t=e&&(n=Math.abs(n-i[e-1]))<t?n:t,1/0),e=Math.round((e[1]-e[0])/t),Dt([i*(n?2:.5),e])):n?2*i:i/2),Math.floor(i)}.bind(this)(t,e),r=t.domain();let o=r[1]<r[0];if(e||"log"!==this._scale){if(i=t.ticks(a),!e&&!["log","time"].includes(this._scale)&&1<i.length){let e=Math.abs(2*Tc(i[1]-i[0]));i=i.filter(t=>{var t=Math.abs(t)%e,n=Tc(t);return n!==t?!n||n===e:0==t})}}else{var e=r.map(t=>Math.log10(t)%1==0?t:(o?zc:Ac)(t)),s=e[1]<e[0],e=e.map(t=>(Mc(t)?-1:1)*([-1,1].includes(t)||Math.abs(t)<1?1:Math.log10(Math.abs(t))));let n=Math.ceil((Math.abs(e[1]-e[0])+1)/(.65*a));i=n<=1&&e[0]===e[1]||s!=o?t.ticks(a).filter(t=>+(""+t).replace("0.","")%2==0):jt(e[0],e[1],e[1]<e[0]?-1:1).concat([e[1]]).filter(t=>Math.abs(t)%n==0).map(t=>+(""+(Mc(t)?-1:1)*(t?Math.pow(10,Math.abs(t)):0<Math.sign(1/t)?1:-1)).replace(/9+/g,"1"))}
2419
+ */function(t,n=!1){var e=$a().domain([200,1200]).range([8,28]),t=t.range(),t=Math.abs(t[1]-t[0]);let i=Math.floor(e(t));return"time"===this._scale&&(i=this._data&&this._data.length?(e=Hi(this._data),t=this._data.reduce((t,n,e,i)=>t=e&&(n=Math.abs(n-i[e-1]))<t?n:t,1/0),e=Math.round((e[1]-e[0])/t),Dt([i*(n?2:.5),e])):n?2*i:i/2),Math.floor(i)}.bind(this)(a,e);if(e||"log"!==this._scale){if(i=a.ticks(t),!e&&!["log","time"].includes(this._scale)&&1<i.length){let e=Math.abs(2*Tc(i[1]-i[0]));i=i.filter(t=>{var t=Math.abs(t)%e,n=Tc(t);return n!==t?!n||n===e:0==t})}}else{var e=r.map(t=>Math.log10(t)%1==0?t:(o?zc:Ac)(t)),s=e[1]<e[0],e=e.map(t=>(Mc(t)?-1:1)*([-1,1].includes(t)||Math.abs(t)<1?1:Math.log10(Math.abs(t))));let n=Math.ceil((Math.abs(e[1]-e[0])+1)/(.65*t));i=n<=1&&e[0]===e[1]||s!=o?a.ticks(t).filter(t=>+(""+t).replace("0.","")%2==0):jt(e[0],e[1],e[1]<e[0]?-1:1).concat([e[1]]).filter(t=>Math.abs(t)%n==0).map(t=>+(""+(Mc(t)?-1:1)*(t?Math.pow(10,Math.abs(t)):0<Math.sign(1/t)?1:-1)).replace(/9+/g,"1"))}
2420
+ // for time scale, if data array has been provided, filter out ticks that are not in the array
2421
+ if("time"===this._scale&&this._data.length){let e=this._data.map(Number);i=i.filter(t=>{let n=+t;return e.find(t=>t>=n-936e5&&t<=936e5+n)})}
2420
2422
  // forces min/max into ticks, if not present
2421
- return this._d3ScaleNegative&&Mc(r[o?1:0])!==i.some(t=>Mc(t))||i.map(Number).includes(+r[0])||i.unshift(r[0]),this._d3ScaleNegative&&Mc(r[o?0:1])!==i.some(t=>Mc(t))||i.map(Number).includes(+r[1])||i.push(r[1]),i="time"===this._scale&&this._data.length?this._data:i}class Nc extends Bi{
2423
+ return this._d3ScaleNegative&&Mc(r[o?1:0])!==i.some(t=>Mc(t))||i.map(Number).includes(+r[0])||i.unshift(r[0]),this._d3ScaleNegative&&Mc(r[o?0:1])!==i.some(t=>Mc(t))||i.map(Number).includes(+r[1])||i.push(r[1]),i}class Nc extends Bi{
2422
2424
  /**
2423
2425
  @memberof Axis
2424
2426
  @desc Sets positioning for the axis bar.
@@ -1,5 +1,5 @@
1
1
  /*
2
- @d3plus/core v3.0.13
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,7 +2810,6 @@
2795
2810
  ticks.push(domain[1]);
2796
2811
  }
2797
2812
  }
2798
- if (this._scale === "time" && this._data.length) ticks = this._data;
2799
2813
  return ticks;
2800
2814
  }
2801
2815
  class Axis extends BaseClass {