1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
use crateChartProps;
use crateSegment;
use cratedraw_chart;
use *;
/// Chart Component
///
/// A Dioxus component that renders a **duty status chart** inside a `<canvas>` element.
/// This chart visually represents different duty statuses (Off Duty, Sleeper, Driving, On Duty)
/// based on the provided data.
///
/// # Properties
/// The `Chart` component accepts a set of customizable properties through the `Properties` struct:
///
/// - **data** *(Signal<Vec<Segment>>)* - The log data containing time segments for different duty statuses.
/// - **width** *(u32)* - The width of the chart in pixels.
/// - **height** *(u32)* - The height of the chart in pixels.
/// - **background_color** *(String)* - The background color of the chart.
/// - **grid_color** *(String)* - The color of the grid lines.
/// - **font** *(String)* - The font used for labels.
/// - **label_color** *(String)* - The color of the labels.
/// - **off_duty_color** *(String)* - The color representing **Off Duty** time.
/// - **sleeper_color** *(String)* - The color representing **Sleeper Berth** time.
/// - **driving_color** *(String)* - The color representing **Driving** time.
/// - **on_duty_color** *(String)* - The color representing **On Duty** time.
///
/// # Examples
///
/// ## Basic Usage
/// This example renders a `Chart` component with sample data:
///
/// ```rust
/// use dioxus::prelude::*;
/// use eld::{Segment, DutyStatus};
/// use eld::dioxus::Chart;
///
/// #[component]
/// fn App() -> Element {
/// let eld_data = use_signal(|| vec![
/// Segment { start_hour: 0.0, end_hour: 6.0, status: DutyStatus::OffDuty, location: "".to_string(), note: "".to_string() },
/// Segment { start_hour: 6.0, end_hour: 12.0, status: DutyStatus::Sleeper, location: "".to_string(), note: "".to_string() },
/// Segment { start_hour: 12.0, end_hour: 18.0, status: DutyStatus::Driving, location: "".to_string(), note: "".to_string() },
/// Segment { start_hour: 18.0, end_hour: 24.0, status: DutyStatus::OnDuty, location: "".to_string(), note: "".to_string() },
/// ]);
///
/// rsx! {
/// Chart {
/// data: eld_data,
/// width: 800,
/// height: 400,
/// background_color: "#ffffff",
/// grid_color: "#cccccc",
/// font: "12px Arial",
/// label_color: "#333333",
/// off_duty_color: "#dddddd",
/// sleeper_color: "#000000",
/// driving_color: "#28a745",
/// on_duty_color: "#ff9800",
/// }
/// }
/// }
/// ```
///
/// # Behavior
/// - When `data` changes, the `use_effect` hook **redraws the chart**.
/// - The chart is **scrollable horizontally** for better visibility on smaller screens.
/// - Uses the `draw_chart` function to render the chart inside the `<canvas>` element.
///
/// # Notes
/// - The `<canvas>` must have a unique `id` (`eld-canvas`) for proper rendering.
/// - The `draw_chart` function must be implemented separately and handle the drawing logic.