Skip to main content

ColorBarOptions

Struct ColorBarOptions 

Source
pub struct ColorBarOptions {
Show 13 fields pub visible: bool, pub side: Side, pub thickness_px: f32, pub gap_px: f32, pub length_frac: f32, pub align: BarAlign, pub offset_x: f32, pub offset_y: f32, pub colormap: ColorMap, pub nan_color: Color, pub border_color: Color, pub border_width: f32, pub axis: AxisOptions,
}
Expand description

The colourbar — and, because it owns the z axis, the chart’s only z scale.

axis is the whole point. It is the same AxisOptions the four chart axes use, so scale (including Logarithmic), min / max, major_spacing, minor_count, label_style (including LabelFormat::Power), tick, and title_option all mean here exactly what they mean there — and tick generation, label formatting, and log handling are the same code, not a parallel implementation that drifts.

axis.min / axis.max are the authority on the z range. A helper may fill them in from matrix statistics, the way AxisOptions::auto_ticks fills in spacing, but nothing else stores a z range.

Consequences worth stating, because they are decisions and not accidents:

  • A Heatmap / Contour / HeatmapContour series requires this to be Some. Without it there is no z range and no colormap anywhere, so there is no value to draw — the renderer rejects the series rather than inventing one.
  • To hide the bar, set visible: false. The options stay, the field still renders, and the band is given back to the data area.
  • There is therefore one z scale per chart. Several heatmaps in one chart share it; two colourbars with different scales is out of scope.

Fields§

§visible: bool

False draws nothing and reserves no band. Field series still render.

§side: Side

Which margin the bar occupies. Left / Right give a vertical bar, Top / Bottom a horizontal one, and this alone decides which.

The discrete half of the bar’s placement, the way Legend::corner is for the legend box; offset_x / offset_y are the continuous half.

§thickness_px: f32

The strip’s short dimension: width for a vertical bar, height for a horizontal one.

§gap_px: f32

Space between the data area and the strip.

§length_frac: f32

Strip length as a fraction of the data area’s length along its side.

§align: BarAlign§offset_x: f32

Free offset from the side + align anchor, in screen pixels — the same contract as Legend::offset_{x,y} and the title / label offsets: margin-noncontributing, so nudging the bar moves it without reflowing the data area under the pointer.

This is where a drag accumulates. Without it the bar had no continuous position at all, which is what kept it out of the selection / drag / resize machinery every other piece of chrome already uses.

§offset_y: f32§colormap: ColorMap§nan_color: Color

Colour for z values the ramp cannot place: NaN, and non-positive z on a logarithmic colourbar. Fully transparent by default — “missing” reads as absent rather than as some particular value.

§border_color: Color§border_width: f32§axis: AxisOptions

The z axis. See the type docs — this is the SSoT for the z range.

Implementations§

Source§

impl ColorBarOptions

Source

pub fn normalized_z(&self, z: f64) -> Option<f32>

Where z falls on the ramp, in [0, 1], or None when the ramp cannot place it — draw those with Self::nan_color.

This is the z→colour normalization. The CPU colourbar strip and the GPU field sampler both go through this formula, so a cell and the tick beside it cannot disagree about what a value looks like:

linear: t = (z - min) / (max - min)
log:    t = (log10 z - log10 min) / (log10 max - log10 min)

clamped to [0, 1]. None for NaN, for a non-positive z on a logarithmic bar (no logarithm to take), and for a degenerate range.

Two things it deliberately does not do:

  • It does not clamp an unplaceable value to an endpoint. “Missing” and “smallest” are different facts, and nan_color is how the second one stays distinguishable.
  • It does not apply axis.inverted. Inverting an axis moves where a value is drawn; it does not change which colour that value has. The strip’s screen ends swap, its ramp does not reverse.
Source

pub fn color_for_z(&self, z: f64) -> Color

The colour for z: the ramp where it can be placed, nan_color where it cannot.

Trait Implementations§

Source§

impl Clone for ColorBarOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ColorBarOptions

Source§

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

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

impl<'de> Deserialize<'de> for ColorBarOptions

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ColorBarOptions

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for ColorBarOptions

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ColorBarOptions

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.