[racket] plot3d & canvas question

From: Neil Toronto (neil.toronto at gmail.com)
Date: Sat Mar 3 14:54:07 EST 2012

On 02/08/2012 01:27 PM, Nikolaus Klepp wrote:
> Am Mittwoch, 8. Februar 2012 schrieb Neil Toronto:
>> Unfortunately, you can't. You'll have to delete the old one from the
>> read-only-text% and insert a new one.
>
> I was afraid, you'd say that.
>
>> If this is for resizing, you have another problem: creating a new plot
>> will reset the viewing angles. I was going to describe how to save and
>> restore them, but it would require copying much larger sections of
>> private `plot' code. You're better off letting the viewing angles reset
>> for now, and waiting for 3d-plot-canvas%, which I'll start on tonight.
>
> In deed it was for resizing. Well, I'll use
> the "delet-and-create-a-new-plot"-workaround for now and come to you
> 3d-plot-canvas% as soon as you release it :-)

Turns out I could do better.

The next nightly build should have a module `unstable/gui/snip', which 
provides `snip-canvas%'. A snip canvas wraps any snip so you can use it 
as a GUI element. Also, the snips returned by `plot-snip' and 
`plot3d-snip' now respond properly to the `resize' message, so they'll 
resize when the snip canvas does.

This program makes a plot snip and wraps it with a snip canvas:

#lang racket/gui

(require plot unstable/gui/snip)

(define (make-plot-snip w h)
   (plot-snip (function sin -4 4) #:width w #:height h))

(define frame (new frame% [label "Test"] [width 300] [height 300]))

(define canvas
   (new snip-canvas% [parent frame] [make-snip make-plot-snip]))

(send frame show #t)


If you resize the frame, you'll see that the plot resizes as well.

Neil ⊥

Posted on the users mailing list.