Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: 修复之前v2-bullet合并问题 * feat: 增加支持垂直方向的子弹图
- Loading branch information
Showing
11 changed files
with
186 additions
and
23 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
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,72 @@ | ||
import { Bullet } from '../../../../src'; | ||
import { bulletDatas } from '../../../data/bullet'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('bullet*label', () => { | ||
it('layout*default*horizontal', () => { | ||
const bullet = new Bullet(createDiv('layout*default*horizontal bullet'), { | ||
width: 400, | ||
height: 400, | ||
data: bulletDatas, | ||
measureField: 'measures', | ||
rangeField: 'ranges', | ||
targetField: 'target', | ||
xField: 'title', | ||
}); | ||
|
||
bullet.render(); | ||
|
||
const chart = bullet.chart; | ||
const [rangeGeometry, measureGeometry, targetGeometry] = chart.geometries; | ||
expect(rangeGeometry.getAdjust('stack')).toMatchObject({ | ||
xField: 'title', | ||
yField: 'ranges', | ||
}); | ||
expect(measureGeometry.getAdjust('stack')).toMatchObject({ | ||
xField: 'title', | ||
yField: 'measures', | ||
}); | ||
// @ts-ignore 默认水平的时候会转换坐标轴 | ||
expect(chart.getCoordinate().isTransposed).toBe(true); | ||
const shapeArr = []; | ||
const elements = targetGeometry.elements; | ||
elements.forEach((ele) => { | ||
shapeArr.push(ele.getModel().shape); | ||
}); | ||
expect(shapeArr).toContain('line'); | ||
}); | ||
|
||
it('layout vertical', () => { | ||
const bullet = new Bullet(createDiv('layout*vertical bullet'), { | ||
width: 400, | ||
height: 400, | ||
data: bulletDatas, | ||
measureField: 'measures', | ||
rangeField: 'ranges', | ||
targetField: 'target', | ||
xField: 'title', | ||
layout: 'vertical', | ||
}); | ||
|
||
bullet.render(); | ||
|
||
const chart = bullet.chart; | ||
const [rangeGeometry, measureGeometry, targetGeometry] = chart.geometries; | ||
expect(rangeGeometry.getAdjust('stack')).toMatchObject({ | ||
xField: 'title', | ||
yField: 'ranges', | ||
}); | ||
expect(measureGeometry.getAdjust('stack')).toMatchObject({ | ||
xField: 'title', | ||
yField: 'measures', | ||
}); | ||
// @ts-ignore 垂直的时候不会转换坐标轴 | ||
expect(chart.getCoordinate().isTransposed).toBe(false); | ||
const shapeArr = []; | ||
const elements = targetGeometry.elements; | ||
elements.forEach((ele) => { | ||
shapeArr.push(ele.getModel().shape); | ||
}); | ||
expect(shapeArr).toContain('hyphen'); | ||
}); | ||
}); |
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,49 @@ | ||
import { Bullet } from '@antv/g2plot'; | ||
|
||
const data = [ | ||
{ | ||
title: '满意度', | ||
ranges: [100], | ||
measures: [80], | ||
target: 85, | ||
}, | ||
]; | ||
|
||
// @TODO 差一张垂直方向的缩略图 | ||
const bulletPlot = new Bullet('container', { | ||
data, | ||
measureField: 'measures', | ||
rangeField: 'ranges', | ||
targetField: 'target', | ||
xField: 'title', | ||
xAxis: { | ||
line: null, | ||
}, | ||
yAxis: false, | ||
layout: 'vertical', | ||
label: { | ||
position: 'middle', | ||
style: { | ||
fill: '#fff', | ||
}, | ||
}, | ||
// 自定义 legend | ||
legend: { | ||
custom: true, | ||
position: 'bottom', | ||
items: [ | ||
{ | ||
value: '实际值', | ||
name: '实际值', | ||
marker: { symbol: 'square', style: { fill: '#5B8FF9', r: 5 } }, | ||
}, | ||
{ | ||
value: '目标值', | ||
name: '目标值', | ||
marker: { symbol: 'line', style: { stroke: '#5B8FF9', r: 5 } }, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
bulletPlot.render(); |
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
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