fnando / sparkline

Generate SVG sparklines with JavaScript without any external dependency.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion: don't render null data

jwhazel opened this issue · comments

Use case: rendering a fixed set of time series data where you may be lacking some future data but need the graph to maintain a consistent width. E.g. here's a graph of today's data viewed at 2pm since future data in each interval isn't available and is null, it gets coerced to 0 on the y-axis:

graph1

That looks kind of ugly and possibly misleading. Here is the desired look of this graph where nulls don't get rendered but interval width is still maintained:

graph2

I accomplished that by simply adding this test on line 113:

if(value !== null){
    pathCoords += ` L ${x} ${y}`;
}

I didn't want to make a PR yet because I haven't had a chance to write any tests nor am I sure this is a use case you even want to support. Just thought I'd throw it out there as a suggestion.

In this case, what happens if you have [1, 2, null, null, 3, 5]? How should this be handled?

Below is how it looks in the real world when there's null data and this change is made. This is monthly data where there are nulls in zero-indexed months 2,3 and 7. It's not ideal as arguably the stroke should not be drawn each side of the nulls, but I think it's clear that there's no data in those gaps because there's no line there.. Contrast that with the top example here, which implies there's data (with value zero) where in fact there is no data.

ml1