1# Draw a histogram given values, colors and labels for each bar, 2# the maximum value to be shown in a bar and the size of the histogram. 3# 4begin histogram colors, labels, values, maxValue, size 5 6 local x, y, numValues 7 8 font "Helvetica", 3 9 linestyle 0.01 10 let y = 1, numValues = length(values) 11 12 # Draw histogram in square, numValues units wide. 13 # Scale this to desired size. 14 # 15 scale size / numValues 16 17 while y <= numValues 18 do 19 # Display colored bar with width dependent on the value it shows. 20 # 21 clearpath 22 color colors[y] 23 let x = values[y] / maxValue * numValues 24 box 0, y - 1, x, y 25 fill 26 color "black" 27 stroke 28 clearpath 29 30 # Position label to the right of the bar. 31 # 32 move x + 0.3, y - 0.8 33 label labels[y] 34 let y = y + 1 35 done 36 37 # Display a border for the histogram. 38 # 39 clearpath 40 color "grey" 41 move numValues, 0 42 draw 0, 0, 0, numValues 43 stroke 44end 45