Login  Register

Re: Drawing graphs iin Dolphin

Posted by Chris Uppal-3 on Jul 05, 2004; 12:43pm
URL: https://forum.world.st/Drawing-graphs-iin-Dolphin-tp3370875p3370877.html

Peter Kenny wrote:

> I suspect I need to have a graph object, which is assigned as the model
> of a graph presenter and is in turn linked to a graph view. I do not know
> whether I can use any existing classes as the presenter and view in this
> set-up; if not, what would be a good point to start subclassing, and
> which methods would I have to override in my subclasses? I am floundering
> at the moment, because I am relatively new to Smalltalk.

That is probably the right place to start.  It's the approach /I've/ taken,
anyway, so I hope it's optimal ;-)

I think the key point that you are missing is that you need to provide your own
implementation of View>>onPaintRequired: that does the actual drawing.  This is
called when Windows decides that it wants your application to refresh part of
its display.  In this case your View would use the data from the Model to paint
the graph on the Canvas.

(BTW, Ian's archive and/or Google will show lots of discussion of the finer
points of graphics work if you search for "Canvas").

Ian also has a tutorial at <http://www.iandb.org.uk/> (the "buildview"
tutorial) which has an example of drawing a histogram as part of an
application.  That tutorial is very slightly out of date in that it mentions
CompositePresenters here and there, but they have been unnecessary since D4 (or
D5?) when OA made all Presenters be able to act as composites.


> a. Am I reinventing the wheel here? There is so much stuff out there in
> people's goodies packs, perhaps there is what I need already. If so I
> would be glad of any pointers (or even shameless plugs from authors).

Oddly, I don't know of anything that anyone has published.  That may be because
its difficult to write a self-contained graphing package without it sprawling
out to be absolutely /huge/ (see the jFreeGraph package for a -- Java --
example of this).  I know that the reason I'm not planning to put my own graph
stuff on my website is that the only way I've been able to keep it simple
enough to be implementable is to concentrate of the features I actually need to
the point where I can't imagine it being any real use to anyone else.


> What is needed is a scalable drawing
> format like WMF. Do any of the available classes provide the possibility
> of saving the display as a .wmf file?

I imagine that there is some way to create a Canvas representing a .wmf file,
but I've never needed to find out how to do it.  For displaying .WMF files, you
can use an ImagePresenter and an OLEPicture, e.g:

    file := 'whatever.wmf'.
    picture := OLEPicture fromFile: file.
    ImagePresenter show: 'Basic image' on: picture.

    -- chris