make line widths customizable

This commit is contained in:
David Gil 2013-08-20 02:38:48 +02:00
parent b98ae8ab1d
commit c613aeb988
4 changed files with 25 additions and 5 deletions

View File

@ -281,10 +281,10 @@ class Morris.Line extends Morris.Grid
.attr('font-weight', @options.gridTextWeight)
.attr('fill', @options.gridTextColor)
drawLinePath: (path, lineColor) ->
drawLinePath: (path, lineColor, lineIndex) ->
@raphael.path(path)
.attr('stroke', lineColor)
.attr('stroke-width', @options.lineWidth)
.attr('stroke-width', @lineWidthForSeries(lineIndex))
drawLinePoint: (xPos, yPos, size, pointColor, lineIndex) ->
@raphael.circle(xPos, yPos, size)
@ -300,6 +300,13 @@ class Morris.Line extends Morris.Grid
strokeForSeries: (index) ->
@options.pointStrokeColors[index % @options.pointStrokeColors.length]
# @private
lineWidthForSeries: (index) ->
if (@options.lineWidth instanceof Array)
@options.lineWidth[index % @options.lineWidth.length]
else
@options.lineWidth
# generate a series of label, timestamp pairs for x-axis labels
#
# @private

View File

@ -1029,8 +1029,8 @@
return this.raphael.text(xPos, yPos, text).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.gridTextColor);
};
Line.prototype.drawLinePath = function(path, lineColor) {
return this.raphael.path(path).attr('stroke', lineColor).attr('stroke-width', this.options.lineWidth);
Line.prototype.drawLinePath = function(path, lineColor, lineIndex) {
return this.raphael.path(path).attr('stroke', lineColor).attr('stroke-width', this.lineWidthForSeries(lineIndex));
};
Line.prototype.drawLinePoint = function(xPos, yPos, size, pointColor, lineIndex) {
@ -1045,6 +1045,14 @@
return this.options.pointStrokeColors[index % this.options.pointStrokeColors.length];
};
Line.prototype.lineWidthForSeries = function(index) {
if (this.options.lineWidth instanceof Array) {
return this.options.lineWidth[index % this.options.lineWidth.length];
} else {
return this.options.lineWidth;
}
};
return Line;
})(Morris.Grid);

2
morris.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -114,6 +114,11 @@ describe 'Morris.Line', ->
Morris.Line @defaults
shouldHavePath /(M[\d\.]+,[\d\.]+C[\d\.]+(,[\d\.]+){5}){2}/
it 'should make line width customizable', ->
chart = Morris.Line $.extend(@defaults, lineWidth: [1, 2])
chart.lineWidthForSeries(0).should.equal 1
chart.lineWidthForSeries(1).should.equal 2
describe '#createPath', ->
it 'should generate a smooth line', ->