Skip to main content

EmbeddedChart

Struct EmbeddedChart 

Source
pub struct EmbeddedChart {
    pub chart_space: ChartSpace,
    pub width_emu: i64,
    pub height_emu: i64,
    pub name: String,
}
Expand description

An inline chart (<w:drawing><wp:inline>..), embedded in a run — RunContent::Chart’s payload. Structurally the same wp:inline skeleton as Image (wp:extent/wp:docPr, wrapping an a:graphic/a:graphicData), but the a:graphicData wraps a <c:chart r:id=".."> graphic frame instead of a pic:pic (see writer.rs::write_embedded_chart) — its own graphic-frame wiring rather than a picture’s, even though both live under wp:inline on the Word side.

A deliberate scope decision, since chart-in-document support is still an evolving corner of the format: cached values only, no embedded .xlsx workbook as a data source. This crate’s chart::ChartSpace already carries every series’ cached values directly (chart::NumericDataSource/StringDataSource), so a Word chart embedded this way renders correctly in Word without any companion workbook part — it just can’t be “edited” via Word’s “Edit Data in Excel” feature the way a real Word-native chart (created through Word’s own UI) can.

Fields§

§chart_space: ChartSpace§width_emu: i64

The width the chart is displayed at, in EMUs (wp:extent’s cx).

§height_emu: i64

The height the chart is displayed at, in EMUs (cy).

§name: String

Alt text / description (wp:docPr’s descr/name attributes). May be empty.

Implementations§

Source§

impl EmbeddedChart

Source

pub fn new( chart_space: ChartSpace, width_emu: i64, height_emu: i64, ) -> EmbeddedChart

Creates an embedded chart with an explicit display size in EMUs.

Examples found in repository?
examples/docx_images_and_charts.rs (line 25)
18fn main() -> office_toolkit::Result<()> {
19    let path = output_path("docx_images_and_charts.docx");
20    let image_bytes = std::fs::read(image_fixture_path())?;
21
22    // 2 inches wide, 1.5 inches tall (914,400 EMU per inch).
23    let image = Image::new(image_bytes, ImageFormat::Png, 1_828_800, 1_371_600)
24        .with_description("Project test image");
25    let chart = EmbeddedChart::new(sample_chart_space(), 4_572_000, 2_743_200)
26        .with_name("Quarterly revenue");
27
28    let document = Document::new()
29        .with_paragraph(heading("An inline image", false))
30        .with_paragraph(Paragraph::new().with_run(Run::with_image(image)))
31        .with_paragraph(heading("An embedded bar chart", true))
32        .with_paragraph(Paragraph::new().with_run(Run::with_chart(chart)));
33
34    document.save_to_file(&path)?;
35    println!("Wrote {}", path.display());
36    Ok(())
37}
Source

pub fn with_name(self, name: impl Into<String>) -> EmbeddedChart

Sets the chart’s alt text / name and returns it for chaining.

Examples found in repository?
examples/docx_images_and_charts.rs (line 26)
18fn main() -> office_toolkit::Result<()> {
19    let path = output_path("docx_images_and_charts.docx");
20    let image_bytes = std::fs::read(image_fixture_path())?;
21
22    // 2 inches wide, 1.5 inches tall (914,400 EMU per inch).
23    let image = Image::new(image_bytes, ImageFormat::Png, 1_828_800, 1_371_600)
24        .with_description("Project test image");
25    let chart = EmbeddedChart::new(sample_chart_space(), 4_572_000, 2_743_200)
26        .with_name("Quarterly revenue");
27
28    let document = Document::new()
29        .with_paragraph(heading("An inline image", false))
30        .with_paragraph(Paragraph::new().with_run(Run::with_image(image)))
31        .with_paragraph(heading("An embedded bar chart", true))
32        .with_paragraph(Paragraph::new().with_run(Run::with_chart(chart)));
33
34    document.save_to_file(&path)?;
35    println!("Wrote {}", path.display());
36    Ok(())
37}

Trait Implementations§

Source§

impl Clone for EmbeddedChart

Source§

fn clone(&self) -> EmbeddedChart

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 EmbeddedChart

Source§

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

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

impl PartialEq for EmbeddedChart

Source§

fn eq(&self, other: &EmbeddedChart) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for EmbeddedChart

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

Source§

type Output = T

Should always be Self
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.