[RkWard-devel] grid inplot_options

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Wed Mar 21 17:00:32 UTC 2007


Hi,

On Wednesday 21 March 2007 08:10, Prasenjit Kapat wrote:
> I have given this a shot. Not very elegant though. But does the job. It is
> implemented in the following way:

Thanks! I've done a few changes:
> 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.

> 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.

> 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.

> 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:

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.

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. and the fact that any statements that should 
be added after the plot itself are available in plot_options.code.calculate. 
If we are to ever change the internals of plot_options and / or grid, we 
won't have to fix up all the embedding plugins as well.

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.

(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).

> 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).

> 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.

Regards
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20070321/9dfdb978/attachment.sig>


More information about the Rkward-devel mailing list