Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: sfeam Newsgroups: comp.graphics.apps.gnuplot Subject: Re: Multiple canvas plots share same state variable? Followup-To: comp.graphics.apps.gnuplot Date: Tue, 21 Aug 2012 09:26:13 -0700 Organization: gnuplot development team Lines: 39 Message-ID: References: <93687e00-9428-4a48-a203-88724c19c651@googlegroups.com> Reply-To: sfeam@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Tue, 21 Aug 2012 16:26:15 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="de68407e1e0278021e2f738a9cf7b10c"; logging-data="3343"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BRcQXCH5sxT4Vs5TIIkI1" User-Agent: KNode/4.4.9 Cancel-Lock: sha1:0k4w3/wYG0yppDKjYUrZptoKA/A= Xref: csiph.com comp.graphics.apps.gnuplot:1348 tombert wrote: > Hi all, > > I wonder why the gnuplot canvas javascript are using a common static > variable var gnuplot = { } > > For example in file gnuplot_common.js there is the statement > if (gnuplot.zoomed) { > .... > } > > When I build up multiple independent plots in a single html page, > zooming into one plot automatically zooms the other plots. > > Am I doing something wrong? Did I miss something? Apparently so, because if you look at the demo plots on http://gnuplot.sourceforge.net/demo_canvas/ you will see they do not suffer from the problem you describe. In fact the gnuplot object you mention is there exactly for the purpose of isolating the different plots from each other and from any other javascript entities that might otherwise be in the same namespace. If you place multiple canvas elements on the same page, you must give them distinct names. The name of the "active" canvas is loaded into the gnuplot object when the canvas is entered, and the contents of the object are repopulated to correspond to the new active plot. Please read the file .../term/js/README This does have the down-side that if the mouse later returns to a canvas that was previously zoomed, the data structure is repopulated from the original plot description so the previous zoom state is lost. If saving that state is important to you, you could add a save/restore operation to the set of actions triggered on mouse exit/entry. You would not need to modify gnuplot itself to do this, it would be sufficient to locally modify the script file gnuplot_mouse.js.