From 7d155181aae58af48b7d4e12eee67d27281a6d5d Mon Sep 17 00:00:00 2001 From: Ana Krivokapic Date: Mon, 14 Apr 2014 16:27:12 +0200 Subject: [PATCH] Clear barchart before rendering it When refreshing the bar chart, it is necessary to clear the html before rendering it. Otherwise the old chart remains on the page, and the new one is added on top of it. This patch ensures that the old chart is cleared first, before rendering the new chart. This also replaces occurrences of .html('') with .empty(), as the latter is more efficient and explicit. Closes-bug: #1307563 Change-Id: I5705cb82093dcf45b5111f5ab52d3dfda74ce64a --- horizon/static/horizon/js/horizon.d3barchart.js | 2 ++ horizon/static/horizon/js/horizon.d3linechart.js | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/horizon/static/horizon/js/horizon.d3barchart.js b/horizon/static/horizon/js/horizon.d3barchart.js index 72f0b18be4..c09ed875a4 100644 --- a/horizon/static/horizon/js/horizon.d3barchart.js +++ b/horizon/static/horizon/js/horizon.d3barchart.js @@ -240,6 +240,8 @@ horizon.d3_bar_chart = { */ self.refresh = function(){ var self = this; + // Clear the chart before rendering it + self.jquery_element.empty(); self.render(); }; diff --git a/horizon/static/horizon/js/horizon.d3linechart.js b/horizon/static/horizon/js/horizon.d3linechart.js index 73f529f253..524c76d55f 100644 --- a/horizon/static/horizon/js/horizon.d3linechart.js +++ b/horizon/static/horizon/js/horizon.d3linechart.js @@ -374,8 +374,8 @@ horizon.d3_line_chart = { url: self.final_url, success: function (data, textStatus, jqXHR) { // Clearing the old chart data. - $(self.html_element).html(''); - $(self.legend_element).html(''); + self.jquery_element.empty(); + $(self.legend_element).empty(); self.series = data.series; self.stats = data.stats; @@ -384,7 +384,7 @@ horizon.d3_line_chart = { if (self.series.length <= 0) { $(self.html_element).html(gettext('No data available.')); - $(self.legend_element).html(''); + $(self.legend_element).empty(); // Setting a fix height breaks things when legend is getting // bigger. $(self.legend_element).css('height', ''); @@ -394,7 +394,7 @@ horizon.d3_line_chart = { }, error: function (jqXHR, textStatus, errorThrown) { $(self.html_element).html(gettext('No data available.')); - $(self.legend_element).html(''); + $(self.legend_element).empty(); // Setting a fix height breaks things when legend is getting // bigger. $(self.legend_element).css('height', ''); @@ -548,7 +548,7 @@ horizon.d3_line_chart = { $(self.html_element).append(self.backdrop); // Hide the legend. - $(self.legend_element).html('').addClass('disabled'); + $(self.legend_element).empty().addClass('disabled'); // Show the spinner. self.spinner = $('
');