factor/charts.factor

23 lines
905 B
Factor
Raw Normal View History

2017-01-06 03:38:03 -05:00
! Copyright (C) 2016-2017 Alexander Ilin.
2017-01-19 20:04:23 -05:00
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel ui.gadgets ;
2017-01-06 03:38:03 -05:00
IN: charts
TUPLE: chart < gadget ;
M: chart pref-dim* drop { 300 300 } ;
2017-01-06 17:36:30 -05:00
! Return the x and y ranges of the visible area.
2017-01-06 03:38:03 -05:00
: chart-axes ( chart -- seq )
2017-01-13 05:59:07 -05:00
drop { { 0 300 } { 0 300 } } ;
2017-01-06 03:38:03 -05:00
! Return the { width height } of the visible area, in pixels.
: chart-dim ( chart -- seq ) dim>> ;
2017-01-19 19:44:44 -05:00
2017-01-06 03:38:03 -05:00
! There are several things to do to present data on the screen.
! Map the data coordinates to the screen coordinates.
2017-01-06 17:36:30 -05:00
! Cut off data outside the presentation window. When cutting off vertically, split the line into segments and add new points if necessary. Return an array of line segments.
2017-01-06 03:38:03 -05:00
! Remove redundant points from the drawing pass.
! chart new line new COLOR: blue >>color { { 0 100 } { 100 0 } { 100 50 } { 150 50 } { 200 100 } } >>data add-gadget "Chart" open-window