embedded_charts/data/
mod.rs

1//! Data management module for chart data structures and operations.
2//!
3//! This module provides efficient data structures for storing and managing chart data
4//! with static allocation and predictable memory usage. All data structures are designed
5//! for embedded systems with limited memory.
6//!
7//! ## Data Processing Features
8//!
9//! ### Aggregation and Downsampling
10//! Efficient algorithms for reducing data density while preserving important characteristics:
11//! ```rust
12//! use embedded_charts::prelude::*;
13//! use embedded_charts::data::aggregation::*;
14//!
15//! let mut large_dataset: StaticDataSeries<Point2D, 10000> = StaticDataSeries::new();
16//! // ... populate with data ...
17//!
18//! // Aggregate using different strategies
19//! let config = AggregationConfig {
20//!     strategy: AggregationStrategy::Mean,
21//!     target_points: 100,
22//!     preserve_endpoints: true,
23//!     ..Default::default()
24//! };
25//! let aggregated: StaticDataSeries<Point2D, 256> = large_dataset.aggregate(&config)?;
26//!
27//! // Downsample using LTTB algorithm
28//! let downsample_config = DownsamplingConfig {
29//!     max_points: 50,
30//!     ..Default::default()
31//! };
32//! let downsampled: StaticDataSeries<Point2D, 256> = large_dataset.downsample_lttb(&downsample_config)?;
33//! # Ok::<(), embedded_charts::error::DataError>(())
34//! ```
35//!
36//! ## Core Data Types
37//!
38//! ### Point2D
39//! Basic 2D point representation for chart data:
40//! ```rust
41//! use embedded_charts::prelude::*;
42//!
43//! let point = Point2D::new(1.0, 25.5);
44//! println!("X: {}, Y: {}", point.x(), point.y());
45//! ```
46//!
47//! ### StaticDataSeries
48//! Fixed-capacity data series with compile-time bounds:
49//! ```rust
50//! use embedded_charts::prelude::*;
51//!
52//! // Create a series with capacity for 256 points
53//! let mut series: StaticDataSeries<Point2D, 256> = StaticDataSeries::new();
54//!
55//! // Add data points
56//! series.push(Point2D::new(0.0, 10.0))?;
57//! series.push(Point2D::new(1.0, 20.0))?;
58//! series.push(Point2D::new(2.0, 15.0))?;
59//!
60//! // Create from tuples
61//! let series: StaticDataSeries<Point2D, 256> = StaticDataSeries::from_tuples(&[
62//!     (0.0, 10.0),
63//!     (1.0, 20.0),
64//!     (2.0, 15.0),
65//! ])?;
66//!
67//! println!("Series has {} points", series.len());
68//! # Ok::<(), embedded_charts::error::DataError>(())
69//! ```
70//!
71//! ### MultiSeries
72//! Container for multiple data series with automatic color assignment:
73//! ```rust
74//! use embedded_charts::prelude::*;
75//!
76//! // Container for 8 series, 256 points each
77//! let mut multi_series: MultiSeries<Point2D, 8, 256> = MultiSeries::new();
78//!
79//! let temp_data = data_points![(0.0, 22.5), (1.0, 23.1), (2.0, 24.2)];
80//! let humidity_data = data_points![(0.0, 65.0), (1.0, 68.0), (2.0, 72.0)];
81//!
82//! multi_series.add_series(temp_data)?;
83//! multi_series.add_series(humidity_data)?;
84//!
85//! println!("Multi-series has {} series", multi_series.series_count());
86//! # Ok::<(), embedded_charts::error::DataError>(())
87//! ```
88//!
89//! ## Data Bounds
90//!
91//! Automatic calculation of data bounds for optimal chart scaling:
92//! ```rust
93//! use embedded_charts::prelude::*;
94//!
95//! let data = data_points![(0.0, 10.0), (5.0, 30.0), (10.0, 15.0)];
96//!
97//! // Calculate bounds for single series
98//! let bounds = data.bounds()?;
99//! println!("X: {} to {}, Y: {} to {}",
100//!          bounds.min_x, bounds.max_x, bounds.min_y, bounds.max_y);
101//!
102//! // For multi-series, bounds are calculated per chart implementation
103//! # Ok::<(), embedded_charts::error::DataError>(())
104//! ```
105//!
106//! ## Streaming Data (feature: "animations")
107//!
108//! Real-time data management with sliding windows:
109//! ```rust,no_run
110//! # #[cfg(feature = "animations")]
111//! # {
112//! use embedded_charts::prelude::*;
113//!
114//! // Sliding window for real-time data (100 points)
115//! let mut streaming_data: SlidingWindowSeries<Point2D, 100> =
116//!     SlidingWindowSeries::new();
117//!
118//! // Add data points (automatically removes old ones when full)
119//! for i in 0..150 {
120//!     let timestamp = i as f32 * 0.1;
121//!     let value = (timestamp * 2.0).sin() * 10.0 + 50.0;
122//!     let _ = streaming_data.push(Point2D::new(timestamp, value));
123//! }
124//!
125//! println!("Streaming data has {} points", streaming_data.len());
126//! # }
127//! # Ok::<(), embedded_charts::error::DataError>(())
128//! ```
129//!
130//! ## Memory Efficiency
131//!
132//! All data structures use static allocation for predictable memory usage:
133//! - **No heap allocation**: All data is stored in fixed-size arrays
134//! - **Compile-time bounds**: Memory usage is known at compile time
135//! - **Zero-cost abstractions**: High-level API with no runtime overhead
136//! - **Configurable capacity**: Adjust memory usage per application needs
137//!
138//! ## Data Point Types
139//!
140//! ### Basic Points
141//! - [`Point2D`] - Standard 2D floating-point coordinates
142//! - [`IntPoint`] - Integer coordinates for memory-constrained systems
143//! - [`TimestampedPoint`] - Points with timestamp information
144//!
145//! ### Specialized Points
146//! Different point types for specific use cases:
147//! ```rust
148//! use embedded_charts::prelude::*;
149//!
150//! // Integer points for memory efficiency
151//! let int_point = IntPoint::new(10, 25);
152//!
153//! // Timestamped points for time-series data
154//! let timestamped = TimestampedPoint::new(1234567890.0, 25.5);
155//! ```
156//!
157//! ## Data Series Trait
158//!
159//! All data containers implement the [`DataSeries`] trait:
160//! ```rust,no_run
161//! use embedded_charts::data::DataSeries;
162//!
163//! fn process_data<T: DataSeries>(data: &T) {
164//!     println!("Processing {} data points", data.len());
165//!     if data.is_empty() {
166//!         println!("No data available");
167//!     }
168//! }
169//! ```
170//!
171//! ## Utility Macros
172//!
173//! Convenient macros for creating data:
174//! ```rust
175//! use embedded_charts::prelude::*;
176//!
177//! // Create data points from tuples
178//! let data = data_points![
179//!     (0.0, 10.0),
180//!     (1.0, 20.0),
181//!     (2.0, 15.0),
182//!     (3.0, 25.0),
183//! ];
184//!
185//! assert_eq!(data.len(), 4);
186//! ```
187
188pub mod aggregation;
189pub mod bounds;
190pub mod point;
191pub mod ring_buffer;
192pub mod series;
193
194#[cfg(feature = "animations")]
195pub mod streaming;
196
197pub use aggregation::*;
198pub use bounds::*;
199pub use point::*;
200pub use ring_buffer::*;
201pub use series::*;
202
203#[cfg(feature = "animations")]
204pub use streaming::*;