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
impl DrawingManager
Sourcepub fn register(&mut self, kind: &'static str, factory: DrawingFactory)
pub fn register(&mut self, kind: &'static str, factory: DrawingFactory)
Registers (or replaces) the factory of kind.
Sourcepub fn add(&mut self, pane: PaneId, data: &DrawingData) -> Result<DrawingId>
pub fn add(&mut self, pane: PaneId, data: &DrawingData) -> Result<DrawingId>
Adds a drawing on pane (on top of the others).
§Errors
Error::UnknownIdfor an unknown pane;Error::InvalidArgumentfor an unregistered kind, non-finite prices, too few anchors, or parameters the factory refuses.
Sourcepub fn get(&self, id: DrawingId) -> Option<&dyn DrawingTool>
pub fn get(&self, id: DrawingId) -> Option<&dyn DrawingTool>
A drawing.
Sourcepub fn data(&self, id: DrawingId) -> Option<DrawingData>
pub fn data(&self, id: DrawingId) -> Option<DrawingData>
The saved form of a drawing.
Sourcepub fn set_anchors(&mut self, id: DrawingId, anchors: &[Anchor]) -> Result<()>
pub fn set_anchors(&mut self, id: DrawingId, anchors: &[Anchor]) -> Result<()>
Moves a drawing’s anchors (undoable).
§Errors
Error::UnknownIdfor an unknown drawing;Error::InvalidArgumentif the number of anchors differs or a price is not finite.
Sourcepub fn set_param(
&mut self,
id: DrawingId,
key: &str,
value: Param,
) -> Result<()>
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
Error::UnknownIdfor an unknown drawing;Error::InvalidArgumentif the tool refuses the value; the drawing is unchanged.
Sourcepub fn is_visible(&self, id: DrawingId) -> Option<bool>
pub fn is_visible(&self, id: DrawingId) -> Option<bool>
Whether a drawing is visible.
Sourcepub fn set_locked(&mut self, id: DrawingId, locked: bool) -> Result<()>
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.
Sourcepub fn bring_to_front(&mut self, id: DrawingId) -> Result<()>
pub fn bring_to_front(&mut self, id: DrawingId) -> Result<()>
Sourcepub fn send_to_back(&mut self, id: DrawingId) -> Result<()>
pub fn send_to_back(&mut self, id: DrawingId) -> Result<()>
Sourcepub fn start_tool(&mut self, kind: &str) -> Result<()>
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.
Sourcepub fn cancel_tool(&mut self)
pub fn cancel_tool(&mut self)
Disarms the tool and drops a drawing being created.
Sourcepub fn active_tool(&self) -> Option<&'static str>
pub fn active_tool(&self) -> Option<&'static str>
The armed tool, or the kind being created.
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clears the undo/redo history.