use embedded_charts::prelude::*;
#[path = "../common/mod.rs"]
mod common;
use common::{window, WindowConfig, CHART_MARGINS};
#[cfg(feature = "std")]
fn main() -> ChartResult<()> {
let mut series = StaticDataSeries::new();
let data = [
(0.0, 10.0),
(1.0, 15.0),
(2.0, 8.0),
(3.0, 22.0),
(4.0, 18.0),
(5.0, 25.0),
(6.0, 12.0),
(7.0, 30.0),
(8.0, 28.0),
(9.0, 35.0),
];
for (x, y) in &data {
series
.push(Point2D::new(*x, *y))
.map_err(ChartError::from)?;
}
let bounds = series.bounds()?;
let ((x_min, x_max), (y_min, y_max)) =
calculate_nice_ranges_from_bounds(&bounds, RangeCalculationConfig::default());
let x_range = x_max - x_min;
let y_range = y_max - y_min;
let x_tick_count = if x_range <= 10.0 { 6 } else { 8 };
let y_tick_count = if y_range <= 20.0 {
5
} else if y_range <= 50.0 {
6
} else {
8
};
let x_axis = presets::professional_x_axis(x_min, x_max)
.tick_count(x_tick_count)
.show_grid(true)
.build()?;
let y_axis = presets::professional_y_axis(y_min, y_max)
.tick_count(y_tick_count)
.show_grid(true)
.build()?;
let mut margins = CHART_MARGINS;
margins.right += 120;
let chart = LineChart::builder()
.line_color(Rgb565::BLUE)
.line_width(2)
.with_title("Temperature Over Time")
.background_color(Rgb565::WHITE)
.margins(margins)
.with_x_axis(x_axis)
.with_y_axis(y_axis)
.build()?;
window::run(
WindowConfig::new("Axis System Demo")
.theme(common::WindowTheme::Default)
.background(Rgb565::WHITE),
|display, viewport, _elapsed| chart.draw(&series, chart.config(), viewport, display),
)
}
#[cfg(not(feature = "std"))]
fn main() {
utils::print_feature_requirement("std", "visual");
}