-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_text.rs
More file actions
110 lines (94 loc) · 3.24 KB
/
test_text.rs
File metadata and controls
110 lines (94 loc) · 3.24 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
use plotpy::{Plot, StrError, Text};
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
const OUT_DIR: &str = "/tmp/plotpy/integ_tests";
#[test]
fn test_text() -> Result<(), StrError> {
// text object and options
let mut text = Text::new();
text.set_color("blue")
.set_align_horizontal("center")
.set_align_vertical("center")
.set_fontsize(40.0)
.set_rotation(45.0)
.set_bbox(true)
.set_bbox_facecolor("pink")
.set_bbox_edgecolor("black")
.set_bbox_alpha(0.3)
// .set_bbox_style("square,pad=0.3");
// .set_bbox_style("circle,pad=0.3");
// .set_bbox_style("larrow,pad=0.3");
// .set_bbox_style("rarrow,pad=0.3");
// .set_bbox_style("darrow,pad=0.3");
// .set_bbox_style("round,pad=0.3,rounding_size=0.15");
// .set_bbox_style("round4,pad=0.3,rounding_size=0.2");
.set_bbox_style("sawtooth,pad=0.3,tooth_size=0.1")
.set_extra("fontweight=10");
// .set_bbox_style("roundtooth,pad=0.3,tooth_size=0.2");
// draw text
text.draw(0.5, 0.5, "message: $\\frac{\\alpha}{\\beta} = \\gamma$");
// add text to plot
let mut plot = Plot::new();
plot.add(&text);
// save figure
let path = Path::new(OUT_DIR).join("integ_text.svg");
plot.set_show_errors(true).save(&path)?;
// check number of lines
let file = File::open(path).map_err(|_| "cannot open file")?;
let buffered = BufReader::new(file);
let lines_iter = buffered.lines();
assert!(lines_iter.count() > 560);
Ok(())
}
#[test]
fn test_text_negative_rotation() -> Result<(), StrError> {
// text object and options
let mut text = Text::new();
// draw text
text.set_align_horizontal("center")
.set_align_vertical("center")
.set_fontsize(20.0)
.set_rotation(-30.0)
.draw(0.5, 0.5, "NEGATIVE ROTATION");
// add text to plot
let mut plot = Plot::new();
plot.add(&text).set_range(0.0, 1.0, 0.0, 1.0);
// save figure
let path = Path::new(OUT_DIR).join("integ_text_negative_rotation.svg");
plot.set_show_errors(true).save(&path)?;
// check number of lines
let file = File::open(path).map_err(|_| "cannot open file")?;
let buffered = BufReader::new(file);
let lines_iter = buffered.lines();
let n = lines_iter.count();
assert!(n > 570 && n < 620);
Ok(())
}
#[test]
fn test_text_3d() -> Result<(), StrError> {
// text object and options
let mut text = Text::new();
text.set_color("blue")
.set_align_horizontal("center")
.set_align_vertical("center")
.set_fontsize(32.0)
.set_bbox(true)
.set_bbox_facecolor("pink")
.set_bbox_edgecolor("black")
.set_bbox_alpha(0.3);
// draw text
text.draw_3d(0.5, 0.5, 0.5, "message: $\\frac{\\alpha}{\\beta} = \\gamma$");
// add text to plot
let mut plot = Plot::new();
plot.add(&text);
// save figure
let path = Path::new(OUT_DIR).join("integ_text_3d.svg");
plot.save(&path)?;
// check number of lines
let file = File::open(path).map_err(|_| "cannot open file")?;
let buffered = BufReader::new(file);
let lines_iter = buffered.lines();
assert!(lines_iter.count() > 800);
Ok(())
}