From 664922ca216f43c0aedfe5f905d338cd510b6df6 Mon Sep 17 00:00:00 2001 From: Alexander Iljin <ajsoft@yandex.ru> Date: Fri, 20 Jan 2017 03:44:02 +0300 Subject: [PATCH] charts.lines: add scale --- lines/lines-tests.factor | 8 +++++++- lines/lines.factor | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lines/lines-tests.factor b/lines/lines-tests.factor index d548eab506..24301d3187 100644 --- a/lines/lines-tests.factor +++ b/lines/lines-tests.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2017 Alexander Ilin. -USING: kernel sequences tools.test charts.lines +USING: kernel math sequences tools.test charts.lines charts.lines.private ; IN: charts.lines.tests @@ -231,6 +231,12 @@ IN: charts.lines.tests { 0 300 } flip-y-axis ] unit-test +{ + { 0 30 60 90 120 150 180 210 240 270 300 } +} [ + 11 iota [ 10 + ] map [ 300 swap 20 10 scale ] map +] unit-test + { { } } [ { } { } clip-data ] unit-test diff --git a/lines/lines.factor b/lines/lines.factor index 4b885c142c..79d9e8bfba 100644 --- a/lines/lines.factor +++ b/lines/lines.factor @@ -211,6 +211,9 @@ SYMBOL: elt : flip-y-axis ( chunks ymin,ymax -- chunks ) first2 middle 2 * '[ [ first2 _ swap - 2array ] map ] map ; +! value' = (value - min) / (max - min) * width +: scale ( width value max min -- value' ) neg [ + ] curry bi@ / * ; + PRIVATE> : draw-line ( seq -- )