egui_charts/drawings/domain/
pitchfork.rs1use crate::model::LineStyle;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8pub struct PitchforkLevel {
9 pub value: f32,
11 pub visible: bool,
13 pub color: [u8; 4],
15 pub line_style: LineStyle,
17 #[serde(default)]
19 pub width: Option<f32>,
20}
21
22#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
24pub struct PitchforkConfig {
25 pub levels: Vec<PitchforkLevel>,
27 pub show_background: bool,
29 pub background_opacity: u8,
31}
32
33impl Default for PitchforkConfig {
34 fn default() -> Self {
37 use super::drawing::{BLUE, CYAN, PINK, PURPLE, RED, TEAL};
38 let level = |value, color, visible| PitchforkLevel {
39 value,
40 visible,
41 color,
42 line_style: LineStyle::Solid,
43 width: None,
44 };
45 Self {
46 levels: vec![
47 level(0.0, RED, true),
48 level(0.25, [255, 183, 77, 255], false),
49 level(0.382, [129, 199, 132, 255], false),
50 level(0.5, TEAL, true),
51 level(0.618, TEAL, false),
52 level(0.75, CYAN, false),
53 level(1.0, BLUE, true),
54 level(1.5, PURPLE, false),
55 level(1.75, PINK, false),
56 level(2.0, [247, 124, 128, 255], false),
57 ],
58 show_background: true,
59 background_opacity: 51,
60 }
61 }
62}
63
64impl PitchforkConfig {
65 pub(crate) fn legacy() -> Self {
68 Self {
69 levels: [0.0, 0.5, 1.0, 1.5]
70 .map(|value| PitchforkLevel {
71 value,
72 visible: true,
73 color: [33, 150, 243, 255],
74 line_style: LineStyle::Solid,
75 width: None,
76 })
77 .to_vec(),
78 show_background: true,
79 background_opacity: 20,
80 }
81 }
82}