graphChart.vue
3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<div>
<basic ref="basic" :chartId="chartId" :chartData="chartData"></basic>
</div>
</template>
<script>
import mixin from "./mixin";
import _ from "underscore";
export default {
mixins: [mixin],
data() {
return {};
},
methods: {
/**
* 预处理option参数
* */
preChartData(cdata) {
return cdata;
},
/**
* 处理option参数
* */
dealChartData(optionFormat) {
/*********格式化自定义的 y 轴*****************/
optionFormat.legend = Object.assign({},{
show:true,
orient: "horizontal",
itemWidth: 12,
itemHeight: 12,
itemGap: 10,
bottom: 0
});
optionFormat.tooltip = optionFormat.tooltip||{
show:true
};
//optionFormat.tooltip.formatter = '{a}, {b},{c},{d},{e}';
optionFormat.series = _.map(optionFormat.series, item => {
_.each(item.data.nodes,(node,index)=>{
let source = _.pluck(_.filter(item.data.links,{sourceId:node.id}),'value');
let target = _.pluck(_.filter(item.data.links,{targetId:node.id}),'value');
node.source = _.reduce(source, function(memo, num){ return memo + num; }, 0);
node.target = _.reduce(target, function(memo, num){ return memo + num; }, 0);
node.value = node.source + node.target;
});
let maxNVal = _.max(item.data.nodes,(node)=>node.value).value;
_.each(item.data.nodes,(node,index)=>{
let min = 6,max=30;
let size = Math.round(max*node.value/maxNVal);
let symbolSize = size<min?min:size>max?max:size;
node.symbolSize = symbolSize;
})
let maxVal = _.max(item.data.links,(link)=>link.value).value;
_.each(item.data.links,(link,index)=>{
let max = 15;
let width = Math.round(max*link.value/maxVal);
link.lineStyle={
width:width||1
}
});
return {
name: item.title,
type: 'graph',
layout: 'circular',
force:{
repulsion:100,
gravity:0.1,
edgeLength: [10, 50],
layoutAnimation:false
},
circular: {
rotateLabel: true
},
data: item.data.nodes,
links: item.data.links,
categories: item.data.categories,
roam: true,
label: {
show:true,
position: 'right',
formatter: '{b}',
},
lineStyle: {
width:1,
color: 'source',
curveness: 0.3
}
}
});
// 覆盖格式化后的`option`数据 按需修改
let coverTemp = {
grid: {
left: 0,
right: 0,
top: 0,
bottom: 20,
}
};
const _that = this;
let option = JSON.parse(
JSON.stringify({ ...optionFormat, ...coverTemp })
);
return option;
},
},
created() { },
};
</script>
<style scoped>
</style>