diff options
author | Richard Wall <richard@largo> | 2010-10-04 00:54:48 +0100 |
---|---|---|
committer | Richard Wall <richard@largo> | 2010-10-04 00:54:48 +0100 |
commit | 319abdbf06a052180b61bc8f5be5eb272690b4f2 (patch) | |
tree | 2bdfe437bb892990522d138633280edaf62fa36f | |
parent | 9c71054a0e3f6e0bb5b524ada9b9c73ca90c2913 (diff) |
Add an error placeholder instead of replacing entire template content with error message - preventing subsequent chart rendering.
-rw-r--r-- | docs/examples/index.html | 1 | ||||
-rw-r--r-- | jarmon/jarmon.js | 12 |
2 files changed, 10 insertions, 3 deletions
diff --git a/docs/examples/index.html b/docs/examples/index.html index 9d12389..3debd18 100644 --- a/docs/examples/index.html +++ b/docs/examples/index.html @@ -208,6 +208,7 @@ </div> <div class="chart-container"> <h2 class="title"></h2> + <div class="error"></div> <div class="chart"></div> <div class="graph-legend"></div> </div> diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index 6ac410c..06ec4c8 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -521,6 +521,9 @@ jarmon.Chart.prototype.draw = function() { return MochiKit.Async.gatherResults(results) .addCallback( function(self, data) { + // Clear any previous error messages. + self.template.find('.error').empty().hide(); + var i, label, disabled = []; unit = ''; for(i=0; i<data.length; i++) { @@ -537,7 +540,7 @@ jarmon.Chart.prototype.draw = function() { } } - $.plot(self.template.find('.chart'), data, self.options); + $.plot(self.template.find('.chart').empty().show(), data, self.options); var yaxisUnitLabel = $('<div>').text(self.siPrefix + unit) .css({width: '100px', @@ -556,7 +559,7 @@ jarmon.Chart.prototype.draw = function() { // table is useful as it generates an optimum label element // width which we can copy to the new divs + a little extra // to accomodate the color box - var legend = self.template.find('.graph-legend'); + var legend = self.template.find('.graph-legend').show(); legend.empty(); self.template.find('.legendLabel') .each(function(i, el) { @@ -585,7 +588,10 @@ jarmon.Chart.prototype.draw = function() { }, this) .addErrback( function(self, failure) { - self.template.text('error: ' + failure.message); + self.template.find('.chart').empty().hide(); + self.template.find('.graph-legend').empty().hide(); + self.template.find('.error').text('error: ' + failure.message); + }, this) .addBoth( function(self, res) { |