Morris.Donut#select(idx) for selecting donut segments (ref #79).

This commit is contained in:
Olly Smith 2012-09-26 21:37:25 +01:00
parent 9bb723057f
commit 43019eeeaf
3 changed files with 9 additions and 7 deletions

View File

@ -85,13 +85,14 @@ class Morris.Donut
idx = 0 idx = 0
for d in @data for d in @data
if d.value == max_value if d.value == max_value
@select @segments[idx] @select idx
break break
idx += 1 idx += 1
# @private # Select the segment at the given index.
select: (segment) => select: (idx) =>
s.deselect() for s in @segments s.deselect() for s in @segments
segment = @segments[idx]
segment.select() segment.select()
@setLabels segment.data.label, @options.formatter(segment.data.value) @setLabels segment.data.label, @options.formatter(segment.data.value)

View File

@ -143,7 +143,7 @@
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 (d.value === max_value) {
this.select(this.segments[idx]); this.select(idx);
break; break;
} }
_results.push(idx += 1); _results.push(idx += 1);
@ -151,13 +151,14 @@
return _results; return _results;
}; };
Donut.prototype.select = function(segment) { Donut.prototype.select = function(idx) {
var s, _i, _len, _ref; var s, segment, _i, _len, _ref;
_ref = this.segments; _ref = this.segments;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
s = _ref[_i]; s = _ref[_i];
s.deselect(); s.deselect();
} }
segment = this.segments[idx];
segment.select(); segment.select();
return this.setLabels(segment.data.label, this.options.formatter(segment.data.value)); return this.setLabels(segment.data.label, this.options.formatter(segment.data.value));
}; };

2
morris.min.js vendored

File diff suppressed because one or more lines are too long