Add option to add title
This commit is contained in:
parent
6301fa651d
commit
0b1b2f84b2
4 changed files with 12 additions and 3 deletions
|
@ -7,12 +7,15 @@ Depends on [[https://github.com/dlozeve/fancy][Fancy]] for colors and display.
|
|||
#+ATTR_HTML: :width 100% :style margin-left: auto; margin-right: auto;
|
||||
[[./demo.png]]
|
||||
|
||||
Annual CO₂ emissions (t) (source: [[https://ourworldindata.org/grapher/annual-co2-emissions-per-country?tab=chart&time=1850..latest&country=CHN~USA~Europe][Our World in Data]])
|
||||
(source: [[https://ourworldindata.org/grapher/annual-co2-emissions-per-country?tab=chart&time=1850..latest&country=CHN~USA~Europe][Our World in Data]])
|
||||
|
||||
** Features
|
||||
|
||||
- Braille canvas for plotting
|
||||
- Line plots
|
||||
- Axes and tick labels showing ranges
|
||||
- Optional title, x-axis label, and legend
|
||||
- Input data loading from a CSV file
|
||||
|
||||
** References
|
||||
|
||||
|
|
BIN
demo.png
BIN
demo.png
Binary file not shown.
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 26 KiB |
2
demo.ss
2
demo.ss
|
@ -14,5 +14,5 @@
|
|||
(for/collect ((row csv))
|
||||
(for/collect ((x row))
|
||||
(or (string->number x) +nan.0)))))
|
||||
(displayln (line-plot lsts
|
||||
(displayln (line-plot lsts title: (if (null? args) "" (car args))
|
||||
xlabel: (car names) names: (cdr names))))
|
||||
|
|
|
@ -64,9 +64,14 @@
|
|||
(set! (plot-str plot)
|
||||
(str (plot-str plot) (make-string (quotient (plot-hsize plot) 2) #\ ) xlabel "\n")))
|
||||
|
||||
(def (add-title! plot title)
|
||||
(set! (plot-str plot)
|
||||
(str "\n" (make-string (quotient (- (plot-hsize plot) 10) 2) #\ ) title "\n\n"
|
||||
(plot-str plot))))
|
||||
|
||||
(def (line-plot lsts (colors +default-colors+)
|
||||
width: (width 160) height: (height 100)
|
||||
xlabel: (xlabel "") names: (names []))
|
||||
title: (title "") xlabel: (xlabel "") names: (names []))
|
||||
(define-values (xmin xmax ymin ymax canvases)
|
||||
(match lsts
|
||||
([ys] (let ((xmin 0)
|
||||
|
@ -104,4 +109,5 @@
|
|||
(add-border! plot xmin xmax ymin ymax)
|
||||
(unless (null? names) (add-legend! plot names colors))
|
||||
(unless (string-empty? xlabel) (add-xlabel! plot xlabel))
|
||||
(unless (string-empty? title) (add-title! plot title))
|
||||
(plot-str plot))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue