2929; ; First: some tiny datoms to play with.
3030
3131(def penguins
32- [{:species " Adelie" :bill_length 29.1 :bill_depth 18.7 :sex " MALE" }
33- {:species " Adelie" :bill_length 33.5 :bill_depth 15.4 :sex " FEMALE" }
34- {:species " Chinstrap" :bill_length 43.5 :bill_depth 17.9 :sex " FEMALE" }
35- {:species " Gentoo" :bill_length 47.3 :bill_depth 13.8 :sex " MALE" }])
32+ [{:species " Adelie" :bill_length 22.1 :bill_depth 22.7 :sex " MALE" }
33+ {:species " Adelie" :bill_length 31.5 :bill_depth 14.4 :sex " FEMALE" }
34+ {:species " Adelie" :bill_length 35.8 :bill_depth 19.2 :sex " MALE" }
35+ {:species " Chinstrap" :bill_length 39.5 :bill_depth 27.9 :sex " FEMALE" }
36+ {:species " Chinstrap" :bill_length 46.2 :bill_depth 26.8 :sex " MALE" }
37+ {:species " Gentoo" :bill_length 49.1 :bill_depth 14.2 :sex " FEMALE" }])
3638
3739(def penguin-db
3840 (let [conn (d/create-conn )]
@@ -84,24 +86,27 @@ penguin-db
8486
8587^:kind/hiccup
8688[:svg {:width " 100%" :height " 300"
87- :viewBox " 0 0 50 50 "
89+ :viewBox " 10 10 30 30 "
8890 :xmlns " http://www.w3.org/2000/svg" }
8991 [:g {:stroke " gray" , :fill " none" }
9092 (plot-basic bill-scatter)]]
9193
9294; ; We can also query for relationships between entities.
9395; ; For example, pairs of penguins from the same species:
9496
95- (def same-species-relationships
97+ (def same-species-different-sex
9698 [:graphic {:db penguin-db
9799 :query '{:find [?x1 ?y1 ?x2 ?y2]
98100 :where [[?e1 :species ?s]
99101 [?e2 :species ?s]
102+ [(not= ?e1 ?e2)]
103+ [?e1 :sex ?sex1]
104+ [?e2 :sex ?sex2]
105+ [(not= ?sex1 ?sex2)]
100106 [?e1 :bill_length ?x1]
101107 [?e1 :bill_depth ?y1]
102108 [?e2 :bill_length ?x2]
103- [?e2 :bill_depth ?y2]
104- [(not= ?e1 ?e2)]]}
109+ [?e2 :bill_depth ?y2]]}
105110 :geometry [:line ]}])
106111
107112; ; This small example shows that the mapping lives in the query.
@@ -113,11 +118,11 @@ penguin-db
113118
114119^:kind/hiccup
115120[:svg {:width " 100%" :height " 300"
116- :viewBox " 0 0 50 50 "
121+ :viewBox " 10 10 30 30 "
117122 :xmlns " http://www.w3.org/2000/svg" }
118123 [:g {:stroke " gray" , :fill " none" }
119- (plot-basic bill-scatter )
120- (plot-basic same-species-relationships )]]
124+ (plot-basic same-species-different-sex )
125+ (plot-basic bill-scatter )]]
121126
122127; ; Plots as queries let us say more.
123128; ; Points and edges can be defined by a query.
0 commit comments