@spider-analyzer/timeline 5.0.4 → 5.0.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spider-analyzer/timeline",
3
- "version": "5.0.4",
3
+ "version": "5.0.5",
4
4
  "description": "React graphical component to display metric over time with a time selection feature.",
5
5
  "author": "Thibaut Raballand <spider.analyzer@gmail.com> (https://spider-analyzer.io)",
6
6
  "license": "MIT",
package/src/TimeLine.tsx CHANGED
@@ -189,9 +189,19 @@ const TimeLineInner = forwardRef<TimeLineHandle, any>(function TimeLine(props, r
189
189
  xAxis.clamp(true);
190
190
  xAxisRef.current = xAxis;
191
191
 
192
- const ticks = xAxis.ticks(_floor(histoWidth / p.xAxis.spaceBetweenTicks));
192
+ const tickCount = _floor(histoWidth / p.xAxis.spaceBetweenTicks);
193
+ const ticks = xAxis.ticks(tickCount);
194
+ // intervalMs should be domainSpan/(visibleTickCount*barsBetweenTicks).
195
+ // Use ticks[1]-ticks[0] when d3 gives us >= 2 "nice" ticks (preserves
196
+ // the original intent of snapping to minute/hour-aligned intervals);
197
+ // otherwise fall back to domainSpan/tickCount so we never regress to
198
+ // smallestResolution on the very first render (when tick generation
199
+ // can be momentarily sparse).
200
+ const tickIntervalMs = ticks.length >= 2
201
+ ? ticks[1].getTime() - ticks[0].getTime()
202
+ : (+domain.max - +domain.min) / Math.max(tickCount, 1);
193
203
  const intervalMs = _max([
194
- _round(moment(ticks[1]).diff(moment(ticks[0])) / p.xAxis.barsBetweenTicks),
204
+ _round(tickIntervalMs / p.xAxis.barsBetweenTicks),
195
205
  propsRef.current.smallestResolution.asMilliseconds(),
196
206
  ]) as number;
197
207