19 this._$ = this.$(_el); |
19 this._$ = this.$(_el); |
20 } |
20 } |
21 this.options.width = this.options.width || this._$.width(); |
21 this.options.width = this.options.width || this._$.width(); |
22 this.options.height = this.options.height || this._$.height(); |
22 this.options.height = this.options.height || this._$.height(); |
23 this.options.minHeight = this.options.minHeight || 0; |
23 this.options.minHeight = this.options.minHeight || 0; |
|
24 this.lastheights = []; |
24 this.update(data, true); |
25 this.update(data, true); |
25 } |
26 } |
26 |
27 |
27 Btv_Podium.prototype.update = function(data, noAnimate) { |
28 Btv_Podium.prototype.update = function(data, noAnimate) { |
28 var _data = data || [], |
29 var _data = data || []; |
29 _oldcount = this._$.children().length; |
|
30 while (_data.length > this._$.children().length) { |
30 while (_data.length > this._$.children().length) { |
31 var _newCol = document.createElement("div"); |
31 var _newCol = document.createElement("div"); |
32 this.$(_newCol).css({ |
32 this.$(_newCol).css({ |
33 "float": "left", |
33 "float": "left", |
34 "background": this.options.barBgd, |
34 "background": this.options.barBgd, |
35 "margin-top": this.options.height, |
|
36 "width": 0, |
35 "width": 0, |
37 "height": 0, |
36 "height": 0, |
38 "margin-left": 0 |
37 "margin-top": this.options.height, |
|
38 "margin-left": 0, |
39 }); |
39 }); |
40 this._$.append(_newCol); |
40 this._$.append(_newCol); |
41 } |
41 } |
42 while (_data.length < this._$.children().length) { |
42 while (_data.length < this._$.children().length) { |
43 this._$.children().last().detach(); |
43 this._$.children().last().detach(); |
47 return Math.max(_memo, _val); |
47 return Math.max(_memo, _val); |
48 }, 1), |
48 }, 1), |
49 _scale = (this.options.height - this.options.minHeight) / _max, |
49 _scale = (this.options.height - this.options.minHeight) / _max, |
50 _spacing = Math.min(this.options.spacing, Math.floor(.5*this.options.width/_data.length)), |
50 _spacing = Math.min(this.options.spacing, Math.floor(.5*this.options.width/_data.length)), |
51 _width = Math.floor(( this.options.width - (_data.length - 1) * _spacing) / _data.length), |
51 _width = Math.floor(( this.options.width - (_data.length - 1) * _spacing) / _data.length), |
52 _this = this; |
52 _this = this, |
|
53 _heights = []; |
53 this._$.children().each(function(_i, _e) { |
54 this._$.children().each(function(_i, _e) { |
54 var _height = Math.floor(_scale * _data[_i] + _this.options.minHeight), |
55 var _height = Math.floor(_scale * _data[_i] + _this.options.minHeight), |
55 _css = {}; |
56 _css = {}, |
56 if (_height != _this.$(_e).height()) { |
57 _changed = false; |
57 _css["margin-top"] = _this.options.height - _height, |
58 _heights.push(_height); |
58 _css["height"] = _height |
59 if (_data.length != _this.lastheights.length) { |
59 } |
|
60 if (_data.length != _oldcount) { |
|
61 _css["width"] = _width; |
60 _css["width"] = _width; |
62 _css["margin-left"] = (_i ? _spacing : 0); |
61 _css["margin-left"] = (_i ? _spacing : 0); |
|
62 _changed = true; |
63 } |
63 } |
64 if (noAnimate) { |
64 if (_i >= _data.length || _height != _this.lastheights[_i]) { |
65 _this.$(_e).css(_css); |
65 _css["height"] = _height; |
66 } else { |
66 _css["margin-top"] = _this.options.height - _height |
67 _this.$(_e).animate(_css); |
67 _changed = true; |
|
68 } |
|
69 if (_changed) { |
|
70 if (noAnimate) { |
|
71 _this.$(_e).css(_css); |
|
72 } else { |
|
73 _this.$(_e).animate(_css); |
|
74 } |
68 } |
75 } |
69 }); |
76 }); |
|
77 this.lastheights = _heights; |
70 } |
78 } |
71 } |
79 } |