diff --git a/guile/mu/plot.scm b/guile/mu/plot.scm index af9329f0..1c55fc38 100644 --- a/guile/mu/plot.scm +++ b/guile/mu/plot.scm @@ -19,7 +19,9 @@ (define-module (mu plot) :use-module (mu) :use-module (ice-9 popen) - :export (mu:plot)) + :export ( mu:plot ;; alias for mu:plot-histogram + mu:plot-histogram + )) (define (export-pairs pairs) "Write a temporary file with the list of PAIRS in table format, and @@ -33,9 +35,26 @@ return the file name." (close output) datafile)) -(define* (mu:plot data title x-label y-label #:optional (text-only #f)) +(define (find-program-in-path prog) + "Find exutable program PROG in PATH; return the full path, or #f if +not found." + (let* ((path (getenv "PATH")) + (progdir (search-path path prog))) + (if (not prog) + #f + (let ((fullpath (string-append progdir "/" prog))) + (if (access? fullpath X_OK) ;; is + fullpath + #f))))) + + +(define* (mu:plot-histogram data title x-label y-label #:optional (text-only #f)) "Plot DATA with TITLE, X-LABEL and X-LABEL. If TEXT-ONLY is true, -display using raw text, otherwise, use a graphical window." +display using raw text, otherwise, use a graphical window. DATA is a +list of cons-pairs (X . Y)." + (if (not (find-program-in-path "gnuplot")) + (error "cannot find 'gnuplot' in path")) + (let ((datafile (export-pairs data)) (gnuplot (open-pipe "gnuplot -p" OPEN_WRITE))) (display (string-append @@ -48,3 +67,6 @@ display using raw text, otherwise, use a graphical window." "plot \"" datafile "\" using 2:xticlabels(1) with boxes fs solid\n") gnuplot) (close-pipe gnuplot))) + +;; backward compatibility +(define mu-plot mu:plot-histogram) diff --git a/guile/scripts/msgs-per-day.scm b/guile/scripts/msgs-per-day.scm index e268d05c..3827bc1d 100755 --- a/guile/scripts/msgs-per-day.scm +++ b/guile/scripts/msgs-per-day.scm @@ -31,7 +31,7 @@ exec guile -e main -s $0 $@ "Count the total number of messages for each weekday (0-6 for Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text display, otherwise, use a graphical window." - (mu:plot + (mu:plot-histogram (mu:weekday-numbers->names (sort (mu:tabulate (lambda (msg) diff --git a/guile/scripts/msgs-per-hour.scm b/guile/scripts/msgs-per-hour.scm index 01d33c28..a681a0a7 100755 --- a/guile/scripts/msgs-per-hour.scm +++ b/guile/scripts/msgs-per-hour.scm @@ -31,7 +31,7 @@ exec guile -e main -s $0 $@ "Count the total number of messages for each weekday (0-6 for Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text display, otherwise, use a graphical window." - (mu:plot + (mu:plot-histogram (sort (mu:tabulate (lambda (msg) diff --git a/guile/scripts/msgs-per-month.scm b/guile/scripts/msgs-per-month.scm index 69912199..d44b9f2c 100755 --- a/guile/scripts/msgs-per-month.scm +++ b/guile/scripts/msgs-per-month.scm @@ -31,7 +31,7 @@ exec guile -e main -s $0 $@ "Count the total number of messages for each weekday (0-6 for Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text display, otherwise, use a graphical window." - (mu:plot + (mu:plot-histogram (mu:month-numbers->names (sort (mu:tabulate diff --git a/guile/scripts/msgs-per-year-month.scm b/guile/scripts/msgs-per-year-month.scm index 546cf590..c5195718 100755 --- a/guile/scripts/msgs-per-year-month.scm +++ b/guile/scripts/msgs-per-year-month.scm @@ -31,7 +31,7 @@ exec guile -e main -s $0 $@ "Count the total number of messages for each weekday (0-6 for Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text display, otherwise, use a graphical window." - (mu:plot + (mu:plot-histogram (sort (mu:tabulate (lambda (msg) (string->number diff --git a/guile/scripts/msgs-per-year.scm b/guile/scripts/msgs-per-year.scm index db70224d..01c688d7 100755 --- a/guile/scripts/msgs-per-year.scm +++ b/guile/scripts/msgs-per-year.scm @@ -31,7 +31,7 @@ exec guile -e main -s $0 $@ "Count the total number of messages for each weekday (0-6 for Sun..Sat) that match EXPR. If TEXT-ONLY is true, use a plain-text display, otherwise, use a graphical window." - (mu:plot + (mu:plot-histogram (sort (mu:tabulate (lambda (msg) (+ 1900 (tm:year (localtime (mu:date msg))))) expr)