2

I'm trying to make a real time chart in racket. I've looked at the Plot and GUI libraries, and it seems like I'm missing something. When calling plot, it returns an image snip% or a number of other picture formats. But I can't seem to find any way to add or remove points from the chart without calling plot again. Now I suppose I could use a method like

https://planet.racket-lang.org/package-source/williams/animated-canvas.plt/2/5/planet-docs/animated-canvas/index.html

but then I have to reimplement all the manipulation mechanisms that come with the snip%. Now it may be the case that I have to do it anyway, but what I'm asking is if there are any existing mechanisms that let you manipulate the graph and data of a plot snip% after its been created, or do I have to just redraw it manually every time I want to change how it looks? Also is there any existing work that has been done for making real time charts in Racket in general?

dg123
  • 33
  • 4

1 Answers1

0

After digging into Rackets OOP and gui libraries, I eventually came upon (and understood) plot/dc which the docs claim can be used for such applications: https://docs.racket-lang.org/plot/plotting.html?q=plot%2Fdc#%28def._%28%28lib._plot%2Fmain..rkt%29._plot%2Fdc%29%29

It seems to work better than animated canvas when rendering, but I will still have to reimplement zooming and clicking and all the stuff that comes with snip%s, unless someone has better ideas.

#lang racket

(require racket/gui plot racket/draw)

(define num 0)

(define f (new frame% [label "Test graph"]
               [width 200]
               [height 200]))
(define c (new canvas% [parent f]))


(send f show #t)

(define (loop)
  (set! num (add1 num))
  (plot/dc (function sin (- pi) num)
           (send c get-dc)
           0 0
           (- (send f get-width) 40) ;; figure out how to get the actual size of the text outside the graphs boarder?
           (- (send f get-height) 40)
           #:title "Graph"
           #:x-label "num"
           #:y-label "sin"
           )
  (sleep/yield .2)
  (loop))

(loop)
dg123
  • 33
  • 4