Add ability to customize points in a series

This commit is contained in:
Sam Figueroa 2012-10-09 17:27:15 +02:00
parent 7775332aeb
commit 0d42a6f026
4 changed files with 62 additions and 6 deletions

View File

@ -62,6 +62,23 @@ class Morris.Line
'#cb4b4b' '#cb4b4b'
'#9440ed' '#9440ed'
] ]
pointWidths: [
1
1
1
1
1
1
]
pointStrokeColors: [
'#ffffff'
'#ffffff'
'#ffffff'
'#ffffff'
'#ffffff'
'#ffffff'
'#ffffff'
]
ymax: 'auto' ymax: 'auto'
ymin: 'auto 0' ymin: 'auto 0'
marginTop: 25 marginTop: 25
@ -297,9 +314,11 @@ class Morris.Line
else else
circle = @r.circle(c.x, c.y, @options.pointSize) circle = @r.circle(c.x, c.y, @options.pointSize)
.attr('fill', @colorForSeries(i)) .attr('fill', @colorForSeries(i))
.attr('stroke-width', 1) .attr('stroke-width', @strokeWidthForSeries(i))
.attr('stroke', '#ffffff') .attr('stroke', @strokeForSeries(i))
@seriesPoints[i].push(circle) @seriesPoints[i].push(circle)
console.log @strokeWidthForSeries(i)
console.log @strokeForSeries(i)
# create a path for a data series # create a path for a data series
# #
@ -435,6 +454,14 @@ class Morris.Line
colorForSeries: (index) -> colorForSeries: (index) ->
@options.lineColors[index % @options.lineColors.length] @options.lineColors[index % @options.lineColors.length]
# @private
strokeWidthForSeries: (index) ->
@options.pointWidths[index % @options.pointWidths.length]
# @private
strokeForSeries: (index) ->
@options.pointStrokeColors[index % @options.pointStrokeColors.length]
# Parse a date into a javascript timestamp # Parse a date into a javascript timestamp
# #

View File

@ -353,6 +353,8 @@
lineWidth: 3, lineWidth: 3,
pointSize: 4, pointSize: 4,
lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'],
pointWidths: [1, 1, 1, 1, 1, 1],
pointStrokeColors: ['#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff'],
ymax: 'auto', ymax: 'auto',
ymin: 'auto 0', ymin: 'auto 0',
marginTop: 25, marginTop: 25,
@ -636,9 +638,11 @@
if (c === null) { if (c === null) {
circle = null; circle = null;
} else { } else {
circle = this.r.circle(c.x, c.y, this.options.pointSize).attr('fill', this.colorForSeries(i)).attr('stroke-width', 1).attr('stroke', '#ffffff'); circle = this.r.circle(c.x, c.y, this.options.pointSize).attr('fill', this.colorForSeries(i)).attr('stroke-width', this.strokeWidthForSeries(i)).attr('stroke', this.strokeForSeries(i));
} }
_results1.push(this.seriesPoints[i].push(circle)); this.seriesPoints[i].push(circle);
console.log(this.strokeWidthForSeries(i));
_results1.push(console.log(this.strokeForSeries(i)));
} }
return _results1; return _results1;
}).call(this)); }).call(this));
@ -799,6 +803,14 @@
return this.options.lineColors[index % this.options.lineColors.length]; return this.options.lineColors[index % this.options.lineColors.length];
}; };
Line.prototype.strokeWidthForSeries = function(index) {
return this.options.pointWidths[index % this.options.pointWidths.length];
};
Line.prototype.strokeForSeries = function(index) {
return this.options.pointStrokeColors[index % this.options.pointStrokeColors.length];
};
return Line; return Line;
})(); })();

2
morris.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -29,3 +29,20 @@ describe 'Morris.Line', ->
labels: ['dontcare'] labels: ['dontcare']
) )
fn.should.throw(/Graph placeholder not found./) fn.should.throw(/Graph placeholder not found./)
it 'should make point styles user accessible', ->
my_data = [{x: 1, y: 1}, {x: 2, y: 2}]
red = '#ff0000'
blue = '#0000ff'
chart = Morris.Line
element: 'graph'
data: my_data
xkey: 'x'
ykeys: ['y']
labels: ['dontcare']
pointStrokeColors: [red, blue]
pointWidths: [1, 2]
chart.strokeWidthForSeries(0).should.equal 1
chart.strokeForSeries(0).should.equal red
chart.strokeWidthForSeries(1).should.equal 2
chart.strokeForSeries(1).should.equal blue