diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 89c97e54..6a87c037 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -213,7 +213,6 @@ function plotly_layout(plt::Plot) plotattributes_out = KW() w, h = plt[:size] - plotattributes_out[:width], plotattributes_out[:height] = w, h plotattributes_out[:paper_bgcolor] = rgba_string(plt[:background_color_outside]) plotattributes_out[:margin] = KW(:l=>0, :b=>20, :r=>0, :t=>20) @@ -910,28 +909,45 @@ function plotly_html_head(plt::Plot) end function plotly_html_body(plt, style = nothing) - if style === nothing - w, h = plt[:size] - style = "width:$(w)px;height:$(h)px;" + if style == nothing + style = "width:100%;height:100%;" end uuid = UUIDs.uuid4() - html = """ -
- """ - html +
+ + """ end -function js_body(plt::Plot, uuid) - js = """ - PLOT = document.getElementById('$(uuid)'); - Plotly.plot(PLOT, $(plotly_series_json(plt)), $(plotly_layout_json(plt))); +function js_body(plt::Plot, divid) + """ + gd = (function() { + var WIDTH_IN_PERCENT_OF_PARENT = 100; + var HEIGHT_IN_PERCENT_OF_PARENT = 100; + var gd = Plotly.d3.select('body') + .append('div').attr("id", "$(divid)") + .style({ + width: WIDTH_IN_PERCENT_OF_PARENT + '%', + 'margin-left': (100 - WIDTH_IN_PERCENT_OF_PARENT) / 2 + '%', + height: HEIGHT_IN_PERCENT_OF_PARENT + 'vh', + 'margin-top': (100 - HEIGHT_IN_PERCENT_OF_PARENT) / 2 + 'vh' + }) + .node(); + var data = $(plotly_series_json(plt)); + var layout = $(plotly_layout_json(plt)); + Plotly.newPlot(gd, data, layout); + window.onresize = function() { + Plotly.Plots.resize(gd); + }; + return gd; + })(); """ end +# ---------------------------------------------------------------- + function plotly_show_js(io::IO, plot::Plot) data = [] for series in plot.series_list @@ -958,3 +974,4 @@ end function _display(plt::Plot{PlotlyBackend}) standalone_html_window(plt) end +