forked from yuankunzhang/charming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
les_miserables.rs
36 lines (35 loc) · 1.26 KB
/
les_miserables.rs
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
use charming::{
component::{Legend, Title},
element::{Label, LabelPosition, LineStyle, Tooltip},
series::{Graph, GraphData, GraphLayout, GraphLayoutCircular, GraphNodeLabel},
Chart,
};
pub fn chart() -> Chart {
let mut data: GraphData = serde_json::from_str(include_str!("les-miserables.json")).unwrap();
for d in data.nodes.iter_mut() {
if d.symbol_size > 30.0 {
d.label = Some(GraphNodeLabel::new().show(true));
}
}
let legend: Vec<String> = data.categories.iter().map(|c| c.name.clone()).collect();
Chart::new()
.title(
Title::new()
.text("Les Miserables")
.subtext("Circular layout")
.top("bottom")
.left("right"),
)
.legend(Legend::new().data(legend))
.tooltip(Tooltip::new())
.series(
Graph::new()
.name("Les Miserables")
.layout(GraphLayout::Circular)
.circular(GraphLayoutCircular::new().rotate_label(true))
.roam(true)
.label(Label::new().position(LabelPosition::Right).formatter("{b}"))
.line_style(LineStyle::new().color("source").curveness(0.3))
.data(data),
)
}