[REBOL] REBOL dynamic graph code problems and REBOL mindset
From: johnmacshea:gma:il at: 21-Feb-2008 10:15
Hello REBOLers,
I am a recent returner to REBOL, about 5 years ago I wrote some scripts but
they were mainly simple message based, and now I can see some potential cool
solutions in my company, if I can get over some initial stumbling blocks.
I am trying to do some graphical manipulation, but I am having difficulty in
doing some of the simplest things.
Here is a simplified version of what I have and what I would like to do.
I have a rebol script that shows a line graph based on a time series of
data.
When I manually set the data for each individual time series everything
works fine, its only when I try to update the view and make things a little
more dynamic do things start to go awry. I think I am being caught by a
combination of type issues and functional language (as opposed to
command/procedural based issues), and just some commands that I dont yet
understand.
So here is a snippet.
data0: [100 110 105 120 ...]
plot0: copy [pen green line]
x: 10
foreach y data0 [append plot0 as-pair x y
x:x + 1]
graph_view: layout [the_box: box snow 1000x500 effect reduce ['draw plot0]]
view graph_view
This works fine - I may have left out a couple of things - but thats
basically the graphing code.
When I manually add a data1, plot1, data2, plot2 etc, it also works fine.
However when I try to do something, which i would of thought is incredibly
simple, things come unstuck.
For example, I cant seem to put all the plots into a series, and then
iterate over them later in the graph view.
What i really want to do is add something like this (pseudo-ish code)to the
graph_view:
foreach current_curve in curves[ toggle_for_current_curve: "on" "off"
[either value = true [add current curve to curve series if not there (then)
show the_box] [remove current curve from the curve series if there (then)
show the_box]
I've spent about a day trying to get the simplest version of this scenario
going without even the buttons above- which is just to push each (manually
described) plot into a series, and then iterate over them to draw the
different curves.
I have pulled out the effect called it box_effect, and tried to do this
before the layout code.
I went through a whole bunch of iterators trying various ones, different
ways of adding to series, and eventually through trial and error got a
functioning box_effect, which however had the same curve multiple times, I
think its something to do with dereferencing the draw and the plot
functions.
Here for example is me trying to create the box_effect.
(having already created a plot0, plot1, and plot2 above this)
box_effect: []
all_plots: reduce [plot0 plot1 plot2]
plot_length: length? all_plots
repeat index plot_length [a_plot: pick all_plots index
append box_effect ['draw a_plot]
]
This kind of works (I went through quite some iterations to get here, for
each did not seem to always work, insert into a series did not seem to work,
sometime pick series index_var, did not seem to work, sometimes the plot was
'none' etc etc) - now it gives me the same curve three times.
This post is not just a query as to how i do such a simple thing, but more a
question as to "how to 'get' REBOL", it just seems too hard to do something
so simple, I feel like I am fighting the language, that my mindset is wrong,
but I cant seem to figure out how to do it right.
Any help would be much appreciated !
Best regards,
John