~bendersteed/wikisophy-fe

0faa9d37642eabbb09442d89976dbf52f351aaea — Dimakakos Dimos 3 years ago 33d264f
Add: some minor changes, graph creation change
2 files changed, 15 insertions(+), 67 deletions(-)

M public/css/site.css
M src/wikisophy/core.cljs
M public/css/site.css => public/css/site.css +1 -0
@@ 47,6 47,7 @@ a:hover {

#vis {
    margin-top: 2em;
    transition: ease-in 2s;
}

.loading {

M src/wikisophy/core.cljs => src/wikisophy/core.cljs +14 -67
@@ 59,70 59,11 @@
                :on-click #(do (reset! path "waiting")
                               (get-query! @query))}]])))

(defn path-tree [path]
  {:$schema "https://vega.github.io/schema/vega/v5.json"
   :width 700
   :height 600
   :padding 5
   :autosize {:type "fit-x"
              :resize true}
   :signals [{:name "labels"
              :value true}
             {:name "layout"
              :value "tidy"}
             {:name "links"
              :value "diagonal"}
             {:name "separation"
              :value false}]
   :data [{:name "path",
           :values path
           :transform
           [{:type "stratify",
             :key "id",
             :parentKey "parent"}
            {:type "tree",
             :size
             [{:signal "height"}
              {:signal "width - 100"}],
             :separation {:signal "separation"},
             :as ["x" "y" "depth" "children"]}]}
          {:name "links",
           :source "path",
           :transform
           [{:type "treelinks"}
            {:type "linkpath",
             :shape {:signal "links"}}]}]
   :marks [{:type "path",
     :from {:data "links"},
     :encode
     {:update
      {:path {:field "path"},
       :stroke {:value "#a9a9a9"}}}}
    {:type "symbol",
     :from {:data "path"},
     :encode
     {:enter
      {:size {:value 100},
       :stroke {:value "#663399"}
       :strokewidth {:value 6}},
      :update
      {:x {:field "x"}
       :y {:field "y"}}}}
    {:type "text",
     :from {:data "path"},
     :encode
     {:enter
      {:text {:field "value"},
       :fontSize {:value 16},
       :baseline {:value "middle"}},
      :update
      {:x {:field "x"},
       :y {:field "y"},
       :dx {:signal "datum.children ? -12 : 12"},
       :align
       {:signal
        "datum.children ? 'right' : 'left'"},
       :opacity {:signal "labels ? 1 : 0"}}}}]})
(defn article-listing [article]
  (let [title (get article :value)
        id (get article :id)]
    [:div {:key id}
     [:a {:href (str "https://en.wikipedia.org/wiki/" title)} title]]))

(defn graph []
  (fn []


@@ 133,8 74,12 @@
       [:p "Please wait while crawling through Wikipedia."]]
      (= @path []) [:div#vis]
      :else 
      [:div
       [oz/vega (path-tree @path)]])))
      [:div#vis
       [:p (let [last-node (get (last @path) :value)]
             (if (= last-node "Philosophy")
               "It does ✅"
               "It doesn't ❎"))]
       (map article-listing @path)])))

;; -------------------------
;; Pages


@@ 151,7 96,9 @@

(defn analytics-page []
  [:body [navbar]
   [:h1 "Analytics Page"]])
   [:h1 "Analytics Page"]
   [:p "Analytics have not been implemented yet, stay tuned to learn
   more!"]])

;; -------------------------
;; Routing