Skip to content

Commit 030a21a

Browse files
committed
style/color: derive serialize & deserialize
Using serde is useful in production, not just during development, so move it to normal dependencies instead of dev-dependencies. This allows to derive serialize/deserialize for the color structs which are very simple using the default implementation, allowing to pass colors along via serialization channels and formats.
1 parent cb7791f commit 030a21a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

plotters/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ deprecated = { level = "allow" }
2020
[dependencies]
2121
num-traits = "0.2.14"
2222
chrono = { version = "0.4.32", optional = true }
23+
serde = { version = "1.0.139", features = ["derive"] }
2324

2425
[dependencies.plotters-backend]
2526
version = "0.3.6"
@@ -122,7 +123,6 @@ itertools = "0.10.0"
122123
criterion = "0.5.1"
123124
rayon = "1.5.1"
124125
serde_json = "1.0.82"
125-
serde = "1.0.139"
126126
serde_derive = "1.0.140"
127127

128128
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]

plotters/src/style/color.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use super::ShapeStyle;
33

44
use plotters_backend::{BackendColor, BackendStyle};
55

6+
use serde::{Deserialize, Serialize};
7+
68
use std::marker::PhantomData;
79

810
/// Any color representation
@@ -63,7 +65,7 @@ impl<T: Color> Color for &'_ T {
6365
/// of color
6466
///
6567
/// If you want to directly create a RGB color with transparency use [RGBColor::mix]
66-
#[derive(Copy, Clone, PartialEq, Debug, Default)]
68+
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
6769
pub struct RGBAColor(pub u8, pub u8, pub u8, pub f64);
6870

6971
impl Color for RGBAColor {
@@ -83,7 +85,7 @@ impl From<RGBColor> for RGBAColor {
8385
}
8486

8587
/// A color in the given palette
86-
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
88+
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default, Serialize, Deserialize)]
8789
pub struct PaletteColor<P: Palette>(usize, PhantomData<P>);
8890

8991
impl<P: Palette> PaletteColor<P> {
@@ -104,7 +106,7 @@ impl<P: Palette> Color for PaletteColor<P> {
104106
}
105107

106108
/// The color described by its RGB value
107-
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
109+
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default, Serialize, Deserialize)]
108110
pub struct RGBColor(pub u8, pub u8, pub u8);
109111

110112
impl BackendStyle for RGBAColor {
@@ -129,7 +131,7 @@ impl BackendStyle for RGBColor {
129131
}
130132

131133
/// The color described by HSL color space
132-
#[derive(Copy, Clone, PartialEq, Debug, Default)]
134+
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
133135
pub struct HSLColor(pub f64, pub f64, pub f64);
134136

135137
impl Color for HSLColor {

0 commit comments

Comments
 (0)