diff --git a/Cargo.toml b/Cargo.toml
index 08a41db..a8cc7a3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,10 +21,10 @@ readme = "./README.md"
[dependencies]
charts-rs-derive = { path = "./charts-rs-derive", version = "0.1.21" }
fontdue = "0.8.0"
-once_cell = "1.18.0"
+once_cell = "1.19.0"
png = { version = "0.17.10", optional = true }
regex = "1.10.2"
-resvg = { version = "0.36.0", default-features = false, features = [ "text", "system-fonts" ], optional = true }
+resvg = { version = "0.37.0", default-features = false, features = [ "text", "system-fonts" ], optional = true }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
snafu = "0.7.5"
diff --git a/asset/radar_chart/three_points.svg b/asset/radar_chart/three_points.svg
index c3b437f..150c7d1 100644
--- a/asset/radar_chart/three_points.svg
+++ b/asset/radar_chart/three_points.svg
@@ -43,4 +43,13 @@ Information Technology
+
+4200
+
+
+3000
+
+
+20000
+
\ No newline at end of file
diff --git a/src/charts/radar_chart.rs b/src/charts/radar_chart.rs
index b41bc86..bf8a595 100644
--- a/src/charts/radar_chart.rs
+++ b/src/charts/radar_chart.rs
@@ -263,6 +263,7 @@ impl RadarChart {
});
}
+ let mut label_positions = vec![];
for (index, series) in self.series_list.iter().enumerate() {
let color = get_color(&self.series_colors, series.index.unwrap_or(index));
let mut points = vec![];
@@ -273,10 +274,16 @@ impl RadarChart {
} else {
*value / item.max * r
};
+
if ir > r {
ir = r;
}
let p = get_pie_point(cx, cy, ir, angle * i as f32);
+ if series.label_show {
+ let label =
+ format_series_value(value.to_owned(), &self.series_label_formatter);
+ label_positions.push((p.clone(), label));
+ }
points.push(p);
}
}
@@ -289,6 +296,28 @@ impl RadarChart {
..Default::default()
});
}
+ for item in label_positions.iter() {
+ let mut dx = None;
+ let text = item.1.clone();
+ let point = item.0;
+ if let Ok(value) =
+ measure_text_width_family(&self.font_family, self.series_label_font_size, &text)
+ {
+ dx = Some(-value.width() / 2.0);
+ }
+ c.text(Text {
+ text: text.clone(),
+ dy: Some(-8.0),
+ dx,
+ font_family: Some(self.font_family.clone()),
+ font_color: Some(self.series_label_font_color),
+ font_size: Some(self.series_label_font_size),
+ font_weight: self.series_label_font_weight.clone(),
+ x: Some(point.x),
+ y: Some(point.y),
+ ..Default::default()
+ });
+ }
c.svg()
}
@@ -417,7 +446,7 @@ mod tests {
#[test]
fn radar_three_points() {
- let radar_chart = RadarChart::new(
+ let mut radar_chart = RadarChart::new(
vec![
Series::new(
"Allocated Budget".to_string(),
@@ -434,6 +463,7 @@ mod tests {
("Information Technology", 30000.0).into(),
],
);
+ radar_chart.series_list[0].label_show = true;
assert_eq!(
include_str!("../../asset/radar_chart/three_points.svg"),
diff --git a/src/charts/table_chart.rs b/src/charts/table_chart.rs
index 0abedce..db1185d 100644
--- a/src/charts/table_chart.rs
+++ b/src/charts/table_chart.rs
@@ -616,21 +616,21 @@ mod tests {
],
]);
table_chart.title_text = "NASDAQ".to_string();
- table_chart.text_aligns = vec![
- Align::Left,
- Align::Center,
+ table_chart.text_aligns = vec![Align::Left, Align::Center];
+ table_chart.cell_styles = vec![
+ TableCellStyle {
+ indexes: vec![1, 2],
+ font_weight: Some("bold".to_string()),
+ background_color: Some("#3bb357".into()),
+ font_color: Some(("#fff").into()),
+ },
+ TableCellStyle {
+ indexes: vec![2, 1],
+ background_color: Some("#3bb357".into()),
+ font_color: Some(("#fff").into()),
+ ..Default::default()
+ },
];
- table_chart.cell_styles = vec![TableCellStyle {
- indexes: vec![1, 2],
- font_weight: Some("bold".to_string()),
- background_color: Some("#3bb357".into()),
- font_color: Some(("#fff").into()),
- }, TableCellStyle {
- indexes: vec![2, 1],
- background_color: Some("#3bb357".into()),
- font_color: Some(("#fff").into()),
- ..Default::default()
- }];
assert_eq!(
include_str!("../../asset/table_chart/multi_lines.svg"),
table_chart.svg().unwrap()