MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / new

Function new

examples/reference_lines.rs:25–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23}
24
25fn new() -> PlotWidget {
26 // Plot some interesting functions with asymptotes.
27 let clamp = |y: f64| y.clamp(-20.0, 20.0);
28
29 let mut tan_seg1 = Vec::new();
30 let end1 = PI - 0.0001;
31 let mut x = 0.0;
32 while x <= end1 {
33 tan_seg1.push([x, clamp((x - PI / 2.0).tan())]);
34 x += 0.01;
35 }
36
37 let mut tan_seg2 = Vec::new();
38 let start2 = PI + 0.0001;
39 let end2 = TAU - 0.0001;
40 x = start2;
41 while x <= end2 {
42 tan_seg2.push([x, clamp((x - PI / 2.0).tan())]);
43 x += 0.01;
44 }
45
46 let tan1 = Series::squares(tan_seg1, 4.0)
47 .with_label("tan_1")
48 .with_color(Color::from_rgb(0.3, 0.6, 0.9));
49
50 let tan2 = Series::line_only(tan_seg2, LineStyle::solid())
51 .with_marker_style(MarkerStyle::star(10.0))
52 .with_color(Color::from_rgb(0.7, 0.2, 0.1))
53 .with_label("tan_2");
54
55 let k = 1.2;
56 let mut tanh_positions = Vec::new();
57 x = 0.0;
58 while x <= TAU {
59 tanh_positions.push([x, (k * (x - 1.5 * PI)).tanh()]);
60 x += 0.01;
61 }
62 let tanh_s = Series::line_only(tanh_positions, LineStyle::dashed(8.0))
63 .with_label("y = tanh(1.2·(x - 1.5π))")
64 .with_color(Color::from_rgb(0.2, 0.8, 0.5));
65
66 // Add vertical reference lines at the asymptotes of tan(x - π/2)
67 let vline1 = VLine::new(PI)
68 .with_label("π")
69 .with_color(Color::from_rgb(0.9, 0.3, 0.3))
70 .with_width(2.0)
71 .with_style(LineStyle::solid());
72
73 let vline2 = VLine::new(TAU)
74 .with_label("2π")
75 .with_color(Color::from_rgb(0.9, 0.5, 0.3))
76 .with_width(2.0)
77 .with_style(LineStyle::dashed(1.0));
78
79 // Add horizontal reference lines at y = ±1 (asymptotes of tanh)
80 let hline1 = HLine::new(1.0)
81 .with_label("y=1.0")
82 .with_color(Color::from_rgb(0.3, 0.9, 0.5))

Callers

nothing calls this directly

Calls 12

with_marker_styleMethod · 0.80
buildMethod · 0.80
with_cursor_overlayMethod · 0.80
with_y_labelMethod · 0.80
with_x_labelMethod · 0.80
with_colorMethod · 0.45
with_labelMethod · 0.45
with_styleMethod · 0.45
with_widthMethod · 0.45
add_hlineMethod · 0.45
add_vlineMethod · 0.45
add_seriesMethod · 0.45

Tested by

no test coverage detected