Skip to content

"Exception: Prelude.!!: negative index" when using AreaSpots4D #225

@chrissound

Description

@chrissound
import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Backend.Cairo
import Data.Time.LocalTime
import Control.Lens
import Data.Colour
import Data.Colour.Names


renderCfg :: FileOptions
renderCfg = FileOptions (2100, 1600) PNG

renderCfg' :: Int -> Int -> FileOptions
renderCfg' a b = FileOptions (a, b) PNG

spots :: [(Double, Int, Double, Double)] -> AreaSpots4D Double Double Double Int 
spots v = area_spots_4d_title .~ "random value"
          $ area_spots_4d_max_radius .~ 20
          $ area_spots_4d_values .~ v
          $ area_spots_4d_palette .~ [red, blue]
          $ def

chart' :: Renderable ()
chart' = toRenderable $
    (layout_plots .~ [toPlot (spots v)]) (def )
      where v =
              [ (0,0,0,0)
              ]

Just trying to get a simple chart based on https://github.com/timbod7/haskell-chart/wiki/example-8 however getting a Exception: Prelude.!!: negative index error unfortunately...

Definitely related to the v = [ (0,0,0,0)] as when I instead set it to [] no error occurs...

I'm just not sure why this exception is being triggered.


Hacking the source code of the library:

-              let colour  = _area_spots_4d_palette p !! t 
+
+              let colour  = case _area_spots_4d_palette p !!? t of
+                               Nothing -> do
+                                 error $ show t ++ "out of" ++ (show $ _area_spots_4d_palette p)
+                               Just colour' -> colour'

Which then errors with:

*** Exception: -9223372036854775808out of[Data.Colour.SRGB.Linear.rgb 1.0 0.0 0.0,Data.Colour.SRGB.Linear.rgb 0.0 0.0 1.0]

No idea where -9223372036854775808 is coming from... ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions