Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(funnel): 支持尖底漏斗图以及样式设置 (#2634)
* docs(funnel): 补充漏斗图动态高度的文档说明 * refactor(funnel): 漏斗图抽取 constant 以及暴露常用的字段作为静态属性 * feat(funnel): 基础漏斗图支持shape设置金字塔以及支持 funnelStyle 设置 * docs: 添加尖底漏斗图 demo * feat(mix-plot): 多图层图表增加 funnel & 添加复合漏斗图 demo * test(funnel): 增加漏斗图单测
- Loading branch information
Showing
20 changed files
with
433 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Funnel, FUNNEL_CONVERSATION_FIELD } from '../../../../src'; | ||
import { DEFAULT_OPTIONS } from '../../../../src/plots/funnel/constant'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('funnel', () => { | ||
const data = [ | ||
{ stage: '简历筛选', number: 253 }, | ||
{ stage: '初试人数', number: 151 }, | ||
{ stage: '复试人数', number: 113 }, | ||
{ stage: '录取人数', number: 87 }, | ||
{ stage: '入职人数', number: 59 }, | ||
]; | ||
|
||
const plot = new Funnel(createDiv(), { | ||
data: data, | ||
xField: 'stage', | ||
yField: 'number', | ||
legend: false, | ||
}); | ||
|
||
plot.render(); | ||
|
||
it('defaultOptions', () => { | ||
expect(plot.type).toBe('funnel'); | ||
|
||
expect(Funnel.getDefaultOptions()).toEqual(DEFAULT_OPTIONS); | ||
// @ts-ignore | ||
expect(plot.getDefaultOptions()).toEqual(DEFAULT_OPTIONS); | ||
}); | ||
|
||
it('static properties', () => { | ||
expect(Funnel.CONVERSATION_FIELD).toBeDefined(); | ||
// 兼容旧的 | ||
expect(Funnel.CONVERSATION_FIELD).toBe(FUNNEL_CONVERSATION_FIELD); | ||
expect(Funnel.PERCENT_FIELD).toBeDefined(); | ||
expect(Funnel.TOTAL_PERCENT_FIELD).toBeDefined(); | ||
}); | ||
}); |
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,52 @@ | ||
import { Funnel } from '../../../../src'; | ||
import { PV_DATA_COMPARE } from '../../../data/conversion'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('funnel', () => { | ||
const plot = new Funnel(createDiv(), { | ||
data: PV_DATA_COMPARE, | ||
autoFit: true, | ||
xField: 'action', | ||
yField: 'pv', | ||
minSize: 0.3, | ||
maxSize: 0.8, | ||
funnelStyle: { | ||
fill: 'red', | ||
}, | ||
}); | ||
|
||
plot.render(); | ||
|
||
it('default', () => { | ||
expect(plot.type).toBe('funnel'); | ||
|
||
const geometry = plot.chart.geometries[0]; | ||
const elements = geometry.elements; | ||
expect(elements[0].shape.attr('fill')).toEqual('red'); | ||
|
||
plot.update({ funnelStyle: () => ({ fill: 'red', stroke: 'blue' }) }); | ||
expect(plot.chart.geometries[0].elements[0].shape.attr('stroke')).toEqual('blue'); | ||
}); | ||
|
||
it('对比漏斗图', () => { | ||
plot.update({ compareField: 'quarter' }); | ||
expect(plot.chart.views.length).toEqual(2); | ||
|
||
const geometry = plot.chart.views[0].geometries[0]; | ||
const elements = geometry.elements; | ||
expect(elements[0].shape.attr('fill')).toEqual('red'); | ||
expect(elements[0].shape.attr('stroke')).toEqual('blue'); | ||
expect(elements[0].shape.attr('lineWidth')).toEqual(1); | ||
|
||
plot.update({ funnelStyle: undefined }); | ||
// 还原默认 | ||
expect(plot.chart.views[0].geometries[0].elements[0].shape.attr('stroke')).toEqual('#fff'); | ||
|
||
plot.update({ funnelStyle: { stroke: 'yellow' } }); | ||
expect(plot.chart.views[0].geometries[0].elements[0].shape.attr('stroke')).toEqual('yellow'); | ||
|
||
// function | ||
plot.update({ funnelStyle: () => ({ stroke: 'blue' }) }); | ||
expect(plot.chart.views[0].geometries[0].elements[0].shape.attr('stroke')).toEqual('blue'); | ||
}); | ||
}); |
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
Oops, something went wrong.