|
10 | 10 | :keywords [:datavis] |
11 | 11 | :toc true |
12 | 12 | :toc-depth 4 |
13 | | - :toc-expand 4}}} |
| 13 | + :toc-expand 4 |
| 14 | + :image "aog_iris.png"}}} |
14 | 15 | (ns data-visualization.aog-in-clojure-part1 |
15 | 16 | (:require [tablecloth.api :as tc] |
16 | 17 | [scicloj.kindly.v4.kind :as kind])) |
|
1239 | 1240 |
|
1240 | 1241 | Args: |
1241 | 1242 | - spec: Plot spec map with :=layers |
1242 | | - - opts: Optional map with: |
1243 | | - - :width - Width in pixels (default 600) |
1244 | | - - :height - Height in pixels (default 400) |
1245 | | - - :target - Rendering target (:geomviz, :vl, :plotly) |
| 1243 | + - target-or-opts: Either: |
| 1244 | + - Keyword - rendering target (:geom, :vl, :plotly) |
| 1245 | + - Map with options: |
| 1246 | + - :width - Width in pixels (default 600) |
| 1247 | + - :height - Height in pixels (default 400) |
| 1248 | + - :target - Rendering target (:geom, :vl, :plotly) |
1246 | 1249 |
|
1247 | 1250 | The rendering target is determined by: |
1248 | | - 1. :target in opts (highest priority) |
1249 | | - 2. `:=target` key in spec (set via `target` function) |
1250 | | - 3. :geomviz (static SVG) as default |
| 1251 | + 1. target-or-opts if it's a keyword (highest priority) |
| 1252 | + 2. :target in opts map (if target-or-opts is a map) |
| 1253 | + 3. `:=target` key in spec (set via `target` function) |
| 1254 | + 4. :geom (static SVG) as default |
1251 | 1255 |
|
1252 | 1256 | Returns: |
1253 | 1257 | - Kindly-wrapped visualization specification |
|
1264 | 1268 | (mapping :x :y) |
1265 | 1269 | (scatter))) |
1266 | 1270 | |
1267 | | - ;; With options: |
| 1271 | + ;; With target shorthand: |
1268 | 1272 | (-> penguins |
1269 | 1273 | (mapping :x :y) |
1270 | 1274 | (scatter) |
1271 | | - (plot {:width 800 :height 600}))" |
| 1275 | + (plot :plotly)) |
| 1276 | + |
| 1277 | + ;; With full options: |
| 1278 | + (-> penguins |
| 1279 | + (mapping :x :y) |
| 1280 | + (scatter) |
| 1281 | + (plot {:target :vl :width 800 :height 600}))" |
1272 | 1282 | ([spec] |
1273 | 1283 | (plot-impl spec {})) |
1274 | | - ([spec opts] |
1275 | | - (plot-impl spec opts))) |
| 1284 | + ([spec target-or-opts] |
| 1285 | + (if (keyword? target-or-opts) |
| 1286 | + ;; Shorthand: (plot spec :plotly) |
| 1287 | + (plot-impl spec {:target target-or-opts}) |
| 1288 | + ;; Full options: (plot spec {:target :plotly :width 800}) |
| 1289 | + (plot-impl spec target-or-opts)))) |
1276 | 1290 |
|
1277 | 1291 | (defn- ensure-vec |
1278 | 1292 | "Wrap single items in a vector if not already sequential. |
@@ -5595,3 +5609,12 @@ iris |
5595 | 5609 | ;; for the space to try new ideas. |
5596 | 5610 |
|
5597 | 5611 | ;; --- |
| 5612 | + |
| 5613 | +(-> iris |
| 5614 | + (mapping :sepal-length |
| 5615 | + :petal-length |
| 5616 | + {:color :species}) |
| 5617 | + (=+ (scatter) |
| 5618 | + (linear)) |
| 5619 | + (plot :plotly)) |
| 5620 | + |
0 commit comments