From octave-graphics-request at bevo dot che dot wisc dot edu Fri Mar 12 10:44:15 1999 Subject: Re: Canvas vs Plot Widget From: Jonathan King To: octave-graphics at bevo dot che dot wisc dot edu Date: Fri, 12 Mar 1999 10:43:57 -0600 (CST) On 12 Mar 1999, Rafael Laboissiere wrote: > I had thought about the Plot Widget implementation, as well as the > necessity of a canvas widget. I will try to reply to some posts in this > mailing list regarding these issues. > > >>>>> "JK" == Jonathan King writes: > > JK> Another very desirable thing if you want to do interactive plots > JK> and "handle" like graphics is a good Canvas widget. Tk has one; > JK> gtk might have one if you roll gnome into the mix, and I'm not > JK> sure about wxWindows. [Aside: somebody did locate the wxWindows widget after all. :-)] > The Tk canvas widget is great because you > JK> can embed almost anything in it from images to text to menubars, > JK> and, for better or for worse, it's easy to see how you could > JK> implement satanic handle graphics for it. > > If I understand correctly, having a canvas widget would enable us to easier > emulate some aspects of Handle Graphics, like the association of callbacks > to mouse actions on plot objects (lines, axis, whatever). I'd say "implement" rather than emulate, but, yes, that's one advantage. (Of course, you'd also want to provide a less stupid interface than Matlab's, but I digress.) Another advantage of a decent canvas widget is that you can, for example, combine images and line graphs on the same "page" without having to worry about whether the underlying graphics libraries can generate stuff like this in a flexible way. > I have written some programs in Matlab that exploit this, but they > all suck. User-written mouse interaction in Matlab is a way too slow. :-) > Furthermore, from the point of view of programming, the combination > of the interpreted language + set/get constructs is just evil ( > some would say satanic ;-) On machines I've used, performance isn't always as bad as you suggest, and the devil writes a lot of code. I guess I'd recommend a policy of tolerance plus providing a clearly better way. > My idea was to create a simple Plot Widget that contains essentially a > pixmap. This is to answer JWE's question: OK, that alone will get you into trouble. The pixmap itself is what you display, but if you want mouse interaction, you need to know which pixels belong to what objects. This can be done by keeping track of what regions correspond to what objects (and which are "on top" of others) and having a function like point_in_region that can test where, say, a mouse_click "really" happened and what event is bound to that action... In other words, it's going to require something an awful lot like a canavas widget. (Which is not to say that canvases solve everything nicely all the time; it at least used to be the case that if you plotted thousands of points or lines on a Tk canvas that you wish you hadn't, although there were workarounds, and some improvements since then....) > Of course, this widget could be packed in a window widget, along with > other widgets like menus, buttons and the like. > > Do you guys think that this design is too constraining? I think it will be really tough to come up with a convincing implementation using just pixmaps without other data structures. This doesn't mean you can't use something like PLplot as the basis for creating your pixmaps, only that you need to compose those pixmaps with other stuff. jking