Skip to content

Commit

Permalink
improved chart mesh and y-axis range
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Jan 18, 2024
1 parent 0ef625c commit fa009a3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
6 changes: 6 additions & 0 deletions resources/themes/toucan.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
primary = "#000000"
secondary = "#FF8000"
outgoing = "#FFFFFF"
text_body = "#33FF33"
text_headers = "#232634"
starred = "#FFFF00"
33 changes: 22 additions & 11 deletions src/chart/types/traffic_chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,38 +98,49 @@ impl Chart<Message> for TrafficChart {
let first_time_displayed = if self.ticks > 30 { self.ticks - 30 } else { 0 };

let colors = self.style.get_palette();
let ext = self.style.get_extension();
let color_incoming = to_rgb_color(colors.secondary);
let color_outgoing = to_rgb_color(colors.outgoing);
let color_font = to_rgb_color(colors.text_body);
let color_mix = self.style.get_extension().alpha_chart_badge;
let color_mix = ext.alpha_chart_badge;
let buttons_color = to_rgb_color(ext.buttons_color);

chart_builder
.margin_right(30)
.margin_bottom(0)
.set_label_area_size(LabelAreaPosition::Left, 60)
.set_label_area_size(LabelAreaPosition::Bottom, 50);

let y_axis_range = if self.chart_type.eq(&ChartType::Packets) {
let fs = self.max_received_packets - self.min_sent_packets;
#[allow(clippy::cast_possible_truncation, clippy::cast_precision_loss)]
let gap = (fs as f64 * 0.1) as i64;
self.min_sent_packets - gap..self.max_received_packets + gap
} else {
let fs = self.max_received_bytes - self.min_sent_bytes;
#[allow(clippy::cast_possible_truncation, clippy::cast_precision_loss)]
let gap = (fs as f64 * 0.1) as i64;
self.min_sent_bytes - gap..self.max_received_bytes + gap
};

let mut chart = chart_builder
.build_cartesian_2d(
first_time_displayed..tot_seconds,
if self.chart_type.eq(&ChartType::Packets) {
self.min_sent_packets..self.max_received_packets
} else {
self.min_sent_bytes..self.max_received_bytes
},
)
.expect("Error drawing packets chart");
.build_cartesian_2d(first_time_displayed..tot_seconds, y_axis_range)
.expect("Error drawing chart");

// Mesh
chart
.configure_mesh()
.axis_style(buttons_color)
.bold_line_style(buttons_color.mix(0.67))
.light_line_style(buttons_color.mix(0.33))
.y_max_light_lines(1)
.y_labels(7)
.label_style(
("Sarasa Mono SC", 12)
.into_font()
.style(font_weight)
.color(&color_font),
)
.y_labels(7)
.y_label_formatter(if self.chart_type.eq(&ChartType::Packets) {
&|packets| packets.abs().to_string()
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/gui/styles/style_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ pub const NIGHT_PALETTE: Palette = Palette {
};

pub const BUTTONS_NIGHT: Color = Color {
r: 0.1,
g: 0.1,
b: 0.1,
r: 0.12,
g: 0.12,
b: 0.12,
a: 1.0,
};

Expand All @@ -45,8 +45,8 @@ pub const NIGHT_PALETTE_EXTENSION: PaletteExtension = PaletteExtension {
font: SARASA_MONO,
font_headers: SARASA_MONO_BOLD,
alpha_chart_badge: 0.15,
alpha_round_borders: 0.35,
alpha_round_containers: 0.25,
alpha_round_borders: 0.4,
alpha_round_containers: 0.3,
buttons_color: BUTTONS_NIGHT,
};

Expand Down

0 comments on commit fa009a3

Please sign in to comment.