1 | use plotters::prelude::*; |
2 | |
3 | const OUT_FILE_NAME: &'static str = "plotters-doc-data/full_palette.png" ; |
4 | |
5 | fn main() -> Result<(), Box<dyn std::error::Error>> { |
6 | let root = BitMapBackend::new(OUT_FILE_NAME, (2000, 850)).into_drawing_area(); |
7 | |
8 | root.fill(&WHITE)?; |
9 | |
10 | let mut chart = ChartBuilder::on(&root) |
11 | .caption("Demonstration of full_palette Colors" , ("sans-serif" , 50)) |
12 | .build_cartesian_2d(-0.5f32..19f32, -1f32..15f32)?; |
13 | |
14 | use full_palette::*; |
15 | let colors = [ |
16 | [ |
17 | RED, RED_50, RED_100, RED_200, RED_300, RED_400, RED_500, RED_600, RED_700, RED_800, |
18 | RED_900, RED_A100, RED_A200, RED_A400, RED_A700, |
19 | ], |
20 | [ |
21 | PINK, PINK_50, PINK_100, PINK_200, PINK_300, PINK_400, PINK_500, PINK_600, PINK_700, |
22 | PINK_800, PINK_900, PINK_A100, PINK_A200, PINK_A400, PINK_A700, |
23 | ], |
24 | [ |
25 | PURPLE, |
26 | PURPLE_50, |
27 | PURPLE_100, |
28 | PURPLE_200, |
29 | PURPLE_300, |
30 | PURPLE_400, |
31 | PURPLE_500, |
32 | PURPLE_600, |
33 | PURPLE_700, |
34 | PURPLE_800, |
35 | PURPLE_900, |
36 | PURPLE_A100, |
37 | PURPLE_A200, |
38 | PURPLE_A400, |
39 | PURPLE_A700, |
40 | ], |
41 | [ |
42 | DEEPPURPLE, |
43 | DEEPPURPLE_50, |
44 | DEEPPURPLE_100, |
45 | DEEPPURPLE_200, |
46 | DEEPPURPLE_300, |
47 | DEEPPURPLE_400, |
48 | DEEPPURPLE_500, |
49 | DEEPPURPLE_600, |
50 | DEEPPURPLE_700, |
51 | DEEPPURPLE_800, |
52 | DEEPPURPLE_900, |
53 | DEEPPURPLE_A100, |
54 | DEEPPURPLE_A200, |
55 | DEEPPURPLE_A400, |
56 | DEEPPURPLE_A700, |
57 | ], |
58 | [ |
59 | INDIGO, |
60 | INDIGO_50, |
61 | INDIGO_100, |
62 | INDIGO_200, |
63 | INDIGO_300, |
64 | INDIGO_400, |
65 | INDIGO_500, |
66 | INDIGO_600, |
67 | INDIGO_700, |
68 | INDIGO_800, |
69 | INDIGO_900, |
70 | INDIGO_A100, |
71 | INDIGO_A200, |
72 | INDIGO_A400, |
73 | INDIGO_A700, |
74 | ], |
75 | [ |
76 | BLUE, BLUE_50, BLUE_100, BLUE_200, BLUE_300, BLUE_400, BLUE_500, BLUE_600, BLUE_700, |
77 | BLUE_800, BLUE_900, BLUE_A100, BLUE_A200, BLUE_A400, BLUE_A700, |
78 | ], |
79 | [ |
80 | LIGHTBLUE, |
81 | LIGHTBLUE_50, |
82 | LIGHTBLUE_100, |
83 | LIGHTBLUE_200, |
84 | LIGHTBLUE_300, |
85 | LIGHTBLUE_400, |
86 | LIGHTBLUE_500, |
87 | LIGHTBLUE_600, |
88 | LIGHTBLUE_700, |
89 | LIGHTBLUE_800, |
90 | LIGHTBLUE_900, |
91 | LIGHTBLUE_A100, |
92 | LIGHTBLUE_A200, |
93 | LIGHTBLUE_A400, |
94 | LIGHTBLUE_A700, |
95 | ], |
96 | [ |
97 | CYAN, CYAN_50, CYAN_100, CYAN_200, CYAN_300, CYAN_400, CYAN_500, CYAN_600, CYAN_700, |
98 | CYAN_800, CYAN_900, CYAN_A100, CYAN_A200, CYAN_A400, CYAN_A700, |
99 | ], |
100 | [ |
101 | TEAL, TEAL_50, TEAL_100, TEAL_200, TEAL_300, TEAL_400, TEAL_500, TEAL_600, TEAL_700, |
102 | TEAL_800, TEAL_900, TEAL_A100, TEAL_A200, TEAL_A400, TEAL_A700, |
103 | ], |
104 | [ |
105 | GREEN, GREEN_50, GREEN_100, GREEN_200, GREEN_300, GREEN_400, GREEN_500, GREEN_600, |
106 | GREEN_700, GREEN_800, GREEN_900, GREEN_A100, GREEN_A200, GREEN_A400, GREEN_A700, |
107 | ], |
108 | [ |
109 | LIGHTGREEN, |
110 | LIGHTGREEN_50, |
111 | LIGHTGREEN_100, |
112 | LIGHTGREEN_200, |
113 | LIGHTGREEN_300, |
114 | LIGHTGREEN_400, |
115 | LIGHTGREEN_500, |
116 | LIGHTGREEN_600, |
117 | LIGHTGREEN_700, |
118 | LIGHTGREEN_800, |
119 | LIGHTGREEN_900, |
120 | LIGHTGREEN_A100, |
121 | LIGHTGREEN_A200, |
122 | LIGHTGREEN_A400, |
123 | LIGHTGREEN_A700, |
124 | ], |
125 | [ |
126 | LIME, LIME_50, LIME_100, LIME_200, LIME_300, LIME_400, LIME_500, LIME_600, LIME_700, |
127 | LIME_800, LIME_900, LIME_A100, LIME_A200, LIME_A400, LIME_A700, |
128 | ], |
129 | [ |
130 | YELLOW, |
131 | YELLOW_50, |
132 | YELLOW_100, |
133 | YELLOW_200, |
134 | YELLOW_300, |
135 | YELLOW_400, |
136 | YELLOW_500, |
137 | YELLOW_600, |
138 | YELLOW_700, |
139 | YELLOW_800, |
140 | YELLOW_900, |
141 | YELLOW_A100, |
142 | YELLOW_A200, |
143 | YELLOW_A400, |
144 | YELLOW_A700, |
145 | ], |
146 | [ |
147 | AMBER, AMBER_50, AMBER_100, AMBER_200, AMBER_300, AMBER_400, AMBER_500, AMBER_600, |
148 | AMBER_700, AMBER_800, AMBER_900, AMBER_A100, AMBER_A200, AMBER_A400, AMBER_A700, |
149 | ], |
150 | [ |
151 | ORANGE, |
152 | ORANGE_50, |
153 | ORANGE_100, |
154 | ORANGE_200, |
155 | ORANGE_300, |
156 | ORANGE_400, |
157 | ORANGE_500, |
158 | ORANGE_600, |
159 | ORANGE_700, |
160 | ORANGE_800, |
161 | ORANGE_900, |
162 | ORANGE_A100, |
163 | ORANGE_A200, |
164 | ORANGE_A400, |
165 | ORANGE_A700, |
166 | ], |
167 | [ |
168 | DEEPORANGE, |
169 | DEEPORANGE_50, |
170 | DEEPORANGE_100, |
171 | DEEPORANGE_200, |
172 | DEEPORANGE_300, |
173 | DEEPORANGE_400, |
174 | DEEPORANGE_500, |
175 | DEEPORANGE_600, |
176 | DEEPORANGE_700, |
177 | DEEPORANGE_800, |
178 | DEEPORANGE_900, |
179 | DEEPORANGE_A100, |
180 | DEEPORANGE_A200, |
181 | DEEPORANGE_A400, |
182 | DEEPORANGE_A700, |
183 | ], |
184 | [ |
185 | BROWN, BROWN_50, BROWN_100, BROWN_200, BROWN_300, BROWN_400, BROWN_500, BROWN_600, |
186 | BROWN_700, BROWN_800, BROWN_900, BROWN_A100, BROWN_A200, BROWN_A400, BROWN_A700, |
187 | ], |
188 | [ |
189 | GREY, GREY_50, GREY_100, GREY_200, GREY_300, GREY_400, GREY_500, GREY_600, GREY_700, |
190 | GREY_800, GREY_900, GREY_A100, GREY_A200, GREY_A400, GREY_A700, |
191 | ], |
192 | [ |
193 | BLUEGREY, |
194 | BLUEGREY_50, |
195 | BLUEGREY_100, |
196 | BLUEGREY_200, |
197 | BLUEGREY_300, |
198 | BLUEGREY_400, |
199 | BLUEGREY_500, |
200 | BLUEGREY_600, |
201 | BLUEGREY_700, |
202 | BLUEGREY_800, |
203 | BLUEGREY_900, |
204 | BLUEGREY_A100, |
205 | BLUEGREY_A200, |
206 | BLUEGREY_A400, |
207 | BLUEGREY_A700, |
208 | ], |
209 | ]; |
210 | let color_names = [ |
211 | [ |
212 | "RED" , "RED_50" , "RED_100" , "RED_200" , "RED_300" , "RED_400" , "RED_500" , "RED_600" , |
213 | "RED_700" , "RED_800" , "RED_900" , "RED_A100" , "RED_A200" , "RED_A400" , "RED_A700" , |
214 | ], |
215 | [ |
216 | "PINK" , |
217 | "PINK_50" , |
218 | "PINK_100" , |
219 | "PINK_200" , |
220 | "PINK_300" , |
221 | "PINK_400" , |
222 | "PINK_500" , |
223 | "PINK_600" , |
224 | "PINK_700" , |
225 | "PINK_800" , |
226 | "PINK_900" , |
227 | "PINK_A100" , |
228 | "PINK_A200" , |
229 | "PINK_A400" , |
230 | "PINK_A700" , |
231 | ], |
232 | [ |
233 | "PURPLE" , |
234 | "PURPLE_50" , |
235 | "PURPLE_100" , |
236 | "PURPLE_200" , |
237 | "PURPLE_300" , |
238 | "PURPLE_400" , |
239 | "PURPLE_500" , |
240 | "PURPLE_600" , |
241 | "PURPLE_700" , |
242 | "PURPLE_800" , |
243 | "PURPLE_900" , |
244 | "PURPLE_A100" , |
245 | "PURPLE_A200" , |
246 | "PURPLE_A400" , |
247 | "PURPLE_A700" , |
248 | ], |
249 | [ |
250 | "DEEPPURPLE" , |
251 | "DEEPPURPLE_50" , |
252 | "DEEPPURPLE_100" , |
253 | "DEEPPURPLE_200" , |
254 | "DEEPPURPLE_300" , |
255 | "DEEPPURPLE_400" , |
256 | "DEEPPURPLE_500" , |
257 | "DEEPPURPLE_600" , |
258 | "DEEPPURPLE_700" , |
259 | "DEEPPURPLE_800" , |
260 | "DEEPPURPLE_900" , |
261 | "DEEPPURPLE_A100" , |
262 | "DEEPPURPLE_A200" , |
263 | "DEEPPURPLE_A400" , |
264 | "DEEPPURPLE_A700" , |
265 | ], |
266 | [ |
267 | "INDIGO" , |
268 | "INDIGO_50" , |
269 | "INDIGO_100" , |
270 | "INDIGO_200" , |
271 | "INDIGO_300" , |
272 | "INDIGO_400" , |
273 | "INDIGO_500" , |
274 | "INDIGO_600" , |
275 | "INDIGO_700" , |
276 | "INDIGO_800" , |
277 | "INDIGO_900" , |
278 | "INDIGO_A100" , |
279 | "INDIGO_A200" , |
280 | "INDIGO_A400" , |
281 | "INDIGO_A700" , |
282 | ], |
283 | [ |
284 | "BLUE" , |
285 | "BLUE_50" , |
286 | "BLUE_100" , |
287 | "BLUE_200" , |
288 | "BLUE_300" , |
289 | "BLUE_400" , |
290 | "BLUE_500" , |
291 | "BLUE_600" , |
292 | "BLUE_700" , |
293 | "BLUE_800" , |
294 | "BLUE_900" , |
295 | "BLUE_A100" , |
296 | "BLUE_A200" , |
297 | "BLUE_A400" , |
298 | "BLUE_A700" , |
299 | ], |
300 | [ |
301 | "LIGHTBLUE" , |
302 | "LIGHTBLUE_50" , |
303 | "LIGHTBLUE_100" , |
304 | "LIGHTBLUE_200" , |
305 | "LIGHTBLUE_300" , |
306 | "LIGHTBLUE_400" , |
307 | "LIGHTBLUE_500" , |
308 | "LIGHTBLUE_600" , |
309 | "LIGHTBLUE_700" , |
310 | "LIGHTBLUE_800" , |
311 | "LIGHTBLUE_900" , |
312 | "LIGHTBLUE_A100" , |
313 | "LIGHTBLUE_A200" , |
314 | "LIGHTBLUE_A400" , |
315 | "LIGHTBLUE_A700" , |
316 | ], |
317 | [ |
318 | "CYAN" , |
319 | "CYAN_50" , |
320 | "CYAN_100" , |
321 | "CYAN_200" , |
322 | "CYAN_300" , |
323 | "CYAN_400" , |
324 | "CYAN_500" , |
325 | "CYAN_600" , |
326 | "CYAN_700" , |
327 | "CYAN_800" , |
328 | "CYAN_900" , |
329 | "CYAN_A100" , |
330 | "CYAN_A200" , |
331 | "CYAN_A400" , |
332 | "CYAN_A700" , |
333 | ], |
334 | [ |
335 | "TEAL" , |
336 | "TEAL_50" , |
337 | "TEAL_100" , |
338 | "TEAL_200" , |
339 | "TEAL_300" , |
340 | "TEAL_400" , |
341 | "TEAL_500" , |
342 | "TEAL_600" , |
343 | "TEAL_700" , |
344 | "TEAL_800" , |
345 | "TEAL_900" , |
346 | "TEAL_A100" , |
347 | "TEAL_A200" , |
348 | "TEAL_A400" , |
349 | "TEAL_A700" , |
350 | ], |
351 | [ |
352 | "GREEN" , |
353 | "GREEN_50" , |
354 | "GREEN_100" , |
355 | "GREEN_200" , |
356 | "GREEN_300" , |
357 | "GREEN_400" , |
358 | "GREEN_500" , |
359 | "GREEN_600" , |
360 | "GREEN_700" , |
361 | "GREEN_800" , |
362 | "GREEN_900" , |
363 | "GREEN_A100" , |
364 | "GREEN_A200" , |
365 | "GREEN_A400" , |
366 | "GREEN_A700" , |
367 | ], |
368 | [ |
369 | "LIGHTGREEN" , |
370 | "LIGHTGREEN_50" , |
371 | "LIGHTGREEN_100" , |
372 | "LIGHTGREEN_200" , |
373 | "LIGHTGREEN_300" , |
374 | "LIGHTGREEN_400" , |
375 | "LIGHTGREEN_500" , |
376 | "LIGHTGREEN_600" , |
377 | "LIGHTGREEN_700" , |
378 | "LIGHTGREEN_800" , |
379 | "LIGHTGREEN_900" , |
380 | "LIGHTGREEN_A100" , |
381 | "LIGHTGREEN_A200" , |
382 | "LIGHTGREEN_A400" , |
383 | "LIGHTGREEN_A700" , |
384 | ], |
385 | [ |
386 | "LIME" , |
387 | "LIME_50" , |
388 | "LIME_100" , |
389 | "LIME_200" , |
390 | "LIME_300" , |
391 | "LIME_400" , |
392 | "LIME_500" , |
393 | "LIME_600" , |
394 | "LIME_700" , |
395 | "LIME_800" , |
396 | "LIME_900" , |
397 | "LIME_A100" , |
398 | "LIME_A200" , |
399 | "LIME_A400" , |
400 | "LIME_A700" , |
401 | ], |
402 | [ |
403 | "YELLOW" , |
404 | "YELLOW_50" , |
405 | "YELLOW_100" , |
406 | "YELLOW_200" , |
407 | "YELLOW_300" , |
408 | "YELLOW_400" , |
409 | "YELLOW_500" , |
410 | "YELLOW_600" , |
411 | "YELLOW_700" , |
412 | "YELLOW_800" , |
413 | "YELLOW_900" , |
414 | "YELLOW_A100" , |
415 | "YELLOW_A200" , |
416 | "YELLOW_A400" , |
417 | "YELLOW_A700" , |
418 | ], |
419 | [ |
420 | "AMBER" , |
421 | "AMBER_50" , |
422 | "AMBER_100" , |
423 | "AMBER_200" , |
424 | "AMBER_300" , |
425 | "AMBER_400" , |
426 | "AMBER_500" , |
427 | "AMBER_600" , |
428 | "AMBER_700" , |
429 | "AMBER_800" , |
430 | "AMBER_900" , |
431 | "AMBER_A100" , |
432 | "AMBER_A200" , |
433 | "AMBER_A400" , |
434 | "AMBER_A700" , |
435 | ], |
436 | [ |
437 | "ORANGE" , |
438 | "ORANGE_50" , |
439 | "ORANGE_100" , |
440 | "ORANGE_200" , |
441 | "ORANGE_300" , |
442 | "ORANGE_400" , |
443 | "ORANGE_500" , |
444 | "ORANGE_600" , |
445 | "ORANGE_700" , |
446 | "ORANGE_800" , |
447 | "ORANGE_900" , |
448 | "ORANGE_A100" , |
449 | "ORANGE_A200" , |
450 | "ORANGE_A400" , |
451 | "ORANGE_A700" , |
452 | ], |
453 | [ |
454 | "DEEPORANGE" , |
455 | "DEEPORANGE_50" , |
456 | "DEEPORANGE_100" , |
457 | "DEEPORANGE_200" , |
458 | "DEEPORANGE_300" , |
459 | "DEEPORANGE_400" , |
460 | "DEEPORANGE_500" , |
461 | "DEEPORANGE_600" , |
462 | "DEEPORANGE_700" , |
463 | "DEEPORANGE_800" , |
464 | "DEEPORANGE_900" , |
465 | "DEEPORANGE_A100" , |
466 | "DEEPORANGE_A200" , |
467 | "DEEPORANGE_A400" , |
468 | "DEEPORANGE_A700" , |
469 | ], |
470 | [ |
471 | "BROWN" , |
472 | "BROWN_50" , |
473 | "BROWN_100" , |
474 | "BROWN_200" , |
475 | "BROWN_300" , |
476 | "BROWN_400" , |
477 | "BROWN_500" , |
478 | "BROWN_600" , |
479 | "BROWN_700" , |
480 | "BROWN_800" , |
481 | "BROWN_900" , |
482 | "BROWN_A100" , |
483 | "BROWN_A200" , |
484 | "BROWN_A400" , |
485 | "BROWN_A700" , |
486 | ], |
487 | [ |
488 | "GREY" , |
489 | "GREY_50" , |
490 | "GREY_100" , |
491 | "GREY_200" , |
492 | "GREY_300" , |
493 | "GREY_400" , |
494 | "GREY_500" , |
495 | "GREY_600" , |
496 | "GREY_700" , |
497 | "GREY_800" , |
498 | "GREY_900" , |
499 | "GREY_A100" , |
500 | "GREY_A200" , |
501 | "GREY_A400" , |
502 | "GREY_A700" , |
503 | ], |
504 | [ |
505 | "BLUEGREY" , |
506 | "BLUEGREY_50" , |
507 | "BLUEGREY_100" , |
508 | "BLUEGREY_200" , |
509 | "BLUEGREY_300" , |
510 | "BLUEGREY_400" , |
511 | "BLUEGREY_500" , |
512 | "BLUEGREY_600" , |
513 | "BLUEGREY_700" , |
514 | "BLUEGREY_800" , |
515 | "BLUEGREY_900" , |
516 | "BLUEGREY_A100" , |
517 | "BLUEGREY_A200" , |
518 | "BLUEGREY_A400" , |
519 | "BLUEGREY_A700" , |
520 | ], |
521 | ]; |
522 | |
523 | use plotters::style::text_anchor::*; |
524 | let centered = Pos::new(HPos::Center, VPos::Top); |
525 | let label_style = TextStyle::from(("monospace" , 14.0).into_font()).pos(centered); |
526 | |
527 | for (col, colors) in colors.iter().enumerate() { |
528 | chart.draw_series(colors.iter().zip(color_names[col].iter()).enumerate().map( |
529 | |(row, (color, &name))| { |
530 | let row = row as f32; |
531 | let col = col as f32; |
532 | EmptyElement::at((col, row)) |
533 | + Circle::new((0, 0), 15, color.filled()) |
534 | + Text::new(name, (0, 16), &label_style) |
535 | }, |
536 | ))?; |
537 | } |
538 | |
539 | // To avoid the IO failure being ignored silently, we manually call the present function |
540 | root.present().expect("Unable to write result to file, please make sure 'plotters-doc-data' dir exists under current dir" ); |
541 | println!("Result has been saved to {}" , OUT_FILE_NAME); |
542 | |
543 | Ok(()) |
544 | } |
545 | #[test] |
546 | fn entry_point() { |
547 | main().unwrap() |
548 | } |
549 | |