]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.gadgets.charts.axes: replace boolean property with subclasses
authorAlexander Iljin <ajsoft@yandex.ru>
Sun, 5 Feb 2017 17:46:44 +0000 (20:46 +0300)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 17 Apr 2017 20:54:51 +0000 (13:54 -0700)
The vertical? property of the axis tuple was replaced with two subclasses:
vertical-axis and horizontal-axis.

extra/ui/gadgets/charts/axes/axes.factor
extra/ui/gadgets/charts/demos/demos.factor

index b88333f02a61916622448774397ebbd2c2bfb5d3..fa93951e2899df604c04850cd0486a5c9040ce20 100644 (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 ;
index 43a629dfa66545af31366cd70ab1722c568b3f0a..96546edc4a07425997b2261d0a2e56f0dedac0bf 100644 (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>