views:

34

answers:

1

Question update: I'm almost there, just missing dotted line style for the grid. alt text

grid: [1100 600] step-grid: 5 max-n-points: grid/1 / step-grid x-axis-border: 20 Y-margin: 10

max-random: 1000 n-points: 300

get-random-data: func[n p][
  block: copy []
  repeat i n [
    append block RANDOM p
  ]
  block
]

get-extremes: func[block][
  extreme: none
  foreach element block [
    if none? extreme [
      extreme: copy []
      repeat i 2 [append extreme element]
    ]
    if element > extreme/1 [
      extreme/1: element
    ]
    if element < extreme/2 [
      extreme/2: element
    ]    
  ]
  extreme
]

data0: get-random-data n-points max-random


extremes: get-extremes data0
height: extremes/1 - extremes/2
ratio: (grid/2 - x-axis-border - (Y-margin * 2)) / height

data: copy []

foreach element skip data0 (n-points - max-n-points) [      
  append data to-integer (ratio * element)
]


plot: copy []
color: 0.0.0

append plot [
  pen green line
]
x: 0
foreach y data [
    append plot as-pair x (grid/2 - x-axis-border - Y-margin) - y
    x: x + 5
]

main: layout [
    origin 20x0
    space 1x1
    panel1: box 1100x580 black effect reduce [
    'line-pattern 4 4
    'grid 30x30 0x0 200.200.200
    'draw plot
    ]   
    panel2: box 1100x0 black 
    panel3: box 1100x20 black    
]

view main

=== former question

The space between each box is too big and I cannot draw dotted grid, how to do this ?

plot: copy []
color: 0.0.0

append plot [line-pattern 4 4]
repeat x 400 [
    repeat y 200 [
        append plot compose [
            box (xy: 25 * as-pair x - 1 y - 1) (xy + 25)
        ]
    ]
]

main: layout [
    origin 0x0
    panel1: box 800x400 black effect reduce ['draw plot]   
    panel2: box 800x180 black 
    panel3: box 800x20 black    
]

view main
+1  A: 

use the space keyword to control spacing

See http://www.rebol.com/docs/view-guide.html#section-29

Also, you can use the 'grid for drawing a grid

"grid Generate a two dimensional grid of lines. This is a useful backdrop for graphical layout programs. The optional arguments are: a PAIR that specifies the horizontal and vertical spacing of the grid lines, a PAIR that specifies the offset of the first lines, a PAIR that indicates the THICKNESS of the horizontal and vertical lines, and a TUPLE that provides the color of the lines."

Graham Chiu
Thanks, that's good except I can't see dotted style parameters for the grid so is it possible or will I have to draw the lines by myself just to get the dotted style ? In that case maybe I can go to the vid source code to hack the grid where should I get it ?
Rebol Tutorial
I presume it just inherits the line style last used.
Graham Chiu