Category talk:Wren-plot: Difference between revisions
Content added Content deleted
m (→Source code: Added quotes to 'lang' attribute.) |
(→Source code: Labels can now be scaled for display purposes.) |
||
Line 45: | Line 45: | ||
} |
} |
||
// Prints 'text' centered at unscaled coordinates (x, y) |
// Prints 'text' centered at unscaled coordinates (x, y) |
||
// relative to the origin in a given color. |
// relative to the origin in a given color. |
||
print(x, y, text, color) { |
print(x, y, text, color) { |
||
Line 53: | Line 53: | ||
// Adds marks to x and y axes at the appropriate scaled coordinates. |
// Adds marks to x and y axes at the appropriate scaled coordinates. |
||
// The marks themselves are drawn in a given color and line thickness. |
// The marks themselves are drawn in a given color and line thickness. |
||
// The label is printed in 'lblColor'. |
// The label is printed in 'lblColor'. Before being displayed the labels |
||
// are scaled by dividing them by xDiv and yDiv for the respective axes. |
|||
⚫ | |||
label(xMarks, yMarks, color, thickness, lblColor, xDiv, yDiv) { |
|||
for (xm in xMarks) { |
for (xm in xMarks) { |
||
var x = (xm - _rx.from) * scaleX |
var x = (xm - _rx.from) * scaleX |
||
Canvas.line(_ox + x, _oy, _ox + x, _oy + 10, color, thickness) |
Canvas.line(_ox + x, _oy, _ox + x, _oy + 10, color, thickness) |
||
var label = xm.toString |
var label = (xm/xDiv).toString |
||
var v = Canvas.getPrintArea(label) |
var v = Canvas.getPrintArea(label) |
||
Canvas.print(label, _ox + x - v.x/2, _oy + 10 + v.y, lblColor) |
Canvas.print(label, _ox + x - v.x/2, _oy + 10 + v.y, lblColor) |
||
Line 65: | Line 66: | ||
var y = (ym - _ry.from) * scaleY |
var y = (ym - _ry.from) * scaleY |
||
Canvas.line(_ox, _oy - y, _ox - 10, _oy - y, color, thickness) |
Canvas.line(_ox, _oy - y, _ox - 10, _oy - y, color, thickness) |
||
var label = ym.toString |
var label = (ym/yDiv).toString |
||
var v = Canvas.getPrintArea(label) |
var v = Canvas.getPrintArea(label) |
||
Canvas.print(label, _ox - 14 - v.x, _oy - y - v.y/2, lblColor) |
Canvas.print(label, _ox - 14 - v.x, _oy - y - v.y/2, lblColor) |
||
} |
} |
||
} |
|||
// Convenience version of 'label' which doesn't scale the labels prior to display. |
|||
⚫ | |||
label(xMarks, yMarks, color, thickness, lblColor, 1, 1) |
|||
} |
} |
||