Add option to align Y labels left

This commit is contained in:
Jelte Fennema 2014-07-15 23:56:54 +02:00
parent a9076b2cc4
commit 20ffef7c0e
3 changed files with 16 additions and 16 deletions

View File

@ -255,13 +255,6 @@ class Morris.Bar extends Morris.Grid
y = @top + (index + 0.5) * @height / @data.length
[content, x, y, true]
drawXAxisLabel: (xPos, yPos, text) ->
label = @raphael.text(xPos, yPos, text)
.attr('font-size', @options.gridTextSize)
.attr('font-family', @options.gridTextFamily)
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.gridTextColor)
drawBar: (xPos, yPos, width, height, barColor, opacity, radiusArray) ->
maxRadius = Math.max(radiusArray...)
if maxRadius == 0 or maxRadius > height

View File

@ -105,6 +105,7 @@ class Morris.Grid extends Morris.EventEmitter
gridTextWeight: 'normal'
hideHover: false
yLabelFormat: null
yLabelAlign: 'right'
xLabelAngle: 0
numLines: 5
padding: 25
@ -395,7 +396,10 @@ class Morris.Grid extends Morris.EventEmitter
#
# @private
getYAxisLabelX: ->
@left - @options.padding / 2
if @options.yLabelAlign is 'right'
@left - @options.padding / 2
else
@options.padding / 2
# draw y axis labels, horizontal lines
@ -456,12 +460,22 @@ class Morris.Grid extends Morris.EventEmitter
.attr('stroke-width', @options.eventStrokeWidth)
drawYAxisLabel: (xPos, yPos, text) ->
label = @raphael.text(xPos, yPos, text)
.attr('font-size', @options.gridTextSize)
.attr('font-family', @options.gridTextFamily)
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.gridTextColor)
if @options.yLabelAlign == 'right'
label.attr('text-anchor', 'end')
else
label.attr('text-anchor', 'start')
drawXAxisLabel: (xPos, yPos, text) ->
@raphael.text(xPos, yPos, text)
.attr('font-size', @options.gridTextSize)
.attr('font-family', @options.gridTextFamily)
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.gridTextColor)
.attr('text-anchor', 'end')
drawGridLine: (path) ->
@raphael.path(path)

View File

@ -323,13 +323,6 @@ class Morris.Line extends Morris.Grid
else
@options.trendLineColors[sidx % @options.trendLineColors.length]
drawXAxisLabel: (xPos, yPos, text) ->
@raphael.text(xPos, yPos, text)
.attr('font-size', @options.gridTextSize)
.attr('font-family', @options.gridTextFamily)
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.gridTextColor)
drawLinePath: (path, lineColor, lineIndex) ->
@raphael.path(path)
.attr('stroke', lineColor)