mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-11 05:46:37 +01:00
Fix createPath bug.
This commit is contained in:
parent
0bce4d3076
commit
0068e54c4b
@ -173,9 +173,9 @@ class Morris.Line extends Morris.Grid
|
|||||||
lg = grads[i - 1]
|
lg = grads[i - 1]
|
||||||
ix = (coord.x - prevCoord.x) / 4
|
ix = (coord.x - prevCoord.x) / 4
|
||||||
x1 = prevCoord.x + ix
|
x1 = prevCoord.x + ix
|
||||||
y1 = Math.max(bottom, prevCoord.y + ix * lg)
|
y1 = Math.min(bottom, prevCoord.y + ix * lg)
|
||||||
x2 = coord.x - ix
|
x2 = coord.x - ix
|
||||||
y2 = Math.max(bottom, coord.y - ix * g)
|
y2 = Math.min(bottom, coord.y - ix * g)
|
||||||
path += "C#{x1},#{y1},#{x2},#{y2},#{coord.x},#{coord.y}"
|
path += "C#{x1},#{y1},#{x2},#{y2},#{coord.x},#{coord.y}"
|
||||||
else
|
else
|
||||||
path += "L#{coord.x},#{coord.y}"
|
path += "L#{coord.x},#{coord.y}"
|
||||||
|
@ -683,9 +683,9 @@
|
|||||||
lg = grads[i - 1];
|
lg = grads[i - 1];
|
||||||
ix = (coord.x - prevCoord.x) / 4;
|
ix = (coord.x - prevCoord.x) / 4;
|
||||||
x1 = prevCoord.x + ix;
|
x1 = prevCoord.x + ix;
|
||||||
y1 = Math.max(bottom, prevCoord.y + ix * lg);
|
y1 = Math.min(bottom, prevCoord.y + ix * lg);
|
||||||
x2 = coord.x - ix;
|
x2 = coord.x - ix;
|
||||||
y2 = Math.max(bottom, coord.y - ix * g);
|
y2 = Math.min(bottom, coord.y - ix * g);
|
||||||
path += "C" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + coord.x + "," + coord.y;
|
path += "C" + x1 + "," + y1 + "," + x2 + "," + y2 + "," + coord.x + "," + coord.y;
|
||||||
} else {
|
} else {
|
||||||
path += "L" + coord.x + "," + coord.y;
|
path += "L" + coord.x + "," + coord.y;
|
||||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
@ -119,25 +119,25 @@ describe 'Morris.Line', ->
|
|||||||
|
|
||||||
it 'should generate a smooth line', ->
|
it 'should generate a smooth line', ->
|
||||||
testData = [{x: 0, y: 10}, {x: 10, y: 0}, {x: 20, y: 10}]
|
testData = [{x: 0, y: 10}, {x: 10, y: 0}, {x: 20, y: 10}]
|
||||||
path = Morris.Line.createPath(testData, true, 0)
|
path = Morris.Line.createPath(testData, true, 20)
|
||||||
path.should.equal 'M0,10C2.5,7.5,7.5,0,10,0C12.5,0,17.5,7.5,20,10'
|
path.should.equal 'M0,10C2.5,7.5,7.5,0,10,0C12.5,0,17.5,7.5,20,10'
|
||||||
|
|
||||||
it 'should generate a jagged line', ->
|
it 'should generate a jagged line', ->
|
||||||
testData = [{x: 0, y: 10}, {x: 10, y: 0}, {x: 20, y: 10}]
|
testData = [{x: 0, y: 10}, {x: 10, y: 0}, {x: 20, y: 10}]
|
||||||
path = Morris.Line.createPath(testData, false, 0)
|
path = Morris.Line.createPath(testData, false, 20)
|
||||||
path.should.equal 'M0,10L10,0L20,10'
|
path.should.equal 'M0,10L10,0L20,10'
|
||||||
|
|
||||||
it 'should prevent paths from descending below the bottom of the chart', ->
|
it 'should prevent paths from descending below the bottom of the chart', ->
|
||||||
testData = [{x: 0, y: 20}, {x: 10, y: 10}, {x: 20, y: 30}]
|
testData = [{x: 0, y: 20}, {x: 10, y: 30}, {x: 20, y: 10}]
|
||||||
path = Morris.Line.createPath(testData, true, 10)
|
path = Morris.Line.createPath(testData, true, 30)
|
||||||
path.should.equal 'M0,20C2.5,17.5,7.5,10,10,10C12.5,11.25,17.5,25,20,30'
|
path.should.equal 'M0,20C2.5,22.5,7.5,30,10,30C12.5,28.75,17.5,15,20,10'
|
||||||
|
|
||||||
it 'should break the line at null values', ->
|
it 'should break the line at null values', ->
|
||||||
testData = [{x: 0, y: 10}, {x: 10, y: 0}, {x: 20, y: null}, {x: 30, y: 10}, {x: 40, y: 0}]
|
testData = [{x: 0, y: 10}, {x: 10, y: 0}, {x: 20, y: null}, {x: 30, y: 10}, {x: 40, y: 0}]
|
||||||
path = Morris.Line.createPath(testData, true, 0)
|
path = Morris.Line.createPath(testData, true, 20)
|
||||||
path.should.equal 'M0,10C2.5,7.5,7.5,2.5,10,0M30,10C32.5,7.5,37.5,2.5,40,0'
|
path.should.equal 'M0,10C2.5,7.5,7.5,2.5,10,0M30,10C32.5,7.5,37.5,2.5,40,0'
|
||||||
|
|
||||||
it 'should ignore leading and trailing null values', ->
|
it 'should ignore leading and trailing null values', ->
|
||||||
testData = [{x: 0, y: null}, {x: 10, y: 10}, {x: 20, y: 0}, {x: 30, y: 10}, {x: 40, y: null}]
|
testData = [{x: 0, y: null}, {x: 10, y: 10}, {x: 20, y: 0}, {x: 30, y: 10}, {x: 40, y: null}]
|
||||||
path = Morris.Line.createPath(testData, true, 0)
|
path = Morris.Line.createPath(testData, true, 20)
|
||||||
path.should.equal 'M10,10C12.5,7.5,17.5,0,20,0C22.5,0,27.5,7.5,30,10'
|
path.should.equal 'M10,10C12.5,7.5,17.5,0,20,0C22.5,0,27.5,7.5,30,10'
|
||||||
|
Loading…
Reference in New Issue
Block a user