Category talk:Wren-plot: Difference between revisions

→‎Source code: Labels can now be scaled for display purposes.
m (→‎Source code: Added quotes to 'lang' attribute.)
(→‎Source code: Labels can now be scaled for display purposes.)
Line 45:
}
 
// Prints 'text' centered at unscaled coordinates (x, y)
// relative to the origin in a given color.
print(x, y, text, color) {
Line 53:
// 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 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) {
label(xMarks, yMarks, color, thickness, lblColor, xDiv, yDiv) {
for (xm in xMarks) {
var x = (xm - _rx.from) * scaleX
Canvas.line(_ox + x, _oy, _ox + x, _oy + 10, color, thickness)
var label = (xm/xDiv).toString
var v = Canvas.getPrintArea(label)
Canvas.print(label, _ox + x - v.x/2, _oy + 10 + v.y, lblColor)
Line 65 ⟶ 66:
var y = (ym - _ry.from) * scaleY
Canvas.line(_ox, _oy - y, _ox - 10, _oy - y, color, thickness)
var label = (ym/yDiv).toString
var v = Canvas.getPrintArea(label)
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) {
label(xMarks, yMarks, color, thickness, lblColor, 1, 1)
}
 
9,476

edits