parseFloat for donut values.

This commit is contained in:
Olly Smith 2013-02-24 17:20:17 +00:00
parent c3df64cbd4
commit a7a22532e3
3 changed files with 14 additions and 9 deletions

View file

@ -72,8 +72,11 @@ class Morris.Donut
idx = 0 idx = 0
@segments = [] @segments = []
for d in @data for d in @data
next = last + min + C * (d.value / total) next = last + min + C * (parseFloat(d.value) / total)
seg = new Morris.DonutSegment(cx, cy, w*2, w, last, next, @options.colors[idx % @options.colors.length], @options.backgroundColor, d, @raphael) seg = new Morris.DonutSegment(
cx, cy, w*2, w, last, next,
@options.colors[idx % @options.colors.length],
@options.backgroundColor, d, @raphael)
seg.render() seg.render()
@segments.push seg @segments.push seg
seg.on 'hover', @select seg.on 'hover', @select
@ -81,10 +84,10 @@ class Morris.Donut
idx += 1 idx += 1
@text1 = @drawEmptyDonutLabel(cx, cy - 10, @options.labelColor, 15, 800) @text1 = @drawEmptyDonutLabel(cx, cy - 10, @options.labelColor, 15, 800)
@text2 = @drawEmptyDonutLabel(cx, cy + 10, @options.labelColor, 14) @text2 = @drawEmptyDonutLabel(cx, cy + 10, @options.labelColor, 14)
max_value = Math.max.apply(null, d.value for d in @data) max_value = Math.max.apply(null, parseFloat(d.value) for d in @data)
idx = 0 idx = 0
for d in @data for d in @data
if d.value == max_value if parseFloat(d.value) == max_value
@select idx @select idx
break break
idx += 1 idx += 1
@ -94,7 +97,9 @@ class Morris.Donut
s.deselect() for s in @segments s.deselect() for s in @segments
if typeof idx is 'number' then segment = @segments[idx] else segment = idx if typeof idx is 'number' then segment = @segments[idx] else segment = idx
segment.select() segment.select()
@setLabels segment.data.label, @options.formatter(segment.data.value, segment.data) @setLabels(
segment.data.label,
@options.formatter(segment.data.value, segment.data))
# @private # @private
setLabels: (label1, label2) -> setLabels: (label1, label2) ->

View file

@ -1401,7 +1401,7 @@
_ref1 = this.data; _ref1 = this.data;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
d = _ref1[_j]; d = _ref1[_j];
next = last + min + C * (d.value / total); next = last + min + C * (parseFloat(d.value) / total);
seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.options.colors[idx % this.options.colors.length], this.options.backgroundColor, d, this.raphael); seg = new Morris.DonutSegment(cx, cy, w * 2, w, last, next, this.options.colors[idx % this.options.colors.length], this.options.backgroundColor, d, this.raphael);
seg.render(); seg.render();
this.segments.push(seg); this.segments.push(seg);
@ -1417,7 +1417,7 @@
_results = []; _results = [];
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
d = _ref2[_k]; d = _ref2[_k];
_results.push(d.value); _results.push(parseFloat(d.value));
} }
return _results; return _results;
}).call(this)); }).call(this));
@ -1426,7 +1426,7 @@
_results = []; _results = [];
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
d = _ref2[_k]; d = _ref2[_k];
if (d.value === max_value) { if (parseFloat(d.value) === max_value) {
this.select(idx); this.select(idx);
break; break;
} }

2
morris.min.js vendored

File diff suppressed because one or more lines are too long