Skip to content

Commit

Permalink
Donut label color - fixes #159.
Browse files Browse the repository at this point in the history
  • Loading branch information
oesmith committed Feb 6, 2013
1 parent 481401c commit 49a7a02
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ <h1>Donut Chart</h1>
{value: 5, label: 'A really really long label'}
],
backgroundColor: '#ccc',
labelColor: '#060',
colors: [
'#0BA462',
'#39B580',
'#67C69D',
'#95D7BB'
],
formatter: function (x) { return x + "%"}
});
</pre>
Expand Down
11 changes: 7 additions & 4 deletions lib/morris.donut.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Morris.Donut
'#042135'
],
backgroundColor: '#FFFFFF',
labelColor: '#000000',
formatter: Morris.commas

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

drawEmptyDonutLabel: (xPos, yPos, fontSize, fontWeight) ->
text = @raphael.text(xPos, yPos, '').attr('font-size', fontSize)
drawEmptyDonutLabel: (xPos, yPos, color, fontSize, fontWeight) ->
text = @raphael.text(xPos, yPos, '')
.attr('font-size', fontSize)
.attr('fill', color)
text.attr('font-weight', fontWeight) if fontWeight?
return text

Expand Down
9 changes: 5 additions & 4 deletions morris.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 49a7a02

Please sign in to comment.