chart may be freezing on small but non-zero values
I have seen chart freeze my application when I am giving small but non-zero values. It is annoying to reproduce but I think I could make a stand-alone example if needed.
I expect plotting something like [(0, 0), (1, 0.5e-320), (2, 1.0e-320)] would reproduce this.
This example will reproduce it for me
{-# OPTIONS_GHC -Wall #-}
import Control.Lens
import Control.Monad ( void )
import Data.Default.Class
import Graphics.Rendering.Chart
import Graphics.Rendering.Chart.Backend.Cairo
values :: [(Double, Double)]
values =
[ (0, 1.0e-322)
, (1, 1.0e-322)
]
chart :: Renderable ()
chart = toRenderable layout
where
plotLines :: PlotLines Double Double
plotLines = plot_lines_values .~ [values]
$ def
layout = layout_plots .~ [toPlot plotLines]
$ def
main :: IO ()
main = void $ renderableToFile def "example1_big.png" chart
Those values are very small :-)
I think the issue is in the scaledAxis function. In particular the logic that searches for a nice axis scale loops forever if the range has size 0. We protect against this here:
range [] = (0,1)
range _ | minV == maxV = if minV==0 then (-1,1) else
let d = abs (minV * 0.01) in (minV-d,maxV+d)
but the logic fails if d ends up equal to zero, which it does for 1e-322.
I realize they're abnormal values, but I did come across this in a real world situation. Thanks for the pointer, I'll try to fix it it you don't get to it first.
I have a fix in https://github.com/timbod7/haskell-chart/pull/130