Skip to main content

Drawing

Struct Drawing 

Source
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 frame
  • chart_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: usize

Unique 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: bool

Whether pointer and programmatic selection can select this drawing.

§saveable: bool

Whether chart saves and persistence notifications include this drawing.

§listed: bool

Whether 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: Value

Host-defined settings passed to the registered renderer and saved without interpretation.

§tool_type: DrawingToolType

Type 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: f32

Stroke width in pixels

§completed: bool

Whether 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: LineStyle

Line 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: bool

Whether the drawing is locked (prevents editing/moving)

§visible: bool

Whether the drawing is visible

§font_size: f32

Font size for text annotations

§font_weight: FontWeight

Font weight for text annotations

§italic: bool

Whether 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: bool

Whether 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: bool

Whether 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: bool

Extend line to left edge

§extend_right: bool

Extend line to right edge

§arrow_start_style: ArrowStyle

Arrow style at start of line

§arrow_end_style: ArrowStyle

Arrow style at end of line

§timeframe_visibility: TimeframeVisibility

Per-timeframe visibility

§price_axis_label: bool

Whether 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: bool

Whether 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: PositionSizing

Instrument 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: bool

Whether 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: bool

Whether 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: ElliottDegree

Notation 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: i32

Z-order for rendering priority (higher = drawn on top)

Implementations§

Source§

impl Drawing

Source

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 Drawing

Source

pub fn serialize<__S>( __self: &Drawing, __serializer: __S, ) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Source§

impl<'de> Drawing

Source

pub fn deserialize<__D>(__deserializer: __D) -> Result<Drawing, __D::Error>
where __D: Deserializer<'de>,

Source§

impl Drawing

Source

pub fn new(id: usize, tool_type: DrawingToolType) -> Self

Create a new drawing with default properties

Source

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.

Source

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.

Source

pub fn with_text(id: usize, text: String) -> Self

Create a new text label drawing

Source

pub fn update_screen_coords<F, G>(&mut self, bar_to_x: F, price_to_y: G)
where F: Fn(f32) -> f32, G: Fn(f64) -> f32,

Update screen coordinates from chart_points using current transforms

This should be called each frame before rendering.

Source

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.

Source

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.

Source

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.

Source

pub fn alert_level(&self, source: &AlertSource) -> Option<usize>

The level of this drawing that source, from Self::alert_source, names.

Source

pub fn add_point_with_chart_coords<F, G>( &mut self, screen_point: Pos2, x_to_bar: F, y_to_price: G, )
where F: Fn(f32) -> f32, G: Fn(f32) -> f64,

Add a point with both screen and chart coordinates

Source

pub fn update_last_point_with_chart_coords<F, G>( &mut self, screen_point: Pos2, x_to_bar: F, y_to_price: G, )
where F: Fn(f32) -> f32, G: Fn(f32) -> f64,

Update the last point with both screen and chart coordinates

Source

pub fn add_point(&mut self, point: Pos2)

Add a screen point (legacy method)

Source

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)

Source

pub fn color32(&self) -> Color32

Get the egui Color32 from the RGBA array

Source

pub fn fill_color32(&self) -> Option<Color32>

Get the fill color as Color32, if set

Source

pub fn stroke(&self) -> Stroke

Get the stroke for rendering

Source

pub fn is_visible_on_timeframe(&self, timeframe: &str) -> bool

Check if this drawing is visible on the given timeframe

Source

pub fn z_order(&self) -> i32

Get the z-order of this drawing

Source

pub fn set_z_order(&mut self, order: i32)

Set the z-order of this drawing

Source

pub fn bounding_rect(&self) -> Option<Rect>

Get the bounding rect of the drawing’s points

Source

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

Source

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.

Source§

impl Drawing

Source

pub fn render_original( &self, painter: &Painter, rect: Rect, view: &ChartView<'_>, )

Renders the drawing as unselected.

Source

pub fn render(&self, painter: &Painter, rect: Rect, view: &ChartView<'_>)

Render this drawing using the modular render system

Trait Implementations§

Source§

impl Clone for Drawing

Source§

fn clone(&self) -> Drawing

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Drawing

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Drawing

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Drawing

Source§

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.

Source§

impl Serialize for Drawing

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. 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
§

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

§

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

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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

impl<T> MaybeSend for T
where T: Send + Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.