| 21 | } |
| 22 | |
| 23 | fn new() -> PlotWidget { |
| 24 | let upper_positions: Vec<[f64; 2]> = (0..450) |
| 25 | .map(|i| { |
| 26 | let x = i as f64 * 0.03; |
| 27 | let y = 1.1 + 0.8 * (x * 0.7).sin() + 0.12 * (x * 2.3).cos(); |
| 28 | [x, y] |
| 29 | }) |
| 30 | .collect(); |
| 31 | |
| 32 | let lower_positions: Vec<[f64; 2]> = (0..95) |
| 33 | .map(|i| { |
| 34 | let x = i as f64 * 0.13; |
| 35 | let y = 0.2 + 0.45 * (x * 0.9 + 0.3).sin() - 0.08 * (x * 1.7).cos(); |
| 36 | [x, y] |
| 37 | }) |
| 38 | .collect(); |
| 39 | |
| 40 | // Create a bunch of series and lines. |
| 41 | let upper_series = Series::line_only(upper_positions, LineStyle::solid()) |
| 42 | .with_marker_style(MarkerStyle::circle(3.5)) |
| 43 | .with_color(Color::from_rgb(0.15, 0.55, 0.95)) |
| 44 | .with_label("upper series"); |
| 45 | let lower_series = Series::line_only(lower_positions, LineStyle::dashed(8.0)) |
| 46 | .with_marker_style(MarkerStyle::ring(3.0)) |
| 47 | .with_color(Color::from_rgb(0.95, 0.45, 0.15)) |
| 48 | .with_label("lower series (sparse)"); |
| 49 | let baseline = HLine::new(0.0) |
| 50 | .with_label("y = 0") |
| 51 | .with_style(LineStyle::dotted(4.0)) |
| 52 | .with_color(Color::from_rgb(0.7, 0.7, 0.7)); |
| 53 | let hband_low = HLine::new(1.9) |
| 54 | .with_label("h-band low") |
| 55 | .with_color(Color::from_rgb(0.55, 0.65, 0.95)); |
| 56 | let hband_high = HLine::new(2.4) |
| 57 | .with_label("h-band high") |
| 58 | .with_color(Color::from_rgb(0.55, 0.65, 0.95)); |
| 59 | let vband_left = VLine::new(2.0) |
| 60 | .with_label("v-band left") |
| 61 | .with_color(Color::from_rgb(0.9, 0.65, 0.5)); |
| 62 | let vband_right = VLine::new(3.1) |
| 63 | .with_label("v-band right") |
| 64 | .with_color(Color::from_rgb(0.9, 0.65, 0.5)); |
| 65 | |
| 66 | // Create the "Fills". |
| 67 | let fill_series_to_series = Fill::new(upper_series.id, lower_series.id) |
| 68 | .with_label("fill: upper ↔ lower") |
| 69 | .with_color(Color::from_rgba(0.2, 0.7, 1.0, 0.24)); |
| 70 | let fill_to_zero = Fill::new(lower_series.id, baseline.id) |
| 71 | .with_label("fill: lower ↔ y=0") |
| 72 | .with_color(Color::from_rgba(0.25, 0.85, 0.45, 0.16)); |
| 73 | let fill_hband = Fill::new(hband_low.id, hband_high.id) |
| 74 | .with_label("fill: horizontal band") |
| 75 | .with_color(Color::from_rgba(0.5, 0.6, 0.95, 0.16)); |
| 76 | let fill_vband = Fill::new(vband_left.id, vband_right.id) |
| 77 | .with_label("fill: vertical band") |
| 78 | .with_color(Color::from_rgba(0.95, 0.7, 0.5, 0.14)); |
| 79 | |
| 80 | PlotWidgetBuilder::new() |