ui.gadgets.charts.axes: replace boolean property with subclasses

The vertical? property of the axis tuple was replaced with two subclasses:
vertical-axis and horizontal-axis.
char-rename
Alexander Iljin 2017-02-05 20:46:44 +03:00 committed by John Benediktsson
parent c91d7dbcb9
commit 07f35d95ac
2 changed files with 21 additions and 11 deletions

View File

@ -5,7 +5,9 @@ math.order opengl sequences ui.gadgets ui.gadgets.charts
ui.gadgets.charts.lines ui.gadgets.charts.utils ui.render ;
IN: ui.gadgets.charts.axes
TUPLE: axis < gadget vertical? color ;
TUPLE: axis < gadget color ;
TUPLE: vertical-axis < axis ;
TUPLE: horizontal-axis < axis ;
<PRIVATE
@ -18,18 +20,26 @@ ALIAS: y second
:: 0x-y-chunk ( x y -- chunk ) 0 y 2array x y 2array 2array ;
: flip-y ( axis-y xmax ymax -- xmax axis-y' ) rot - ;
: ?[x/y] ( ? -- quot )
[ x ] [ y ] ? [ call( a -- b ) ] curry ; inline
GENERIC: axis-line ( pos xmax ymax axis -- chunk )
GENERIC: chart-dims ( chart axis -- pixel-width axis-min,max )
M: vertical-axis axis-line
drop nip x-0y-chunk ;
M: horizontal-axis axis-line
drop flip-y 0x-y-chunk ;
M: vertical-axis chart-dims
drop [ dim>> x ] [ chart-axes x ] bi ;
M: horizontal-axis chart-dims
drop [ dim>> y ] [ chart-axes y ] bi ;
PRIVATE>
M: axis draw-gadget*
dup parent>> dup chart? [| axis chart |
axis vertical?>> :> vert?
chart dim>> :> dim
COLOR: black axis default-color
dim chart chart-axes vert? ?[x/y] bi@
[ axis-pos ] keep first2 swap scale
dim first2 vert? [ nip x-0y-chunk ] [ flip-y 0x-y-chunk ] if
draw-line
chart axis chart-dims [ axis-pos ] keep first2 swap scale
chart dim>> first2 axis axis-line draw-line
] [ 2drop ] if ;

View File

@ -24,8 +24,8 @@ CONSTANT: -pi $[ pi neg ]
chart new ${ ${ -pi pi } { -1 1 } } >>axes
line new COLOR: blue >>color n sine-wave >>data add-gadget
line new COLOR: red >>color n cosine-wave >>data add-gadget
axis new add-gadget
axis new t >>vertical? add-gadget
vertical-axis new add-gadget
horizontal-axis new add-gadget
"Chart" open-window ;
PRIVATE>