-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sankey): 桑基图支持 state 配置 (#2757)
* feat(sankey): 桑基图支持 state 配置 新增 nodeState & edgeState ✅ 文档 * test(sankey): 增加桑基图文本样式修改
- Loading branch information
Showing
8 changed files
with
204 additions
and
13 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,65 @@ | ||
import { Datum, Sankey } from '../../../../src'; | ||
import { createDiv, removeDom } from '../../../utils/dom'; | ||
import { ENERGY_RELATIONS } from '../../../data/sankey-energy'; | ||
import { EDGES_VIEW_ID, NODES_VIEW_ID } from '../../../../src/plots/sankey/constant'; | ||
|
||
describe('sankey', () => { | ||
const div = createDiv(); | ||
const sankey = new Sankey(div, { | ||
height: 500, | ||
data: ENERGY_RELATIONS, | ||
sourceField: 'source', | ||
targetField: 'target', | ||
weightField: 'value', | ||
}); | ||
|
||
sankey.render(); | ||
it('state', () => { | ||
sankey.update({ | ||
nodeState: { | ||
active: { | ||
style: { | ||
fill: 'red', | ||
}, | ||
}, | ||
selected: { | ||
style: { | ||
stroke: 'red', | ||
}, | ||
}, | ||
}, | ||
edgeState: { | ||
active: { | ||
style: { | ||
fill: 'blue', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
sankey.setState('active', (datum: Datum) => { | ||
return datum.isNode; | ||
}); | ||
|
||
let elements = sankey.chart.views.find((v) => v.id === NODES_VIEW_ID).geometries[0].elements; | ||
elements.forEach((element) => expect(element.shape.attr('fill')).toBe('red')); | ||
|
||
sankey.setState('selected', (datum: Datum) => { | ||
return datum.isNode; | ||
}); | ||
|
||
elements = sankey.chart.views.find((v) => v.id === NODES_VIEW_ID).geometries[0].elements; | ||
elements.forEach((element) => expect(element.shape.attr('stroke')).toBe('red')); | ||
|
||
sankey.setState('active', (datum: Datum) => { | ||
return !datum.isNode; | ||
}); | ||
elements = sankey.chart.views.find((v) => v.id === EDGES_VIEW_ID).geometries[0].elements; | ||
elements.forEach((element) => expect(element.shape.attr('fill')).toBe('blue')); | ||
}); | ||
|
||
afterAll(() => { | ||
sankey.destroy(); | ||
removeDom(div); | ||
}); | ||
}); |
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,40 @@ | ||
import { Sankey } from '@antv/g2plot'; | ||
|
||
const DATA = [ | ||
{ source1: '首次打开', target: '首页 UV', value: 160 }, | ||
{ source1: '结果页', target: '首页 UV', value: 40 }, | ||
{ source1: '验证页', target: '首页 UV', value: 10 }, | ||
{ source1: '我的', target: '首页 UV', value: 10 }, | ||
{ source1: '朋友', target: '首页 UV', value: 8 }, | ||
{ source1: '其他来源', target: '首页 UV', value: 27 }, | ||
{ source1: '首页 UV', target: '理财', value: 30 }, | ||
{ source1: '首页 UV', target: '扫一扫', value: 40 }, | ||
{ source1: '首页 UV', target: '服务', value: 35 }, | ||
{ source1: '首页 UV', target: '蚂蚁森林', value: 25 }, | ||
{ source1: '首页 UV', target: '跳失', value: 10 }, | ||
{ source1: '首页 UV', target: '借呗', value: 30 }, | ||
{ source1: '首页 UV', target: '花呗', value: 40 }, | ||
{ source1: '首页 UV', target: '其他流向', value: 45 }, | ||
]; | ||
|
||
const sankey = new Sankey('container', { | ||
data: DATA, | ||
sourceField: 'source1', | ||
targetField: 'target', | ||
weightField: 'value', | ||
nodeWidthRatio: 0.018, | ||
nodePaddingRatio: 0.03, | ||
nodeState: { | ||
active: { | ||
style: { | ||
linewidth: 1.5 | ||
} | ||
} | ||
}, | ||
tooltip: { showTitle: true } | ||
}); | ||
|
||
sankey.render(); | ||
sankey.setState('active', (datum) => { | ||
return datum.isNode && datum.name === '首次打开' | ||
}); |
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