1use crate::Error;
2
3use super::{Plot, PlotDescription};
4use crate::data::{
5 DataColumn, BAR_INTERVAL_LOWER, BAR_INTERVAL_UPPER, BAR_UNITS, COLOR, DUMBBELL_RIGHT,
6 FACET_COLUMN, FACET_ROW, FACET_WRAP, GROUP, HIGHLIGHT_CELLS, HUE, INTERVAL_LOWER,
7 INTERVAL_UPPER, SERIES, X, Y,
8};
9use crate::input::{AxisValues, PlotInput};
10use crate::layers::{BarPointLayer, GuideSpec, PointLayer};
11use crate::layout::AuthoredAxisSpec;
12use crate::layout::AxisTick;
13use crate::render::backend::PointStyle;
14use crate::spec::{
15 AxisScale, BarInput, BarSpacing, Bootstrap, CategoryOrder, ConfidenceIntervalAlgorithm,
16 DumbbellEndpoints, ErrorBarKind, HeatmapAnnotations, HeatmapLayout, HeatmapNullRowAnnotation,
17 HistogramBins, HistogramComposite, HistogramStat, LegendPolicy, LegendPosition, LinePathStyle,
18 PlotKind, PlotTextAnnotation, QqLine, RawOverlay, RegressionBand, WaterfallLabels,
19};
20use crate::{
21 plots::{HistogramGeometry, RaincloudGeometry},
22 NumericFormat,
23};
24
25impl PlotDescription {
26 pub(crate) fn text_layouts(&self) -> &crate::text::roles::TextRoles {
27 &self.payload.text_layouts
28 }
29
30 pub(crate) fn theme_spec(&self) -> Option<&crate::theme::Theme> {
31 self.payload.theme.as_deref()
32 }
33
34 pub(crate) fn resolve_theme(&self) -> Result<crate::theme::ResolvedTheme, Error> {
35 let mut theme = match self.theme_spec().or(self.payload.default_theme.as_deref()) {
36 Some(theme) => theme.resolve(),
37 None => crate::theme::Theme::publication().resolve(),
38 }?;
39 theme.text_layouts = self.payload.text_layouts.clone();
40 theme.apply_text_defaults(self.kind());
41 Ok(theme)
42 }
43
44 pub(crate) fn source_row_map(&self) -> Option<&crate::data::SourceRows> {
45 self.payload.source_rows.as_ref()
46 }
47
48 pub(crate) fn configured_source_rows(&self) -> Result<Option<&crate::data::SourceRows>, Error> {
49 if let Some(rows) = self.source_row_map() {
50 if rows.len() != self.row_count() {
51 return Err(Error::Data(
52 format!(
53 "chart source-row map has length {}, but chart data has {} rows",
54 rows.len(),
55 self.row_count()
56 )
57 .into(),
58 ));
59 }
60 }
61 Ok(self.source_row_map())
62 }
63
64 pub(crate) fn has_raw_key_axis(&self) -> bool {
65 matches!(
66 self.payload.input.as_ref(),
67 PlotInput::Line {
68 x: AxisValues::Keys(_),
69 ..
70 } | PlotInput::Trajectory {
71 x: AxisValues::Keys(_),
72 ..
73 }
74 )
75 }
76
77 pub(crate) fn row_count(&self) -> usize {
78 self.payload.input.len()
79 }
80
81 fn series_values(&self) -> Option<&crate::CategoryValues> {
82 self.payload
83 .input
84 .required_series()
85 .or(self.payload.series.as_ref())
86 }
87
88 fn group_values(&self) -> Option<&crate::CategoryValues> {
89 self.payload
90 .input
91 .required_group()
92 .or(self.payload.group.as_ref())
93 }
94
95 fn color_values(&self) -> Option<&crate::NumericValues> {
96 self.payload.input.continuous_color()
97 }
98
99 pub(crate) fn beeswarm_fixed_color(&self) -> Option<crate::Color> {
100 match self.payload.input.as_ref() {
101 PlotInput::Beeswarm {
102 color: Some(crate::scales::ColorSource::Fixed(color)),
103 ..
104 } => Some(*color),
105 _ => None,
106 }
107 }
108
109 pub(crate) fn x_col(&self) -> Option<&'static str> {
110 self.payload.input.x_name().map(|_| X)
111 }
112
113 pub(crate) fn y_col(&self) -> Option<&'static str> {
114 self.payload.input.y_name().map(|_| Y)
115 }
116
117 pub(crate) fn hue_col(&self) -> Option<&'static str> {
118 if self.kind.uses_unified_series() {
119 self.series_values().map(|_| SERIES)
120 } else {
121 self.payload.hue.as_ref().map(|_| HUE)
122 }
123 }
124
125 pub(crate) fn hue_name(&self) -> Option<&str> {
126 if self.kind.uses_unified_series() {
127 self.series_values().map(crate::CategoryValues::name)
128 } else {
129 self.payload.hue.as_ref().map(crate::CategoryValues::name)
130 }
131 }
132
133 pub(crate) fn hue_field(&self) -> Option<crate::data::category::RawField> {
134 if self.kind.uses_unified_series() {
135 self.series_values().map(crate::CategoryValues::raw_field)
136 } else {
137 self.payload
138 .hue
139 .as_ref()
140 .map(crate::CategoryValues::raw_field)
141 }
142 }
143
144 pub(crate) fn group_col(&self) -> Option<&'static str> {
145 if self.kind.uses_unified_series() {
146 self.series_values().map(|_| SERIES)
147 } else {
148 self.group_values().map(|_| GROUP)
149 }
150 }
151
152 pub(crate) fn group_name(&self) -> Option<&str> {
153 if self.kind.uses_unified_series() {
154 self.series_values().map(crate::CategoryValues::name)
155 } else {
156 self.group_values().map(crate::CategoryValues::name)
157 }
158 }
159
160 pub(crate) fn color_col(&self) -> Option<&'static str> {
161 self.color_values().map(|_| COLOR)
162 }
163
164 pub(crate) fn data_column(&self, key: &str) -> Option<DataColumn<'_>> {
165 if key == X {
166 return self.x_data_column();
167 }
168 if key == Y {
169 return self.y_data_column();
170 }
171 match key {
172 HUE => self.payload.hue.as_ref().map(DataColumn::Category),
173 GROUP => self.group_values().map(DataColumn::Category),
174 SERIES => self.series_values().map(DataColumn::Category),
175 COLOR => self.color_values().map(DataColumn::Numeric),
176 HIGHLIGHT_CELLS => self
177 .payload
178 .highlight_cells
179 .as_ref()
180 .map(DataColumn::Boolean),
181 INTERVAL_LOWER => self
182 .drawable_bounds()
183 .map(|bounds| DataColumn::Numeric(bounds.lower())),
184 INTERVAL_UPPER => self
185 .drawable_bounds()
186 .map(|bounds| DataColumn::Numeric(bounds.upper())),
187 BAR_INTERVAL_LOWER => self
188 .bar_input()
189 .and_then(BarInput::bounds)
190 .map(|bounds| DataColumn::Numeric(bounds.lower())),
191 BAR_INTERVAL_UPPER => self
192 .bar_input()
193 .and_then(BarInput::bounds)
194 .map(|bounds| DataColumn::Numeric(bounds.upper())),
195 BAR_UNITS => self
196 .bar_input()
197 .and_then(BarInput::error_bar)
198 .and_then(|error_bar| match error_bar.kind() {
199 ErrorBarKind::ConfidenceInterval(interval) => match &interval.algorithm {
200 ConfidenceIntervalAlgorithm::Bootstrap(Bootstrap {
201 units: Some(units),
202 ..
203 }) => Some(DataColumn::Category(units)),
204 ConfidenceIntervalAlgorithm::Bootstrap(Bootstrap {
205 units: None, ..
206 })
207 | ConfidenceIntervalAlgorithm::StudentT => None,
208 },
209 ErrorBarKind::Hidden
210 | ErrorBarKind::StandardDeviation(_)
211 | ErrorBarKind::PercentileInterval(_)
212 | ErrorBarKind::StandardError(_) => None,
213 }),
214 DUMBBELL_RIGHT => match self.payload.input.as_ref() {
215 PlotInput::Dumbbell { right, .. } => Some(DataColumn::Numeric(right)),
216 _ => None,
217 },
218 FACET_ROW => self
219 .payload
220 .facet
221 .as_ref()
222 .and_then(crate::layout::FacetSpec::row_values)
223 .map(DataColumn::Category),
224 FACET_COLUMN => self
225 .payload
226 .facet
227 .as_ref()
228 .and_then(crate::layout::FacetSpec::column_values)
229 .map(DataColumn::Category),
230 FACET_WRAP => self
231 .payload
232 .facet
233 .as_ref()
234 .and_then(crate::layout::FacetSpec::wrap_values)
235 .map(DataColumn::Category),
236 _ => self
237 .payload
238 .facet
239 .as_ref()
240 .and_then(|facet| facet.values().find(|values| values.name() == key))
241 .map(DataColumn::Category)
242 .or_else(|| match self.payload.input.as_ref() {
243 PlotInput::Matrix { variables } => variables
244 .columns()
245 .find(|values| values.raw_name() == key)
246 .map(DataColumn::Numeric),
247 _ => None,
248 }),
249 }
250 }
251
252 pub(crate) fn column_role(&self, key: &str) -> Option<crate::data::DataRole> {
255 use crate::data::DataRole as Role;
256 use crate::plots::PlotKind;
257 Some(match key {
258 X => match self.kind() {
259 PlotKind::Histogram => Role::Samples,
260 PlotKind::Density | PlotKind::Qq | PlotKind::Beeswarm => Role::Value,
261 PlotKind::PointInterval | PlotKind::Forest | PlotKind::Coefficient => {
262 Role::Estimate
263 }
264 PlotKind::Interaction => Role::Condition,
265 PlotKind::Dumbbell
266 | PlotKind::Bar
267 | PlotKind::HorizontalBar
268 | PlotKind::StackedBar
269 | PlotKind::StackedHorizontalBar
270 | PlotKind::Boxplot
271 | PlotKind::Violin
272 | PlotKind::Raincloud
273 | PlotKind::Waterfall => Role::Category,
274 _ => Role::X,
275 },
276 Y => match self.kind() {
277 PlotKind::PointInterval | PlotKind::Beeswarm => Role::Category,
278 PlotKind::Forest | PlotKind::Coefficient => Role::Term,
279 PlotKind::Interaction => Role::Estimate,
280 PlotKind::Dumbbell => Role::Left,
281 PlotKind::Bar | PlotKind::HorizontalBar => {
282 if self.bar_input()?.is_samples() {
283 Role::Samples
284 } else {
285 Role::Estimate
286 }
287 }
288 PlotKind::StackedBar
289 | PlotKind::StackedHorizontalBar
290 | PlotKind::Boxplot
291 | PlotKind::Violin
292 | PlotKind::Raincloud => Role::Value,
293 PlotKind::Waterfall => Role::Delta,
294 _ => Role::Y,
295 },
296 HUE => Role::Hue,
297 GROUP => Role::Group,
298 SERIES => Role::Series,
299 COLOR if self.kind() == PlotKind::Heatmap => Role::Fill,
300 COLOR => Role::Color,
301 HIGHLIGHT_CELLS => Role::HighlightCells,
302 INTERVAL_LOWER | BAR_INTERVAL_LOWER => Role::Lower,
303 INTERVAL_UPPER | BAR_INTERVAL_UPPER => Role::Upper,
304 BAR_UNITS => Role::SamplingUnits,
305 DUMBBELL_RIGHT => Role::Right,
306 FACET_ROW => Role::FacetRow,
307 FACET_COLUMN => Role::FacetColumn,
308 FACET_WRAP => Role::FacetWrap,
309 _ => return None,
310 })
311 }
312
313 fn x_data_column(&self) -> Option<DataColumn<'_>> {
314 match self.payload.input.as_ref() {
315 PlotInput::Scatter { x, .. }
316 | PlotInput::Regression { x, .. }
317 | PlotInput::Marginal { x, .. }
318 | PlotInput::LinePath { x, .. } => Some(DataColumn::Numeric(x)),
319 PlotInput::Histogram { input } => input.samples_input().map(DataColumn::Numeric),
320 PlotInput::Density { values } | PlotInput::Qq { values } => {
321 Some(DataColumn::Numeric(values))
322 }
323 PlotInput::PointInterval { estimate, .. } | PlotInput::Forest { estimate, .. } => {
324 Some(DataColumn::Numeric(estimate))
325 }
326 PlotInput::Coefficient { input, .. } => Some(DataColumn::Numeric(input.values())),
327 PlotInput::Line { x, .. } | PlotInput::Trajectory { x, .. } => match x {
328 AxisValues::Numeric(values) => Some(DataColumn::Numeric(values)),
329 AxisValues::Category(values) => Some(DataColumn::Category(values)),
330 AxisValues::Keys(_) => None,
331 },
332 PlotInput::Interaction { condition, .. }
333 | PlotInput::Dumbbell {
334 category: condition,
335 ..
336 }
337 | PlotInput::Heatmap { x: condition, .. }
338 | PlotInput::Bar {
339 category: condition,
340 ..
341 }
342 | PlotInput::HorizontalBar {
343 category: condition,
344 ..
345 }
346 | PlotInput::StackedBar {
347 category: condition,
348 ..
349 }
350 | PlotInput::StackedHorizontalBar {
351 category: condition,
352 ..
353 }
354 | PlotInput::Boxplot {
355 category: condition,
356 ..
357 }
358 | PlotInput::Violin {
359 category: condition,
360 ..
361 }
362 | PlotInput::Waterfall {
363 labels: condition, ..
364 } => Some(DataColumn::Category(condition)),
365 PlotInput::Raincloud { input } => input
366 .samples_input()
367 .map(|(category, _)| DataColumn::Category(category)),
368 PlotInput::Beeswarm { value, .. } => Some(DataColumn::Numeric(value)),
369 PlotInput::Matrix { .. } => None,
370 }
371 }
372
373 fn y_data_column(&self) -> Option<DataColumn<'_>> {
374 match self.payload.input.as_ref() {
375 PlotInput::Scatter { y, .. }
376 | PlotInput::Line { y, .. }
377 | PlotInput::Trajectory { y, .. }
378 | PlotInput::LinePath { y, .. }
379 | PlotInput::Regression { y, .. }
380 | PlotInput::Marginal { y, .. } => Some(DataColumn::Numeric(y)),
381 PlotInput::PointInterval { category, .. }
382 | PlotInput::Coefficient { term: category, .. }
383 | PlotInput::Forest { term: category, .. }
384 | PlotInput::Beeswarm { category, .. } => Some(DataColumn::Category(category)),
385 PlotInput::Interaction { estimate, .. }
386 | PlotInput::Dumbbell { left: estimate, .. }
387 | PlotInput::StackedBar {
388 value: estimate, ..
389 }
390 | PlotInput::StackedHorizontalBar {
391 value: estimate, ..
392 }
393 | PlotInput::Boxplot {
394 value: estimate, ..
395 }
396 | PlotInput::Violin {
397 value: estimate, ..
398 }
399 | PlotInput::Waterfall {
400 deltas: estimate, ..
401 } => Some(DataColumn::Numeric(estimate)),
402 PlotInput::Raincloud { input } => input
403 .samples_input()
404 .map(|(_, values)| DataColumn::Numeric(values)),
405 PlotInput::Bar { input, .. } | PlotInput::HorizontalBar { input, .. } => {
406 Some(DataColumn::Numeric(input.values()))
407 }
408 PlotInput::Heatmap { y, .. } => Some(DataColumn::Category(y)),
409 PlotInput::Histogram { .. }
410 | PlotInput::Density { .. }
411 | PlotInput::Qq { .. }
412 | PlotInput::Matrix { .. } => None,
413 }
414 }
415
416 pub(crate) fn automatic_axis_category_values(
417 &self,
418 kind: PlotKind,
419 x_axis: bool,
420 ) -> Option<&crate::CategoryValues> {
421 let column = if x_axis {
422 match kind {
423 PlotKind::Interaction
424 | PlotKind::Heatmap
425 | PlotKind::Bar
426 | PlotKind::StackedBar
427 | PlotKind::Boxplot
428 | PlotKind::Violin
429 | PlotKind::Raincloud
430 | PlotKind::Line
431 | PlotKind::Trajectory
432 | PlotKind::LinePath => self.x_data_column(),
433 _ => None,
434 }
435 } else {
436 match kind {
437 PlotKind::PointInterval
438 | PlotKind::Coefficient
439 | PlotKind::Forest
440 | PlotKind::Beeswarm
441 | PlotKind::Heatmap => self.y_data_column(),
442 PlotKind::Dumbbell
443 | PlotKind::HorizontalBar
444 | PlotKind::StackedHorizontalBar
445 | PlotKind::Waterfall => self.x_data_column(),
446 _ => None,
447 }
448 };
449 match column {
450 Some(DataColumn::Category(values)) => Some(values),
451 Some(DataColumn::Numeric(_) | DataColumn::Boolean(_)) | None => None,
452 }
453 }
454
455 #[expect(
456 clippy::too_many_lines,
457 reason = "one exhaustive closed-input match keeps every family's aligned channels auditable"
458 )]
459 pub(crate) fn aligned_columns(&self) -> Vec<DataColumn<'_>> {
460 let mut columns = match self.payload.input.as_ref() {
461 PlotInput::Scatter { x, y }
462 | PlotInput::Regression { x, y }
463 | PlotInput::Marginal { x, y } => {
464 vec![DataColumn::Numeric(x), DataColumn::Numeric(y)]
465 }
466 PlotInput::Histogram { input } => input
467 .samples_input()
468 .map_or_else(Vec::new, |values| vec![DataColumn::Numeric(values)]),
469 PlotInput::Density { values } | PlotInput::Qq { values } => {
470 vec![DataColumn::Numeric(values)]
471 }
472 PlotInput::PointInterval {
473 estimate, category, ..
474 }
475 | PlotInput::Forest {
476 estimate,
477 term: category,
478 ..
479 } => vec![
480 DataColumn::Numeric(estimate),
481 DataColumn::Category(category),
482 ],
483 PlotInput::Coefficient { input, term } => vec![
484 DataColumn::Numeric(input.values()),
485 DataColumn::Category(term),
486 ],
487 PlotInput::Line { y, .. } | PlotInput::Trajectory { y, .. } => {
488 let mut columns = self.x_data_column().into_iter().collect::<Vec<_>>();
489 columns.push(DataColumn::Numeric(y));
490 if let PlotInput::Trajectory { group, .. } = self.payload.input.as_ref() {
491 columns.push(DataColumn::Category(group));
492 }
493 columns
494 }
495 PlotInput::LinePath { x, y, group } => {
496 let mut columns = vec![DataColumn::Numeric(x), DataColumn::Numeric(y)];
497 columns.extend(group.iter().map(DataColumn::Category));
498 columns
499 }
500 PlotInput::Interaction {
501 condition,
502 estimate,
503 group,
504 ..
505 } => vec![
506 DataColumn::Category(condition),
507 DataColumn::Numeric(estimate),
508 DataColumn::Category(group),
509 ],
510 PlotInput::Dumbbell {
511 category,
512 left,
513 right,
514 ..
515 } => vec![
516 DataColumn::Category(category),
517 DataColumn::Numeric(left),
518 DataColumn::Numeric(right),
519 ],
520 PlotInput::Heatmap { x, y, fill } => vec![
521 DataColumn::Category(x),
522 DataColumn::Category(y),
523 DataColumn::Numeric(fill),
524 ],
525 PlotInput::Bar { category, input } | PlotInput::HorizontalBar { category, input } => {
526 let mut columns = vec![
527 DataColumn::Category(category),
528 DataColumn::Numeric(input.values()),
529 ];
530 if let Some(bounds) = input.bounds() {
531 columns.push(DataColumn::Numeric(bounds.lower()));
532 columns.push(DataColumn::Numeric(bounds.upper()));
533 }
534 if let Some(DataColumn::Category(units)) = self.data_column(BAR_UNITS) {
535 columns.push(DataColumn::Category(units));
536 }
537 columns
538 }
539 PlotInput::StackedBar {
540 category,
541 value,
542 series,
543 }
544 | PlotInput::StackedHorizontalBar {
545 category,
546 value,
547 series,
548 } => vec![
549 DataColumn::Category(category),
550 DataColumn::Numeric(value),
551 DataColumn::Category(series),
552 ],
553 PlotInput::Boxplot { category, value } | PlotInput::Violin { category, value } => {
554 vec![DataColumn::Category(category), DataColumn::Numeric(value)]
555 }
556 PlotInput::Beeswarm {
557 category, value, ..
558 } => {
559 let mut columns = vec![DataColumn::Category(category), DataColumn::Numeric(value)];
560 columns.extend(self.color_values().map(DataColumn::Numeric));
561 columns
562 }
563 PlotInput::Raincloud { input } => {
564 input.samples_input().map_or_else(Vec::new, |input| {
565 vec![DataColumn::Category(input.0), DataColumn::Numeric(input.1)]
566 })
567 }
568 PlotInput::Matrix { variables } => {
569 variables.columns().map(DataColumn::Numeric).collect()
570 }
571 PlotInput::Waterfall { labels, deltas, .. } => {
572 vec![DataColumn::Category(labels), DataColumn::Numeric(deltas)]
573 }
574 };
575 columns.extend(self.payload.series.iter().map(DataColumn::Category));
576 columns.extend(self.payload.hue.iter().map(DataColumn::Category));
577 columns.extend(self.payload.group.iter().map(DataColumn::Category));
578 if let Some(bounds) = self.drawable_bounds() {
579 columns.push(DataColumn::Numeric(bounds.lower()));
580 columns.push(DataColumn::Numeric(bounds.upper()));
581 }
582 columns.extend(self.payload.highlight_cells.iter().map(DataColumn::Boolean));
583 if let Some(facet) = &self.payload.facet {
584 columns.extend(facet.values().map(DataColumn::Category));
585 }
586 columns
587 }
588
589 #[must_use]
591 pub(crate) fn color_label_text(&self) -> Option<&str> {
592 self.payload.color_label.provided().map(crate::Text::as_str)
593 }
594
595 pub(crate) fn copy_color_title(&self) -> Result<crate::Text, Error> {
596 self.payload.color_label.try_copy()
597 }
598
599 pub(crate) fn same_color_title(&self, title: &crate::Text) -> bool {
600 self.payload.color_label == *title
601 }
602
603 pub(crate) fn authored_raincloud_hue_title(&self) -> Option<(&str, &crate::Text)> {
604 let raw_hue = self
605 .raincloud_geometry_input()?
606 .data
607 .hue_dimension
608 .as_deref()?;
609 self.payload
610 .raincloud_hue_label
611 .provided()
612 .map(|title| (raw_hue, title))
613 }
614
615 pub(crate) fn copy_raincloud_hue_title(&self) -> Result<crate::Text, Error> {
616 self.payload.raincloud_hue_label.try_copy()
617 }
618
619 pub(crate) fn same_raincloud_hue_title(&self, title: &crate::Text) -> bool {
620 self.payload.raincloud_hue_label == *title
621 }
622
623 #[must_use]
625 pub(crate) fn heatmap_layout_spec(&self) -> HeatmapLayout {
626 self.payload.heatmap_layout
627 }
628
629 #[must_use]
631 pub(crate) fn continuous_color_scale_spec(
632 &self,
633 ) -> Option<&crate::scales::ContinuousColorScale> {
634 self.payload.continuous_color_scale.as_ref()
635 }
636
637 pub(crate) fn continuous_selection_in(
639 &self,
640 owner: &crate::theme::ColorScales,
641 ) -> Result<crate::theme::ContinuousColorScale, crate::Error> {
642 use crate::theme::ContinuousColorScale;
643 let family = match self.kind() {
644 crate::plots::PlotKind::Heatmap => "heatmap",
645 crate::plots::PlotKind::Beeswarm => "beeswarm",
646 _ => {
647 return Err(crate::Error::Render(
648 "continuous selection requires Heatmap or Beeswarm".into(),
649 ))
650 }
651 };
652 let context = |error| match error {
653 crate::Error::Data(message) => crate::Error::Data(message.with_prefix(family)),
654 error => error,
655 };
656 let default;
657 let selection = if let Some(selection) = self.continuous_color_scale_spec() {
658 selection
659 } else {
660 default = ContinuousColorScale::sequential(None, None)?;
661 &default
662 };
663 selection.resolved_in(owner).map_err(context)
664 }
665
666 #[must_use]
668 pub(crate) fn heatmap_annotations_spec(&self) -> &HeatmapAnnotations {
669 &self.payload.heatmap_annotations
670 }
671
672 #[must_use]
674 pub(crate) fn heatmap_null_row_annotations_spec(&self) -> &[HeatmapNullRowAnnotation] {
675 &self.payload.heatmap_null_row_annotations
676 }
677
678 pub(crate) fn highlight_cells_col(&self) -> Option<&'static str> {
679 self.payload
680 .highlight_cells
681 .as_ref()
682 .map(|_| HIGHLIGHT_CELLS)
683 }
684
685 #[must_use]
687 pub(crate) fn estimate_labels_spec(&self) -> Option<&NumericFormat> {
688 self.payload.estimate_labels.as_ref()
689 }
690
691 pub(crate) const fn significance_mark_style_override(
692 &self,
693 ) -> Option<crate::elements::SignificanceMarkStyle> {
694 self.significance_mark_style
695 }
696
697 pub(crate) fn category_order_spec(&self) -> &CategoryOrder {
698 &self.payload.category_orders.primary
699 }
700
701 pub(crate) fn x_category_order_spec(&self) -> &CategoryOrder {
702 &self.payload.category_orders.x
703 }
704
705 pub(crate) fn y_category_order_spec(&self) -> &CategoryOrder {
706 &self.payload.category_orders.y
707 }
708
709 #[must_use]
711 pub(crate) fn histogram_bins_spec(&self) -> HistogramBins {
712 self.payload.histogram_bins
713 }
714
715 #[must_use]
717 pub(crate) fn histogram_stat_spec(&self) -> HistogramStat {
718 self.histogram_geometry_input().map_or_else(
719 || self.payload.histogram_stat.unwrap_or_default(),
720 |geometry| geometry.get_bins().bin_stat(),
721 )
722 }
723
724 pub(crate) fn histogram_sample_stat(&self) -> Option<HistogramStat> {
725 self.payload.histogram_stat
726 }
727
728 #[must_use]
730 pub(crate) fn histogram_composite_spec(&self) -> &HistogramComposite {
731 &self.payload.histogram_composite
732 }
733
734 pub(crate) fn histogram_geometry_input(&self) -> Option<&HistogramGeometry> {
735 match self.payload.input.as_ref() {
736 PlotInput::Histogram { input } => input.get_geometry(),
737 _ => None,
738 }
739 }
740
741 #[must_use]
743 pub(crate) fn qq_line_spec(&self) -> QqLine {
744 self.payload.qq_line
745 }
746
747 #[must_use]
749 pub(crate) fn colors_by_sign(&self) -> bool {
750 self.payload.color_by_sign
751 }
752
753 #[must_use]
755 pub(crate) fn zero_line_visible(&self) -> bool {
756 self.payload.zero_line
757 }
758
759 pub(crate) fn interval_bound_cols(&self) -> Option<(&'static str, &'static str)> {
760 self.drawable_bounds()
761 .map(|_| (INTERVAL_LOWER, INTERVAL_UPPER))
762 }
763
764 fn drawable_bounds(&self) -> Option<&crate::data::Bounds> {
765 match self.payload.input.as_ref() {
766 PlotInput::PointInterval { bounds, .. }
767 | PlotInput::Interaction { bounds, .. }
768 | PlotInput::Forest { bounds, .. } => Some(bounds),
769 PlotInput::Coefficient { input, .. } => input.bounds(),
770 _ => self.payload.line_band.as_ref(),
771 }
772 }
773
774 pub(crate) fn line_band_configured(&self) -> bool {
775 self.payload.line_band.is_some()
776 }
777
778 pub(crate) fn bar_input(&self) -> Option<&BarInput> {
779 match self.payload.input.as_ref() {
780 PlotInput::Bar { input, .. } | PlotInput::HorizontalBar { input, .. } => Some(input),
781 _ => None,
782 }
783 }
784
785 pub(crate) fn bar_bound_cols(&self) -> Option<(&'static str, &'static str)> {
786 self.bar_input()
787 .and_then(BarInput::bounds)
788 .map(|_| (BAR_INTERVAL_LOWER, BAR_INTERVAL_UPPER))
789 }
790
791 pub(crate) fn bar_units_col(&self) -> Option<&'static str> {
792 self.data_column(BAR_UNITS).map(|_| BAR_UNITS)
793 }
794
795 pub(crate) fn estimate_status_values(&self) -> Option<&[crate::data::EstimateStatus]> {
796 self.payload
797 .estimate_status
798 .as_ref()
799 .map(crate::data::EstimateStatusBinding::statuses)
800 }
801
802 pub(crate) fn markers_visible(&self) -> bool {
803 self.payload.markers_visible
804 }
805
806 #[must_use]
808 pub(crate) const fn regression_band_spec(&self) -> RegressionBand {
809 self.regression_band
810 }
811
812 #[must_use]
814 pub(crate) const fn line_path_style_spec(&self) -> LinePathStyle {
815 self.line_path_style
816 }
817
818 #[must_use]
820 pub(crate) const fn raw_overlay_spec(&self) -> RawOverlay {
821 self.raw_overlay
822 }
823
824 pub(crate) fn raincloud_geometry_input(&self) -> Option<&RaincloudGeometry> {
825 match self.payload.input.as_ref() {
826 PlotInput::Raincloud { input } => input.geometry_input(),
827 _ => None,
828 }
829 }
830
831 pub(crate) fn coefficient_reference_line_value(&self) -> Option<f64> {
832 self.payload.coefficient_reference_line
833 }
834
835 pub(crate) fn forest_reference_value(&self) -> f64 {
836 match self.payload.input.as_ref() {
837 PlotInput::Forest { reference, .. } => *reference,
838 _ => 0.0,
839 }
840 }
841
842 pub(crate) fn axis_scale_spec(&self) -> AxisScale {
843 self.payload.axis_scale
844 }
845
846 pub(crate) const fn interaction_connectors_spec(&self) -> Option<bool> {
847 self.interaction_connectors
848 }
849
850 pub(crate) const fn interaction_connectors_visible(&self) -> bool {
851 match self.interaction_connectors {
852 Some(visible) => visible,
853 None => true,
854 }
855 }
856
857 pub(crate) fn interaction_styles_spec(&self) -> Option<&[crate::plots::InteractionStyle]> {
858 self.payload.interaction_styles.as_deref()
859 }
860
861 pub(crate) fn categorical_color_scale_spec(
862 &self,
863 ) -> Option<&crate::scales::CategoricalColorScale> {
864 self.payload.categorical_color_scale.as_ref()
865 }
866
867 pub(crate) fn validate_categorical_colors<'a>(
868 &self,
869 levels: impl IntoIterator<Item = &'a str>,
870 ) -> Result<(), Error> {
871 let Some(map) = self
872 .categorical_color_scale_spec()
873 .and_then(crate::scales::CategoricalColorScale::map)
874 .filter(|_| !self.colors_by_sign())
875 else {
876 return Ok(());
877 };
878 for level in levels {
879 let values = self
880 .color_category_values()
881 .ok_or_else(|| Error::Render("categorical map has no original source".into()))?;
882 let key = crate::data::category::CategoryKey::from_raw(
883 self.categorical_field()
884 .expect("prepared categorical field"),
885 values.raw_category(level)?,
886 );
887 key.mapped_color(map)?;
888 }
889 Ok(())
890 }
891
892 #[must_use]
894 pub(crate) fn panel_text_annotations(&self) -> &[PlotTextAnnotation] {
895 &self.payload.panel_text_annotations
896 }
897
898 pub(crate) fn waterfall_base(&self) -> Option<f64> {
899 match self.payload.input.as_ref() {
900 PlotInput::Waterfall { base, .. } => Some(*base),
901 _ => None,
902 }
903 }
904
905 #[must_use]
907 pub(crate) fn waterfall_labels_spec(&self) -> Option<&WaterfallLabels> {
908 self.payload.waterfall_labels.as_ref()
909 }
910
911 pub(crate) fn total_format_spec(
912 &self,
913 ) -> Option<&std::sync::Arc<crate::numeric::format::NumericFormat>> {
914 self.payload.total_format.as_ref()
915 }
916
917 pub(crate) fn dumbbell_right_col(&self) -> Option<&'static str> {
918 matches!(self.payload.input.as_ref(), PlotInput::Dumbbell { .. }).then_some(DUMBBELL_RIGHT)
919 }
920
921 #[must_use]
923 pub(crate) fn dumbbell_endpoints_spec(&self) -> Option<&DumbbellEndpoints> {
924 match self.payload.input.as_ref() {
925 PlotInput::Dumbbell { endpoints, .. } => Some(endpoints),
926 _ => None,
927 }
928 }
929
930 #[must_use]
932 pub(crate) fn title_text(&self) -> Option<&str> {
933 self.title.provided().map(crate::Text::as_str)
934 }
935
936 #[must_use]
938 pub(crate) fn subtitle_text(&self) -> Option<&str> {
939 self.subtitle.provided().map(crate::Text::as_str)
940 }
941
942 #[must_use]
944 pub(crate) fn caption_text(&self) -> Option<&str> {
945 self.payload.caption.provided().map(crate::Text::as_str)
946 }
947
948 pub(crate) fn prose(&self) -> [Option<&crate::Text>; 3] {
949 [&self.title, &self.subtitle, &self.payload.caption].map(crate::Text::provided)
950 }
951
952 pub(crate) fn prose_alignments(&self) -> [Option<crate::text::TextAlignment>; 3] {
953 [&self.title, &self.subtitle, &self.payload.caption].map(crate::Text::alignment_request)
954 }
955
956 pub(crate) fn copy_prose(&self) -> Result<[crate::Text; 3], Error> {
957 Ok([
958 self.title.try_copy()?,
959 self.subtitle.try_copy()?,
960 self.payload.caption.try_copy()?,
961 ])
962 }
963
964 pub(crate) fn same_prose(&self, prose: &[crate::Text; 3]) -> bool {
965 [&self.title, &self.subtitle, &self.payload.caption]
966 .into_iter()
967 .zip(prose)
968 .all(|(left, right)| left == right)
969 }
970
971 pub(crate) fn validate_display_text(&self) -> Result<(), Error> {
972 for (source, role) in [
973 (self.title_text(), "plot title"),
974 (self.subtitle_text(), "plot subtitle"),
975 (self.caption_text(), "plot caption"),
976 (
977 self.payload.x_label.provided().map(crate::Text::as_str),
978 "x-axis title",
979 ),
980 (
981 self.payload.y_label.provided().map(crate::Text::as_str),
982 "y-axis title",
983 ),
984 (self.color_label_text(), "color guide title"),
985 (
986 self.payload
987 .raincloud_hue_label
988 .provided()
989 .map(crate::Text::as_str),
990 "raincloud hue guide title",
991 ),
992 ] {
993 if let Some(source) = source {
994 crate::text::validate_for(source, role)?;
995 }
996 }
997 Ok(())
998 }
999
1000 pub(crate) fn resolve_label(&self, raw: &str) -> Result<String, Error> {
1001 self.payload.labels.resolve(raw)
1002 }
1003
1004 pub(crate) fn get_labels(&self) -> &crate::formatting::Labels {
1005 &self.payload.labels
1006 }
1007
1008 pub(crate) fn resolve_axis_label_domain<'b>(
1009 &self,
1010 domain: &str,
1011 raw_labels: impl IntoIterator<Item = &'b str>,
1012 ) -> Result<Vec<String>, Error> {
1013 self.payload.labels.resolve_domain(domain, raw_labels)
1014 }
1015
1016 pub(crate) fn copy_axis_titles(&self) -> Result<[crate::Text; 2], Error> {
1017 Ok([
1018 self.payload.x_label.try_copy()?,
1019 self.payload.y_label.try_copy()?,
1020 ])
1021 }
1022
1023 pub(crate) fn same_axis_titles(&self, titles: &[crate::Text; 2]) -> bool {
1024 self.payload.x_label == titles[0] && self.payload.y_label == titles[1]
1025 }
1026
1027 pub(crate) fn prepare_axis_labels(
1028 &self,
1029
1030 policy: Option<&crate::formatting::Labels>,
1031 ) -> Result<[Option<crate::Text>; 2], Error> {
1032 let mut labels = [None, None];
1033 for ((target, source), authored) in labels
1034 .iter_mut()
1035 .zip(self.axis_label_sources(self.kind))
1036 .zip([
1037 self.payload.x_label.provided(),
1038 self.payload.y_label.provided(),
1039 ])
1040 {
1041 *target = if let Some(text) = authored {
1042 text.required_source("axis title")?;
1043 Some(text.try_copy()?)
1044 } else {
1045 source
1046 .map(|(raw, inferred)| {
1047 if inferred {
1048 policy
1049 .unwrap_or(&self.payload.labels)
1050 .resolve(raw)
1051 .map(crate::Text::from)
1052 } else {
1053 crate::text::validate_for(raw, "axis title")?;
1054 crate::data::source::copy_source_string(raw).map(crate::Text::from)
1055 }
1056 })
1057 .transpose()?
1058 };
1059 }
1060 Ok(labels)
1061 }
1062
1063 pub(crate) fn resolve_label_domain<'b>(
1064 &self,
1065 domain: &str,
1066 raw_labels: impl IntoIterator<Item = &'b str>,
1067 ) -> Result<Vec<String>, crate::Error> {
1068 self.payload.labels.resolve_domain(domain, raw_labels)
1069 }
1070
1071 fn axis_label_sources(&self, kind: PlotKind) -> [Option<(&str, bool)>; 2] {
1072 let x_name = self.payload.input.x_name().map(|name| (name, true));
1073 let y_name = self.payload.input.y_name().map(|name| (name, true));
1074 let x = match kind {
1075 PlotKind::HorizontalBar
1076 | PlotKind::StackedHorizontalBar
1077 | PlotKind::Waterfall
1078 | PlotKind::Dumbbell => y_name,
1079 PlotKind::Qq => Some(("Theoretical normal quantiles", false)),
1080 PlotKind::Histogram => self
1081 .histogram_geometry_input()
1082 .map_or_else(|| x_name, |input| Some((input.get_value_dimension(), true))),
1083 PlotKind::Raincloud => self.raincloud_geometry_input().map_or_else(
1084 || x_name,
1085 |input| Some((input.data.category_dimension.as_str(), true)),
1086 ),
1087 PlotKind::Matrix => None,
1088 _ => x_name,
1089 };
1090 let y = match kind {
1091 PlotKind::HorizontalBar
1092 | PlotKind::StackedHorizontalBar
1093 | PlotKind::Waterfall
1094 | PlotKind::Dumbbell
1095 | PlotKind::Qq => x_name,
1096 PlotKind::Histogram => self.histogram_geometry_input().map_or_else(
1097 || match self.histogram_stat_spec() {
1098 HistogramStat::Count => Some(("Count", false)),
1099 HistogramStat::Probability => Some(("Probability", false)),
1100 HistogramStat::Density => Some(("Density", false)),
1101 },
1102 |input| Some((input.get_height_dimension(), true)),
1103 ),
1104 PlotKind::Raincloud => self.raincloud_geometry_input().map_or_else(
1105 || y_name,
1106 |input| Some((input.data.value_dimension.as_str(), true)),
1107 ),
1108 PlotKind::Density => Some(("Density", false)),
1109 PlotKind::Matrix => None,
1110 _ => y_name,
1111 };
1112 [x, y]
1113 }
1114
1115 pub(crate) fn prepare_color_label(
1116 &self,
1117
1118 policy: Option<&crate::formatting::Labels>,
1119 ) -> Result<crate::Text, Error> {
1120 if let Some(label) = self.payload.color_label.provided() {
1121 label.required_source("color guide title")?;
1122 label.try_copy()
1123 } else if let Some(values) = self.color_values() {
1124 policy
1125 .unwrap_or(&self.payload.labels)
1126 .resolve(values.raw_name())
1127 .map(crate::Text::from)
1128 } else {
1129 Ok(crate::Text::new(String::new()))
1130 }
1131 }
1132
1133 pub(crate) fn color_dimension_key(&self) -> Option<&str> {
1134 self.color_values().map(crate::NumericValues::raw_name)
1135 }
1136
1137 pub(crate) fn legend_group_values(&self) -> Option<&crate::CategoryValues> {
1138 if self.kind.uses_unified_series() {
1139 self.series_values()
1140 } else {
1141 self.group_values()
1142 }
1143 }
1144
1145 pub(crate) fn legend_hue_values(&self) -> Option<&crate::CategoryValues> {
1146 if let Some(input) = self.raincloud_geometry_input() {
1147 return input.data.hue.as_ref();
1148 }
1149 if self.kind.uses_unified_series() {
1150 self.series_values()
1151 } else {
1152 self.payload.hue.as_ref()
1153 }
1154 }
1155
1156 pub(crate) fn same_group_hue_field(&self) -> bool {
1157 self.legend_group_values()
1158 .zip(self.legend_hue_values())
1159 .is_some_and(|(group, hue)| group.original_field() == hue.original_field())
1160 }
1161
1162 pub(crate) fn collective_legend_identity(
1163 &self,
1164 pair: &crate::data::CollectivePair,
1165 ) -> Result<crate::decorations::legend::GuideEntryIdentity, Error> {
1166 use crate::decorations::legend::GuideEntryIdentity;
1167 let group = self.legend_group_values().zip(pair.group.as_deref());
1168 let hue = self.legend_hue_values().zip(pair.hue.as_deref());
1169 Ok(match (group, hue) {
1170 (Some((group, group_value)), Some((hue, hue_value))) => {
1171 let group_field = group.raw_field();
1172 let hue_field = hue.raw_field();
1173 let group_value = group.raw_category(group_value)?;
1174 let hue_value = hue.raw_category(hue_value)?;
1175 if group_field == hue_field {
1176 if group_value != hue_value {
1177 return Err(Error::Render(
1178 "same-field collective legend identity contains different original values".into(),
1179 ));
1180 }
1181 GuideEntryIdentity::category(group_field, group_value)
1182 } else {
1183 GuideEntryIdentity::pair(group_field, group_value, hue_field, hue_value)
1184 }
1185 }
1186 (Some((field, value)), None) | (None, Some((field, value))) => {
1187 GuideEntryIdentity::category(field.raw_field(), field.raw_category(value)?)
1188 }
1189 _ => {
1190 return Err(Error::Render(
1191 "collective legend identity has no resolved group or hue value".into(),
1192 ))
1193 }
1194 })
1195 }
1196
1197 pub(crate) fn guide_category_identity(
1199 &self,
1200 field: &str,
1201 label: &str,
1202 ) -> Result<crate::decorations::legend::GuideEntryIdentity, Error> {
1203 use crate::{data::category::RawField, decorations::legend::GuideEntryIdentity};
1204 if let Some(input) = self.raincloud_geometry_input() {
1205 if input.data.hue_dimension.as_deref() == Some(field) {
1206 let values =
1207 input.data.hue.as_ref().ok_or_else(|| {
1208 Error::Render("supplied hue dimension has no values".into())
1209 })?;
1210 return Ok(GuideEntryIdentity::category(
1211 RawField::new(field)?,
1212 values.raw_category(label)?,
1213 ));
1214 }
1215 }
1216 let values = [self.legend_group_values(), self.legend_hue_values()]
1217 .into_iter()
1218 .flatten()
1219 .find(|values| values.name() == field)
1220 .ok_or_else(|| Error::Render("categorical guide entry has no prepared field".into()))?;
1221 Ok(GuideEntryIdentity::category(
1222 values.raw_field(),
1223 values.raw_category(label)?,
1224 ))
1225 }
1226
1227 pub(crate) fn point_legend_identity(
1228 &self,
1229 label: &str,
1230 ) -> Result<crate::decorations::legend::GuideEntryIdentity, Error> {
1231 let field = self
1232 .payload
1233 .interaction_styles
1234 .as_ref()
1235 .and(self.group_name())
1236 .or_else(|| self.hue_dimension_key())
1237 .ok_or_else(|| Error::Render("categorical guide entry has no prepared field".into()))?;
1238 self.guide_category_identity(field, label)
1239 }
1240
1241 pub(crate) fn color_guide_field(&self) -> Option<crate::data::category::RawField> {
1242 self.color_values().map(crate::NumericValues::raw_field)
1243 }
1244
1245 pub(crate) fn hue_dimension_key(&self) -> Option<&str> {
1246 self.hue_name().or_else(|| {
1247 self.raincloud_geometry_input()
1248 .and_then(|input| input.data.hue_dimension.as_deref())
1249 })
1250 }
1251
1252 pub(crate) fn categorical_color_field(&self) -> Option<crate::data::category::RawField> {
1253 if self.colors_by_sign() {
1254 return None;
1255 }
1256 if self.hue_dimension_key().is_some()
1257 || (self.kind() == crate::plots::PlotKind::Interaction && self.group_name().is_some())
1258 {
1259 self.categorical_field()
1260 } else {
1261 None
1262 }
1263 }
1264
1265 pub(crate) fn color_category_values(&self) -> Option<&crate::CategoryValues> {
1266 if let Some(hue) = self.legend_hue_values() {
1267 return Some(hue);
1268 }
1269 match self.kind() {
1270 crate::plots::PlotKind::Interaction => self.legend_group_values(),
1271 crate::plots::PlotKind::Bar
1272 | crate::plots::PlotKind::HorizontalBar
1273 | crate::plots::PlotKind::StackedBar
1274 | crate::plots::PlotKind::StackedHorizontalBar
1275 | crate::plots::PlotKind::Boxplot
1276 | crate::plots::PlotKind::Violin
1277 | crate::plots::PlotKind::Raincloud => self
1278 .x_data_column()
1279 .and_then(|column| match column {
1280 DataColumn::Category(values) => Some(values),
1281 _ => None,
1282 })
1283 .or_else(|| {
1284 self.raincloud_geometry_input()
1285 .map(|input| &input.data.category)
1286 }),
1287 _ => None,
1288 }
1289 }
1290
1291 pub(crate) fn categorical_field(&self) -> Option<crate::data::category::RawField> {
1292 self.hue_field()
1293 .or_else(|| {
1294 self.raincloud_geometry_input()
1295 .and_then(|input| input.data.hue_dimension.as_deref())
1296 .map(|field| {
1297 crate::data::category::RawField::from_shared(std::sync::Arc::from(field))
1298 })
1299 })
1300 .or_else(|| {
1301 if self.kind() == crate::plots::PlotKind::Interaction {
1302 self.group_values().map(crate::CategoryValues::raw_field)
1303 } else if matches!(
1304 self.kind(),
1305 crate::plots::PlotKind::Bar
1306 | crate::plots::PlotKind::HorizontalBar
1307 | crate::plots::PlotKind::StackedBar
1308 | crate::plots::PlotKind::StackedHorizontalBar
1309 | crate::plots::PlotKind::Boxplot
1310 | crate::plots::PlotKind::Violin
1311 | crate::plots::PlotKind::Raincloud
1312 ) {
1313 self.x_data_column()
1314 .and_then(|column| match column {
1315 DataColumn::Category(values) => Some(values.raw_field()),
1316 _ => None,
1317 })
1318 .or_else(|| {
1319 self.raincloud_geometry_input().map(|input| {
1320 crate::data::category::RawField::from_shared(std::sync::Arc::from(
1321 input.data.category_dimension.as_str(),
1322 ))
1323 })
1324 })
1325 } else {
1326 None
1327 }
1328 })
1329 }
1330
1331 #[must_use]
1333 pub(crate) fn x_axis_spec(&self) -> &AuthoredAxisSpec {
1334 &self.payload.axes[0]
1335 }
1336
1337 pub(crate) fn explicit_x_ticks(&self) -> Option<&[AxisTick]> {
1338 self.payload.axes[0].exact_ticks.as_deref()
1339 }
1340
1341 pub(crate) fn y_axis_spec(&self) -> &AuthoredAxisSpec {
1342 &self.payload.axes[1]
1343 }
1344
1345 pub(crate) fn explicit_y_ticks(&self) -> Option<&[AxisTick]> {
1346 self.payload.axes[1].exact_ticks.as_deref()
1347 }
1348
1349 pub(crate) fn guides(&self) -> &[GuideSpec] {
1350 &self.payload.guides
1351 }
1352
1353 pub(crate) fn point_layers(&self) -> &[PointLayer] {
1354 &self.payload.point_layers
1355 }
1356
1357 pub(crate) fn bar_point_layers(&self) -> &[BarPointLayer] {
1358 &self.payload.bar_point_layers
1359 }
1360
1361 pub(crate) fn significance_annotations(
1362 &self,
1363 ) -> &[crate::significance::SignificanceAnnotation] {
1364 &self.payload.significance
1365 }
1366
1367 pub(crate) const fn sizing_request(&self) -> crate::layout::RootRequest {
1368 self.root_size
1369 }
1370
1371 pub(crate) fn matrix_variables(&self) -> Option<&crate::data::VariableValues> {
1372 match self.payload.input.as_ref() {
1373 PlotInput::Matrix { variables } => Some(variables),
1374 _ => None,
1375 }
1376 }
1377
1378 pub(crate) fn bar_spacing_spec(&self) -> BarSpacing {
1379 self.payload.bar_spacing
1380 }
1381
1382 pub(crate) fn point_style(
1383 &self,
1384 theme: &crate::theme::ResolvedTheme,
1385 color: (u8, u8, u8),
1386 radius: u32,
1387 ) -> PointStyle {
1388 theme.marks.get_points().get_primary().backend_style(
1389 color,
1390 radius,
1391 self.payload.point_outline_visible,
1392 )
1393 }
1394
1395 pub(crate) fn distribution_point_style(
1396 &self,
1397 role: &crate::theme::mark::SizedPointTheme,
1398 color: (u8, u8, u8),
1399 ) -> PointStyle {
1400 role.backend_style(color, self.payload.point_outline_visible)
1401 }
1402
1403 pub(crate) fn legend_policy_spec(&self) -> LegendPolicy {
1404 self.payload.legend_policy
1405 }
1406
1407 pub(crate) fn legend_position_spec(&self) -> LegendPosition {
1408 self.payload.legend_policy.position()
1409 }
1410
1411 pub(crate) fn color_label_format_spec(
1412 &self,
1413 ) -> Option<&std::sync::Arc<crate::numeric::format::NumericFormat>> {
1414 self.payload.color_label_format.as_ref()
1415 }
1416
1417 pub(crate) const fn kind(&self) -> PlotKind {
1418 self.kind
1419 }
1420}
1421
1422impl<K: crate::kind::Facet> Plot<K> {
1423 #[must_use]
1425 pub fn get_facet(&self) -> Option<&crate::layout::FacetSpec> {
1426 self.description.payload.facet.as_ref()
1427 }
1428}
1429
1430impl<K: crate::kind::Marker> Plot<K> {
1431 pub fn get_significance(&self) -> Option<&[crate::elements::SignificanceAnnotation]> {
1433 let annotations = self.description.significance_annotations();
1434 (!annotations.is_empty()).then_some(annotations)
1435 }
1436
1437 pub fn get_theme(&self) -> Option<&crate::Theme> {
1439 self.description.theme_spec()
1440 }
1441
1442 pub fn get_default_theme(&self) -> Option<&crate::Theme> {
1444 self.description.payload.default_theme.as_deref()
1445 }
1446
1447 #[must_use]
1449 pub fn get_labels(&self) -> &crate::formatting::Labels {
1450 self.description.get_labels()
1451 }
1452
1453 pub(crate) const fn description(&self) -> &PlotDescription {
1454 &self.description
1455 }
1456
1457 pub(crate) fn into_description(self) -> PlotDescription {
1458 self.description
1459 }
1460
1461 #[must_use]
1463 pub const fn kind(&self) -> PlotKind {
1464 self.description.kind
1465 }
1466}