Skip to content

Commit

Permalink
fix(trend): legend displayed below x-axis label (#135)
Browse files Browse the repository at this point in the history
* fix(trend): legend displayed below x-axis label

Adjust plotly layout object to show the legend of plotted variables below the x-axis label for time series plots.

Fixes #129

* Set the image download options to use the width and height of the displayed dom element, solving legend and variable
labels overlapping
  • Loading branch information
flakstad authored May 8, 2020
1 parent 01bc3b6 commit 093fcb2
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/cse_client/trend.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,27 @@
:showlegend true
:uirevision true
:margin {:l 0 :r 0 :t 25 :pad 5}
:xaxis {:automargin true}
:yaxis {:automargin true}
:legend {:orientation "h"}})
:legend {:orientation "h"
:uirevision true}})

(def trend-layout
(merge common-layout
{:xaxis {:title "Time [s]"}}))
{:xaxis {:automargin true
:title {:text "Time [s]"
:font {:size 14}}}}))

(def scatter-layout
(merge common-layout
{:xaxis {:autorange true
:autotick true
:ticks ""}}))
:ticks ""
:automargin true}}))

(def options
{:responsive true
:toImageButtonOptions {:width 1280 :height 768}})

(defn- plotly-expand-button [plot-height plot-expanded?]
(if @plot-expanded?
Expand Down Expand Up @@ -146,7 +155,7 @@
(update :y conj yvals)))
init-data trend-values)]
(update-traces dom-node trend-values)
(js/Plotly.update dom-node (clj->js data) (clj->js layout))))
(js/Plotly.update dom-node (clj->js data) (clj->js layout) (clj->js options))))

(defn- relayout-callback [js-event]
(let [event (js->clj js-event)
Expand Down Expand Up @@ -182,7 +191,7 @@
:mode "lines"
:type "scatter"}])
(clj->js layout)
(clj->js {:responsive true}))))]
(clj->js options))))]
(r/create-class
{:component-did-mount (fn [comp]
(render-plot comp)
Expand Down Expand Up @@ -255,6 +264,7 @@
:trend-id id}]]

(when (not @plot-expanded?)

[variables-table active-trend-index trend-values])]))))

(rf/reg-sub ::active-trend #(get-in % [:state :trends (-> % :active-trend-index int)]))
Expand Down

0 comments on commit 093fcb2

Please sign in to comment.