]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.gadgets.charts.utils: move some common code to the new vocab
authorAlexander Iljin <ajsoft@yandex.ru>
Sat, 4 Feb 2017 01:25:29 +0000 (04:25 +0300)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 17 Apr 2017 20:54:51 +0000 (13:54 -0700)
extra/ui/gadgets/charts/axes/axes.factor
extra/ui/gadgets/charts/lines/lines-tests.factor
extra/ui/gadgets/charts/lines/lines.factor
extra/ui/gadgets/charts/utils/authors.txt [new file with mode: 0644]
extra/ui/gadgets/charts/utils/utils.factor [new file with mode: 0644]

index 24c9d5f24d47c605db414609a5bb9aa599c5ee6a..b88333f02a61916622448774397ebbd2c2bfb5d3 100644 (file)
@@ -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 - ;
index 95c89abb83273da96bda6d42a045afcd8ad034e1..9b50cb79526279ff751d31602762312da1767427 100644 (file)
@@ -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
index 756ba8f438c0739eb12aa0d92d22e7de88edd798..21420fda768c6634ffbb5616e16895a18f2ced36 100644 (file)
@@ -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
diff --git a/extra/ui/gadgets/charts/utils/authors.txt b/extra/ui/gadgets/charts/utils/authors.txt
new file mode 100644 (file)
index 0000000..8e1955f
--- /dev/null
@@ -0,0 +1 @@
+Alexander Ilin
diff --git a/extra/ui/gadgets/charts/utils/utils.factor b/extra/ui/gadgets/charts/utils/utils.factor
new file mode 100644 (file)
index 0000000..9971a82
--- /dev/null
@@ -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@ / * ;