pub struct Drawing {Show 58 fields
pub id: usize,
pub stored_id: Option<String>,
pub created_at: Option<i64>,
pub notes: Option<String>,
pub label: Option<String>,
pub pane: Option<usize>,
pub selectable: bool,
pub saveable: bool,
pub listed: bool,
pub group: Option<String>,
pub folder: Vec<String>,
pub custom_tool: Option<String>,
pub custom_settings: Value,
pub tool_type: DrawingToolType,
pub points: Vec<Pos2>,
pub chart_points: Vec<ChartPoint>,
pub level_ys: Vec<f32>,
pub screen_anchor: Option<[f32; 2]>,
pub color: [u8; 4],
pub stroke_width: f32,
pub completed: bool,
pub text: Option<String>,
pub post: Option<PostLink>,
pub line_style: LineStyle,
pub fill_color: Option<[u8; 4]>,
pub locked: bool,
pub visible: bool,
pub font_size: f32,
pub font_weight: FontWeight,
pub italic: bool,
pub text_color: Option<[u8; 4]>,
pub background: bool,
pub border: bool,
pub border_color: Option<[u8; 4]>,
pub extend_left: bool,
pub extend_right: bool,
pub arrow_start_style: ArrowStyle,
pub arrow_end_style: ArrowStyle,
pub timeframe_visibility: TimeframeVisibility,
pub price_axis_label: bool,
pub time_axis_label: bool,
pub position_size: Option<PositionSize>,
pub position_sizing: PositionSizing,
pub position_target_color: Option<[u8; 4]>,
pub position_stop_color: Option<[u8; 4]>,
pub fib_config: Option<FibonacciConfig>,
pub volume_profile: Option<VolumeProfileConfig>,
pub regression_trend: Option<RegressionTrendConfig>,
pub vwap: Option<VwapConfig>,
pub gann: Option<GannConfig>,
pub ghost_feed: Option<GhostFeedConfig>,
pub channel_midline: bool,
pub image: Option<ImageConfig>,
pub closed: bool,
pub pitchfork: Option<PitchforkConfig>,
pub elliott_degree: ElliottDegree,
pub bars_pattern: Option<BarsPatternConfig>,
pub z_order: i32,
}Expand description
A drawing on the chart
Drawings use a dual coordinate system:
points: Vec<Pos2>- Screen coordinates, updated each framechart_points: Vec<ChartPoint>- Chart coordinates (bar_idx, price), stable across pan/zoom
§Example
use egui_charts::drawings::{Drawing, DrawingToolType};
let mut drawing = Drawing::new(1, DrawingToolType::TrendLine);
drawing.color = [33, 150, 243, 255]; // Blue
drawing.stroke_width = 2.0;Serde covers the tool and its settings only: the id, the points and the
completion state are left out, since the anchors are stored as
timestamps by persistence. A field added
later needs #[serde(default)], so that saved version 2 files still load.
Fields§
§id: usizeUnique identifier for this drawing
stored_id: Option<String>Id of the stored record this drawing was restored from; None for a drawing never
stored, which is saved under its id
created_at: Option<i64>Creation time, in Unix milliseconds, of the stored record this drawing was restored
from; None for a drawing never stored, which is saved with the time of the save
notes: Option<String>User notes, saved with the drawing and restored from its stored record
label: Option<String>Optional object-tree name, saved with the drawing.
pane: Option<usize>Owning study id, or None for the main price pane. Follows that study when panes move
or merge; hosts restoring studies must retain or remap their ids. Older files use main.
selectable: boolWhether pointer and programmatic selection can select this drawing.
saveable: boolWhether chart saves and persistence notifications include this drawing.
listed: boolWhether host object lists should include this drawing. Rendering is independent.
group: Option<String>Host-defined group identity, retained through saving and undo.
folder: Vec<String>Named object-tree folder path, from outermost to innermost; empty means the root. Independent of host-defined groups. Older saved drawings start at the root.
custom_tool: Option<String>Stable id of a host-registered tool; None uses the built-in renderer.
custom_settings: ValueHost-defined settings passed to the registered renderer and saved without interpretation.
tool_type: DrawingToolTypeType of drawing tool
points: Vec<Pos2>Screen coordinates (updated each frame from chart_points)
chart_points: Vec<ChartPoint>Persistent chart coordinates (bar_idx, price) - stable across pan/zoom
level_ys: Vec<f32>Screen y of each visible level of a Fibonacci retracement or extension, in config order,
or of the far corner of a fixed Gann square (empty for other tools); rebuilt with points
by Self::update_screen_coords
screen_anchor: Option<[f32; 2]>Position as fractions of the pane width and height for anchored text.
None adopts the first displayed position, including for older saved drawings.
A pin saved with one takes the bar and price under it the first time a chart draws it,
and the chart then clears it.
color: [u8; 4]Drawing colour as RGBA; also the text and border colour of annotations that have none of their own.
stroke_width: f32Stroke width in pixels
completed: boolWhether the drawing is complete
text: Option<String>Optional annotation content, preserved with the drawing. Tables use one row per line
and tab-separated cells. Images use an image URI resolved by the host’s egui image
loaders. Posts and ideas use the first line as author or title and the rest as body,
when they have no post.
post: Option<PostLink>The post or idea a post or idea drawing shows: its link and the content the host
resolved it to through Posts. The content is saved with the
drawing, so it shows without asking the host again. While it is set, the card shows it
instead of text. Other tools ignore it.
line_style: LineStyleLine style (Solid, Dashed, Dotted)
fill_color: Option<[u8; 4]>Fill colour of shapes and the background colour of annotation boxes. None leaves shapes
unfilled and gives an annotation box its tool’s default colour.
locked: boolWhether the drawing is locked (prevents editing/moving)
visible: boolWhether the drawing is visible
font_size: f32Font size for text annotations
font_weight: FontWeightFont weight for text annotations
italic: boolWhether annotation text is slanted. Older drawings are upright.
text_color: Option<[u8; 4]>Text colour of annotations; None uses the tool’s default, the drawing colour except on
a solid label, which takes white or black, whichever reads on its fill.
background: boolWhether an annotation draws a box behind its text, in fill_color or else the tool’s
default: the theme’s panel colour, or the drawing colour for a solid label. Older
drawings have it on.
border: boolWhether an annotation’s box has a 1 px border. Older drawings have it on.
border_color: Option<[u8; 4]>Border colour of annotation boxes; None uses the drawing colour.
extend_left: boolExtend line to left edge
extend_right: boolExtend line to right edge
arrow_start_style: ArrowStyleArrow style at start of line
arrow_end_style: ArrowStyleArrow style at end of line
timeframe_visibility: TimeframeVisibilityPer-timeframe visibility
price_axis_label: boolWhether a horizontal line, horizontal ray or cross line shows its price as a tag on the price axis. Other tools ignore it. Drawings saved without it show the tag.
time_axis_label: boolWhether a vertical line or cross line shows its time as a tag on the time axis. Other tools ignore it. Drawings saved without it show the tag.
position_size: Option<PositionSize>Quantity of the long and short position tools
position_sizing: PositionSizingInstrument economics for long and short position sizing. Older drawings use unit sizing.
position_target_color: Option<[u8; 4]>Target zone and level colour of position tools; None keeps the default green.
position_stop_color: Option<[u8; 4]>Stop zone and level colour of position tools; None keeps the default red.
fib_config: Option<FibonacciConfig>Customizable Fibonacci levels for Fib tools
volume_profile: Option<VolumeProfileConfig>Rows and value area of the volume profile tools
regression_trend: Option<RegressionTrendConfig>Band width of the regression trend tool
vwap: Option<VwapConfig>Bands of the anchored VWAP. Older drawings use the defaults.
gann: Option<GannConfig>Levels, fan lines, arcs and background of the Gann tools; None draws
GannConfig::for_tool.
ghost_feed: Option<GhostFeedConfig>Average range and noise, in ticks, of the candles a Ghost Feed projects.
channel_midline: boolWhether a rectangle or parallel channel draws its dashed halfway line.
image: Option<ImageConfig>Frame size and opacity of the image tool; None uses the defaults.
closed: boolWhether a polyline joins its last anchor back to its first. Clicking the first anchor while placing a polyline closes it; older saved drawings are open.
pitchfork: Option<PitchforkConfig>Level lines and band fill of the pitchfork tools.
elliott_degree: ElliottDegreeNotation of the wave labels of the Elliott wave tools. Older drawings use the default.
bars_pattern: Option<BarsPatternConfig>Draw mode, mirroring and flipping of a bars pattern’s copy. None uses the defaults,
as drawings saved before this setting do.
z_order: i32Z-order for rendering priority (higher = drawn on top)
Implementations§
Source§impl Drawing
impl Drawing
Sourcepub fn alert_levels_with_bars(
&self,
bar: f64,
scale: PriceScaleMode,
bars: &[Bar],
) -> Vec<(usize, String, f64)>
pub fn alert_levels_with_bars( &self, bar: f64, scale: PriceScaleMode, bars: &[Bar], ) -> Vec<(usize, String, f64)>
Self::alert_levels with the main-series bars needed by a regression drawing. The
fitted median is level 0, upper band 1 and lower band 2. Regression uses the same closes,
residual deviation and axis interpolation between fitted endpoints as its painted lines.
Empty when the anchored range has fewer than two bars or invalid geometry.
Source§impl<'de> Drawing
impl<'de> Drawing
pub fn deserialize<__D>(__deserializer: __D) -> Result<Drawing, __D::Error>where
__D: Deserializer<'de>,
Source§impl Drawing
impl Drawing
Sourcepub fn new(id: usize, tool_type: DrawingToolType) -> Self
pub fn new(id: usize, tool_type: DrawingToolType) -> Self
Create a new drawing with default properties
Sourcepub fn custom(tool: impl Into<String>) -> Self
pub fn custom(tool: impl Into<String>) -> Self
Creates a host-defined drawing. The manager looks up tool in its registry; the
built-in polyline identity supplies anchor handles and multi-click input only.
Sourcepub fn with_color(id: usize, tool_type: DrawingToolType, color: [u8; 4]) -> Self
pub fn with_color(id: usize, tool_type: DrawingToolType, color: [u8; 4]) -> Self
Create a new drawing with a specific line colour; a fill tinted from the tool’s default
line colour takes the same tint of color.
Sourcepub fn update_screen_coords<F, G>(&mut self, bar_to_x: F, price_to_y: G)
pub fn update_screen_coords<F, G>(&mut self, bar_to_x: F, price_to_y: G)
Update screen coordinates from chart_points using current transforms
This should be called each frame before rendering.
Sourcepub fn update_pane_coords(&mut self, pane: Rect)
pub fn update_pane_coords(&mut self, pane: Rect)
Rebuilds anchored text coordinates relative to the pane. Call after
update_screen_coords; other tools retain their chart coordinates. Older drawings
adopt their first displayed position. Resizing preserves the width and height fractions.
Sourcepub fn alert_levels(
&self,
bar: f64,
scale: PriceScaleMode,
) -> Vec<(usize, String, f64)>
pub fn alert_levels( &self, bar: f64, scale: PriceScaleMode, ) -> Vec<(usize, String, f64)>
The price levels an alert can follow at the fractional bar index bar, each with its
level number, name and price: a line’s price extended through its two anchors, the base and
second lines of parallel or disjoint channels, the trend and flat lines of a flat
top/bottom, a horizontal level, a rectangle’s top and bottom, a position’s entry, target
and stop, and each visible Fibonacci retracement or extension level, numbered by its place
in the level settings. Sloping lines are straight on the price axis scale paints, so
they are linear in price except on a logarithmic scale.
Fork levels use two stable slots per configured level (first and second line), with
only the first slot used by a median. Regression levels require
Self::alert_levels_with_bars. Empty for other drawings and for
geometry with no price at bar, such as a vertical line or a sloping line through a
non-positive price on a logarithmic scale.
Sourcepub fn alert_source(&self, level: usize) -> AlertSource
pub fn alert_source(&self, level: usize) -> AlertSource
The alert source of level level of Self::alert_levels: the drawing’s stored id, or
its id when it was never stored, followed by # and the level for levels after the
first. % and # in the id are escaped as %25 and %23 so distinct drawings cannot
share a source. It names the same level after the drawing is saved and restored.
Sourcepub fn alert_level(&self, source: &AlertSource) -> Option<usize>
pub fn alert_level(&self, source: &AlertSource) -> Option<usize>
The level of this drawing that source, from Self::alert_source, names.
Sourcepub fn add_point_with_chart_coords<F, G>(
&mut self,
screen_point: Pos2,
x_to_bar: F,
y_to_price: G,
)
pub fn add_point_with_chart_coords<F, G>( &mut self, screen_point: Pos2, x_to_bar: F, y_to_price: G, )
Add a point with both screen and chart coordinates
Sourcepub fn update_last_point_with_chart_coords<F, G>(
&mut self,
screen_point: Pos2,
x_to_bar: F,
y_to_price: G,
)
pub fn update_last_point_with_chart_coords<F, G>( &mut self, screen_point: Pos2, x_to_bar: F, y_to_price: G, )
Update the last point with both screen and chart coordinates
Sourcepub fn shift_bar_indices(&mut self, from: f32, delta: f32)
pub fn shift_bar_indices(&mut self, from: f32, delta: f32)
Shift the bar indices at or after from by a delta (used when bars are inserted in front
of them)
Sourcepub fn fill_color32(&self) -> Option<Color32>
pub fn fill_color32(&self) -> Option<Color32>
Get the fill color as Color32, if set
Sourcepub fn is_visible_on_timeframe(&self, timeframe: &str) -> bool
pub fn is_visible_on_timeframe(&self, timeframe: &str) -> bool
Check if this drawing is visible on the given timeframe
Sourcepub fn set_z_order(&mut self, order: i32)
pub fn set_z_order(&mut self, order: i32)
Set the z-order of this drawing
Sourcepub fn bounding_rect(&self) -> Option<Rect>
pub fn bounding_rect(&self) -> Option<Rect>
Get the bounding rect of the drawing’s points
Sourcepub fn quadratic_bezier(p0: Pos2, p1: Pos2, p2: Pos2, t: f32) -> Pos2
pub fn quadratic_bezier(p0: Pos2, p1: Pos2, p2: Pos2, t: f32) -> Pos2
Quadratic bezier curve interpolation
Returns a point on the bezier curve defined by p0, p1, p2 at parameter t. Used for smooth curve rendering (e.g., arcs, spirals).
Source§impl Drawing
impl Drawing
Sourcepub fn volume_profile_of(&self, view: &ChartView<'_>) -> Option<VolumeProfile>
pub fn volume_profile_of(&self, view: &ChartView<'_>) -> Option<VolumeProfile>
The profile that a fixed range or anchored volume profile shows over the view’s bars,
with its source: executed volume when
ChartView::executions holds complete bars in the selected span, those from
Footprint::complete_from, else the finer bars
of ChartView::finer, else the bar estimate.
None for other tools, a drawing without its anchors, or an empty selection.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Drawing
impl<'de> Deserialize<'de> for Drawing
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
A saved gann object takes the fields it leaves out from GannConfig::for_tool of the
drawing’s tool, which a drawing without one draws.
Auto Trait Implementations§
impl Freeze for Drawing
impl RefUnwindSafe for Drawing
impl Send for Drawing
impl Sync for Drawing
impl Unpin for Drawing
impl UnsafeUnpin for Drawing
impl UnwindSafe for Drawing
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more