Start building up the spec coverage. Fix hover label bug (yay, specs!)

This commit is contained in:
Olly Smith 2012-10-25 08:23:20 +01:00
parent 69f949b132
commit 5ae2dfc478
5 changed files with 70 additions and 14 deletions

View File

@ -192,7 +192,7 @@ class Morris.Line extends Morris.Grid
@hoverSet.push(@hover)
@hoverSet.push(@xLabel)
@yLabels = []
for i in [0...@data.length]
for i in [0...@options.ykeys.length]
yLabel = @r.text(0, @options.hoverFontSize * 1.5 * (i + 1.5) - @hoverHeight / 2, '')
.attr('fill', @colorForSeries(i))
.attr('font-size', @options.hoverFontSize)

View File

@ -812,7 +812,7 @@
this.hoverSet.push(this.xLabel);
this.yLabels = [];
_results = [];
for (i = _i = 0, _ref = this.data.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
for (i = _i = 0, _ref = this.options.ykeys.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
yLabel = this.r.text(0, this.options.hoverFontSize * 1.5 * (i + 1.5) - this.hoverHeight / 2, '').attr('fill', this.colorForSeries(i)).attr('font-size', this.options.hoverFontSize);
this.yLabels.push(yLabel);
_results.push(this.hoverSet.push(yLabel));

2
morris.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,67 @@
describe 'Morris.Line data', ->
it 'should not alter user-supplied data', ->
my_data = [{x: 1, y: 1}, {x: 2, y: 2}]
expected_data = [{x: 1, y: 1}, {x: 2, y: 2}]
Morris.Line
element: 'graph'
data: my_data
xkey: 'x'
ykeys: ['y']
labels: ['dontcare']
my_data.should.deep.equal expected_data
describe 'ymin/ymax', ->
it 'should use a user-specified minimum and maximum value', ->
line = Morris.Line
element: 'graph'
data: [{x: 1, y: 1}]
xkey: 'x'
ykeys: ['y', 'z']
labels: ['y', 'z']
ymin: 10
ymax: 20
line.ymin.should.equal 10
line.ymax.should.equal 20
describe 'auto', ->
it 'should automatically calculate the minimum and maximum value', ->
line = Morris.Line
element: 'graph'
data: [{x: 1, y: 10}, {x: 2, y: 15}, {x: 3, y: null}, {x: 4}]
xkey: 'x'
ykeys: ['y', 'z']
labels: ['y', 'z']
ymin: 'auto'
ymax: 'auto'
line.ymin.should.equal 10
line.ymax.should.equal 15
describe 'auto [n]', ->
it 'should automatically calculate the minimum and maximum value', ->
line = Morris.Line
element: 'graph'
data: [{x: 1, y: 10}, {x: 2, y: 15}, {x: 3, y: null}, {x: 4}]
xkey: 'x'
ykeys: ['y', 'z']
labels: ['y', 'z']
ymin: 'auto 12'
ymax: 'auto 12'
line.ymin.should.equal 10
line.ymax.should.equal 15
it 'should use a user-specified minimum and maximum value', ->
line = Morris.Line
element: 'graph'
data: [{x: 1, y: 10}, {x: 2, y: 15}, {x: 3, y: null}, {x: 4}]
xkey: 'x'
ykeys: ['y', 'z']
labels: ['y', 'z']
ymin: 'auto 5'
ymax: 'auto 20'
line.ymin.should.equal 5
line.ymax.should.equal 20

View File

@ -1,16 +1,5 @@
describe 'Morris.Line', ->
it 'should not alter user-supplied data', ->
my_data = [{x: 1, y: 1}, {x: 2, y: 2}]
expected_data = [{x: 1, y: 1}, {x: 2, y: 2}]
Morris.Line
element: 'graph'
data: my_data
xkey: 'x'
ykeys: ['y']
labels: ['dontcare']
my_data.should.deep.equal expected_data
it 'should raise an error when the placeholder element is not found', ->
my_data = [{x: 1, y: 1}, {x: 2, y: 2}]
fn = ->