Merge pull request #518 from JelteF/in-bar-value

Add an option to display the value of a bar in the bar itself
This commit is contained in:
Jelte Fennema 2015-01-08 12:51:36 +01:00
commit d008d9317f

View File

@ -31,6 +31,10 @@ class Morris.Bar extends Morris.Grid
xLabelMargin: 50
horizontal: false
shown: true
inBarValue: false
inBarValueTextColor: 'white'
inBarValueMinTopMargin: 1
inBarValueRightMargin: 4
# Do any size-related calculations
#
@ -177,6 +181,15 @@ class Morris.Bar extends Morris.Grid
@options.barOpacity, @options.barRadius)
lastTop -= size
if @options.inBarValue and
barWidth > @options.gridTextSize + 2*@options.inBarValueMinTopMargin
barMiddle = left + 0.5 * barWidth
@raphael.text(bottom - @options.inBarValueRightMargin, barMiddle, @yLabelFormat(row.y[sidx], sidx))
.attr('font-size', @options.gridTextSize)
.attr('font-family', @options.gridTextFamily)
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.inBarValueTextColor)
.attr('text-anchor', 'end')
else
null