Donut label color - fixes #159.

This commit is contained in:
Olly Smith 2013-02-06 08:27:13 +00:00
parent 481401c3b7
commit 49a7a02774
4 changed files with 20 additions and 9 deletions

View File

@ -25,6 +25,13 @@ Morris.Donut({
{value: 5, label: 'A really really long label'} {value: 5, label: 'A really really long label'}
], ],
backgroundColor: '#ccc', backgroundColor: '#ccc',
labelColor: '#060',
colors: [
'#0BA462',
'#39B580',
'#67C69D',
'#95D7BB'
],
formatter: function (x) { return x + "%"} formatter: function (x) { return x + "%"}
}); });
</pre> </pre>

View File

@ -23,6 +23,7 @@ class Morris.Donut
'#042135' '#042135'
], ],
backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
labelColor: '#000000',
formatter: Morris.commas formatter: Morris.commas
# Create and render a donut chart. # Create and render a donut chart.
@ -78,8 +79,8 @@ class Morris.Donut
seg.on 'hover', @select seg.on 'hover', @select
last = next last = next
idx += 1 idx += 1
@text1 = @drawEmptyDonutLabel(cx, cy - 10, 15, 800) @text1 = @drawEmptyDonutLabel(cx, cy - 10, @options.labelColor, 15, 800)
@text2 = @drawEmptyDonutLabel(cx, cy + 10, 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, d.value for d in @data)
idx = 0 idx = 0
for d in @data for d in @data
@ -110,8 +111,10 @@ class Morris.Donut
text2scale = Math.min(maxWidth / text2bbox.width, maxHeightBottom / text2bbox.height) text2scale = Math.min(maxWidth / text2bbox.width, maxHeightBottom / text2bbox.height)
@text2.attr(transform: "S#{text2scale},#{text2scale},#{text2bbox.x + text2bbox.width / 2},#{text2bbox.y}") @text2.attr(transform: "S#{text2scale},#{text2scale},#{text2bbox.x + text2bbox.width / 2},#{text2bbox.y}")
drawEmptyDonutLabel: (xPos, yPos, fontSize, fontWeight) -> drawEmptyDonutLabel: (xPos, yPos, color, fontSize, fontWeight) ->
text = @raphael.text(xPos, yPos, '').attr('font-size', fontSize) text = @raphael.text(xPos, yPos, '')
.attr('font-size', fontSize)
.attr('fill', color)
text.attr('font-weight', fontWeight) if fontWeight? text.attr('font-weight', fontWeight) if fontWeight?
return text return text

View File

@ -1353,6 +1353,7 @@
Donut.prototype.defaults = { Donut.prototype.defaults = {
colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'], colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'],
backgroundColor: '#FFFFFF', backgroundColor: '#FFFFFF',
labelColor: '#000000',
formatter: Morris.commas formatter: Morris.commas
}; };
@ -1406,8 +1407,8 @@
last = next; last = next;
idx += 1; idx += 1;
} }
this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, 15, 800); this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, this.options.labelColor, 15, 800);
this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, 14); this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, this.options.labelColor, 14);
max_value = Math.max.apply(null, (function() { max_value = Math.max.apply(null, (function() {
var _k, _len2, _ref2, _results; var _k, _len2, _ref2, _results;
_ref2 = this.data; _ref2 = this.data;
@ -1474,9 +1475,9 @@
}); });
}; };
Donut.prototype.drawEmptyDonutLabel = function(xPos, yPos, fontSize, fontWeight) { Donut.prototype.drawEmptyDonutLabel = function(xPos, yPos, color, fontSize, fontWeight) {
var text; var text;
text = this.raphael.text(xPos, yPos, '').attr('font-size', fontSize); text = this.raphael.text(xPos, yPos, '').attr('font-size', fontSize).attr('fill', color);
if (fontWeight != null) { if (fontWeight != null) {
text.attr('font-weight', fontWeight); text.attr('font-weight', fontWeight);
} }

2
morris.min.js vendored

File diff suppressed because one or more lines are too long