Skip to main content

DrawingManager

Struct DrawingManager 

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

The drawings of a chart (Chart::drawings).

Changes made through the manager (and by the user with the mouse and keyboard) are undoable: adding, removing, moving and restyling a drawing. Selection, visibility, locking and z order are not part of the history.

§Examples

use ferrochart_core::chart::{SeriesData, SeriesOptions};
use ferrochart_core::drawing::{Anchor, DrawingData};
use ferrochart_core::frame::SeriesKind;
use ferrochart_core::testing::random_walk;
use ferrochart_core::{Chart, ChartOptions};

let mut chart = Chart::new(ChartOptions::default());
let pane = chart.main_pane();
let candles = chart.add_series(pane, SeriesKind::Candlestick, SeriesOptions::default())?;
chart.set_data(candles, SeriesData::Ohlc(random_walk(1, 100, 0, 60_000)?))?;

let line = DrawingData::new("trend_line", vec![
    Anchor { time: 0, price: 100.0 },
    Anchor { time: 50 * 60_000, price: 110.0 },
]);
let id = chart.drawings().add(pane, &line)?;
assert_eq!(chart.drawings().ids().count(), 1);
chart.drawings().undo();
assert!(chart.drawings().data(id).is_none());
chart.drawings().redo();
assert!(chart.drawings().data(id).is_some());

Implementations§

Source§

impl DrawingManager

Source

pub fn register(&mut self, kind: &'static str, factory: DrawingFactory)

Registers (or replaces) the factory of kind.

Source

pub fn kinds(&self) -> impl Iterator<Item = &'static str> + '_

Registered kinds.

Source

pub fn add(&mut self, pane: PaneId, data: &DrawingData) -> Result<DrawingId>

Adds a drawing on pane (on top of the others).

§Errors
Source

pub fn remove(&mut self, id: DrawingId) -> Result<()>

Removes a drawing.

§Errors

Error::UnknownId for an unknown drawing.

Source

pub fn ids(&self) -> impl Iterator<Item = DrawingId> + '_

Ids of all drawings, bottom to top.

Source

pub fn get(&self, id: DrawingId) -> Option<&dyn DrawingTool>

A drawing.

Source

pub fn data(&self, id: DrawingId) -> Option<DrawingData>

The saved form of a drawing.

Source

pub fn pane_of(&self, id: DrawingId) -> Option<PaneId>

The pane of a drawing.

Source

pub fn set_anchors(&mut self, id: DrawingId, anchors: &[Anchor]) -> Result<()>

Moves a drawing’s anchors (undoable).

§Errors
Source

pub fn set_style(&mut self, id: DrawingId, style: DrawingStyle) -> Result<()>

Changes a drawing’s style (undoable).

§Errors

Error::UnknownId for an unknown drawing.

Source

pub fn set_param( &mut self, id: DrawingId, key: &str, value: Param, ) -> Result<()>

Sets a tool-specific parameter (undoable), e.g. "text" of a text or "levels" of a Fibonacci retracement.

§Errors
Source

pub fn set_visible(&mut self, id: DrawingId, visible: bool) -> Result<()>

Shows or hides a drawing.

§Errors

Error::UnknownId for an unknown drawing.

Source

pub fn is_visible(&self, id: DrawingId) -> Option<bool>

Whether a drawing is visible.

Source

pub fn set_locked(&mut self, id: DrawingId, locked: bool) -> Result<()>

Locks a drawing: it can be selected and deleted, but not dragged.

§Errors

Error::UnknownId for an unknown drawing.

Source

pub fn is_locked(&self, id: DrawingId) -> Option<bool>

Whether a drawing is locked.

Source

pub fn bring_to_front(&mut self, id: DrawingId) -> Result<()>

Moves a drawing above all others.

§Errors

Error::UnknownId for an unknown drawing.

Source

pub fn send_to_back(&mut self, id: DrawingId) -> Result<()>

Moves a drawing below all others.

§Errors

Error::UnknownId for an unknown drawing.

Source

pub fn select(&mut self, id: Option<DrawingId>) -> Result<()>

Selects a drawing (None clears the selection).

§Errors

Error::UnknownId for an unknown drawing.

Source

pub fn selected(&self) -> Option<DrawingId>

The selected drawing.

Source

pub fn start_tool(&mut self, kind: &str) -> Result<()>

Arms a tool: the next click on a plot starts creating a drawing of kind. Escape cancels.

§Errors

Error::InvalidArgument for an unregistered kind.

Source

pub fn cancel_tool(&mut self)

Disarms the tool and drops a drawing being created.

Source

pub fn active_tool(&self) -> Option<&'static str>

The armed tool, or the kind being created.

Source

pub fn can_undo(&self) -> bool

Whether there is something to undo.

Source

pub fn can_redo(&self) -> bool

Whether there is something to redo.

Source

pub fn clear_history(&mut self)

Clears the undo/redo history.

Source

pub fn undo(&mut self) -> bool

Undoes the last change; false if there was none.

Source

pub fn redo(&mut self) -> bool

Redoes the last undone change; false if there was none.

Trait Implementations§

Source§

impl Debug for DrawingManager

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<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, 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.