Commit ba943737 by ChenXiHi

桑基图

parent 0cc6d2ac
import { getLabel, getLegend, getPadding, getTheme, getTooltip } from '@/views/chart/chart/common/common_antv'
import { getLabel, getLegend, getPadding, getTheme, getTooltip, getXAxis } from '@/views/chart/chart/common/common_antv'
import { Sankey } from '@antv/g2plot'
import { antVCustomColor } from '@/views/chart/chart/util'
export function baseSankeyOptionAntV(plot, container, chart, action) {
// theme
const theme = getTheme(chart)
// attr
const label = getLabel(chart)
const tooltip = getTooltip(chart)
// style
const legend = getLegend(chart)
// data
// const data = chart.data.data
console.log(
'plot, container, chart, action', plot, container, chart, action
)
const data = [
{
'Survived': 'Perished',
'Sex': 'Male',
'Age': 'Adult',
'Class': 'Crew',
'value': 670
},
{
'Survived': 'Perished',
'Sex': 'Male',
'Age': 'Adult',
'Class': 'Third Class',
'value': 387
},
{
'Survived': 'Perished',
'Sex': 'Male',
'Age': 'Adult',
'Class': 'Second Class',
'value': 154
},
{
'Survived': 'Perished',
'Sex': 'Male',
'Age': 'Adult',
'Class': 'First Class',
'value': 118
},
{
'Survived': 'Perished',
'Sex': 'Male',
'Age': 'Child',
'Class': 'Third Class',
'value': 35
},
{
'Survived': 'Perished',
'Sex': 'Female',
'Age': 'Adult',
'Class': 'Crew',
'value': 3
},
{
'Survived': 'Perished',
'Sex': 'Female',
'Age': 'Adult',
'Class': 'Third Class',
'value': 89
},
{
'Survived': 'Perished',
'Sex': 'Female',
'Age': 'Adult',
'Class': 'Second Class',
'value': 13
},
{
'Survived': 'Perished',
'Sex': 'Female',
'Age': 'Adult',
'Class': 'First Class',
'value': 4
},
{
'Survived': 'Perished',
'Sex': 'Female',
'Age': 'Child',
'Class': 'Third Class',
'value': 17
},
{
'Survived': 'Survived',
'Sex': 'Male',
'Age': 'Adult',
'Class': 'Crew',
'value': 192
},
{
'Survived': 'Survived',
'Sex': 'Male',
'Age': 'Adult',
'Class': 'Third Class',
'value': 75
},
{
'Survived': 'Survived',
'Sex': 'Male',
'Age': 'Adult',
'Class': 'Second Class',
'value': 14
},
{
'Survived': 'Survived',
'Sex': 'Male',
'Age': 'Adult',
'Class': 'First Class',
'value': 57
},
{
'Survived': 'Survived',
'Sex': 'Male',
'Age': 'Child',
'Class': 'Third Class',
'value': 13
},
{
'Survived': 'Survived',
'Sex': 'Male',
'Age': 'Child',
'Class': 'Second Class',
'value': 11
},
{
'Survived': 'Survived',
'Sex': 'Male',
'Age': 'Child',
'Class': 'First Class',
'value': 5
},
{
'Survived': 'Survived',
'Sex': 'Female',
'Age': 'Adult',
'Class': 'Crew',
'value': 20
},
{
'Survived': 'Survived',
'Sex': 'Female',
'Age': 'Adult',
'Class': 'Third Class',
'value': 76
},
{
'Survived': 'Survived',
'Sex': 'Female',
'Age': 'Adult',
'Class': 'Second Class',
'value': 80
},
{
'Survived': 'Survived',
'Sex': 'Female',
'Age': 'Adult',
'Class': 'First Class',
'value': 140
},
{
'Survived': 'Survived',
'Sex': 'Female',
'Age': 'Child',
'Class': 'Third Class',
'value': 14
},
{
'Survived': 'Survived',
'Sex': 'Female',
'Age': 'Child',
'Class': 'Second Class',
'value': 13
},
{
'Survived': 'Survived',
'Sex': 'Female',
'Age': 'Child',
'Class': 'First Class',
'value': 1
}
]
const data = chart.data.tableRow
const sankeyData = []
const keys = ['Survived', 'Sex', 'Age', 'Class']
data.forEach((d) => {
keys.reduce((a, b) => {
if (a && b) {
sankeyData.push({
source: d[a],
target: d[b],
value: d.value,
path: `${d[keys[0]]} -> ${d[keys[1]]} -> ${d[keys[2]]} -> ${d[keys[3]]}`
})
}
return b
})
}
)
console.log('sankeyData==', sankeyData)
const valueName = chart.data.fields.find((item) => { return item.originName === 'value' })
const keys = chart.data.fields.map((v) => {
if (v.originName !== 'value') {
return v.dataeaseName
}
}).filter((i) => i)
if (data && keys.length > 0) {
data.forEach((d) => {
keys.reduce((a, b) => {
if (a && b) {
sankeyData.push({
source: d[a],
target: d[b],
value: d[valueName.dataeaseName],
path: keys.map((item) => {
const num = []
num.push(d[item])
return num
}).join('->')
})
}
return b
})
}
)
}
// options
const options = {
theme: theme,
......@@ -231,8 +64,8 @@ export function baseSankeyOptionAntV(plot, container, chart, action) {
plot.destroy()
}
plot = new Sankey(container, options)
plot.off('interval:click')
plot.on('interval:click', action)
// plot.off('interval:click')
// plot.on('interval:click', action)
return plot
}
......@@ -1914,7 +1914,6 @@ export const TYPE_CONFIGS = [
properties: [
'color-selector',
'label-selector-ant-v',
'tooltip-selector-ant-v',
'title-selector-ant-v',
'legend-selector-ant-v'
],
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论