diff --git a/extra/ui/gadgets/charts/axes/axes.factor b/extra/ui/gadgets/charts/axes/axes.factor index 34248b95e9..24c9d5f24d 100644 --- a/extra/ui/gadgets/charts/axes/axes.factor +++ b/extra/ui/gadgets/charts/axes/axes.factor @@ -1,11 +1,39 @@ ! Copyright (C) 2017 Alexander Ilin. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel locals ui.gadgets ui.gadgets.charts +USING: accessors arrays colors.constants kernel locals math +math.order opengl sequences ui.gadgets ui.gadgets.charts +ui.gadgets.charts.lines ui.gadgets.charts.lines.private ui.render ; IN: ui.gadgets.charts.axes -TUPLE: axis < gadget vertical? ; +TUPLE: axis < gadget vertical? color ; + +> dup [ swap ] unless gl-color drop ; + +:: x-0y-chunk ( x y -- chunk ) x 0 2array x y 2array 2array ; +:: 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 + +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 ] [ 2drop ] if ; diff --git a/extra/ui/gadgets/charts/demos/demos.factor b/extra/ui/gadgets/charts/demos/demos.factor index d893100cc1..43a629dfa6 100644 --- a/extra/ui/gadgets/charts/demos/demos.factor +++ b/extra/ui/gadgets/charts/demos/demos.factor @@ -2,7 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays colors.constants kernel literals locals math math.constants math.functions sequences ui ui.gadgets -ui.gadgets.charts ui.gadgets.charts.lines ; +ui.gadgets.charts ui.gadgets.charts.axes ui.gadgets.charts.lines +; IN: ui.gadgets.charts.demos CONSTANT: -pi $[ pi neg ] @@ -23,6 +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 "Chart" open-window ; PRIVATE>