Improve color handling
This commit is contained in:
parent
516237d2bc
commit
46d5d0a90d
5 changed files with 23 additions and 18 deletions
|
@ -44,7 +44,7 @@
|
|||
(def (indexf pred . lsts)
|
||||
(find pred (apply map list lsts)))
|
||||
|
||||
(def (canvases->string canvases (colors '(red green cyan yellow magenta white)))
|
||||
(def (canvases->string canvases colors)
|
||||
(def canvases-str (map canvas->string canvases))
|
||||
(def size (string-length (car canvases-str)))
|
||||
(apply str
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
:dlozeve/uniplot/braille
|
||||
:dlozeve/fancy/format)
|
||||
|
||||
(def +default-colors+ '(green blue red yellow cyan magenta white))
|
||||
|
||||
(def (scale-fn lo hi)
|
||||
(lambda (x) (/ (- x lo) (- hi lo))))
|
||||
|
||||
|
@ -18,20 +20,18 @@
|
|||
#t))
|
||||
canvas)
|
||||
|
||||
(def (line-plot lsts width: (width 160) height: (height 80))
|
||||
(match lsts
|
||||
([ys] (canvas->string
|
||||
(draw-canvas (iota (length ys)) ys
|
||||
(scale-fn 0 (length ys))
|
||||
(scale-fn (apply min ys) (apply max ys))
|
||||
width: width height: height)))
|
||||
([xs ys] (canvas->string
|
||||
(draw-canvas xs ys
|
||||
(scale-fn (apply min xs) (apply max xs))
|
||||
(scale-fn (apply min ys) (apply max ys))
|
||||
width: width height: height)))
|
||||
([xs . yss]
|
||||
(canvases->string
|
||||
(def (line-plot lsts (colors +default-colors+) width: (width 160) height: (height 80))
|
||||
(canvases->string
|
||||
(match lsts
|
||||
([ys] [(draw-canvas (iota (length ys)) ys
|
||||
(scale-fn 0 (length ys))
|
||||
(scale-fn (apply min ys) (apply max ys))
|
||||
width: width height: height)])
|
||||
([xs ys] [(draw-canvas xs ys
|
||||
(scale-fn (apply min xs) (apply max xs))
|
||||
(scale-fn (apply min ys) (apply max ys))
|
||||
width: width height: height)])
|
||||
([xs . yss]
|
||||
(let* ((x-scale-fn (scale-fn (apply min xs) (apply max xs)))
|
||||
(all-ys (flatten yss))
|
||||
(min-ys (apply min all-ys))
|
||||
|
@ -39,4 +39,5 @@
|
|||
(y-scale-fn (scale-fn min-ys max-ys)))
|
||||
(for/collect ((ys yss))
|
||||
(draw-canvas xs ys x-scale-fn y-scale-fn
|
||||
width: width height: height)))))))
|
||||
width: width height: height)))))
|
||||
colors))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue