pub struct SlideChart {
pub id: u32,
pub name: String,
pub chart_space: ChartSpace,
pub offset_emu: (i64, i64),
pub extent_emu: (i64, i64),
}Expand description
An embedded chart (<p:graphicFrame> wrapping a <c:chart r:id="..">).
Reuses the chart crate’s ChartSpace verbatim, same posture as
word-ooxml::EmbeddedChart/excel-ooxml::SheetChart — cached values only, no embedded
.xlsx workbook as a data source, matching the scope of those two.
Fields§
§id: u32<p:cNvPr id=".."> — same uniqueness rules as AutoShape::id.
name: String<p:cNvPr name="..">.
chart_space: ChartSpace§offset_emu: (i64, i64)<p:xfrm><a:off x=".." y="..">, in EMUs. Like Picture, a chart’s position/size is never
optional — <p:xfrm> is its only source of it (no separate anchor, unlike Excel’s
SheetChart).
extent_emu: (i64, i64)<p:xfrm><a:ext cx=".." cy="..">, in EMUs.
Implementations§
Source§impl SlideChart
impl SlideChart
Sourcepub fn new(
id: u32,
name: impl Into<String>,
chart_space: ChartSpace,
width_emu: i64,
height_emu: i64,
) -> SlideChart
pub fn new( id: u32, name: impl Into<String>, chart_space: ChartSpace, width_emu: i64, height_emu: i64, ) -> SlideChart
Creates an embedded chart at the given size, positioned at (0, 0) (use
SlideChart::with_offset to place it elsewhere).
Examples found in repository?
examples/pptx_media.rs (lines 60-66)
20fn main() -> office_toolkit::Result<()> {
21 let path = output_path("pptx_media.pptx");
22 let image_bytes = std::fs::read(image_fixture_path())?;
23
24 let embedded_picture = Picture::new(
25 2,
26 "Embedded picture",
27 image_bytes.clone(),
28 PictureFormat::Png,
29 3_000_000,
30 2_000_000,
31 )
32 .with_offset(838_200, 838_200)
33 .with_description("Project test image");
34
35 let linked_picture = Picture::new(
36 2,
37 "Externally linked picture",
38 image_bytes,
39 PictureFormat::Png,
40 3_000_000,
41 2_000_000,
42 )
43 .with_offset(838_200, 838_200)
44 .with_external_link("https://example.com/original-image.png");
45
46 // Placeholder bytes — a real .pptx would carry a genuine video file
47 // here. This example only demonstrates the model/writer plumbing.
48 let poster_image = vec![0x89, 0x50, 0x4E, 0x47]; // fake, just enough bytes to have *some* data
49 let media = SlideMedia::new(
50 2,
51 "Video clip",
52 vec![0u8; 16],
53 MediaFormat::Mp4,
54 4_000_000,
55 2_250_000,
56 )
57 .with_offset(838_200, 838_200)
58 .with_poster_image(poster_image, PictureFormat::Png);
59
60 let chart = SlideChart::new(
61 2,
62 "Quarterly revenue",
63 sample_chart_space(),
64 6_000_000,
65 3_500_000,
66 )
67 .with_offset(838_200, 838_200);
68
69 let presentation = Presentation::new()
70 .with_slide(Slide::new().with_shape(Shape::Picture(embedded_picture)))
71 .with_slide(Slide::new().with_shape(Shape::Picture(linked_picture)))
72 .with_slide(Slide::new().with_shape(Shape::Media(media)))
73 .with_slide(Slide::new().with_shape(Shape::Chart(Box::new(chart))));
74
75 presentation.save_to_file(&path)?;
76 println!("Wrote {}", path.display());
77 Ok(())
78}Sourcepub fn with_offset(self, x_emu: i64, y_emu: i64) -> SlideChart
pub fn with_offset(self, x_emu: i64, y_emu: i64) -> SlideChart
Sets this chart’s position.
Examples found in repository?
examples/pptx_media.rs (line 67)
20fn main() -> office_toolkit::Result<()> {
21 let path = output_path("pptx_media.pptx");
22 let image_bytes = std::fs::read(image_fixture_path())?;
23
24 let embedded_picture = Picture::new(
25 2,
26 "Embedded picture",
27 image_bytes.clone(),
28 PictureFormat::Png,
29 3_000_000,
30 2_000_000,
31 )
32 .with_offset(838_200, 838_200)
33 .with_description("Project test image");
34
35 let linked_picture = Picture::new(
36 2,
37 "Externally linked picture",
38 image_bytes,
39 PictureFormat::Png,
40 3_000_000,
41 2_000_000,
42 )
43 .with_offset(838_200, 838_200)
44 .with_external_link("https://example.com/original-image.png");
45
46 // Placeholder bytes — a real .pptx would carry a genuine video file
47 // here. This example only demonstrates the model/writer plumbing.
48 let poster_image = vec![0x89, 0x50, 0x4E, 0x47]; // fake, just enough bytes to have *some* data
49 let media = SlideMedia::new(
50 2,
51 "Video clip",
52 vec![0u8; 16],
53 MediaFormat::Mp4,
54 4_000_000,
55 2_250_000,
56 )
57 .with_offset(838_200, 838_200)
58 .with_poster_image(poster_image, PictureFormat::Png);
59
60 let chart = SlideChart::new(
61 2,
62 "Quarterly revenue",
63 sample_chart_space(),
64 6_000_000,
65 3_500_000,
66 )
67 .with_offset(838_200, 838_200);
68
69 let presentation = Presentation::new()
70 .with_slide(Slide::new().with_shape(Shape::Picture(embedded_picture)))
71 .with_slide(Slide::new().with_shape(Shape::Picture(linked_picture)))
72 .with_slide(Slide::new().with_shape(Shape::Media(media)))
73 .with_slide(Slide::new().with_shape(Shape::Chart(Box::new(chart))));
74
75 presentation.save_to_file(&path)?;
76 println!("Wrote {}", path.display());
77 Ok(())
78}Trait Implementations§
Source§impl Clone for SlideChart
impl Clone for SlideChart
Source§fn clone(&self) -> SlideChart
fn clone(&self) -> SlideChart
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SlideChart
impl Debug for SlideChart
Source§impl PartialEq for SlideChart
impl PartialEq for SlideChart
impl StructuralPartialEq for SlideChart
Auto Trait Implementations§
impl Freeze for SlideChart
impl RefUnwindSafe for SlideChart
impl Send for SlideChart
impl Sync for SlideChart
impl Unpin for SlideChart
impl UnsafeUnpin for SlideChart
impl UnwindSafe for SlideChart
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