-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualize.scala
134 lines (110 loc) · 4.63 KB
/
Visualize.scala
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import model.{Person, Link}
import org.apache.spark.graphx.{Edge, Graph}
import org.graphstream.graph.implementations._
import org.graphstream.graph.{Graph => GraphStream}
/**
* Created by mac on 3/25/16.
* 个性化可视化功能模块.
*/
object Visualize {
/*
可视化显示顶点的ID和名称.
*/
def displayGraphWithIdAndName(graph:Graph[Person,Link],name:String):SingleGraph={
val graphStream:SingleGraph = new SingleGraph(name);
// Set up the visual attributes for graph visualization
graphStream.addAttribute("ui.stylesheet","url(./style/stylesheet.css)")
graphStream.addAttribute("ui.quality") //to enable slower but better rendering.
graphStream.addAttribute("ui.antialias") //to enable anti-aliasing(抗锯齿或边缘柔化) of shapes drawn by the viewer
// Given the egoNetwork, load the graphX vertices into GraphStream
for ((id,person:Person) <- graph.vertices.collect()) {
val node = graphStream.addNode(id.toString).asInstanceOf[SingleNode]
node.addAttribute("ui.label",id +"\n"+person.name)
}
// Load the graphX edges into GraphStream edges
for (Edge(x,y,link:Link) <- graph.edges.collect()) {
val edge = graphStream.addEdge(x.toString ++ y.toString,
x.toString, y.toString,
true).
asInstanceOf[AbstractEdge]
}
graphStream.display()
graphStream
}
/*
可视化显示顶点的名称.
*/
def displayGraphWithName(graph:Graph[Person,Link],name:String):SingleGraph={
val graphStream:SingleGraph = new SingleGraph(name);
// Set up the visual attributes for graph visualization
graphStream.addAttribute("ui.stylesheet","url(./style/stylesheet.css)")
graphStream.addAttribute("ui.quality") //to enable slower but better rendering.
graphStream.addAttribute("ui.antialias") //to enable anti-aliasing(抗锯齿或边缘柔化) of shapes drawn by the viewer
// Given the egoNetwork, load the graphX vertices into GraphStream
for ((id,person:Person) <- graph.vertices.collect()) {
val node = graphStream.addNode(id.toString).asInstanceOf[SingleNode]
node.addAttribute("ui.label",person.name)
}
// Load the graphX edges into GraphStream edges
for (Edge(x,y,link:Link) <- graph.edges.collect()) {
val edge = graphStream.addEdge(x.toString ++ y.toString,
x.toString, y.toString,
true).
asInstanceOf[AbstractEdge]
}
graphStream.display()
graphStream
}
/*
可视化显示顶点的名称和边的名称.
*/
def displayGraphWithNameAndLink(graph:Graph[Person,Link],name:String):SingleGraph={
val graphStream:SingleGraph = new SingleGraph(name);
// Set up the visual attributes for graph visualization
graphStream.addAttribute("ui.stylesheet","url(./style/stylesheet.css)")
graphStream.addAttribute("ui.quality") //to enable slower but better rendering.
graphStream.addAttribute("ui.antialias") //to enable anti-aliasing(抗锯齿或边缘柔化) of shapes drawn by the viewer
// Given the egoNetwork, load the graphX vertices into GraphStream
for ((id,person:Person) <- graph.vertices.collect()) {
val node = graphStream.addNode(id.toString).asInstanceOf[SingleNode]
node.addAttribute("ui.label",person.name)
}
// Load the graphX edges into GraphStream edges
// graph.edges.collect().foreach(println)
for (Edge(x,y,link:Link) <- graph.edges.collect()) {
val edge = graphStream.addEdge(x.toString ++ y.toString,
x.toString, y.toString,
true).
asInstanceOf[AbstractEdge]
edge.addAttribute("ui.label",link.relationship)
}
graphStream.display()
graphStream
}
/*
将给定的子图和中心顶点用不同的样式加以区分显示.
*/
def subgraphMark(graphStream:SingleGraph,subgraph:Graph[Person,Link],centralId:Long)={
for((id,person:Person) <- subgraph.vertices.collect()){
val node = graphStream.getNode(id.toString).asInstanceOf[SingleNode]
node.addAttribute("ui.class","important")
}
graphStream.getNode(centralId.toString).asInstanceOf[SingleNode].
addAttribute("ui.class","central")
for(Edge(x,y,_)<- subgraph.edges.collect()){
val edge = graphStream.getEdge(x.toString++y.toString).asInstanceOf[AbstractEdge]
edge.addAttribute("ui.class","important" )
}
graphStream.display()
}
/*
将给定的顶点数组用不同的样式加以区分显示.
*/
def subgraphMark(graphStream:SingleGraph,array:Array[(Long,Int)])={
for((id,level)<-array){
graphStream.getNode(id.toString).asInstanceOf[SingleNode].
addAttribute("ui.class","important"+level)
}
graphStream.display()
}
}