diff --git a/README.org b/README.org index 98361b8..4a82dad 100644 --- a/README.org +++ b/README.org @@ -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 diff --git a/demo.png b/demo.png index d0d6330..500c82f 100644 Binary files a/demo.png and b/demo.png differ diff --git a/demo.ss b/demo.ss index 60bb196..b253aa7 100755 --- a/demo.ss +++ b/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)))) diff --git a/uniplot/lineplot.ss b/uniplot/lineplot.ss index 794af01..a8f245c 100644 --- a/uniplot/lineplot.ss +++ b/uniplot/lineplot.ss @@ -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))