-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqplot.lisp
More file actions
38 lines (32 loc) · 1.52 KB
/
qplot.lisp
File metadata and controls
38 lines (32 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
;;; -*- Mode: LISP; Syntax: Ansi-Common-Lisp; Package: QPLOT -*-
;;; Copyright (c) 2026 Symbolics Pte. Ltd. All rights reserved.
;;; Geometry helpers for common Vega-Lite plot types.
(in-package #:qplot)
(defvar *qplot-debug* nil
"When non-nil, qplot pretty-prints the merged spec before rendering.")
;; TODO:
;; 1. make calling plot optional. With the server in place, we want
;; the spec and choose where to render it, emacs, server or local
;; browser.
;; 2. Add something like (add-plot spec) to plot/vega so we don't
;; have to set vega::*all-plots* and vega::%defplot
(defun qplot (name data &rest layers)
"Quick plot for iterative REPL exploration. Merges LAYERS into a Vega-Lite spec, defines/redefines the named plot, renders it, and returns the plot object.
EXAMPLE:
(qplot 'cars vgcars
`(:title \"HP vs MPG\")
(scatter-plot :horsepower :miles-per-gallon :filled t)
(labs :x \"Horsepower\" :y \"MPG\"))
NAME is a symbol. The plot is registered in VEGA:*ALL-PLOTS* and bound as a special variable, exactly like DEFPLOT. Re-using the same NAME overwrites the previous definition.
Bind QPLOT::*QPLOT-DEBUG* to T to see the merged spec before rendering."
(let* ((spec (apply #'vega:merge-plists
`(:data (:values ,data))
layers))
(plot (vega::%defplot name spec)))
(when *qplot-debug*
(pprint spec))
(proclaim `(special ,name))
(setf (symbol-value name) plot)
(setf (gethash (string name) vega::*all-plots*) plot)
(plot:plot plot)
plot))