Skip to content

Commit

Permalink
Formatter option for donut values (#75).
Browse files Browse the repository at this point in the history
  • Loading branch information
oesmith committed Sep 20, 2012
1 parent 088233d commit fbe3ce8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
3 changes: 2 additions & 1 deletion examples/donut.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ <h1>Donut Chart</h1>
{value: 15, label: 'bar'},
{value: 10, label: 'baz'},
{value: 5, label: 'A really really long label'}
]
],
formatter: function (x) { return x + "%"}
});
</pre>
</body>
33 changes: 17 additions & 16 deletions lib/morris.donut.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
# ]
# });
class Morris.Donut
colors: [
'#0B62A4'
'#3980B5'
'#679DC6'
'#95BBD7'
'#B0CCE1'
'#095791'
'#095085'
'#083E67'
'#052C48'
'#042135'
]
defaults:
colors: [
'#0B62A4'
'#3980B5'
'#679DC6'
'#95BBD7'
'#B0CCE1'
'#095791'
'#095085'
'#083E67'
'#052C48'
'#042135'
],
formatter: Morris.commas

# Create and render a donut chart.
#
Expand All @@ -33,8 +35,7 @@ class Morris.Donut
else
@el = $ options.element

if options.colors?
@colors = options.colors
@options = $.extend {}, @defaults, options

if @el == null || @el.length == 0
throw new Error("Graph placeholder not found.")
Expand Down Expand Up @@ -72,7 +73,7 @@ class Morris.Donut
@segments = []
for d in @data
next = last + min + C * (d.value / total)
seg = new Morris.DonutSegment(cx, cy, w*2, w, last, next, @colors[idx % @colors.length], d)
seg = new Morris.DonutSegment(cx, cy, w*2, w, last, next, @options.colors[idx % @options.colors.length], d)
seg.render @r
@segments.push seg
seg.on 'hover', @select
Expand All @@ -92,7 +93,7 @@ class Morris.Donut
select: (segment) =>
s.deselect() for s in @segments
segment.select()
@setLabels segment.data.label, Morris.commas(segment.data.value)
@setLabels segment.data.label, @options.formatter(segment.data.value)

# @private
setLabels: (label1, label2) ->
Expand Down
13 changes: 7 additions & 6 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 fbe3ce8

Please sign in to comment.