Open brandly opened 3 years ago
i can send a PR. some options:
do this inline
const newTimeRange = new TimeRange(newBegin < newEnd ? [newBegin, newEnd] : [newEnd, newBegin]);
pull that into a function
const ascendingDates = (a, b) =>
a < b ? [a, b] : [b, a]
// ...
const newTimeRange = new TimeRange(ascendingDates(newBegin, newEnd));
3. sort any array of numbers in place
```js
const sortNumbers = (numbers) =>
numbers.sort((a, b) => {
if (a < b) return -1
if (b > a) return 1
return 0
})
// ...
const newTimeRange = new TimeRange(sortNumbers([newBegin, newEnd]));
@pjm17971 what do you think?
🐛Bug report
Before calling
onZoom
,EventHandler
creates the necessaryTimeRange
that will be passed toonZoom
: https://github.com/esnet/react-timeseries-charts/blob/aa9c9b368100d78337b562d9e2833f2d90d9de3d/src/components/EventHandler.js#L206-L209The desired behavior is to produce a
TimeRange
wheretimeRange.begin() < timeRange.end()
. However, array sort in JS is... interesting. To quote MDN:For dates before 1970,
newBegin
andnewEnd
will be negative numbers. In many cases, these numbers will be consistently reversed. For example, in the node repl:To Reproduce Steps to reproduce the behavior:
ChartContainer
withenableDragZoom
set totrue
onTimeRangeChanged
handlerExpected 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.