pub struct SvgCanvas {
pub width: u32,
pub height: u32,
pub elements: Vec<String>,
pub margin: u32,
pub background_color: String,
}
Expand description
A structure for creating and managing an SVG-based drawing canvas.
Fields§
§width: u32
Width of the SVG canvas.
height: u32
Height of the SVG canvas.
elements: Vec<String>
A vector storing SVG elements as strings.
margin: u32
Margin size for the SVG canvas.
background_color: String
Background color of the SVG canvas.
Implementations§
source§impl SvgCanvas
impl SvgCanvas
sourcepub fn new(width: u32, height: u32, background_color: &str, margin: u32) -> Self
pub fn new(width: u32, height: u32, background_color: &str, margin: u32) -> Self
Creates a new SvgCanvas
with the specified dimensions, background color, and margin.
§Parameters
width
: The width of the canvas in pixels.height
: The height of the canvas in pixels.background_color
: The background color as a string.margin
: Margin size in pixels.
§Returns
A new SvgCanvas
instance.
sourcepub fn draw_line(
&mut self,
x1: f64,
y1: f64,
x2: f64,
y2: f64,
color: &str,
stroke_width: f64,
)
pub fn draw_line( &mut self, x1: f64, y1: f64, x2: f64, y2: f64, color: &str, stroke_width: f64, )
Adds a line to the SVG canvas.
§Parameters
x1
,y1
: Coordinates of the start point.x2
,y2
: Coordinates of the end point.color
: The stroke color of the line.stroke_width
: The width of the line stroke.
sourcepub fn draw_line_rgb(
&mut self,
x1: f64,
y1: f64,
x2: f64,
y2: f64,
color: [u8; 3],
stroke_width: f64,
)
pub fn draw_line_rgb( &mut self, x1: f64, y1: f64, x2: f64, y2: f64, color: [u8; 3], stroke_width: f64, )
Adds a line with RGB color to the SVG canvas.
§Parameters
x1
,y1
: Coordinates of the start point.x2
,y2
: Coordinates of the end point.color
: The RGB color of the line.stroke_width
: The width of the line stroke.
sourcepub fn draw_rect(
&mut self,
x: f64,
y: f64,
width: f64,
height: f64,
fill_color: &str,
stroke_color: &str,
stroke_width: f64,
opacity: f64,
)
pub fn draw_rect( &mut self, x: f64, y: f64, width: f64, height: f64, fill_color: &str, stroke_color: &str, stroke_width: f64, opacity: f64, )
Adds a rectangle to the SVG canvas.
§Parameters
x
,y
: Coordinates of the top-left corner.width
,height
: Dimensions of the rectangle.fill_color
: Fill color of the rectangle.stroke_color
: Stroke color of the rectangle.stroke_width
: Width of the rectangle’s border.opacity
: Opacity of the rectangle fill (0.0 to 1.0).
sourcepub fn add_font_style(
&mut self,
font_url: &str,
class_name: &str,
font_family: &str,
)
pub fn add_font_style( &mut self, font_url: &str, class_name: &str, font_family: &str, )
Adds a font style definition to the SVG canvas.
§Parameters
font_url
: URL of the font to be imported.class_name
: CSS class name for applying the font.font_family
: Name of the font family.
sourcepub fn draw_circle(&mut self, cx: f64, cy: f64, r: f64, color: &str)
pub fn draw_circle(&mut self, cx: f64, cy: f64, r: f64, color: &str)
Draws a circle on the SVG canvas.
§Parameters
cx
,cy
: Coordinates of the circle’s center.r
: Radius of the circle.color
: Fill color of the circle.
sourcepub fn draw_text(
&mut self,
x: f64,
y: f64,
text: &str,
font_size: f64,
color: &str,
)
pub fn draw_text( &mut self, x: f64, y: f64, text: &str, font_size: f64, color: &str, )
Adds a text element to the SVG canvas.
§Parameters
x
,y
: Coordinates of the text’s position.text
: The text content.font_size
: Font size of the text.color
: Text color.
sourcepub fn draw_title(
&mut self,
x: f64,
y: f64,
text: &str,
font_size: f64,
color: &str,
)
pub fn draw_title( &mut self, x: f64, y: f64, text: &str, font_size: f64, color: &str, )
Adds a text element to the SVG canvas.
§Parameters
x
,y
: Coordinates of the text’s position.text
: The text content.font_size
: Font size of the text.color
: Text color.
sourcepub fn draw_grid(
&mut self,
x_min: f64,
x_max: f64,
y_min: f64,
y_max: f64,
x_ticks: usize,
y_ticks: usize,
color: &str,
)
pub fn draw_grid( &mut self, x_min: f64, x_max: f64, y_min: f64, y_max: f64, x_ticks: usize, y_ticks: usize, color: &str, )
Draws a grid on the SVG canvas.
§Parameters
x_min
,x_max
: Horizontal range for the grid.y_min
,y_max
: Vertical range for the grid.x_ticks
: Number of grid lines along the x-axis.y_ticks
: Number of grid lines along the y-axis.color
: Color of the grid lines.
sourcepub fn get_svg_as_text(&self) -> String
pub fn get_svg_as_text(&self) -> String
Auto Trait Implementations§
impl Freeze for SvgCanvas
impl RefUnwindSafe for SvgCanvas
impl Send for SvgCanvas
impl Sync for SvgCanvas
impl Unpin for SvgCanvas
impl UnwindSafe for SvgCanvas
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
Mutably borrows from an owned value. Read more
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>
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 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>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.