Skip to content

Commit 3e52d0e

Browse files
committed
aog wip
1 parent 14bc48e commit 3e52d0e

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/data_visualization/aog_in_clojure_part1.clj

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
:keywords [:datavis]
1111
:toc true
1212
:toc-depth 4
13-
:toc-expand 4}}}
13+
:toc-expand 4
14+
:image "aog_iris.png"}}}
1415
(ns data-visualization.aog-in-clojure-part1
1516
(:require [tablecloth.api :as tc]
1617
[scicloj.kindly.v4.kind :as kind]))
@@ -1239,15 +1240,18 @@
12391240
12401241
Args:
12411242
- 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)
12461249
12471250
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
12511255
12521256
Returns:
12531257
- Kindly-wrapped visualization specification
@@ -1264,15 +1268,25 @@
12641268
(mapping :x :y)
12651269
(scatter)))
12661270
1267-
;; With options:
1271+
;; With target shorthand:
12681272
(-> penguins
12691273
(mapping :x :y)
12701274
(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}))"
12721282
([spec]
12731283
(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))))
12761290

12771291
(defn- ensure-vec
12781292
"Wrap single items in a vector if not already sequential.
@@ -5595,3 +5609,12 @@ iris
55955609
;; for the space to try new ideas.
55965610

55975611
;; ---
5612+
5613+
(-> iris
5614+
(mapping :sepal-length
5615+
:petal-length
5616+
{:color :species})
5617+
(=+ (scatter)
5618+
(linear))
5619+
(plot :plotly))
5620+
67.3 KB
Loading

0 commit comments

Comments
 (0)