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
#[cfg(not(target_arch = "wasm32"))]
use iced_graphics::canvas::{Cursor, Event, Frame, Geometry};
#[cfg(not(target_arch = "wasm32"))]
use iced_native::{event::Status, Rectangle, Size};
#[cfg(target_arch = "wasm32")]
use iced_web::{Rectangle, Size};
use plotters::{chart::ChartBuilder, coord::Shift, drawing::DrawingArea};
use plotters_backend::DrawingBackend;
#[cfg(target_arch = "wasm32")]
use dummy::*;
impl<Message, C> Chart<Message> for &mut C
where
C: Chart<Message>,
{
#[inline(always)]
fn build_chart<DB: DrawingBackend>(&self, builder: ChartBuilder<DB>) {
C::build_chart(self, builder)
}
#[inline(always)]
fn draw_chart<DB: DrawingBackend>(&self, root: DrawingArea<DB, Shift>) {
C::draw_chart(self, root)
}
#[inline(always)]
fn draw<F: Fn(&mut Frame)>(&self, size: Size, f: F) -> Geometry {
C::draw(self, size, f)
}
#[inline(always)]
fn update(
&mut self,
event: Event,
bounds: Rectangle,
cursor: Cursor,
) -> (Status, Option<Message>) {
C::update(self, event, bounds, cursor)
}
}
pub trait Chart<Message> {
fn build_chart<DB: DrawingBackend>(&self, builder: ChartBuilder<DB>);
#[inline(always)]
fn draw_chart<DB: DrawingBackend>(&self, root: DrawingArea<DB, Shift>) {
let builder = ChartBuilder::on(&root);
self.build_chart(builder);
}
#[inline(always)]
fn draw<F: Fn(&mut Frame)>(&self, size: Size, f: F) -> Geometry {
let mut frame = Frame::new(size);
f(&mut frame);
frame.into_geometry()
}
#[allow(unused_variables)]
#[inline(always)]
fn update(
&mut self,
event: Event,
bounds: Rectangle,
cursor: Cursor,
) -> (Status, Option<Message>) {
(Status::Ignored, None)
}
}
#[cfg(target_arch = "wasm32")]
#[doc(hidden)]
pub mod dummy {
use super::Size;
pub enum Internal {}
pub type Cursor = Internal;
pub type Event = Internal;
pub enum Status {
Ignored,
}
pub struct Frame;
impl Frame {
#[inline(always)]
pub fn new(_size: Size) -> Self {
Self
}
#[inline(always)]
pub fn into_geometry(self) -> Geometry {
()
}
}
pub type Geometry = ();
}