ui.gadgets.charts.[axes|demos]: add simple axis drawing
parent
dd3fcfdadf
commit
90087cebc1
|
@ -1,11 +1,39 @@
|
||||||
! Copyright (C) 2017 Alexander Ilin.
|
! Copyright (C) 2017 Alexander Ilin.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! 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 ;
|
ui.render ;
|
||||||
IN: ui.gadgets.charts.axes
|
IN: ui.gadgets.charts.axes
|
||||||
|
|
||||||
TUPLE: axis < gadget vertical? ;
|
TUPLE: axis < gadget vertical? color ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
ALIAS: x first
|
||||||
|
ALIAS: y second
|
||||||
|
|
||||||
|
: axis-pos ( min,max -- value ) 0 swap first2 clamp ;
|
||||||
|
|
||||||
|
: default-color ( default obj -- )
|
||||||
|
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*
|
M: axis draw-gadget*
|
||||||
dup parent>> dup chart? [| axis chart |
|
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 ;
|
] [ 2drop ] if ;
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays colors.constants kernel literals locals
|
USING: accessors arrays colors.constants kernel literals locals
|
||||||
math math.constants math.functions sequences ui ui.gadgets
|
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
|
IN: ui.gadgets.charts.demos
|
||||||
|
|
||||||
CONSTANT: -pi $[ pi neg ]
|
CONSTANT: -pi $[ pi neg ]
|
||||||
|
@ -23,6 +24,8 @@ CONSTANT: -pi $[ pi neg ]
|
||||||
chart new ${ ${ -pi pi } { -1 1 } } >>axes
|
chart new ${ ${ -pi pi } { -1 1 } } >>axes
|
||||||
line new COLOR: blue >>color n sine-wave >>data add-gadget
|
line new COLOR: blue >>color n sine-wave >>data add-gadget
|
||||||
line new COLOR: red >>color n cosine-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 ;
|
"Chart" open-window ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
Loading…
Reference in New Issue