在 Haskell 中动态更新绘图
我有一个程序执行长期计算,结果显示为绘图。 我目前正在使用 Chart-0.14 为此。我想显示部分结果,并在计算过程中更新。 Graphics.Rendering.Chart.Gtk.updateCanvas :: 可渲染 ->绘图区 -> IO Bool 似乎可以做到这一点,但我没有找到任何方法从图中获取 DrawingArea。函数renderableToWindow::Renderable a ->整数->整数-> IO()
不返回任何内容(而且在窗口关闭之前它也不会返回)。
我想做类似以下的事情:
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
我应该怎么做?我是否需要使用返回 DrawingArea
的版本以及以某种方式重新实现 Graphics.Rendering.Chart.Gtk
中的函数(我该怎么做?forkIO?)不关闭窗口就立即返回?
I have a program which performs a long-going calculation where the result is shown as a plot.
I am currently using Chart-0.14 for this. I want to show the partial results, and update during calculations.Graphics.Rendering.Chart.Gtk.updateCanvas :: Renderable a -> DrawingArea -> IO Bool
seems to do that, but I do not find any way to get a DrawingArea from the plot. The function renderableToWindow :: Renderable a -> Int -> Int -> IO ()
does not return anything (and furthermore it does not return before 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 this? Would I need to reimplement the functions in Graphics.Rendering.Chart.Gtk
with a version that returns the DrawingArea
and in some way (how would I do this? forkIO?) returns immediately without closing the window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找
createRenderableWindow
然后您需要使用 GTK 操作来处理给定的Window
- 我不认为 Chart 包导出任何更高级别Window
上的操作。EDIT2:所以忽略下面的内容 - 即使 GUI 初始化它也不起作用。我的评论是基于类型的猜测。
编辑:
这是一些示例代码。请理解,我只是根据类型将事物拼凑在一起。如果你询问真正了解图书馆的人,可能会有更好的方法。
下面我们使用:
createRenderableWindow
- 这是我答案的关键castToDrawingArea
- 这是从Window< 获取
DrawingArea
所必需的/code> GTK 提供的类型。我认为这些强制转换正在取代 C++ OO 继承。widgetShowAll
- 因为我们还没有实际显示窗口,所以我们最好这样做。我在查看了 renderableToWindow 的源代码后盗用了这个函数。updateCanvas
- 我刚刚在 haddock 文档中看到了这一点,并认为这就是为什么您首先需要DrawingArea
的原因。现在的代码:
You are looking for
createRenderableWindow
and then you need to use the GTK operations to work on the givenWindow
- I don't think the Chart package exports any higher level operations onWindow
s.EDIT2: So ignore the below - it doesn't work even with GUI initilization. My comment was a guess based on types.
EDIT:
Here is some example code. Understand, I'm just piecing things together based on the types. There might be better ways to do things if you ask someone who actually knows the library.
Below we use:
createRenderableWindow
- this was the crux of my answercastToDrawingArea
- This is needed to get aDrawingArea
from theWindow
type provided by GTK. These casts are taking place of C++ OO inheritance, I think.widgetShowAll
- because we haven't actually displayed the window, we best do that. I stole this function after looking at the source forrenderableToWindow
.updateCanvas
- I just saw this in the haddock documentation and figured it is why you wanted aDrawingArea
in the first place.Now for the code: