--- a/client/js/podium.js Fri Feb 24 15:36:11 2012 +0100
+++ b/client/js/podium.js Fri Feb 24 17:46:20 2012 +0100
@@ -21,21 +21,21 @@
this.options.width = this.options.width || this._$.width();
this.options.height = this.options.height || this._$.height();
this.options.minHeight = this.options.minHeight || 0;
+ this.lastheights = [];
this.update(data, true);
}
Btv_Podium.prototype.update = function(data, noAnimate) {
- var _data = data || [],
- _oldcount = this._$.children().length;
+ var _data = data || [];
while (_data.length > this._$.children().length) {
var _newCol = document.createElement("div");
this.$(_newCol).css({
"float": "left",
"background": this.options.barBgd,
- "margin-top": this.options.height,
"width": 0,
"height": 0,
- "margin-left": 0
+ "margin-top": this.options.height,
+ "margin-left": 0,
});
this._$.append(_newCol);
}
@@ -49,23 +49,31 @@
_scale = (this.options.height - this.options.minHeight) / _max,
_spacing = Math.min(this.options.spacing, Math.floor(.5*this.options.width/_data.length)),
_width = Math.floor(( this.options.width - (_data.length - 1) * _spacing) / _data.length),
- _this = this;
+ _this = this,
+ _heights = [];
this._$.children().each(function(_i, _e) {
var _height = Math.floor(_scale * _data[_i] + _this.options.minHeight),
- _css = {};
- if (_height != _this.$(_e).height()) {
- _css["margin-top"] = _this.options.height - _height,
- _css["height"] = _height
- }
- if (_data.length != _oldcount) {
+ _css = {},
+ _changed = false;
+ _heights.push(_height);
+ if (_data.length != _this.lastheights.length) {
_css["width"] = _width;
_css["margin-left"] = (_i ? _spacing : 0);
+ _changed = true;
}
- if (noAnimate) {
- _this.$(_e).css(_css);
- } else {
- _this.$(_e).animate(_css);
+ if (_i >= _data.length || _height != _this.lastheights[_i]) {
+ _css["height"] = _height;
+ _css["margin-top"] = _this.options.height - _height
+ _changed = true;
+ }
+ if (_changed) {
+ if (noAnimate) {
+ _this.$(_e).css(_css);
+ } else {
+ _this.$(_e).animate(_css);
+ }
}
});
+ this.lastheights = _heights;
}
}
\ No newline at end of file