Skip to content

Commit

Permalink
[#2458] Only draw stats chart when canvas is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed Jul 31, 2012
1 parent cf8578c commit da791b1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ckanext/stats/public/ckanext/stats/javascript/modules/plot.js
@@ -1,5 +1,7 @@
this.ckan.module('plot', function (jQuery, _) {
return {
graph: null,
canvas: null,
options: {
xaxis: {},
yaxis: {},
Expand All @@ -16,9 +18,12 @@ this.ckan.module('plot', function (jQuery, _) {

this.setupCanvas();
this.sandbox.body.on("shown", this._onShown);
this.data = this.parseTable(this.el);

var data = this.parseTable(this.el);
this.graph = jQuery.plot(this.canvas, data, this.options);
this.draw();

window.g = window.g || [];
window.g.push(this.graph);
},

teardown: function () {
Expand All @@ -30,6 +35,12 @@ this.ckan.module('plot', function (jQuery, _) {
this.el.replaceWith(this.canvas);
},

draw: function () {
if (!this.drawn && this.canvas.is(':visible')) {
this.graph = jQuery.plot(this.canvas, this.data, this.options);
}
},

parseTable: function (table) {
var data = [];
var _this = this;
Expand Down Expand Up @@ -71,10 +82,8 @@ this.ckan.module('plot', function (jQuery, _) {
},

_onShown: function (event) {
if (!this._redrawn && jQuery.contains(jQuery(event.target.hash)[0], this.canvas[0])) {
this.graph.setupGrid();
this.graph.draw();
this.redrawn = true;
if (!this.drawn && jQuery.contains(jQuery(event.target.hash)[0], this.canvas[0])) {
this.draw();
}
}
};
Expand Down

0 comments on commit da791b1

Please sign in to comment.