Skip to content

Commit 49a7a02

Browse files
committed
Donut label color - fixes #159.
1 parent 481401c commit 49a7a02

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

examples/donut-background-color.html examples/donut-colors.html

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ <h1>Donut Chart</h1>
2525
{value: 5, label: 'A really really long label'}
2626
],
2727
backgroundColor: '#ccc',
28+
labelColor: '#060',
29+
colors: [
30+
'#0BA462',
31+
'#39B580',
32+
'#67C69D',
33+
'#95D7BB'
34+
],
2835
formatter: function (x) { return x + "%"}
2936
});
3037
</pre>

lib/morris.donut.coffee

+7-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Morris.Donut
2323
'#042135'
2424
],
2525
backgroundColor: '#FFFFFF',
26+
labelColor: '#000000',
2627
formatter: Morris.commas
2728

2829
# Create and render a donut chart.
@@ -78,8 +79,8 @@ class Morris.Donut
7879
seg.on 'hover', @select
7980
last = next
8081
idx += 1
81-
@text1 = @drawEmptyDonutLabel(cx, cy - 10, 15, 800)
82-
@text2 = @drawEmptyDonutLabel(cx, cy + 10, 14)
82+
@text1 = @drawEmptyDonutLabel(cx, cy - 10, @options.labelColor, 15, 800)
83+
@text2 = @drawEmptyDonutLabel(cx, cy + 10, @options.labelColor, 14)
8384
max_value = Math.max.apply(null, d.value for d in @data)
8485
idx = 0
8586
for d in @data
@@ -110,8 +111,10 @@ class Morris.Donut
110111
text2scale = Math.min(maxWidth / text2bbox.width, maxHeightBottom / text2bbox.height)
111112
@text2.attr(transform: "S#{text2scale},#{text2scale},#{text2bbox.x + text2bbox.width / 2},#{text2bbox.y}")
112113

113-
drawEmptyDonutLabel: (xPos, yPos, fontSize, fontWeight) ->
114-
text = @raphael.text(xPos, yPos, '').attr('font-size', fontSize)
114+
drawEmptyDonutLabel: (xPos, yPos, color, fontSize, fontWeight) ->
115+
text = @raphael.text(xPos, yPos, '')
116+
.attr('font-size', fontSize)
117+
.attr('fill', color)
115118
text.attr('font-weight', fontWeight) if fontWeight?
116119
return text
117120

morris.js

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)