Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.vscode/settings.json
.idea/
target/
/*.svg
/*.png
/*.json
/*.yml

73 changes: 67 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ plotive-base.workspace = true
plotive-text.workspace = true
# feature dsl
plotive-dsl = { workspace = true, optional = true }
# feature serde
serde = { workspace = true, optional = true }
serde-value = { version = "0.7", optional = true }

[dev-dependencies]
plotive-iced = { path = "iced", features = ["clipboard"] }
Expand All @@ -26,6 +29,9 @@ rand.workspace = true
rand_distr.workspace = true
rand_chacha.workspace = true
ode_solvers = "0.6.1"
serde_json.workspace = true
noyalib = "0.0.6"


[features]
default = ["noto-sans"]
Expand All @@ -37,6 +43,7 @@ noto-sans = ["plotive-text/noto-sans"]
noto-sans-italic = ["plotive-text/noto-sans-italic"]
noto-serif = ["plotive-text/noto-serif"]
noto-serif-italic = ["plotive-text/noto-serif-italic"]
serde = ["plotive-base/serde", "dep:serde", "dep:serde-value"]
time = []
utils = []

Expand Down Expand Up @@ -73,6 +80,9 @@ required-features = ["data-csv"]
name = "iris_dsl"
required-features = ["data-csv", "dsl"]

[[example]]
name = "minimal"

[[example]]
name = "multiple_axes"
required-features = ["utils"]
Expand Down Expand Up @@ -117,7 +127,6 @@ keywords = ["data", "visualization", "plotting"]
plotive = { version = "0.5.0", path = "." }
plotive-base = { version = "0.5.0", path = "base" }
plotive-dsl = { version = "0.5.0", path = "dsl" }
plotive-iced = { version = "0.5.0", path = "iced" }
plotive-pxl = { version = "0.5.0", path = "pxl" }
plotive-svg = { version = "0.5.0", path = "svg" }
plotive-text = { version = "0.5.0", path = "text" }
Expand All @@ -137,6 +146,8 @@ rand_distr = "0.5.1"
rand_chacha = "0.9.0"
rfd = "0.17.1"
rustybuzz = "0.20.1"
serde = { version = "1.0.228" }
serde_json = "1.0.149"
strict-num = "0.2.0"
tiny-skia = "0.11.4"
tiny-skia-path = "0.11.4"
Expand Down
7 changes: 7 additions & 0 deletions base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ keywords.workspace = true
[dependencies]
tiny-skia-path.workspace = true
strict-num.workspace = true
serde = { workspace = true, optional = true }

[dev-dependencies]
serde_json = { workspace = true }

[features]
serde = ["dep:serde"]
38 changes: 29 additions & 9 deletions base/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::str::FromStr;
use std::{error, fmt};

mod css4;
mod xkcd;
pub(crate) mod css4;
pub(crate) mod xkcd;

pub use css4::*;

Expand Down Expand Up @@ -60,7 +60,7 @@ impl Rgba8 {
}

/// Get the HTML hex string representation of the color, e.g. `#ff0000` for red.
/// If the alpha channel is not 255, the form "rgba(r, g, b, a)" is used.
/// If the alpha channel is not 255, the form "rgba(r, g, b, a)" is used instead (with alpha normalized to [0, 1]).
pub fn html(&self) -> String {
if self.a() == 255 {
format!("#{:02x}{:02x}{:02x}", self.r(), self.g(), self.b())
Expand Down Expand Up @@ -376,9 +376,10 @@ impl FromStr for Rgb8 {
}
// named color
else {
if let Some(col) = css4::lookup_name(raw) {
Ok(col.rgb())
} else if let Some(col) = xkcd::lookup_name(raw) {
if let Some(col) = names::lookup(raw) {
if col.a() != 255 {
return Err(ParseError::InvalidAlphaComponent);
}
Ok(col.rgb())
} else {
Err(ParseError::UnknownName)
Expand Down Expand Up @@ -441,9 +442,7 @@ impl FromStr for Rgba8 {
}
// named color
else {
if let Some(col) = css4::lookup_name(raw) {
Ok(col)
} else if let Some(col) = xkcd::lookup_name(raw) {
if let Some(col) = names::lookup(raw) {
Ok(col)
} else {
Err(ParseError::UnknownName)
Expand All @@ -452,6 +451,27 @@ impl FromStr for Rgba8 {
}
}

pub(crate) mod names {
use std::collections::HashMap;
use std::sync::LazyLock;

use crate::Rgba8;
use crate::color::{css4, xkcd};

static MAP: LazyLock<HashMap<&'static str, Rgba8>> = LazyLock::new(|| {
// Start with XKCD colors, then CSS4 so CSS4 names take precedence on collisions.
let mut map = HashMap::with_capacity(xkcd::COLORS.len() + css4::COLORS.len());
map.extend(xkcd::COLORS.iter().map(|(name, rgba)| (*name, *rgba)));
map.extend(css4::COLORS.iter().map(|(name, rgba)| (*name, *rgba)));
map
});

pub(crate) fn lookup(name: &str) -> Option<Rgba8> {
let key = name.trim().to_lowercase();
MAP.get(key.as_str()).copied()
}
}

/// A trait for interpolating between two colors, used for color scales in heatmaps and similar plots.
pub trait Lerp {
/// Interpolate between two colors using a parameter t in the range [0.0, 1.0].
Expand Down
Loading
Loading