Skip to content

Instantly share code, notes, and snippets.

@rmurphey
Created October 24, 2009 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmurphey/217707 to your computer and use it in GitHub Desktop.
Save rmurphey/217707 to your computer and use it in GitHub Desktop.
dojo.provide('hitpost.Graph');
dojo.declare('hitpost.Graph', null, {
min : 0,
max : 6,
wait : 500,
constructor : function(domNode, animate) {
if (!domNode) { return; }
this.animate = animate || false;
this.domNode = domNode;
this.columns = dojo.query('div', this.domNode);
this.baseline = dojo.attr(this.domNode, 'data-dots');
this.variance = dojo.attr(this.domNode, 'data-var');
this._draw();
this.animate && this._animate();
},
_draw : function() {
this.columns.forEach(function(el) {
var rand = Math.floor(Math.random() * (this.variance + this.baseline));
rand = rand > this.max ? this.max : rand < this.min ? this.min : rand;
el.className = '';
dojo.addClass(el, 'value_' + rand);
}, this);
},
_animate : function() {
this.interval = setInterval(dojo.hitch(this, '_draw'), this.wait);
},
stop : function() {
this.interval && clearInterval(this.interval);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment