Haskell Dynamic Story Update

I have a program that performs a long-term calculation, where the result is shown as a graph. I am currently using Chart-0.14 . I want to show partial results and update during calculations. Graphics.Rendering.Chart.Gtk.updateCanvas :: Renderable a -> DrawingArea -> IO Boolseems to be doing this, but I find no way to get the DrawingArea from the plot. The function renderableToWindow :: Renderable a -> Int -> Int -> IO ()returns nothing (and, in addition, it does not return until the window is closed).

I would like to do something like the following:

main = do
drawingArea = forkRenderableToWindow (toRenderable $ plotLayout $
                     plot [0,0.1..10] sin "sin(x)") 640 480
updateCanvas  (toRenderable $ plotLayout $  plot [0,0.1..10] sin "sin(x)") drawingArea

How should I do it? I need to override the functions in the Graphics.Rendering.Chart.Gtkversion that returns DrawingAreaand somehow (how do I do this? ForkIO?) Returns immediately without closing the window?

+5
source share
1 answer

You are looking createRenderableWindow, and then you need to use GTK operations to work on the data Window- I don’t know, t think the Chart package exports any higher level operations to Windows.

EDIT2: Therefore, ignore the following - it does not work even with GUI initialization. My comment was a type-based assumption. EDIT: Here is a sample code. You see, I'm just collecting things based on types. There may be better ways to do something if you ask someone who really knows the library.

Below we use:

  • createRenderableWindow - that was the essence of my answer.
  • castToDrawingArea- This is necessary to obtain DrawingAreafrom the type Windowprovided by GTK. I think these discards come from C ++ OO inheritance.
  • widgetShowAll - , . , renderableToWindow.
  • updateCanvas - , DrawingArea.

:

import Graphics.Rendering.Chart.Gtk
import Graphics.Rendering.Chart.Renderable
import Graphics.UI.Gtk.Misc.DrawingArea
import qualified Graphics.UI.Gtk as G

main = do
        win  <- createRenderableWindow emptyRenderable 400 400
        let draw = castToDrawingArea win
        G.widgetShowAll win
        updateCanvas emptyRenderable draw
+2

All Articles