charts.lines: add scale

char-rename
Alexander Iljin 2017-01-20 03:44:02 +03:00 committed by John Benediktsson
parent 467bc37137
commit 664922ca21
2 changed files with 10 additions and 1 deletions

View File

@ -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

View File

@ -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 -- )