Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reversed ordered data with lines: { steps: true } renders incorrectly. #1313

Open
dashed opened this issue May 23, 2014 · 2 comments
Open

Reversed ordered data with lines: { steps: true } renders incorrectly. #1313

dashed opened this issue May 23, 2014 · 2 comments

Comments

@dashed
Copy link

dashed commented May 23, 2014

This was apparently raised by another user with proper reproducible sandboxed demo in #1223. But was prematurely closed. Demo in question: http://jsfiddle.net/Xr2ZD/4/

If flot is given data in reversed order with respect to the x-axis, flot plots the data incorrectly for the plot style option: lines: { steps: true }.

As far as I know, all other plot styles render data in any order correctly.


I found this bug while investigating reddit-archive/reddit#1048.

Nowhere in flot's documentation mention that data being fed must be in order with respect to the x-axis.

@dnschnur
Copy link
Member

While points and bars can accept data in any order, lines do require data in connected order. There are a number of reasons for this; for example, consider this non-continuous line:

[[0, 5], [1, 4], null, [3, 3], [4, 2]

Without the assumption that the points should be plotted in the given order, there's no way to know where the gap should appear. The panning & zooming sample is another good example.

You're right that this isn't obvious; we should clarify it in the API docs.

@dnschnur dnschnur added this to the Release 0.9 milestone May 26, 2014
@dashed
Copy link
Author

dashed commented May 26, 2014

Ah I see. I was unaware of the null convention.

I briefly looked the source code, and order of the data seems to be very important: L1203-L1216.

One may assume that data is ordered with respect to the x-axis as one expects from a traditional line-chart (such as time series data). To enforce such order, I guess points array would need to be treated as a min-heap.

As an offhand solution, since the array is flattened, group of elements would need to be swapped when percolating them up in the points array with respect to the x-value. This could be done after line 1178. For special cases such as the null convention, they're associated with the previously inserted datapoint, so they get percolated up the array such that they're after the previously inserted data point with a nonnull x-value.

Repeated null values would be ignored, and null as the first data point is also ignored (e.g. [null, [0, 5], [1, 4], null, [3, 3], [4, 2], ...).

All of this may be toggled with the bool option: respectToXAxis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants