timbod7 / haskell-chart

A 2D charting library for haskell
427 stars 86 forks source link

Plot handle inputs containing ∞ or NaNs incorrectly #120

Open Shimuuar opened 8 years ago

Shimuuar commented 8 years ago

If input for plot contains ∞ or NaNs library draws somewhat strange plots. It looks like path is reset and then drawing starts from origin. I'm not sure what is correct behavior in that case. Dropping point and creating gap in the line seems like good idea. Gap makes visible that there's missing point and plot still looks decently

toRenderable
  $ layout_plots .~ 
    [ toPlot ( plot_lines_values .~ [ [(0,1),(1,2),(2,0/0),(3,1),(4,1.5)] ]
             $ def)]
  $ def

download

And real life example download

I'm using cairo backend with ihaskell.

timbod7 commented 8 years ago

The library used to crash on NaN's so at least this is an improvement :-)

Until now handling of NaN's has been left up to the caller - possibly leaving the points out and breaking the lines as you suggest, though I'd prefer an approach that makes the fact there is a problem more obvious.

Shimuuar commented 8 years ago
O snail
Climb Mount Fuji,
But slowly, slowly!

I would expect that caller being lazy will do simplest and likely dumb thing. So any complicated logic should be bundled into library.

Infinities have very simple interpretation: draw line upward/downward to border of viewport. And infinities are quite common they easily arise in log-scale plots since log 0 = -∞. NaN treatment is more complicated I agree.