esnet / esnet/react-timeseries-charts
EventHandler produces reversed TimeRanges
- Dominant language
- JavaScript
- Stars
- 876
- Forks
- 279
- PR merge metrics
- No merged PRs in 30d
Description
# 🐛Bug report
Before calling `onZoom`, `EventHandler` creates the necessary `TimeRange` that will be passed to `onZoom`:
https://github.com/esnet/react-timeseries-charts/blob/aa9c9b368100d78337b562d9e2833f2d90d9de3d/src/components/EventHandler.js#L206-L209
The desired behavior is to produce a `TimeRange` where `timeRange.begin() < timeRange.end()`. However, array sort in JS is... interesting. To quote [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Description):
> all non-undefined array elements are sorted by converting them to strings and comparing strings in UTF-16 code units order.
For dates before 1970, `newBegin` and `newEnd` will be negative numbers. In many cases, these numbers will be consistently reversed. For example, in the node repl:
```
$ node
Welcome to Node.js v14.4.0.
Type ".help" for more information.
> [-390040203141, -204123317277].sort()
[ -204123317277, -390040203141 ]
```
**To Reproduce**
Steps to reproduce the behavior:
1. View a `ChartContainer` with `enableDragZoom` set to `true`
2. Drag to select a time range before 1970
3. View the time range passed to your `onTimeRangeChanged` handler
**Expected behavior**
The values should be properly sorted. `onZoom` is called in three places. Before the other two calls, no sorting takes place.
The other two places might be relying on the surrounding context for sort order, but I think it'd be best to explicitly sort in all three spots.
Contributor guide
Research direction
Start in src/components/EventHandler.js at the onZoom call around lines 206-209, then inspect the other two onZoom call sites. Reproduce the issue with a ChartContainer using enableDragZoom over dates before 1970, and make sure all three paths explicitly produce a TimeRange with begin() less than end().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100