Skip to content

Commit 2ea3d61

Browse files
jqnatividadclaude
andcommitted
fix(parcats): use a parcats-specific ParcatsHoverInfo enum
Addresses roborev finding: Parcats.hover_info reused common::HoverInfo, which cannot express parcats' valid values (count/probability) and offers x/y/z/text/name that parcats ignores. Add ParcatsHoverInfo (count, probability, count+probability, all, none, skip) matching the plotly.js parcats hoverinfo flaglist. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8598864 commit 2ea3d61

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
2626
- [[#422](https://github.com/plotly/plotly.rs/issues/422)] Add `Icicle` trace type (hierarchical icicle chart; sibling of `Treemap`/`Sunburst`)
2727
- [[#422](https://github.com/plotly/plotly.rs/issues/422)] Add layout-level `uirevision` to preserve UI state (zoom/pan/selection) across re-renders (complements the trace-level `uirevision` added in #421)
2828
- Add `Splom` trace type (scatter-plot matrix) with `SplomDimension`/`SplomAxis`/`SplomDiagonal` config and `showupperhalf`/`showlowerhalf` controls
29-
- Add `Parcats` trace type (parallel categories) with `ParcatsDimension`/`ParcatsLine` config and `ParcatsLineShape`/`ParcatsArrangement`/`ParcatsHoverOn`/`ParcatsSortPaths` enums
29+
- Add `Parcats` trace type (parallel categories) with `ParcatsDimension`/`ParcatsLine` config and `ParcatsLineShape`/`ParcatsArrangement`/`ParcatsHoverOn`/`ParcatsSortPaths`/`ParcatsHoverInfo` enums
3030

3131
### Changed
3232

plotly/src/traces/parcats.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde::Serialize;
55

66
use crate::{
77
color::Color,
8-
common::{ColorScale, Dim, Domain, HoverInfo, PlotType},
8+
common::{ColorScale, Dim, Domain, PlotType},
99
layout::CategoryOrder,
1010
Trace,
1111
};
@@ -44,6 +44,22 @@ pub enum ParcatsSortPaths {
4444
Backward,
4545
}
4646

47+
/// Determines which trace information appears on hover for a parcats trace.
48+
///
49+
/// Unlike the cartesian [`HoverInfo`](crate::common::HoverInfo), parcats hover
50+
/// info is limited to `count`/`probability` (plus `all`/`none`/`skip`).
51+
#[derive(Serialize, Clone, Debug)]
52+
#[serde(rename_all = "lowercase")]
53+
pub enum ParcatsHoverInfo {
54+
Count,
55+
Probability,
56+
#[serde(rename = "count+probability")]
57+
CountAndProbability,
58+
All,
59+
None,
60+
Skip,
61+
}
62+
4763
/// A single dimension (column) of a [`Parcats`] trace.
4864
#[serde_with::skip_serializing_none]
4965
#[derive(Serialize, Debug, Clone, FieldSetter)]
@@ -181,9 +197,10 @@ where
181197
// the more general form and is used here.
182198
#[serde(rename = "hovertemplate")]
183199
hover_template: Option<String>,
184-
/// Determines which trace information appears on hover.
200+
/// Determines which trace information appears on hover. Limited to
201+
/// `count`/`probability` (plus `all`/`none`/`skip`).
185202
#[serde(rename = "hoverinfo")]
186-
hover_info: Option<HoverInfo>,
203+
hover_info: Option<ParcatsHoverInfo>,
187204
/// Sets the domain within which this parcats trace is drawn.
188205
domain: Option<Domain>,
189206
}
@@ -276,6 +293,23 @@ mod tests {
276293
assert_eq!(to_value(line).unwrap(), expected);
277294
}
278295

296+
#[test]
297+
fn serialize_parcats_hover_info() {
298+
assert_eq!(to_value(ParcatsHoverInfo::Count).unwrap(), json!("count"));
299+
assert_eq!(
300+
to_value(ParcatsHoverInfo::Probability).unwrap(),
301+
json!("probability")
302+
);
303+
assert_eq!(
304+
to_value(ParcatsHoverInfo::CountAndProbability).unwrap(),
305+
json!("count+probability")
306+
);
307+
assert_eq!(to_value(ParcatsHoverInfo::Skip).unwrap(), json!("skip"));
308+
309+
let trace = Parcats::<i32>::new().hover_info(ParcatsHoverInfo::Count);
310+
assert_eq!(to_value(trace).unwrap()["hoverinfo"], json!("count"));
311+
}
312+
279313
#[test]
280314
fn serialize_parcats_dimension() {
281315
let dim = ParcatsDimension::new()

0 commit comments

Comments
 (0)