ui.gadgets.charts.utils: move some common code to the new vocab
parent
90087cebc1
commit
90a7ce9120
|
@ -2,8 +2,7 @@
|
|||
! 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 ;
|
||||
|
@ -15,9 +14,6 @@ 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 - ;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! 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
|
||||
|
|
|
@ -4,7 +4,8 @@ USING: accessors arrays assocs binary-search combinators
|
|||
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
|
||||
|
@ -208,9 +209,6 @@ ALIAS: y second
|
|||
: 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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Alexander Ilin
|
|
@ -0,0 +1,10 @@
|
|||
! 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@ / * ;
|
Loading…
Reference in New Issue