Merge 4a3160da29bda4ffb62dcd54aabbc5ab38420a19 into 49eba0bf2f0684e8ff02965707a7a7375b1fe51c

This commit is contained in:
Nathan Daly 2021-01-23 17:54:37 +01:00 committed by GitHub
commit 980e1a3d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -213,7 +213,6 @@ function plotly_layout(plt::Plot)
plotattributes_out = KW() plotattributes_out = KW()
w, h = plt[:size] w, h = plt[:size]
plotattributes_out[:width], plotattributes_out[:height] = w, h
plotattributes_out[:paper_bgcolor] = rgba_string(plt[:background_color_outside]) plotattributes_out[:paper_bgcolor] = rgba_string(plt[:background_color_outside])
plotattributes_out[:margin] = KW(:l=>0, :b=>20, :r=>0, :t=>20) plotattributes_out[:margin] = KW(:l=>0, :b=>20, :r=>0, :t=>20)
@ -910,28 +909,45 @@ function plotly_html_head(plt::Plot)
end end
function plotly_html_body(plt, style = nothing) function plotly_html_body(plt, style = nothing)
if style === nothing if style == nothing
w, h = plt[:size] style = "width:100%;height:100%;"
style = "width:$(w)px;height:$(h)px;"
end end
uuid = UUIDs.uuid4() uuid = UUIDs.uuid4()
html = """
<div id=\"$(uuid)\" style=\"$(style)\"></div>
<script>
PLOT = document.getElementById('$(uuid)');
Plotly.plot(PLOT, $(plotly_series_json(plt)), $(plotly_layout_json(plt)));
</script>
""" """
html <div id=\"$(uuid)\" style=\"$(style)\"></div>
<script>
$(js_body(plt, uuid))
</script>
"""
end end
function js_body(plt::Plot, uuid) function js_body(plt::Plot, divid)
js = """ """
PLOT = document.getElementById('$(uuid)'); gd = (function() {
Plotly.plot(PLOT, $(plotly_series_json(plt)), $(plotly_layout_json(plt))); 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 end
# ----------------------------------------------------------------
function plotly_show_js(io::IO, plot::Plot) function plotly_show_js(io::IO, plot::Plot)
data = [] data = []
for series in plot.series_list for series in plot.series_list
@ -958,3 +974,4 @@ end
function _display(plt::Plot{PlotlyBackend}) function _display(plt::Plot{PlotlyBackend})
standalone_html_window(plt) standalone_html_window(plt)
end end