Skip to content

Commit

Permalink
feature: save current plot configuration (#142)
Browse files Browse the repository at this point in the history
* feature: save current plot configuration

Add a button to the simulation status page where the user can save the current plot configuration.

Closes #110

* Use "plot" not "trend", improve tooltip hover text.

* move the export plot config button from simulation status to plot menu

* Update tooltip text to avoid problem of / vs \
  • Loading branch information
flakstad authored May 8, 2020
1 parent 093fcb2 commit be85f4a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
22 changes: 22 additions & 0 deletions src/cse_client/controller.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(:require [kee-frame.core :as k]
[kee-frame.websocket :as websocket]
[cse-client.config :refer [socket-url]]
[ajax.core :as ajax]
[re-frame.loggers :as re-frame-log]
[cljs.spec.alpha :as s]
[cljs.core.async :refer [<! timeout]]
Expand Down Expand Up @@ -299,3 +300,24 @@
(k/reg-event-db ::set-plot-height
(fn [db [height]]
(assoc db :plot-height height)))

(k/reg-event-fx ::save-trends-failure
(fn [_ [error]]
{:dispatch [::feedback-message {:success false
:message error
:command "save-plot-config"}]}))

(k/reg-event-fx ::save-trends-success
(fn [_ [response]]
{:dispatch [::feedback-message {:success true
:message response
:command "save-plot-config"}]}))

(k/reg-event-fx ::save-trends-configuration
(fn [_ _]
{:http-xhrio {:method :post
:uri "http://localhost:8000/plot-config"
:format (ajax/json-request-format)
:on-failure [::save-trends-failure]
:on-success [::save-trends-success]
:response-format (ajax/json-response-format {:keywords? true})}}))
2 changes: 2 additions & 0 deletions src/cse_client/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,5 @@


(rf/reg-sub :plot-height #(:plot-height %))

(rf/reg-sub :config-dir (comp :configDir :state))
38 changes: 21 additions & 17 deletions src/cse_client/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@
(case plot-type

"trend" (semantic/ui-dropdown-item
{:key (str "trend-item-" id)
:text (trend/plot-type-from-label label)
:label "Time series"
:onClick #(rf/dispatch [::controller/add-to-trend current-module name index])})
{:key (str "trend-item-" id)
:text (trend/plot-type-from-label label)
:label "Time series"
:onClick #(rf/dispatch [::controller/add-to-trend current-module name index])})

"scatter" (when (xy-plottable? type)
(let [label-text (trend/plot-type-from-label label)
axis (if (even? count) 'X 'Y)]
(semantic/ui-dropdown-item
{:key (str "trend-item-" id)
:text label-text
:label (str "XY plot - " axis " axis")
:onClick #(rf/dispatch [::controller/add-to-trend current-module name index])})))))
{:key (str "trend-item-" id)
:text label-text
:label (str "XY plot - " axis " axis")
:onClick #(rf/dispatch [::controller/add-to-trend current-module name index])})))))

(defn action-dropdown [current-module name type trend-info]
(when (and (seq trend-info) (plottable? type))
(semantic/ui-dropdown
{:button false :text "Add to plot"}
(semantic/ui-dropdown-menu
{:direction 'left}
(map (partial trend-item current-module name type) trend-info)))))
{:button false :text "Add to plot"}
(semantic/ui-dropdown-menu
{:direction 'left}
(map (partial trend-item current-module name type) trend-info)))))

(defn pages-menu []
(let [current-page @(rf/subscribe [:current-page])
Expand Down Expand Up @@ -151,14 +151,18 @@
(simulation-status-header-text loaded?)]]
(when loaded?
[:div.item
[:div.header "Plots"]
[:div.header "Plots"
(when (not (empty? trend-info))
[:a {:style {:float 'right :cursor 'pointer :color 'gray}
:title (str "Save the current plots with variables as \"PlotConfig.json\""
"\nto " @(rf/subscribe [:config-dir]) ".\n"
"This will overwrite any existing PlotConfig.json file in this directory.")}
[:i.download.gray.icon {:on-click #(rf/dispatch [::controller/save-trends-configuration])}]])]
[:div.menu
[:a.item {:onClick #(rf/dispatch [::controller/new-trend "trend" (str "Time series #" (random-uuid))])}
"Create new time series"
[:i.chart.line.gray.icon]]
"Create new time series"]
[:a.item {:onClick #(rf/dispatch [::controller/new-trend "scatter" (str "XY plot #" (random-uuid))])}
"Create new XY plot"
[:i.chart.line.gray.icon]]
"Create new XY plot"]
(map (fn [{:keys [index label count plot-type]}]
[:div.item {:key label}
[:a.itemstyle {:class (when (and (= index (int active-trend-index)) (= route-name :trend)) "active")
Expand Down

0 comments on commit be85f4a

Please sign in to comment.