-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.clj
146 lines (113 loc) · 3.17 KB
/
index.clj
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
;; # Kind-Clerk demo
(ns index
(:require [scicloj.kindly.v4.kind :as kind]
[scicloj.kind-clerk.api :as kind-clerk]))
(kind-clerk/setup!)
;; ## Plain data
[1 1 3]
{:x "A"
:y "B"}
;; ## Images
(import
java.net.URL)
(def clj-img
(-> "https://clojure.org/images/clojure-logo-120b.png"
(java.net.URL.)
(javax.imageio.ImageIO/read)))
clj-img
;; ## Hiccup
(kind/hiccup
[:big 1234])
^:kind/hiccup
[:big 1234]
;; ## Markdown
(kind/md
"
* a
* b
* c
* d")
;; ## Vega-Lite
(kind/vega-lite
{:data {:values [{:x 1 :y 2}
{:x 2 :y 4}
{:x 3 :y 9}
{:x 4 :y 16}]}
:mark :point
:encoding {:x {:field :x :type :quantitative}
:y {:field :y :type :quantitative}}})
;; ## Cytoscape
(kind/cytoscape
{:elements {:nodes [{:data {:id "a" :parent "b"} :position {:x 215 :y 85}}
{:data {:id "b"}}
{:data {:id "c" :parent "b"} :position {:x 300 :y 85}}
{:data {:id "d"} :position {:x 215 :y 175}}
{:data {:id "e"}}
{:data {:id "f" :parent "e"} :position {:x 300 :y 175}}]
:edges [{:data {:id "ad" :source "a" :target "d"}}
{:data {:id "eb" :source "e" :target "b"}}]}
:style [{:selector "node"
:css {:content "data(id)"
:text-valign "center"
:text-halign "center"}}
{:selector "parent"
:css {:text-valign "top"
:text-halign "center"}}
{:selector "edge"
:css {:curve-style "bezier"
:target-arrow-shape "triangle"}}]
:layout {:name "preset"
:padding 5}})
;; ## Echarts
(kind/echarts
{:xAxis {:data ["Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"]}
:yAxis {}
:series [{:type "bar"
:data [23 24 18 25 27 28 25]}]})
;; ## Plotly
(kind/plotly
(let [n 20
walk (fn [bias]
(->> (repeatedly n #(-> (rand)
(- 0.5)
(+ bias)))
(reductions +)))]
{:data [{:x (walk 1)
:y (walk -1)
:z (map #(* % %)
(walk 2))
:type :scatter3d
:mode :lines+markers
:opacity 0.2
:line {:width 10}
:marker {:size 20
:colorscale :Viridis}}]}))
;; ## Datasets
;; Currently, datasets are printed and rendered as Markdown.
(require '[tablecloth.api :as tc])
(-> {:x [1 3 5]
:y (repeatedly 3 rand)}
tc/dataset
(tc/set-dataset-name "my data"))
;; ## Tables
;; We can also use Clerk's table view:
(-> {:x (range 100)
:y (repeatedly 100 rand)}
tc/dataset
kind/table)
(-> {:column-names [:x :y]
:row-vectors (for [i (range 5)]
[i (rand)])}
kind/table)
(-> {:column-names [:x :y]
:row-maps (for [i (range 5)]
{:x i :y (rand)})}
kind/table)
;; ### Nesting kinds in tables (WIP)
(-> {:column-names [:x :y]
:row-vectors [[1 (rand)]
[2 [3 4]]
[3 {:x 5
:y 6}]
[4 clj-img]]}
kind/table)