! See http://factorcode.org/license.txt for BSD license.
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.gadgets.charts.lines ui.gadgets.charts.utils ui.render ;
IN: ui.gadgets.charts.axes
TUPLE: axis < gadget vertical? color ;
: 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 - ;
! Copyright (C) 2017 Alexander Ilin.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math sequences tools.test
-ui.gadgets.charts.lines ui.gadgets.charts.lines.private ;
+USING: kernel math sequences tools.test ui.gadgets.charts.lines
+ui.gadgets.charts.lines.private ui.gadgets.charts.utils ;
IN: ui.gadgets.charts.lines.tests
{ -2/3 } [ { 1 3 } { -2 5 } calc-line-slope ] unit-test
combinators.short-circuit fry kernel locals make math math.order
math.statistics math.vectors namespaces opengl opengl.gl
sequences specialized-arrays.instances.alien.c-types.float
-splitting.monotonic ui.gadgets ui.gadgets.charts ui.render ;
+splitting.monotonic ui.gadgets ui.gadgets.charts
+ui.gadgets.charts.utils ui.render ;
IN: ui.gadgets.charts.lines
! Data must be a sequence of { x y } coordinates sorted by
: flip-y-axis ( chunks ymin,ymax -- chunks )
first2 + '[ [ _ swap - ] assoc-map ] map ;
-! value' = (value - min) / (max - min) * width
-: scale ( width value max min -- value' ) neg [ + ] curry bi@ / * ;
-
! Return quotation that can be used in map operation.
: scale-mapper ( width min,max -- quot: ( value -- value' ) )
first2 swap '[ _ swap _ _ scale ] ; inline
--- /dev/null
+Alexander Ilin
--- /dev/null
+! Copyright (C) 2017 Alexander Ilin.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors kernel math opengl ;
+IN: ui.gadgets.charts.utils
+
+: default-color ( default obj -- )
+ color>> dup [ swap ] unless gl-color drop ;
+
+! value' = (value - min) / (max - min) * width
+: scale ( width value max min -- value' ) neg [ + ] curry bi@ / * ;