mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-13 07:11:12 +01:00
Add vertical grid lines to line graphs
This commit is contained in:
parent
2356f4977e
commit
c8e14ae163
1 changed files with 25 additions and 0 deletions
|
@ -35,6 +35,9 @@ class Morris.Line extends Morris.Grid
|
|||
xLabels: 'auto'
|
||||
xLabelFormat: null
|
||||
xLabelMargin: 24
|
||||
verticalGrid: false
|
||||
verticalGridHeight: 'full'
|
||||
verticalGridStartOffset: 0
|
||||
hideHover: false
|
||||
trendLine: false
|
||||
trendLineWidth: 2
|
||||
|
@ -152,6 +155,7 @@ class Morris.Line extends Morris.Grid
|
|||
ypos = @bottom + @options.padding / 2
|
||||
prevLabelMargin = null
|
||||
prevAngleMargin = null
|
||||
|
||||
drawLabel = (labelText, xpos) =>
|
||||
label = @drawXAxisLabel(@transX(xpos), ypos, labelText)
|
||||
textBox = label.getBBox()
|
||||
|
@ -173,8 +177,12 @@ class Morris.Line extends Morris.Grid
|
|||
Math.sin(@options.xLabelAngle * Math.PI / 180.0)
|
||||
prevAngleMargin = labelBox.x - margin
|
||||
prevLabelMargin = labelBox.x - @options.xLabelMargin
|
||||
if @options.verticalGrid is true
|
||||
@drawVerticalGridLine(xpos)
|
||||
|
||||
else
|
||||
label.remove()
|
||||
|
||||
if @options.parseTime
|
||||
if @data.length == 1 and @options.xLabels == 'auto'
|
||||
# where there's only one value in the series, we can't make a
|
||||
|
@ -189,6 +197,23 @@ class Morris.Line extends Morris.Grid
|
|||
for l in labels
|
||||
drawLabel(l[0], l[1])
|
||||
|
||||
if typeof @options.verticalGrid is 'string'
|
||||
lines = Morris.labelSeries(@xmin, @xmax, @width, @options.verticalGrid)
|
||||
for l in lines
|
||||
@drawVerticalGridLine(l[1])
|
||||
|
||||
# Draw a vertical grid line
|
||||
#
|
||||
# @private
|
||||
drawVerticalGridLine: (xpos) ->
|
||||
xpos = Math.floor(@transX(xpos)) + 0.5
|
||||
yStart = @yStart + @options.verticalGridStartOffset
|
||||
if @options.verticalGridHeight is 'full'
|
||||
yEnd = @yEnd
|
||||
else
|
||||
yEnd = @yStart - @options.verticalGridHeight
|
||||
@drawGridLine("M#{xpos},#{yStart}V#{yEnd}")
|
||||
|
||||
# draw the data series
|
||||
#
|
||||
# @private
|
||||
|
|
Loading…
Reference in a new issue