[RkWard-devel] grid inplot_options

Prasenjit Kapat kapatp at gmail.com
Thu Mar 22 10:28:19 UTC 2007


Hi,

On Wednesday 21 March 2007 01:00:32 pm Thomas Friedrichsmeier wrote:
> On Wednesday 21 March 2007 08:10, Prasenjit Kapat wrote:
> > 1. grid.xml has an external id: is_embed to notify whether it is embeded
> > or not. This needs to be set from the embedding plugin (plot_options.xml
> > in this case)
>
> There is no need for the external "is_embed" property (at least not in this
> case). Standalone grid can only be used in the x11 context. In this case,
> it is given a property "context", which is set to "x11". If this property
> is empty, we know it is embedded.

Hmm.. I was not aware of such a "context" property! That simplyfies the logics 
a bit.

> > 2. grid.php's printout function echos the neccessary code: grid(...).
>
> I've simplified the logic slightly: If the plugin is embedded, it will echo
> the
> 	dev.set(x)
> otherwise it won't. That's the entire difference between embedded and
> standalone. I've also move the dev.set() to preprocess, but that's just for
> aesthetics.

Better implementation!

> > 3. plot_options.xml uses another external id allow_grid to control
> > whether grid options are to be shown at all or not.
>
> Ok.
>
> > 4. If allow_grid is true then a checkbox (add_grid) controls whether grid
> > is to be added to the current plot or not.
>
> I've moved that checkbox to the grid tab, as this is, where it logically
> belongs. This gave a problem with disabling all the grid options, when
> add_grid is not checked. However, I've changed that from C++: Now, if you
> disable an embedded plugin, all it's child widgets become disabled as well.

See, that was precisely the problem. I was forced to put the checkbox in a 
different place and then enable/disable the whole tab. I had faced this issue 
somewhere (probably color_chooser) earlier too. I think I used a frame 
environment to tackle it then. But you have already taken care of it from the 
C++ end. So, it works perfect now! Great.

> > 5. Now, from the main plugin (say, plot_beta_distribution.xml) we set
> > plot_options.allow_grid to 'true'.
>
> Ok.
>
> > 6. The calculate() function of plot_beta_distribution.php obtains the
> > neccessary code from plot_options.grid_options.code.printout and stores
> > it into a global variable.
>
> I've changed this slightly, so the grid code is put into the
> plot_options.code.calculate property, instead (and only, if applicable).
> plot_beta_distribution then fetches it from there, instead of directly from
> the grid plugin. There are two ideas behind this change:

I knew you would make this change :-) Moving the actual work from calculate() 
to printout() in grid.php helped.

> a) If we also add rug() and whatever to plot_options in later releases,
> we'll only need minimal adjustments in the plugins using plot_options. Most
> likely, there'd be another property "allow_rug", which would need to be set
> to true, but the PHP code would not need to be adjusted any further. You
> simply echo plot_options.code.calculate at the right place, and this will
> contain any grids / lines / rugs / embedded captions or whatever else we
> may chose to add to plot_options in the future.

Totally agreed.

> b) Let's try to keep things modular as much as possible. With your
> approach, any plugin wanting to allow grid in plot_options would need to
> know that 1. there is a property "allow_grid" in plot_options, 2. there is
> a
> property "add_grid" in plot_options, and what it does, 3. the grid options
> are realized using an embedded plugin with the id "grid", 4. the grid
> plugin placed the relevant command(s) in the code section printout. With
> the changed approach this is changed to 1.

Perfect! I have added a small documention in plot_options.rkh under the 
technical section. Hopefully that should be sufficient.

> As a general rule of thumb: If you find yourself accessing anything
> besides "enabled", "visible", "required", or "code" of an embedded plugin
> (or of course its <external> properties), ask yourself, whether this is
> really needed.

Point taken.

> (Note: In the future, we might also add some things to plot_options which
> should be added before the call to plot(), and those should go into
> plot_options.code.preprocess. An example of this might be setting the
> background color, as suggested by Illias a while ago, which would generate
> a par (bg=...)
> which would have to be called before the plot. However, that's for after
> 0.4.7).

Yes.

>
> > 7. Finally, to actually draw the grid, the aobve variable is echoed after
> > the try(curve(..)) function call.
>
> Ok. I've changed it to a) be included inside the try(), and b) added a
> helper function printIndented() which can be used from PHP, and use this to
> echo the grid() call with proper indentation (in this particular case, this
> could be done in an easier way, but if there is ever more than one line to
> execute after the plot, this will make sure, it is echoed with proper
> indentation).

Nice function. Sounds good.

> > As of now, I have only included in plot_beta_distribution plugin. Any
> > improvements are welcome.
>
> One thing we'll still need to take care of is finding a better place for
> the plugin than x11device. Also we'll have to take care of defining
> dependencies between plugins somewhere, as discussed a while ago. However,
> that's probably for after 0.4.7.

You are right. We need some more brainstorming in this regard.


Regards
PK




More information about the Rkward-devel mailing list