pub struct GgsqlPalette { /* private fields */ }Expand description
A resolved ggsci palette ready for ggsql conversion.
The wrapper retains the source palette semantics until a caller selects a ggsql scale kind or converts the colors to an untyped output range.
Implementations§
Source§impl GgsqlPalette
impl GgsqlPalette
Sourcepub fn from_colors(colors: Vec<Rgb>, palette_kind: PaletteKind) -> Self
pub fn from_colors(colors: Vec<Rgb>, palette_kind: PaletteKind) -> Self
Creates a wrapper from already resolved colors and their source semantics.
Sourcepub fn from_spec(spec: &str, n: usize) -> Result<Self, Error>
pub fn from_spec(spec: &str, n: usize) -> Result<Self, Error>
Resolves and samples a core palette using its discrete or continuous semantics.
§Errors
Returns an error when the specification is invalid, the palette is not
known, or a discrete palette does not have n colors.
Sourcepub fn from_continuous(
spec: &str,
n: usize,
options: ContinuousOptions,
) -> Result<Self, Error>
pub fn from_continuous( spec: &str, n: usize, options: ContinuousOptions, ) -> Result<Self, Error>
Resolves and interpolates a continuous core palette with explicit options.
§Errors
Returns an error when the palette cannot be found or is not continuous.
Examples found in repository?
4fn main() -> Result<(), ggsci_ggsql::Error> {
5 let palette = GgsqlPalette::from_continuous(
6 "material:blue-grey",
7 256,
8 ContinuousOptions::new().with_reverse(true),
9 )?;
10
11 let clause = palette.to_default_scale_clause("fill")?;
12 assert!(clause.starts_with("SCALE CONTINUOUS fill TO"));
13
14 let binned = palette.to_scale_clause(ScaleKind::Binned, "fill")?;
15 assert!(binned.starts_with("SCALE BINNED fill TO"));
16
17 Ok(())
18}Sourcepub fn from_iterm(
palette: &str,
variant: ItermVariant,
n: usize,
) -> Result<Self, Error>
pub fn from_iterm( palette: &str, variant: ItermVariant, n: usize, ) -> Result<Self, Error>
Resolves colors from a fixed discrete iTerm theme variant.
§Errors
Returns an error when the theme is unknown or n exceeds the six
colors in a variant.
Sourcepub fn from_gephi(palette: &str, n: usize) -> Result<Self, Error>
pub fn from_gephi(palette: &str, n: usize) -> Result<Self, Error>
Generates colors from a generative discrete Gephi palette.
Use Self::from_gephi_with_seed when reproducibility matters.
§Errors
Returns an error when the palette is unknown or generation fails.
Sourcepub fn from_gephi_with_seed(
palette: &str,
n: usize,
seed: u64,
) -> Result<Self, Error>
pub fn from_gephi_with_seed( palette: &str, n: usize, seed: u64, ) -> Result<Self, Error>
Generates reproducible colors from a generative discrete Gephi palette.
§Errors
Returns an error when the palette is unknown or generation fails.
Sourcepub fn into_colors(self) -> Vec<Rgb>
pub fn into_colors(self) -> Vec<Rgb>
Consumes the wrapper and returns its resolved colors.
Sourcepub const fn palette_kind(&self) -> PaletteKind
pub const fn palette_kind(&self) -> PaletteKind
Returns the source palette’s semantic kind.
Sourcepub fn to_sql_array(&self) -> String
pub fn to_sql_array(&self) -> String
Formats the colors as a ggsql array of uppercase #RRGGBB strings.
Sourcepub fn to_output_range(&self) -> OutputRange
pub fn to_output_range(&self) -> OutputRange
Converts the colors to ggsql’s typed explicit output range.
The resulting value intentionally does not retain scale-kind metadata.
Sourcepub fn to_scale_clause(
&self,
kind: ScaleKind,
aesthetic: &str,
) -> Result<String, Error>
pub fn to_scale_clause( &self, kind: ScaleKind, aesthetic: &str, ) -> Result<String, Error>
Emits an explicit-array ggsql scale clause of the selected kind.
§Errors
Returns Error::InvalidAesthetic unless aesthetic, after trimming,
is an ASCII identifier matching [A-Za-z_][A-Za-z0-9_]*.
Examples found in repository?
4fn main() -> Result<(), ggsci_ggsql::Error> {
5 let palette = GgsqlPalette::from_continuous(
6 "material:blue-grey",
7 256,
8 ContinuousOptions::new().with_reverse(true),
9 )?;
10
11 let clause = palette.to_default_scale_clause("fill")?;
12 assert!(clause.starts_with("SCALE CONTINUOUS fill TO"));
13
14 let binned = palette.to_scale_clause(ScaleKind::Binned, "fill")?;
15 assert!(binned.starts_with("SCALE BINNED fill TO"));
16
17 Ok(())
18}Sourcepub fn to_default_scale_clause(&self, aesthetic: &str) -> Result<String, Error>
pub fn to_default_scale_clause(&self, aesthetic: &str) -> Result<String, Error>
Emits an explicit-array ggsql scale clause whose kind defaults from the source palette semantics.
§Errors
Returns Error::InvalidAesthetic unless aesthetic, after trimming,
is a valid ASCII identifier.
Examples found in repository?
More examples
4fn main() -> Result<(), ggsci_ggsql::Error> {
5 let palette = GgsqlPalette::from_continuous(
6 "material:blue-grey",
7 256,
8 ContinuousOptions::new().with_reverse(true),
9 )?;
10
11 let clause = palette.to_default_scale_clause("fill")?;
12 assert!(clause.starts_with("SCALE CONTINUOUS fill TO"));
13
14 let binned = palette.to_scale_clause(ScaleKind::Binned, "fill")?;
15 assert!(binned.starts_with("SCALE BINNED fill TO"));
16
17 Ok(())
18}Trait Implementations§
Source§impl Clone for GgsqlPalette
impl Clone for GgsqlPalette
Source§fn clone(&self) -> GgsqlPalette
fn clone(&self) -> GgsqlPalette
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GgsqlPalette
impl Debug for GgsqlPalette
impl Eq for GgsqlPalette
Source§impl From<&GgsqlPalette> for OutputRange
impl From<&GgsqlPalette> for OutputRange
Source§fn from(palette: &GgsqlPalette) -> Self
fn from(palette: &GgsqlPalette) -> Self
Source§impl From<GgsqlPalette> for OutputRange
impl From<GgsqlPalette> for OutputRange
Source§fn from(palette: GgsqlPalette) -> Self
fn from(palette: GgsqlPalette) -> Self
Source§impl PartialEq for GgsqlPalette
impl PartialEq for GgsqlPalette
impl StructuralPartialEq for GgsqlPalette
Auto Trait Implementations§
impl Freeze for GgsqlPalette
impl RefUnwindSafe for GgsqlPalette
impl Send for GgsqlPalette
impl Sync for GgsqlPalette
impl Unpin for GgsqlPalette
impl UnsafeUnpin for GgsqlPalette
impl UnwindSafe for GgsqlPalette
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
impl<T> Allocation for T
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more