Commit 28c6d5c3 authored by Sebastien Robin's avatar Sebastien Robin

apachedex: render plotly graph only when displayed, this avoid rendering hidden graphs

parent f7452cce
...@@ -272,17 +272,13 @@ def graph(title, data, options={}, height=300): ...@@ -272,17 +272,13 @@ def graph(title, data, options={}, height=300):
count_graph += 1 count_graph += 1
div_id = "graph_%i" % count_graph div_id = "graph_%i" % count_graph
append = result.append append = result.append
append('<h2>%s</h2><div id="%s" ' append('<h2>%s</h2><div id="%s" class="graph" '
'style="width:600px;height:%ipx"></div>' % (title, div_id, height)) 'style="width:600px;height:%ipx" ' % (title, div_id, height))
append('</script><script type="text/javascript">//<![CDATA[') append(' data-points="')
append(""" append(escape(json.dumps(data), quote=True))
TESTER = document.getElementById('%s'); append('" data-options="')
Plotly.plot( TESTER,""" % div_id) append(escape(json.dumps(options), quote=True))
append(json.dumps(data)) append('"></div>"')
append(',')
append(json.dumps(options))
append(',{modeBarButtonsToRemove: ["sendDataToCloud"]});')
append('//]]></script>')
return ''.join(result) return ''.join(result)
class APDEXStats(object): class APDEXStats(object):
......
...@@ -49,21 +49,9 @@ function updateAxisTransform(axis) { ...@@ -49,21 +49,9 @@ function updateAxisTransform(axis) {
function renderGraph(container) { function renderGraph(container) {
var container = $(container); var container = $(container);
var previousIndex = null; var previousIndex = null;
var tooltip = container.next(".tooltip");
var options = $.parseJSON(container.attr("data-options")); var options = $.parseJSON(container.attr("data-options"));
updateAxisTransform(options.xaxis); var data = $.parseJSON(container.attr("data-points"));
updateAxisTransform(options.yaxis); Plotly.plot(container[0], data, options, {modeBarButtonsToRemove: ["sendDataToCloud"]});
var plot = $.plot(
container,
$.parseJSON(container.attr("data-points")),
options
);
tooltip.detach();
container.append(tooltip);
container.bind("plothover", function (event, pos, item) {
previousIndex = updateGraphTooltip(event, pos, item, previousIndex,
tooltip, plot);
});
} }
function toggleGraph(node) { function toggleGraph(node) {
var container = $(node).parent().find(".container"); var container = $(node).parent().find(".container");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment