-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from antvis/fix-issue-57
fix: set min and max for interval is not work. Closed #57
- Loading branch information
Showing
5 changed files
with
221 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>环图</title> | ||
<link rel="stylesheet" href="./assets/common.css"> | ||
</head> | ||
<body> | ||
<div> | ||
<canvas id="mountNode" style="position: relative;"> | ||
</canvas> | ||
</div> | ||
<script src="./assets/jquery-3.2.1.min.js"></script> | ||
<script src="../build/f2.js"></script> | ||
<script> | ||
const data = [ | ||
{ x: '1', y: 85 } | ||
]; | ||
const chart = new F2.Chart({ | ||
id: 'mountNode', | ||
width: window.innerWidth, | ||
height: window.innerWidth * 0.64, | ||
pixelRatio: window.devicePixelRatio | ||
}); | ||
chart.source(data, { | ||
y: { | ||
max: 100, | ||
min: 0 | ||
} | ||
}); | ||
chart.axis(false); | ||
chart.coord('polar', { | ||
transposed: true, | ||
innerRadius: 0.8 | ||
}); | ||
chart.guide().arc({ | ||
start: [ 0, 0 ], | ||
end: [ 1, 99.98 ], | ||
top: false, | ||
style: { | ||
lineWidth: 20, | ||
stroke: '#ccc' | ||
} | ||
}); | ||
chart.guide().text({ | ||
position: [ '50%', '50%' ], | ||
content: '85%', | ||
style: { | ||
fontSize: 45, | ||
fill: '#1890FF' | ||
} | ||
}) | ||
chart.interval() | ||
.position('x*y') | ||
.size(20) | ||
.animate({ | ||
appear: { | ||
duration: 1500 | ||
} | ||
}); | ||
chart.render(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
const expect = require('chai').expect; | ||
|
||
const F2 = require('../../src/core'); | ||
require('../../src/geom/interval'); | ||
require('../../src/coord/polar'); // 极坐标系 | ||
require('../../src/geom/adjust/stack'); | ||
require('../../src/component/guide/arc'); | ||
const Guide = require('../../src/plugin/guide'); | ||
|
||
const canvas = document.createElement('canvas'); | ||
canvas.width = 500; | ||
canvas.height = 500; | ||
canvas.id = 'colDefs'; | ||
document.body.appendChild(canvas); | ||
|
||
describe('colDefs', () => { | ||
let chart; | ||
let data; | ||
|
||
it('定义了 min 和 max 的柱状图', function() { | ||
data = [ | ||
{ time: '周一', tem: 6.9, rain: 10 }, | ||
{ time: '周二', tem: 9.5, rain: 13 }, | ||
{ time: '周三', tem: 14.5, rain: 14 }, | ||
{ time: '周四', tem: 18.2, rain: 10 }, | ||
{ time: '周五', tem: 21.5, rain: 12 }, | ||
{ time: '周六', tem: 25.2, rain: 16 }, | ||
{ time: '周日', tem: 26.5, rain: 13 } | ||
]; | ||
chart = new F2.Chart({ | ||
id: 'colDefs', | ||
pixelRatio: window.devicePixelRatio | ||
}); | ||
|
||
chart.source(data, { | ||
tem: { | ||
min: 0, | ||
max: 80 | ||
} | ||
}); | ||
|
||
// 配置刻度文字大小,供PC端显示用(移动端可以使用默认值20px) | ||
chart.axis('time', { | ||
label: { | ||
fontSize: 14 | ||
}, | ||
grid: null | ||
}); | ||
chart.axis('tem', { | ||
label: { | ||
fontSize: 14 | ||
} | ||
}); | ||
chart.axis('rain', { | ||
label: { | ||
fontSize: 14 | ||
} | ||
}); | ||
chart.interval().position('time*tem'); | ||
chart.render(); | ||
|
||
const yScale = chart.getYScales()[0]; | ||
expect(yScale.min).to.equal(0); | ||
expect(yScale.max).to.equal(80); | ||
chart.destroy(); | ||
}); | ||
|
||
it('设置了 max 的极坐标转置下的柱状图', function() { | ||
data = [ | ||
{ x: '1', y: 85 } | ||
]; | ||
chart = new F2.Chart({ | ||
id: 'colDefs', | ||
pixelRatio: window.devicePixelRatio, | ||
plugins: Guide | ||
}); | ||
chart.source(data, { | ||
y: { | ||
max: 100, | ||
min: 0 | ||
} | ||
}); | ||
chart.axis(false); | ||
chart.coord('polar', { | ||
transposed: true, | ||
innerRadius: 0.8 | ||
}); | ||
chart.guide().arc({ | ||
start: [ 0, 0 ], | ||
end: [ 1, 99.98 ], | ||
top: false, | ||
style: { | ||
lineWidth: 20, | ||
stroke: '#ccc' | ||
} | ||
}); | ||
chart.interval() | ||
.position('x*y') | ||
.size(20) | ||
.animate({ | ||
appear: { | ||
duration: 1500 | ||
} | ||
}); | ||
chart.render(); | ||
const yScale = chart.getYScales()[0]; | ||
expect(yScale.min).to.equal(0); | ||
expect(yScale.max).to.equal(100); | ||
chart.destroy(); | ||
}); | ||
|
||
it('饼图设置了 max', function() { | ||
data = [ | ||
{ a: '1', b: 0.3, c: '1' }, | ||
{ a: '1', b: 0.3, c: '2' }, | ||
{ a: '1', b: 0.4, c: '3' } | ||
]; | ||
|
||
chart = new F2.Chart({ | ||
id: 'colDefs', | ||
pixelRatio: window.devicePixelRatio | ||
}); | ||
|
||
chart.source(data, { | ||
b: { | ||
max: 100 | ||
} | ||
}); | ||
|
||
chart.coord('polar', { | ||
transposed: true, | ||
inner: 0 | ||
}); | ||
|
||
chart.axis(false); | ||
chart.interval() | ||
.position('a*b') | ||
.color('c') | ||
.adjust('stack'); | ||
chart.render(); | ||
|
||
const yScale = chart.getYScales()[0]; | ||
expect(yScale.min).to.equal(0); | ||
expect(yScale.max).to.equal(1); | ||
chart.destroy(); | ||
document.body.removeChild(canvas); | ||
}); | ||
}); |