APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

EJSs Plotting Procedures- _view objects and procedures post and replies

Return to the EJSs Plotting Procedures- _view objects and procedures thread
Login to post to this thread

_view procedures
Nick Gross
17 Posts

Does EJSs have the _view objects embedded?  Is it possible to call _view.clear and _view.addpoint?

I want to plot to a line, then have the user change some settings, clear the line and plot it again without reinitializing the whole program.

Thanks,
Nick

Post edited May 30, 2014 at 10:32 AM EST.


Replies to _view procedures

Re: _view procedures -
Francisco Esquembre
228 Posts

Hi Nick,

The Java "flavour" of EjsS remains as usual. That means a positive answer for Java.

As for Javascript, the corresponding methods are:
_view._initialize();
and
_view._reset();
(Notice the leading underscore in _initialie and _reset.)

This propagates a call to initialize or reset to all the view elements. The actual response of the element depends on it type. Trails will typically clear their data.

And yes, you can also call:
_view.yourTrailName.addPoint(x,y).

Hope this helps. If it does not, please send your example and I'll try to help.

Paco



Re: Re: _view procedures -
Nick Gross
17 Posts

Hi Paco,
Attached is my attempt to use the _view.trail.addpoint() procedure.
It seems to fail with not particular error.  
I try generating a plot by populating the trail during the initialization procedure.
Any ideas about what I might be doing wrong?

Thanks for all the help.
Nick

Attached File: TestPlot3.ejss.zip



Re: Re: Re: _view procedures -
Francisco Esquembre
228 Posts

Nick,

Two things:

- The method is called addPoint(). Notice the uppercase P.
- The problem is that, by default, the plotting panel has bounds [-1,1]x[-1,1] and AutoScaleX and AutoScaleY are set to false. This means that your trail is out of scale and hence not visible.

Change the AutoscaleX and AutoscaleY properties to true. (Maybe they should be try by default?)
And use addPoint, and you will get it.

Paco



Re: Re: Re: Re: _view procedures -
Nick Gross
17 Posts

Oh! How embarrassing!  
Thanks for the debugging!  Off I go to write the code I actually want to write :)
Nick



Re: Re: Re: Re: Re: _view procedures -
Francisco Esquembre
228 Posts

Don't be embarrassed at all. More often than not, questions like this lead to improvements.

For instance, I am considering now that Autoscale should be true by default on a PlottingPanel.

Paco



Re: Re: _view procedures -
mrg_psu
9 Posts

Is it possible to use some sort of _view call to update just one panel, such as a drawing panel?  I'm modifying the colors array for a cell lattice on the fly, but the graphics don;t update until I resize the browser or some such.  I have trails going in another panel, and they get cleared if I just try view._reset();

The problem code is in the Custom:Image Lib Page in the first function (image_color_mapper)

-Mike Gallis

Attached File: XRayImagingbeta3.zip



Re: Re: Re: _view procedures -
Francisco Esquembre
228 Posts

Mike,

The cellLattice is very time consuming to redraw if it has had no changes. For this reason,we do not refresh it UNLESS you tell us explicitly that it has changed.

You need to add a line like this:

_view.yourCellLatticeName.setChanged(true);

where "yourCellLatticeName" is the name of the cell lattice in your simulation.

Paco

PS: One day, we will document well... :-)



OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book