ColorType

Enum ColorType 

Source
pub enum ColorType<T = String> {
Show 13 variants RGBString(T), RGBInteger(ColorComponent, ColorComponent, ColorComponent), ARGBInteger(ColorComponent, ColorComponent, ColorComponent, ColorComponent), VariableRGBInteger(Vec<RGBInts>), VariableARGBInteger(Vec<ARGBInts>), PaletteFracColor(f64), PaletteCBColor(f64), VariablePaletteColor(Vec<f64>), SavedColorMap(T, Vec<f64>), Index(ColorIndex), VariableIndex(Vec<ColorIndex>), Background, Black,
}
Expand description

Option type (for plots, borders, and text) that allows the various different gnuplot color formats. The gnuplot colorspec reference also explains these.

NOTE: Gnuplot interprets the alpha channel in an unusual way, where 0 is fully opaque and 255 is fully transparent. This wrapper inverts the meaning (as described below) to match the more common interpretation.

There are many equivalent ways of specifying colors, and this allows the user to chose the most convenient. For example, all the following will produce the same blue color: RGBColor("blue".into()), RGBColor("0x0000ff".into()), RGBColor("#0000ff".into()), RGBColor("0xff0000ff".into()), RGBColor("#ff0000ff".into()), RGBIntegerColor(0, 0, 255), ARGBColor(255, 0, 0, 255),

See example usages of these colors in color.rs and variable_color.rs in the Examples folder on Github

Variants§

§

RGBString(T)

string (&str or String, but usually created with &str) in one of the following gnuplot-supported formats

  • colorname — e.g. “blue” [See the gnuplot list of colornames]
  • 0xRRGGBB — string containing hexadecimal constant
  • 0xAARRGGBB — string containing hexadecimal constant
  • #RRGGBB — string containing hexadecimal in x11 format
  • #AARRGGBB — string containing hexadecimal in x11 format

“#AARRGGBB” represents an RGB color with an alpha channel value in the high bits. An alpha value of 255 (FF) represents a fully opaque color; i.e., “#FFRRGGBB” is the same as “#RRGGBB”. An alpha value of 0 represents full transparency.

§

RGBInteger(ColorComponent, ColorComponent, ColorComponent)

tuple of u8 representing red, green and blue values as 0-255

§

ARGBInteger(ColorComponent, ColorComponent, ColorComponent, ColorComponent)

tuple of u8 representing alpha, red, green and blue values as 0-255. As with RGBColor, an alpha value of 255 (FF) represents a fully opaque color; an alpha value of 0 represents full transparency.

§

VariableRGBInteger(Vec<RGBInts>)

Vector of tuples of u8 (as per RGBColor), but instead of a single color for the whole plot, the vector should contain a separte color for each data point.

§

VariableARGBInteger(Vec<ARGBInts>)

Vector of tuples of u8 (as per ARGBColor), but as with VariableRGBColor, a separate color value is given for each data point.

§

PaletteFracColor(f64)

Sets the color of the plot element to a value picked from the current palette (see set_palette()). The value supplied to this color type selects the color within the color range of the palette: i.e. it if the color bar range had been set with ax.set_cb_range(Fix(min), Fix(max)), the value would be expected to be between min and max.

Example of usage is give in the color example.

Compare with PaletteFracColor

§

PaletteCBColor(f64)

Sets the color of the plot element to a value picked from the current palette (see set_palette() . The value supplied to this color type selects the color as a fraction of the current color range i.e. it is expected to be between 0 and 1.

Example of usage is give in the color example.

Comparing with PaletteCBColor: given the following code

use gnuplot::{PaletteCBColor, PaletteFracColor, Fix, Figure, AxesCommon, Color};

assert!(frac >= 0.0);
assert!(frac <= 1.0);

let mut fg = Figure::new();
let ax = fg.axes2d();
ax.set_cb_range(Fix(min), Fix(max));
let col1 = Color(PaletteFracColor(frac));
let cb_range = max - min;
let col2 = Color(PaletteCBColor(min + (frac * cb_range)));
ax.lines(x, y, &[col1]);
ax.lines(x, y, &[col2]);

the two lines should give the same color for any values of max and min, and 0 <= frac <= 1.

§

VariablePaletteColor(Vec<f64>)

Vector of f64 values which act as indexes into the current palette to set the color of each data point. These variable values work in the same was as the single fixed value supplied to a PaletteCBColor

§

SavedColorMap(T, Vec<f64>)

Similar to VariablePaletteColor in that it takes a Vec<f64> to set the indexes into the color map for each data point, but in addition to the color data it takes a string hold the name of the colormap to use. This should have been previously created in the workspace using the create_colormap() function.

§

Index(ColorIndex)

Set the color of all elements of the plot to the nth color in the current gnuplot color cycle.

§

VariableIndex(Vec<ColorIndex>)

A color type that sets the color per element using a index n which represents the nth color in the current gnuplot color scheme. In gnuplot this is the last element in the plot command, in Rust gnuplot, the color type takes a vector of u8, where each index is treated the same as the fixed IndexColor. This is useful for setting bars/boxes etc to be the same color from multiple plot commands. The variable_color example has examples of this usage.

§

Background

Set the color of the plot to the current background color.

§

Black

Fixed black color

Implementations§

Source§

impl<T: Display + Debug> ColorType<T>

Source

pub fn command(&self) -> String

Returns the gnuplot string that will produce the requested color

Source

pub fn data(&self) -> Vec<f64>

Source

pub fn is_variable(&self) -> bool

Source

pub fn has_alpha(&self) -> bool

Source§

impl ColorType<String>

Source

pub fn to_ref(&self) -> ColorType<&str>

Trait Implementations§

Source§

impl<T: Clone> Clone for ColorType<T>

Source§

fn clone(&self) -> ColorType<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for ColorType<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'l> From<&'l str> for ColorType<String>

Source§

fn from(value: &'l str) -> Self

Converts &str into RGBString

Source§

impl<'l> From<&'l str> for ColorType<&'l str>

Source§

fn from(value: &'l str) -> Self

Converts &str into RGBString

Source§

impl<T> From<(u8, u8, u8)> for ColorType<T>

Source§

fn from(value: RGBInts) -> Self

Converts (u8, u8, u8) into RGBInteger

Source§

impl<T> From<(u8, u8, u8, u8)> for ColorType<T>

Source§

fn from(value: ARGBInts) -> Self

Converts (u8, u8, u8, u8) into ARGBInteger

Source§

impl<'l> From<String> for ColorType<String>

Source§

fn from(value: String) -> Self

Converts String into RGBString

Source§

impl<T> From<Vec<(u8, u8, u8)>> for ColorType<T>

Source§

fn from(value: Vec<RGBInts>) -> Self

Converts Vec<(u8, u8, u8)> into VariableRGBInteger

Source§

impl<T> From<Vec<(u8, u8, u8, u8)>> for ColorType<T>

Source§

fn from(value: Vec<ARGBInts>) -> Self

Converts Vec<(u8, u8, u8, u8)> into VariableARGBInteger

Source§

impl<T> From<Vec<u8>> for ColorType<T>

Source§

fn from(value: Vec<ColorIndex>) -> Self

Converts Vec<u8> into VariableIndex

Source§

impl<T> From<u8> for ColorType<T>

Source§

fn from(value: ColorIndex) -> Self

Converts u8 into Index

Source§

impl<T: PartialEq> PartialEq for ColorType<T>

Source§

fn eq(&self, other: &ColorType<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for ColorType<T>

Source§

fn partial_cmp(&self, other: &ColorType<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> TryFrom<(f64, f64, f64)> for ColorType<T>

Source§

fn try_from(value: (f64, f64, f64)) -> Result<Self, Self::Error>

Converts (f64, f64, f64) into RGBInteger. Returns an error unless all values are in the range 0 <= v <= 1.

Source§

type Error = String

The type returned in the event of a conversion error.
Source§

impl<T> TryFrom<(f64, f64, f64, f64)> for ColorType<T>

Source§

fn try_from(value: (f64, f64, f64, f64)) -> Result<Self, Self::Error>

Converts (f64, f64, f64, f64) into ARGBInteger. Returns an error unless all values are in the range 0 <= v <= 1.

Source§

type Error = String

The type returned in the event of a conversion error.
Source§

impl<T> StructuralPartialEq for ColorType<T>

Auto Trait Implementations§

§

impl<T> Freeze for ColorType<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ColorType<T>
where T: RefUnwindSafe,

§

impl<T> Send for ColorType<T>
where T: Send,

§

impl<T> Sync for ColorType<T>
where T: Sync,

§

impl<T> Unpin for ColorType<T>
where T: Unpin,

§

impl<T> UnwindSafe for ColorType<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.