pub struct ChartShape { /* private fields */ }Expand description
高阶图表形状(承载 <p:graphicFrame> + <c:chart r:id="..."/> 引用)。
通过 ChartShape::chart / ChartShape::chart_mut 访问图表数据;
通过 Shape trait 方法(left / top / width / height)调整位置与尺寸。
§内部不变量
frame.graphic 始终保持为 Graphic::Chart(_)。本类型所有便捷方法
(chart_type / set_chart_type / data / data_mut / rid / set_rid)
在不变量被破坏时静默忽略或返回 None,绝不 panic——
这与库整体“零 panic“约定一致(参见 .trae/rules/project_rules.md §5)。
Implementations§
Source§impl ChartShape
impl ChartShape
Sourcepub fn new(chart_type: ChartType, data: ChartData) -> Self
pub fn new(chart_type: ChartType, data: ChartData) -> Self
构造一个指定类型与数据的图表形状(rid 留空,由 presentation 层填充)。
§参数
chart_type:图表类型(柱/条/线/饼)。data:图表数据(类别 + 系列 + 可选标题)。
Sourcepub fn from_frame(frame: OxmlFrame) -> Self
pub fn from_frame(frame: OxmlFrame) -> Self
从 oxml Frame 构造(通常用于读取已有图表时)。
Sourcepub fn chart(&self) -> Option<&OxmlChart>
pub fn chart(&self) -> Option<&OxmlChart>
取内部 oxml Chart 引用。
返回 None 仅在内部不变量被外部错误破坏时(frame.graphic 不是 Chart 变体)。
Sourcepub fn chart_type(&self) -> ChartType
pub fn chart_type(&self) -> ChartType
图表类型(便捷访问)。
若内部不变量被破坏(frame.graphic 不是 Chart),返回 ChartType::Column 作为兜底。
Sourcepub fn set_chart_type(&mut self, chart_type: ChartType)
pub fn set_chart_type(&mut self, chart_type: ChartType)
修改图表类型(保留数据不变)。不变量被破坏时静默忽略。
Sourcepub fn rid(&self) -> &str
pub fn rid(&self) -> &str
当前关联的关系 id(指向 /ppt/charts/chartN.xml)。
新建时为空字符串;由 Presentation::to_opc_package 在写出 chart part 时填充。
不变量被破坏时返回空字符串。
Sourcepub fn set_rid(&mut self, rid: impl Into<String>)
pub fn set_rid(&mut self, rid: impl Into<String>)
设置关系 id(一般由 presentation 层自动调用,用户无需直接设置)。 不变量被破坏时静默忽略。
Sourcepub fn set_placeholder(&mut self, ph_idx: u32, ph_type: Option<&str>)
pub fn set_placeholder(&mut self, ph_idx: u32, ph_type: Option<&str>)
将本图表形状标记为占位符(TODO-007 图表占位符类型化填充)。
写出 XML 时会在 <p:nvGraphicFramePr>/<p:nvPr> 内插入
<p:ph type="chart" idx="..."/>,使 PowerPoint 把该 graphicFrame
识别为图表占位符的填充实例。
§参数
ph_idx:占位符索引(对应<p:ph idx="..."/>)。ph_type:占位符类型字符串(如"chart"/"obj"),None时省略type属性。
Sourcepub fn clear_placeholder(&mut self)
pub fn clear_placeholder(&mut self)
清除占位符标记,使本图表形状变为普通 graphicFrame。
Sourcepub fn is_placeholder(&self) -> bool
pub fn is_placeholder(&self) -> bool
是否被标记为占位符。
Sourcepub fn data_labels(&self) -> Option<&DataLabels>
pub fn data_labels(&self) -> Option<&DataLabels>
图表级数据标签引用(<c:dLbls>,写在图表元素内、<c:ser> 之前)。
系列级 ChartShape::series_data_labels 会覆盖此处的图表级配置。
返回 None 仅在内部不变量被破坏时(frame.graphic 不是 Chart 变体)。
Sourcepub fn set_data_labels(&mut self, labels: Option<DataLabels>)
pub fn set_data_labels(&mut self, labels: Option<DataLabels>)
Sourcepub fn series_data_labels(&self, series_idx: usize) -> Option<&DataLabels>
pub fn series_data_labels(&self, series_idx: usize) -> Option<&DataLabels>
系列级数据标签引用(按系列索引访问)。
系列级配置会覆盖图表级 ChartShape::data_labels。返回 None 的情况:
- 内部不变量被破坏;
- 索引越界;
- 该系列未设置系列级数据标签(继承图表级)。
Sourcepub fn set_series_data_labels(
&mut self,
series_idx: usize,
labels: Option<DataLabels>,
)
pub fn set_series_data_labels( &mut self, series_idx: usize, labels: Option<DataLabels>, )
Sourcepub fn is_series_secondary(&self, series_idx: usize) -> bool
pub fn is_series_secondary(&self, series_idx: usize) -> bool
查询指定系列是否绑定到次坐标轴(右侧 Y 轴)。
返回 false 的情况:
- 内部不变量被破坏;
- 索引越界;
- 该系列绑定主轴(
secondary_axis=false)。
注意:饼图/散点图/气泡图不支持次坐标轴,写出时该字段被忽略。
Sourcepub fn set_series_secondary(&mut self, series_idx: usize, secondary: bool)
pub fn set_series_secondary(&mut self, series_idx: usize, secondary: bool)
Sourcepub fn push_series(&mut self, series: ChartSeries) -> Option<usize>
pub fn push_series(&mut self, series: ChartSeries) -> Option<usize>
添加一个新系列到图表数据末尾,返回新系列的索引。
便捷方法:避免外部构造 ChartData 字面量。不变量被破坏时返回 None。
Trait Implementations§
Source§impl Clone for ChartShape
impl Clone for ChartShape
Source§fn clone(&self) -> ChartShape
fn clone(&self) -> ChartShape
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChartShape
impl Debug for ChartShape
Source§impl Default for ChartShape
impl Default for ChartShape
Source§fn default() -> ChartShape
fn default() -> ChartShape
Source§impl Shape for ChartShape
impl Shape for ChartShape
Source§fn rotation(&self) -> f64
fn rotation(&self) -> f64
图表不支持旋转(OOXML 规范)。调用 Shape::set_rotation 会被忽略。