Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chrissound opened this issue Jul 15, 2021 · 1 comment
Open

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

chrissound opened this issue Jul 15, 2021 · 1 comment

Comments

@chrissound
Copy link

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... ?

@chrissound
Copy link
Author

The issue seem to be that it requires at least 2 different values for the area(?).

If I change v to [ (0,0,0,0) , (0,0,0,1) ] it works correctly - no error is encountered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant