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
impl Heatmap
Sourcepub fn new(opts: HeatmapOptions) -> Result<Self>
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.
Sourcepub fn options(&self) -> &HeatmapOptions
pub fn options(&self) -> &HeatmapOptions
The options.
Sourcepub fn set_display(
&mut self,
scale: ColorScale,
range: HeatmapRange,
colors: HeatmapColors,
) -> Result<()>
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).
Sourcepub fn grid(&self) -> &SparseGrid
pub fn grid(&self) -> &SparseGrid
The cells: a is the size (b is unused).
Sourcepub fn push_trade(
&mut self,
time: Timestamp,
price: f64,
size: f64,
) -> Result<bool>
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.
Sourcepub fn push_depth(&mut self, snapshot: &DepthSnapshot<'_>) -> Result<bool>
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
impl CustomSeries for Heatmap
Source§fn native_params(&self, ctx: &SeriesCtx<'_>, params: &mut [f32; 8])
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
fn kind(&self) -> &'static str
"orderflow.heatmap"; renderers that draw it natively
declare this name.Source§fn axis_mode(&self) -> AxisMode
fn axis_mode(&self) -> AxisMode
Source§fn extremes(&self, from: usize, to: usize) -> Option<(f64, f64)>
fn extremes(&self, from: usize, to: usize) -> Option<(f64, f64)>
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<'_>,
)
fn build( &self, ctx: &SeriesCtx<'_>, from: usize, to: usize, out: &mut FrameBuilder<'_>, )
from..to (the
visible ones and one more on each side). Must not allocate once
warmed up.Source§fn last_value(&self) -> Option<f64>
fn last_value(&self) -> Option<f64>
None hides it.