Skip to content

Commit 2c913c3

Browse files
authored
Fix 61/multi day route colors (#63)
1 parent 876896f commit 2c913c3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

notebooks/rando-planner.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ be morale-crushing."]])
282282

283283
;; - `:date`: This key denotes the date of the daily plan in the format "YYYY-MM-DD". It is used to compute the sun rise and set times.
284284
;; - `:label`: An arbitrary string, a label or description of the daily plan
285-
;; - `:average-speed' [Optional]: The value associated with this key is expected to be
285+
;; - `:color` [Optional]: Color used to draw the portion of route corresponding to the daily plan. It is used only if you provide a color for each day in the daily plan
286+
;; - `:average-speed` [Optional]: The value associated with this key is expected to be
286287
;; a numerical value denoting speed, expressed as km/h.
287288
;; - `:activities`: This key holds a vector of activities planned for the day. Each activity is represented as a map containing:
288289
;; - `:start`: This key denotes the starting time of an activity, in the format "HH:mm"

src/rando_planner/leaflet.clj

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
(assoc plan
1616
:points points
1717
:grouped-by-day (vals grouped-by-day)
18+
:point-groups-colors (remove nil? (map :color (:daily-plans plan)))
1819
:center center
1920
:bounds bounds))
2021
plan))
@@ -100,13 +101,19 @@
100101
(.setView @m (clj->js (:center value)) (:zoom value)))
101102
(.addTo tile-layer @m)
102103
(when (:points value)
103-
(let [point-groups (:grouped-by-day value)]
104-
(js/console.log (count point-groups))
104+
(let [point-groups (:grouped-by-day value)
105+
point-groups-colors (:point-groups-colors value)]
106+
(js/console.log "here!")
107+
(js/console.log point-groups-colors)
105108
(doall
106109
(for [[pp color] (map vector
107110
point-groups
108-
(take (count point-groups)
109-
(cycle '["#660e60","#893f71","#ac6f82","#cfa093","#f3d0a4"])))]
111+
(if (= (count point-groups)
112+
(count point-groups-colors))
113+
point-groups-colors
114+
;; If the user didn't provide a color for each segment
115+
(take (count point-groups)
116+
(cycle '["orange" "green" "red"]))))]
110117
(.addTo (.polyline js/L (clj->js (map (fn [{lat :lat, lon :lon} p]
111118
[lat lon])
112119
pp))

0 commit comments

Comments
 (0)