Skip to content

Commit

Permalink
Merge pull request #66 from open-simulation-platform/feature/rename-t…
Browse files Browse the repository at this point in the history
…rend-labels

feature(trend): rename labels
  • Loading branch information
flakstad authored Mar 18, 2019
2 parents a2aa494 + d19e449 commit 9e3abfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
9 changes: 7 additions & 2 deletions src/cse_client/trend.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
(defn trend-title [{:keys [module signal causality type]}]
(str/join " - " [module signal causality type]))

(defn plot-type-from-label [label]
"Expects label to be a string on format 'Time series #a9123ddc-..'"
(str/trim (first (str/split label "#"))))

(defn new-series [trend-variable]
{:name (trend-title trend-variable)
:x []
Expand Down Expand Up @@ -130,9 +134,10 @@
active-trend-index (rf/subscribe [:active-trend-index])]
(fn []
(let [{:keys [id plot-type label trend-values]} @active-trend
active-trend-index (int @active-trend-index)]
active-trend-index (int @active-trend-index)
name (plot-type-from-label label)]
[:div.ui.one.column.grid
[c/variable-override-editor nil nil label [::controller/set-label]]
[c/variable-override-editor nil nil name [::controller/set-label]]
[:div.two.column.row
[:div.column
(doall (map (partial range-selector @trend-range) range-configs))]
Expand Down
28 changes: 12 additions & 16 deletions src/cse_client/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(case plot-type
"trend" (semantic/ui-dropdown-item
{:key (str "trend-item-" id)
:text label
:text (trend/plot-type-from-label label)
:label "Time series"
:onClick #(rf/dispatch [::controller/add-to-trend current-module name causality type value-reference index])})
"scatter"
Expand All @@ -41,18 +41,15 @@
(semantic/ui-dropdown-item {:text "Add to y"}))))
(semantic/ui-dropdown-item
{:key (str "trend-item-" id)
:text label
:label "Scatter"
:text (trend/plot-type-from-label label)
:label "XY plot"
:onClick #(rf/dispatch [::controller/add-to-trend current-module name causality type value-reference index])})))

(defn action-dropdown [current-module name causality type value-reference trend-info]
(let [default-label (str "Trend #" (-> trend-info count inc))]
(when-not (empty? trend-info)
(semantic/ui-dropdown
{:button true
:text "Add to trend"}
(semantic/ui-dropdown-menu nil
(map (partial trend-item current-module name causality type value-reference) trend-info))))))
(when-not (empty? trend-info)
(semantic/ui-dropdown {:button true :text "Add to trend"}
(semantic/ui-dropdown-menu nil
(map (partial trend-item current-module name causality type value-reference) trend-info)))))

(defn pages-menu []
(let [current-page @(rf/subscribe [:current-page])
Expand Down Expand Up @@ -142,7 +139,6 @@
route-module (-> route :path-params :module)
loaded? @(rf/subscribe [:loaded?])
trend-info @(rf/subscribe [:trend-info])
default-label (str "Trend #" (-> trend-info count inc))
active-trend-index @(rf/subscribe [:active-trend-index])
scenarios @(rf/subscribe [:scenarios])]
[:div.ui.secondary.vertical.fluid.menu
Expand All @@ -158,7 +154,7 @@
[:div.item {:key label}
[:a.itemstyle {:class (when (and (= index (int active-trend-index)) (= route-name :trend)) "active")
:href (k/path-for [:trend {:index index}])}
label]
(trend/plot-type-from-label label)]
[:div.ui.teal.left.pointing.label count]
[:span {:style {:float 'right :cursor 'pointer :z-index 1000}
:data-tooltip "Remove trend"
Expand All @@ -170,11 +166,11 @@
:data-position "top center"}
[:i.eye.slash.gray.icon {:on-click #(rf/dispatch [::controller/untrend index])}]])])
trend-info)
[:a.item {:onClick #(rf/dispatch [::controller/new-trend "trend" default-label])}
[:a.item {:onClick #(rf/dispatch [::controller/new-trend "trend" (str "Time series #" (random-uuid))])}
"Create new time series"
[:i.chart.line.gray.icon]]
[:a.item {:onClick #(rf/dispatch [::controller/new-trend "scatter" default-label])}
"Create new scatter plot"
[:a.item {:onClick #(rf/dispatch [::controller/new-trend "scatter" (str "XY plot #" (random-uuid))])}
"Create new XY plot"
[:i.chart.line.gray.icon]]]])
(when loaded?
[:div.item
Expand Down Expand Up @@ -341,7 +337,7 @@
[:h1.ui.huge.header [k/switch-route (comp :name :data)
:module (or @module "")
:trend (if (and (number? (int active-trend-index)) (not-empty trends))
(:label (nth trends (int active-trend-index)))
(trend/plot-type-from-label (:label (nth trends (int active-trend-index))))
"")
:guide "User guide"
:index (simulation-status-header-text @loaded?)
Expand Down

0 comments on commit 9e3abfc

Please sign in to comment.