Skip to main content

Heatmap

Struct Heatmap 

Source
pub struct Heatmap { /* private fields */ }
Expand description

A heatmap series: add it with Chart::add_custom_series and feed it with crate::append_depth or crate::append_trades.

Columns are placed by time between the candles’ slots (AxisMode::Overlay), so 1 s columns on a 1 min chart add no slots. Each pixel column shows the largest value of the data columns it covers; each level fills the pixel rows between its rounded edges.

§Examples

use ferrochart_core::chart::SeriesOptions;
use ferrochart_core::testing::MonoMeasurer;
use ferrochart_core::{Chart, ChartOptions};
use ferrochart_orderflow::{DepthSnapshot, Heatmap, HeatmapOptions, HeatmapSource, append_depth};

let mut chart = Chart::new(ChartOptions::default());
let opts = HeatmapOptions::new(0.5, 1_000, HeatmapSource::Depth);
let id = chart.add_custom_series(chart.main_pane(), Box::new(Heatmap::new(opts)?), SeriesOptions::default())?;
let (prices, sizes) = ([99.5, 100.0, 100.5], [12.0, 3.0, 40.0]);
append_depth(&mut chart, id, &DepthSnapshot { time: 0, prices: &prices, sizes: &sizes })?;
append_depth(&mut chart, id, &DepthSnapshot { time: 500, prices: &prices[..1], sizes: &[20.0] })?;
let h = chart.custom_series::<Heatmap>(id).unwrap();
// One column; the largest size of each level (100.0 is level 200).
assert_eq!(h.grid().columns(), 1);
assert_eq!(h.grid().column(0).unwrap().at(199), (20.0, 0.0));
chart.build_frame(0.0, &MonoMeasurer);

Implementations§

Source§

impl Heatmap

Source

pub fn new(opts: HeatmapOptions) -> Result<Self>

An empty heatmap.

§Errors

Error::InvalidArgument for a bad price grid, a non-positive column length or a bad range.

Source

pub fn options(&self) -> &HeatmapOptions

The options.

Source

pub fn set_display( &mut self, scale: ColorScale, range: HeatmapRange, colors: HeatmapColors, ) -> Result<()>

Changes the colors and their scale (the data stays).

§Errors

Error::InvalidArgument for a bad range (nothing changes).

Source

pub fn grid(&self) -> &SparseGrid

The cells: a is the size (b is unused).

Source

pub fn push_trade( &mut self, time: Timestamp, price: f64, size: f64, ) -> Result<bool>

Adds one trade to a trade heatmap; returns whether it opened a column.

§Errors

Error::InvalidArgument for a depth heatmap, a non-finite price or a negative size; Error::TimeNotIncreasing if its column is before the last one; Error::OutOfMemory.

Source

pub fn push_depth(&mut self, snapshot: &DepthSnapshot<'_>) -> Result<bool>

Adds an order book snapshot to a depth heatmap; returns whether it opened a column. Within a column each level keeps its largest size.

§Errors

Error::InvalidArgument for a trade heatmap or a bad snapshot (lengths, non-finite prices, negative sizes; nothing changes); Error::TimeNotIncreasing if its column is before the last one; Error::OutOfMemory (the levels added so far stay).

Trait Implementations§

Source§

impl CustomSeries for Heatmap

Source§

fn native_params(&self, ctx: &SeriesCtx<'_>, params: &mut [f32; 8])

[lo, hi, log (1/0), …] of the color scale; also lays out the frame for the native path.

Source§

fn kind(&self) -> &'static str

Kind name, e.g. "orderflow.heatmap"; renderers that draw it natively declare this name.
Source§

fn axis_mode(&self) -> AxisMode

How the points are placed on the time axis; read once, when added.
Source§

fn times(&self) -> &[Timestamp]

Times of the points, strictly increasing.
Source§

fn extremes(&self, from: usize, to: usize) -> Option<(f64, f64)>

Price extremes of points from..to, for auto scaling. Called every frame, so it must be O(log n) (see crate::plugin::MinMaxIndex).
Source§

fn build( &self, ctx: &SeriesCtx<'_>, from: usize, to: usize, out: &mut FrameBuilder<'_>, )

Portable path: writes the primitives of points from..to (the visible ones and one more on each side). Must not allocate once warmed up.
Source§

fn last_value(&self) -> Option<f64>

Value of the last-value label; None hides it.
Source§

fn crosshair_value(&self, point: usize) -> Option<f64>

Value of point point for the crosshair and magnet.
Source§

impl Debug for Heatmap

Source§

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

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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