sveinn-steinarsson / flot-downsample

Downsample plugin for Flot charts.
286 stars 39 forks source link

Add filtering/support for min/max range #7

Closed dsrink closed 10 years ago

dsrink commented 10 years ago

I suggest to add support to only account for data which is actually visible, i.e. after applying min/max range.

My suggestion is to add a pre-filter. Without that, the graphs will look ugly.

An example: You have a graph of 4000 data points. You downsample that to a threshold of 800. After zooming in (using e.g. the selection plugin) to a quarter of the graph, you will see only 200 data points, although the range would contain 1000, out of which downsample should rather display 800 data points. Alternate example: 4000 data points, threshold 800, a 10% range, 80 data points displayed instead of 400.

This way, the point of downsampling is somewhat undermined.

I have prepared a change which fixes that, and skips the added behaviour if min/max are not defined. Note that "out of range" is determined only on x axis, not on y, on purpose - since otherwise threshold plugin might miss some lines to data points outside of the graph. I tested this only for an ordinary graph (with time series x data), hope that it doesn't break anything else.

sveinn-steinarsson commented 10 years ago

I like the idea and I think you should make it into a stand-alone plugin for Flot.

I would however consider using something else than $.grep since it looks at all elements in the list.

dsrink commented 10 years ago

unfortunately this is my first JavaScript project, so everything is a little new here... If I did a standalone plugin, how would I ensure the ordering, that the new plugin (let's name it visibledatafilter) gets called before downsample?

Binary search is a great suggestion. I wasn't sure about whether the data is really ordered.

sveinn-steinarsson commented 10 years ago

Take a look at https://github.com/flot/flot/blob/master/API.md#plugins One idea is to check the global array $.plot.plugins and make sure that the downsample plugin is not in the array (has not been loaded). There are probably some other ways but maybe this one will suffice.