Jump to content

Category talk:Wren-plot: Difference between revisions

Several changes including new methods: rect and rectfill.
(Added source code for new 'Wren-plot' module.)
 
(Several changes including new methods: rect and rectfill.)
Line 15:
// 3. ranges of x and y values: rangeX and rangeY.
// If x-values are non-numeric or discrete, null should be passed for rangeX.
// In that event a range of 0..lengthX will be used by those methods that need it.
construct new(originX, originY, lengthX, lengthY, rangeX, rangeY) {
_ox = originX
Line 20 ⟶ 21:
_lx = lengthX
_ly = lengthY
_rx_rn = (rangeX == null)
_rx = _rn ? 0.._lx : rangeX
_ry = rangeY
}
Line 89 ⟶ 91:
y2 = (y2 - _ry.from) * scaleY
Canvas.line(_ox + x1, _oy - y1, _ox + x2, _oy - y2, color, thickness)
}
 
// Draws a rectangle with the top-left corner at scaled point (x, y)
// relative to the origin and a width of w and height of h in color c.
rect(x, y, w, h, c) {
x = (x - _rx.from) * scaleX
y = (y - _ry.from) * scaleY
Canvas.rect(_ox + x, _oy - y, w, h, c)
}
 
// Draws a filled rectangle with the top-left corner at scaled point (x, y)
// relative to the origin and a width of w and height of h in color c.
rectfill(x, y, w, h, c) {
x = (x - _rx.from) * scaleX
y = (y - _ry.from) * scaleY
Canvas.rectfill(_ox + x, _oy - y, w, h, c)
}
 
Line 168 ⟶ 186:
// 'barColors' list and with a border color of 'brdColor'.
// The interval between bars is calculated by the method.
// If _rx_rn is nulltrue, the method prints the labels on the x-axis at the appropriate positions.
// 'yMarks' are drawn on the y-axis at the appropriate positions in color 'mrkColor'
// and thickness 'mrkThick'. Labels on both the x and y axes are printed in 'lblColor.'
Line 180 ⟶ 198:
Canvas.rectfill(x, _oy - v, barWidth, v, barColors[cix])
Canvas.rect(x, _oy - v, barWidth, v, brdColor)
if (!_rx_rn) {
var label = d[0].toString
var w = Canvas.getPrintArea(label).x
Line 198 ⟶ 216:
// between the bars and 'barWidth' is therefore calculated by the method.
// Otherwise the parameters and remarks are the same as for a bar-chart.
// If _rx_rn isn'tis nullfalse, 'xmarks' are deduced and drawn on the x-axis at the appropriate intervals.
histogram(data, barColors, brdColor, yMarks, mrkColor, mrkThick, lblColor) {
var n = data.count
var rectWidth = _lx/n
barChart(data, rectWidth, rectColors, brdColor, yMarks, mrkColor, mrkThick, lblColor)
if (_rx!_rn) {
var interval = (_rx.to - _rx.from) / n
var xMarks = (0..n+1).map { |i| i * interval }.toList
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.