168
168
; ; You can style elements, using [Tailwind CSS](https://tailwindcss.com/docs/utility-first).
169
169
(clerk/html [:button.bg-sky-500.hover:bg-sky-700.text-white.rounded-xl.px-2.py-1 " ✨ Tailwind CSS" ])
170
170
171
- ; ; The `html` viewer is also able to display SVG, taking either a hiccup vector or a SVG string.
171
+ ; ; The `html` viewer is able to display SVG, taking either a hiccup vector or a SVG string.
172
172
(clerk/html [:svg {:width 500 :height 100 }
173
173
[:circle {:cx 25 :cy 50 :r 25 :fill " blue" }]
174
174
[:circle {:cx 100 :cy 75 :r 25 :fill " red" }]])
175
175
176
+ ; ; You can also embed other viewers inside of hiccup.
177
+
178
+ (clerk/html [:div.flex.justify-center.space-x-6
179
+ [:p " a table is next to me" ]
180
+ (clerk/table [[1 2 ] [3 4 ]])])
181
+
176
182
; ; ### 🔢 Tables
177
183
178
184
; ; Clerk provides a built-in data table viewer that supports the three
339
345
340
346
; ; ### 🍱 Composing Viewers
341
347
342
- ; ; Viewers compose, so you can for example use the plotly viewer inside the grid viewers.
348
+ ; ; Viewers compose, so, for example, you can lay out multiple independent Vega charts using Clerk’s grid viewers:
343
349
344
350
^{::clerk/visibility {:code :fold }}
345
351
(do
346
- (def donut-chart
347
- (clerk/plotly {:data [{:values [27 11 25 8 1 3 25 ]
348
- :labels [" US" " China" " European Union" " Russian Federation" " Brazil" " India" " Rest of World" ]
349
- :text " CO2"
350
- :textposition " inside"
351
- :domain {:column 1 }
352
- :hoverinfo " label+percent+name"
353
- :hole 0.4
354
- :type " pie" }]
355
- :layout {:showlegend false
356
- :width 200
357
- :height 200
358
- :margin {:t 0 :b 0 :r 0 :l 0 }
359
- :annotations [{:font {:size 20 } :showarrow false :x 0.5 :y 0.5 :text " CO2" }]}
360
- :config {:responsive true }}))
361
-
362
- (def contour-plot
363
- (clerk/plotly {:data [{:z [[10 10.625 12.5 15.625 20 ]
364
- [5.625 6.25 8.125 11.25 15.625 ]
365
- [2.5 3.125 5.0 8.125 12.5 ]
366
- [0.625 1.25 3.125 6.25 10.625 ]
367
- [0 0.625 2.5 5.625 10 ]]
368
- :type " contour" }]
369
- :layout {:margin {:t 0 :b 0 :r 0 :l 0 }}})))
370
-
371
- (clerk/col (clerk/row donut-chart donut-chart donut-chart)
372
- contour-plot)
352
+ (def stock-colors
353
+ {" AAPL" " #4c78a8" " AMZN" " #f58518" " GOOG" " #e45756" " IBM" " #72b7b2" " MSFT" " #54a24b" })
354
+ (def combined-stocks-chart
355
+ (clerk/vl {:width 600
356
+ :height 200
357
+ :data {:url " https://vega.github.io/vega-lite/examples/data/stocks.csv" }
358
+ :mark " area"
359
+ :encoding {:x {:timeUnit " yearmonth" :field " date" :axis {:format " %Y" }}
360
+ :y {:aggregate " sum" :field " price" }
361
+ :color {:field " symbol"
362
+ :scale {:domain (keys stock-colors) :range (vals stock-colors)}}}
363
+ :embed/opts {:actions false }}))
364
+ (defn stock-chart [symbol]
365
+ (clerk/vl {:title symbol
366
+ :width 100
367
+ :height 40
368
+ :mark " area"
369
+ :data {:url " https://vega.github.io/vega-lite/examples/data/stocks.csv" }
370
+ :transform [{:filter (str " datum.symbol == '" symbol " '" )}]
371
+ :encoding {:x {:field " date" :type " temporal" :title nil :axis {:grid false }}
372
+ :y {:field " price" :type " quantitative" :title nil :axis {:grid false } :scale {:domain [0 700 ]}}
373
+ :color {:field " symbol" :type " nominal" :legend nil :scale {:domain [symbol]
374
+ :range [(get stock-colors symbol)]}}}
375
+ :embed/opts {:actions false }})))
376
+
377
+ (clerk/col
378
+ (clerk/row (stock-chart " AAPL" )
379
+ (stock-chart " AMZN" )
380
+ (stock-chart " GOOG" )
381
+ (stock-chart " IBM" )
382
+ (stock-chart " MSFT" ))
383
+ combined-stocks-chart)
384
+
385
+ ; ; Viewers can also be embedded in Hiccup. The following example shows
386
+ ; ; how this is used to provide a custom callout for a `clerk/image`.
387
+
388
+ (clerk/html
389
+ [:div.relative
390
+ (clerk/image " https://images.unsplash.com/photo-1608993659399-6508f918dfde?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2070&q=80" )
391
+ [:div.absolute
392
+ {:class " left-[25%] top-[21%]" }
393
+ [:div.border-4.border-emerald-400.rounded-full.shadow
394
+ {:class " w-8 h-8" }]
395
+ [:div.border-t-4.border-emerald-400.absolute
396
+ {:class " w-[80px] rotate-[30deg] left-4 translate-x-[10px] translate-y-[10px]" }]
397
+ [:div.border-4.border-emerald-400.absolute.text-white.font-sans.p-3.rounded-md
398
+ {:class " bg-black bg-opacity-60 text-[13px] w-[280px] top-[66px]" }
399
+ " Cat's paws are adapted to climbing and jumping, walking and running, and have protractible claws for self-defense and hunting." ]]])
400
+
401
+ #_(clerk/html [:div.flex.justify-around donut-chart donut-chart donut-chart])
373
402
374
403
; ; ### 🤹🏻 Applying Viewers
375
404
@@ -475,7 +504,7 @@ v/default-viewers
475
504
476
505
; ; #### ⚙️ Transform
477
506
478
- ; ; When writing your own viewer, the first extention point you should reach for is `:tranform-fn`.
507
+ ; ; When writing your own viewer, the first extention point you should reach for is `:tranform-fn`.
479
508
480
509
#_ " exercise: wrap this in `v/present` and call it at the REPL"
481
510
(v/with-viewer {:transform-fn #(clerk/html [:pre (pr-str %)])}
@@ -502,7 +531,7 @@ v/default-viewers
502
531
" James Clerk Maxwell" ))
503
532
504
533
505
- ; ; **Passing modified viewers down the tree**
534
+ ; ; **Passing modified viewers down the tree**
506
535
507
536
#_ " TODO: move this into clerk?"
508
537
(defn add-child-viewers [viewer viewers]
@@ -705,7 +734,7 @@ v/table-viewer
705
734
; ; ## 🙈 Controlling Visibility
706
735
707
736
; ; Visibility for code and results can be controlled document-wide and
708
- ; ; per top-level form. By default, Clerk will always show code and
737
+ ; ; per top-level form. By default, Clerk will always show code and
709
738
; ; results for a notebook.
710
739
711
740
; ; You can use a map of the following shape to set the visibility of
@@ -736,7 +765,7 @@ v/table-viewer
736
765
; ;
737
766
; ; ^{::clerk/visibility {:code :hide}} (shuffle (range 25))
738
767
; ;
739
- ; ; This will hide the code but only show the result:
768
+ ; ; This will hide the code but only show the result:
740
769
741
770
^{::clerk/visibility {:code :hide }} (shuffle (range 25 ))
742
771
0 commit comments