mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Start building up the spec coverage. Fix hover label bug (yay, specs!)
This commit is contained in:
parent
69f949b132
commit
5ae2dfc478
@ -192,7 +192,7 @@ class Morris.Line extends Morris.Grid
|
|||||||
@hoverSet.push(@hover)
|
@hoverSet.push(@hover)
|
||||||
@hoverSet.push(@xLabel)
|
@hoverSet.push(@xLabel)
|
||||||
@yLabels = []
|
@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, '')
|
yLabel = @r.text(0, @options.hoverFontSize * 1.5 * (i + 1.5) - @hoverHeight / 2, '')
|
||||||
.attr('fill', @colorForSeries(i))
|
.attr('fill', @colorForSeries(i))
|
||||||
.attr('font-size', @options.hoverFontSize)
|
.attr('font-size', @options.hoverFontSize)
|
||||||
|
@ -812,7 +812,7 @@
|
|||||||
this.hoverSet.push(this.xLabel);
|
this.hoverSet.push(this.xLabel);
|
||||||
this.yLabels = [];
|
this.yLabels = [];
|
||||||
_results = [];
|
_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);
|
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);
|
this.yLabels.push(yLabel);
|
||||||
_results.push(this.hoverSet.push(yLabel));
|
_results.push(this.hoverSet.push(yLabel));
|
||||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
67
spec/lib/line/set_data_spec.coffee
Normal file
67
spec/lib/line/set_data_spec.coffee
Normal 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
|
||||||
|
|
@ -1,16 +1,5 @@
|
|||||||
describe 'Morris.Line', ->
|
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', ->
|
it 'should raise an error when the placeholder element is not found', ->
|
||||||
my_data = [{x: 1, y: 1}, {x: 2, y: 2}]
|
my_data = [{x: 1, y: 1}, {x: 2, y: 2}]
|
||||||
fn = ->
|
fn = ->
|
||||||
|
Loading…
Reference in New Issue
Block a user