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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Charts supports nineteen chart types: bar, horizontal bar, line, pie,
//! radar, scatter, candlestick, table, heatmap, funnel, waterfall, multi
//! chart, calendar, gauge, treemap, box plot, sunburst, sankey and tree.
//!
//! It supports ten built-in themes and is very easy to use.
//! Each attribute can be customized, it can be saved as svg, png, jpeg,
//! webp or avif.
//! The chart can be new from json, which sets default value if the field is undefined.
//!
//! # New a bar chart from json, the other charts also support the function.
//! ```rust
//! use charts_rs::{BarChart};
//! let bar_chart = BarChart::from_json(
//! r###"{
//! "width": 630,
//! "height": 410,
//! "margin": {
//! "left": 10,
//! "top": 5,
//! "right": 10
//! },
//! "title_text": "Bar Chart",
//! "title_font_color": "#345",
//! "title_align": "right",
//! "sub_title_text": "demo",
//! "legend_align": "left",
//! "series_list": [
//! {
//! "name": "Email",
//! "label_show": true,
//! "data": [120.0, 132.0, 101.0, 134.0, 90.0, 230.0, 210.0]
//! },
//! {
//! "name": "Union Ads",
//! "data": [220.0, 182.0, 191.0, 234.0, 290.0, 330.0, 310.0]
//! }
//! ],
//! "x_axis_data": [
//! "Mon",
//! "Tue",
//! "Wed",
//! "Thu",
//! "Fri",
//! "Sat",
//! "Sun"
//! ]
//! }"###,
//! ).unwrap();
//! println!("{}", bar_chart.svg().unwrap());
//! ```
//!
//! # New bar chart with theme
//!
//! There are ten built-in themes: light, dark, ant, grafana, vintage,
//! walden, westeros, chalk, shine and shadcn.
//! The light is the default theme.
//! ```rust
//! use charts_rs::{BarChart, Series, THEME_GRAFANA};
//! let bar_chart = BarChart::new_with_theme(
//! vec![
//! ("Email", vec![120.0, 132.0, 101.0, 134.0, 90.0, 230.0, 210.0]).into(),
//! ],
//! vec![
//! "Mon".to_string(),
//! "Tue".to_string(),
//! "Wed".to_string(),
//! "Thu".to_string(),
//! "Fri".to_string(),
//! "Sat".to_string(),
//! "Sun".to_string(),
//! ],
//! THEME_GRAFANA,
//! );
//! println!("{}", bar_chart.svg().unwrap());
//!```
//!
//!
//! # Add more font
//! The fonts will be initialized once, it can be changed before used.
//! ```rust
//! use charts_rs::{get_or_try_init_fonts, BarChart};
//! let data = include_bytes!("./Roboto.ttf") as &[u8];
//! get_or_try_init_fonts(Some(vec![data])).unwrap();
//! let bar_chart = BarChart::from_json(
//! r###"{
//! "width": 630,
//! "height": 410,
//! "font_family": "test",
//! "margin": {
//! "left": 10,
//! "top": 5,
//! "right": 10
//! },
//! "title_text": "Bar Chart",
//! "title_font_color": "#345",
//! "title_align": "right",
//! "sub_title_text": "demo",
//! "legend_align": "left",
//! "series_list": [
//! {
//! "name": "Email",
//! "label_show": true,
//! "data": [120.0, 132.0, 101.0, 134.0, 90.0, 230.0, 210.0]
//! },
//! {
//! "name": "Union Ads",
//! "data": [220.0, 182.0, 191.0, 234.0, 290.0, 330.0, 310.0]
//! }
//! ],
//! "x_axis_data": [
//! "Mon",
//! "Tue",
//! "Wed",
//! "Thu",
//! "Fri",
//! "Sat",
//! "Sun"
//! ]
//! }"###,
//! ).unwrap();
//! println!("{}", bar_chart.svg().unwrap());
//! ```
//!
//! # Basic bar chart
//! ```rust
//! use charts_rs::{BarChart, Series, Box};
//! let mut bar_chart = BarChart::new(
//! vec![
//! Series::new(
//! "Email".to_string(),
//! vec![120.0, 132.0, 101.0, 134.0, 90.0, 230.0, 210.0],
//! ),
//! Series::new(
//! "Union Ads".to_string(),
//! vec![220.0, 182.0, 191.0, 234.0, 290.0, 330.0, 310.0],
//! ),
//! Series::new(
//! "Direct".to_string(),
//! vec![320.0, 332.0, 301.0, 334.0, 390.0, 330.0, 320.0],
//! ),
//! Series::new(
//! "Search Engine".to_string(),
//! vec![820.0, 932.0, 901.0, 934.0, 1290.0, 1330.0, 1320.0],
//! )
//! ],
//! vec![
//! "Mon".to_string(),
//! "Tue".to_string(),
//! "Wed".to_string(),
//! "Thu".to_string(),
//! "Fri".to_string(),
//! "Sat".to_string(),
//! "Sun".to_string(),
//! ],
//! );
//! bar_chart.y_axis_configs[0].axis_width = Some(55.0);
//! bar_chart.title_text = "Bar Chart".to_string();
//! bar_chart.legend_margin = Some(Box {
//! top: 35.0,
//! bottom: 10.0,
//! ..Default::default()
//! });
//! println!("{}", bar_chart.svg().unwrap());
//!```
//!
//! # Bar line mixin chart
//! ```rust
//! use charts_rs::{BarChart, Series, Box, SeriesCategory};
//! let mut bar_chart = BarChart::new(
//! vec![
//! Series::new(
//! "Email".to_string(),
//! vec![120.0, 132.0, 101.0, 134.0, 90.0, 230.0, 210.0],
//! ),
//! Series::new(
//! "Union Ads".to_string(),
//! vec![220.0, 182.0, 191.0, 234.0, 290.0, 330.0, 310.0],
//! ),
//! Series::new(
//! "Direct".to_string(),
//! vec![320.0, 332.0, 301.0, 334.0, 390.0, 330.0, 320.0],
//! ),
//! Series::new(
//! "Search Engine".to_string(),
//! vec![820.0, 932.0, 901.0, 934.0, 1290.0, 1330.0, 1320.0],
//! )
//! ],
//! vec![
//! "Mon".to_string(),
//! "Tue".to_string(),
//! "Wed".to_string(),
//! "Thu".to_string(),
//! "Fri".to_string(),
//! "Sat".to_string(),
//! "Sun".to_string(),
//! ],
//! );
//! bar_chart.series_list[0].category = Some(SeriesCategory::Line);
//! bar_chart.y_axis_configs[0].axis_width = Some(55.0);
//! bar_chart.title_text = "Bar Line Chart".to_string();
//! bar_chart.legend_margin = Some(Box {
//! top: 35.0,
//! bottom: 10.0,
//! ..Default::default()
//! });
//! println!("{}", bar_chart.svg().unwrap());
//! ```
//!
//!
//! # Basic horizontal bar
//! ```rust
//! use charts_rs::{HorizontalBarChart, Series, Align};
//! let mut horizontal_bar_chart = HorizontalBarChart::new(
//! vec![
//! Series::new(
//! "2011".to_string(),
//! vec![18203.0, 23489.0, 29034.0, 104970.0, 131744.0, 630230.0],
//! ),
//! Series::new(
//! "2012".to_string(),
//! vec![19325.0, 23438.0, 31000.0, 121594.0, 134141.0, 681807.0],
//! ),
//! ],
//! vec![
//! "Brazil".to_string(),
//! "Indonesia".to_string(),
//! "USA".to_string(),
//! "India".to_string(),
//! "China".to_string(),
//! "World".to_string(),
//! ],
//! );
//! horizontal_bar_chart.title_text = "World Population".to_string();
//! horizontal_bar_chart.margin.right = 15.0;
//! horizontal_bar_chart.series_list[0].label_show = true;
//! horizontal_bar_chart.title_align = Align::Left;
//! println!("{}", horizontal_bar_chart.svg().unwrap());
//! ```
//!
//! # Basic line chart
//! ```rust
//! use charts_rs::{LineChart, Box};
//! let mut line_chart = LineChart::new(
//! vec![
//! ("Email", vec![120.0, 132.0, 101.0, 134.0, 90.0, 230.0, 210.0]).into(),
//! ("Union Ads", vec![220.0, 182.0, 191.0, 234.0, 290.0, 330.0, 310.0]).into(),
//! ("Direct", vec![320.0, 332.0, 301.0, 334.0, 390.0, 330.0, 320.0]).into(),
//! ("Search Engine", vec![820.0, 932.0, 901.0, 934.0, 1290.0, 1330.0, 1320.0]).into(),
//! ],
//! vec![
//! "Mon".to_string(),
//! "Tue".to_string(),
//! "Wed".to_string(),
//! "Thu".to_string(),
//! "Fri".to_string(),
//! "Sat".to_string(),
//! "Sun".to_string(),
//! ],
//! );
//! line_chart.title_text = "Stacked Area Chart".to_string();
//! line_chart.sub_title_text = "Hello World".to_string();
//! line_chart.legend_margin = Some(Box {
//! top: 50.0,
//! bottom: 10.0,
//! ..Default::default()
//! });
//! line_chart.series_list[3].label_show = true;
//! println!("{}", line_chart.svg().unwrap());
//! ```
//!
//! # Basic pie chart
//! ```rust
//! use charts_rs::{PieChart};
//! let mut pie_chart = PieChart::new(vec![
//! ("rose 1", vec![40.0]).into(),
//! ("rose 2", vec![38.0]).into(),
//! ("rose 3", vec![32.0]).into(),
//! ("rose 4", vec![30.0]).into(),
//! ("rose 5", vec![28.0]).into(),
//! ("rose 6", vec![26.0]).into(),
//! ("rose 7", vec![22.0]).into(),
//! ("rose 8", vec![18.0]).into(),
//! ]);
//! pie_chart.title_text = "Nightingale Chart".to_string();
//! pie_chart.sub_title_text = "Fake Data".to_string();
//! println!("{}", pie_chart.svg().unwrap());
//! ```
//!
//! # Basic radar chart
//! ```rust
//! use charts_rs::{RadarChart};
//! let radar_chart = RadarChart::new(
//! vec![
//! ("Allocated Budget", vec![4200.0, 3000.0, 20000.0, 35000.0, 50000.0, 18000.0, 9000.0]).into(),
//! ("Actual Spending", vec![5000.0, 14000.0, 28000.0, 26000.0, 42000.0, 21000.0, 7000.0]).into(),
//! ],
//! vec![
//! ("Sales", 6500.0).into(),
//! ("Administration", 16000.0).into(),
//! ("Information Technology", 30000.0).into(),
//! ("Customer Support", 38000.0).into(),
//! ("Development", 52000.0).into(),
//! ("Marketing", 25000.0).into(),
//! ("Online", 10000.0).into(),
//! ],
//! );
//! println!("{}", radar_chart.svg().unwrap());
//! ```
//!
//! # Basic table
//! ```rust
//! use charts_rs::{TableChart};
//! let mut table_chart = TableChart::new(vec![
//! vec![
//! "Name".to_string(),
//! "Price".to_string(),
//! "Change".to_string(),
//! ],
//! vec![
//! "Datadog Inc".to_string(),
//! "97.32".to_string(),
//! "-7.49%".to_string(),
//! ],
//! vec![
//! "Hashicorp Inc".to_string(),
//! "28.66".to_string(),
//! "-9.25%".to_string(),
//! ],
//! vec![
//! "Gitlab Inc".to_string(),
//! "51.63".to_string(),
//! "+4.32%".to_string(),
//! ],
//! ]);
//! table_chart.title_text = "NASDAQ".to_string();
//! println!("{}", table_chart.svg().unwrap());
//! ```
//!
//! # Basic funnel chart
//! ```rust
//! use charts_rs::FunnelChart;
//! let funnel_chart = FunnelChart::new(vec![
//! ("Impression", vec![100.0]).into(),
//! ("Click", vec![80.0]).into(),
//! ("Order", vec![30.0]).into(),
//! ]);
//! println!("{}", funnel_chart.svg().unwrap());
//! ```
//!
//! # Basic treemap chart
//! ```rust
//! use charts_rs::TreemapChart;
//! let treemap_chart = TreemapChart::new(vec![
//! ("A", vec![60.0]).into(),
//! ("B", vec![30.0]).into(),
//! ("C", vec![10.0]).into(),
//! ]);
//! println!("{}", treemap_chart.svg().unwrap());
//! ```
//!
//! # Basic sunburst chart
//! ```rust
//! use charts_rs::{SunburstChart, SunburstData};
//! let sunburst_chart = SunburstChart::new(vec![SunburstData {
//! name: "Root".to_string(),
//! children: vec![
//! SunburstData { name: "A".to_string(), value: 3.0, ..Default::default() },
//! SunburstData { name: "B".to_string(), value: 2.0, ..Default::default() },
//! ],
//! ..Default::default()
//! }]);
//! println!("{}", sunburst_chart.svg().unwrap());
//! ```
//!
//! # Basic sankey chart
//! ```rust
//! use charts_rs::SankeyChart;
//! // Nodes are derived from the link endpoints when left empty.
//! let sankey_chart = SankeyChart::new(
//! vec![],
//! vec![
//! ("a", "b", 8.0).into(),
//! ("a", "c", 4.0).into(),
//! ("b", "d", 8.0).into(),
//! ],
//! );
//! println!("{}", sankey_chart.svg().unwrap());
//! ```
//!
//! # Basic tree chart
//! ```rust
//! use charts_rs::{TreeChart, TreeData};
//! let tree_chart = TreeChart::new(vec![TreeData {
//! name: "Root".to_string(),
//! children: vec![
//! TreeData { name: "A".to_string(), ..Default::default() },
//! TreeData { name: "B".to_string(), ..Default::default() },
//! ],
//! ..Default::default()
//! }]);
//! println!("{}", tree_chart.svg().unwrap());
//! ```
pub use *;
const VERSION: &str = env!;