VID dynamic layout
[1/5] from: tmoeller:fastmail:fm at: 13-Jan-2010 9:14
Hi,
i have some problems to generate a dynamic layout. I have an result set
from a database, which returns the percent usage of resources. I try is
to show this as a status bar or progress bar or something like that,
which is green in general, but becoming orange or red depending on its
value.
I tried this with a progress bar but cannot make the bar showing the
values. Simplified i try to do the following:
make-lbl-name: func [lang [word!] type [datatype!]][
to type join 'lbl- lang
]
lay-spec: [
across space 4x4
backdrop effect compose [gradient 1x0 (white) (silver)
]
return
style pgr progress 270 green
]
foreach line result [
append lay-spec compose [
(make-lbl-name to-word line/3 set-word!) text bold 200 (form
line/3)
pgr
return
]
]
I thought in the foreach loop there must be somthing like if line > 80
[PG1: pgr orange and PG1/data: line/ 16] . That doesn't seem to work.
What am i understanding wrong??
Thorsten
--
http://www.fastmail.fm - Same, same, but different...
[2/5] from: henrikmk:gmai:l at: 13-Jan-2010 10:35
On Wed, Jan 13, 2010 at 9:14 AM, Thorsten Moeller <tmoeller-fastmail.fm> wrote:
> lay-spec: [
> =A0 =A0across space 4x4
<<quoted lines omitted: 13>>
> I thought in the foreach loop there must be somthing like if line > 80
> [PG1: pgr orange and PG1/data: line/ 16] . That doesn't seem to work.
You can do that. I don't know which column gives you the data, so I'm
just using line/5 and I'm assuming it's a decimal between 0 and 1:
foreach line result [
append lay-spec compose [
(make-lbl-name to-word line/3 set-word!) text bold 200 (form
line/3)
pgr (line/5) (
case [
line/5 < 0.5 [green]
line/5 < 0.7 [yellow]
line/5 < 0.9 [red]
]
)
return
]
]
There is at least one other way to do it, and that is to duplicate and
modify the progress style, so that it knows what color it needs to
draw, when you give it a specific value. That gives a cleaner and
smaller layout, by abstracting the color decision away from the
layout, but it requires that you redo or append to the progress style
function. If you end up doing a lot of customization, it makes sense
to move the color evaluation to the style, rather than building a huge
layout.
You need to dig out the 'init part of the progress style. 'init is run
as the layout is created:
probe get in get-style 'progress 'init
which gives:
[
if image? image [
if none? size [size: image/size]
if size/y < 0 [size/y: size/x * image/size/y / image/size/x
effect: insert copy effect 'fit]
if color [effect: join effect ['colorize color]]
]
if none? size [size: 100x100]
pane: make bar []
pane/size: size
either size/x > size/y [pane/size/x: 1] [pane/size/y: 1]
if colors [color: first colors pane/color: second colors]
]
Now you need to modify that code and build a derivative style. We can
shave it down a little bit, since you probably don't need images:
stylize/master [
pgr: progress [
init: [
if none? size [size: 100x100]
pane: make bar []
pane/size: size
either size/x > size/y [pane/size/x: 1][pane/size/y: 1]
; here we decide it. COLORS is two colors. The first gives
foreground, the second gives background. (At least I think, swap it
around if it doesn't work)
if not number? data [data: 0] ; for safety
if colors [
colors/1:
case [
data < 0.5 [green]
data < 0.7 [yellow]
data < 0.9 [red]
]
]
if colors [color: first colors pane/color: second colors]
]
]
]
Then your loop would appear like this:
foreach line result [
append lay-spec compose [
(make-lbl-name to-word line/3 set-word!) text bold 200 (form
line/3)
pgr (line/5)
return
]
]
Nice and clean. Code is untested.
--
Regards,
Henrik Mikael Kristensen
[3/5] from: tmoeller:fastmail:fm at: 19-Jan-2010 13:46
Hello Henrik,
i think i understand what you try to do but what i don't understand is
the result from it.
I have 2 further questions:
1. Why is the bar in my result still blue, no matter what kind of value
i use? Especially because it mentioned nowhere.
2. is it possible to set the Maximum Value of the bar to 100? I have
Values which might be very small. Using only values lower than one
result in having very small values i i have to transform them before. I
am experiencing problem with values like 0.03 already and have to
convert them to money if they appear in the resultset.
Thanks
Thorsten
On Wed, 13 Jan 2010 10:35 +0100, "Henrik Mikael Kristensen"
<henrikmk-gmail.com> wrote:
> On Wed, Jan 13, 2010 at 9:14 AM, Thorsten Moeller <tmoeller-fastmail.fm>
> wr
<<quoted lines omitted: 103>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
http://www.fastmail.fm - The way an email service should be
[4/5] from: henrikmk:gma:il at: 19-Jan-2010 15:08
On Tue, Jan 19, 2010 at 1:46 PM, Thorsten Moeller <tmoeller-fastmail.fm> wrote:
> Hello Henrik,
>
> i think i understand what you try to do but what i don't understand is
> the result from it.
>
> I have 2 further questions:
>
> 1. Why is the bar in my result still blue, no matter what kind of value
> i use? Especially because it mentioned nowhere.
it's possible that if you feed it integers, the values will be seen as
sizes and if you specify an integer twice, it's likely that one of
them will be ignored.
Also it seems my example was a bit wrong. Here's a tested version of the CASE:
case [
line/5 > 0.9 [255.0.0]
line/5 > 0.7 [255.240.0]
true [0.128.0]
]
Also you need to specify a color before the case, otherwise the case
color is seen as a background color.
> 2. is it possible to set the Maximum Value of the bar to 100? I have
> Values which might be very small. Using only values lower than one
> result in having very small values i i have to transform them before. I
> am experiencing problem with values like 0.03 already and have to
> convert them to money if they appear in the resultset.
PROGRESS acts on a decimal value between 0 and 1, so the best way is
to divide or multiply the value approproiately to fit between 0 and 1.
--
Regards,
Henrik Mikael Kristensen
[5/5] from: tmoeller:fastmail:fm at: 20-Jan-2010 14:21
Hello Henrik,
got it up and running.
Thanks for your support.
Thorsten
On Tue, 19 Jan 2010 15:08 +0100, "Henrik Mikael Kristensen"
<henrikmk-gmail.com> wrote:
> On Tue, Jan 19, 2010 at 1:46 PM, Thorsten Moeller <tmoeller-fastmail.fm>
> wrote:
<<quoted lines omitted: 33>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
http://www.fastmail.fm - Access all of your messages and folders
wherever you are
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted