From 21c769fc8cd5e614a2955c0ce3a978f8b0491268 Mon Sep 17 00:00:00 2001 From: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> Date: Fri, 13 Feb 2026 20:13:16 +0100 Subject: [PATCH] fix hovertext dimension to be matrix / 2d array type Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> --- examples/scientific_charts/src/main.rs | 12 ++++++++++-- plotly/src/traces/heat_map.rs | 10 ++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/scientific_charts/src/main.rs b/examples/scientific_charts/src/main.rs index 1b4069f8..695fcbc6 100644 --- a/examples/scientific_charts/src/main.rs +++ b/examples/scientific_charts/src/main.rs @@ -2,7 +2,7 @@ use std::f64::consts::PI; -use plotly::common::{ColorScale, ColorScalePalette, Font}; +use plotly::common::{ColorScale, ColorScalePalette, Font, HoverInfo}; use plotly::contour::Contours; use plotly::{Contour, HeatMap, Layout, Plot}; use plotly_utils::write_example_to_html; @@ -124,7 +124,15 @@ fn customizing_spacing_between_x_and_y_ticks(show: bool, file_name: &str) { // ANCHOR: basic_heat_map fn basic_heat_map(show: bool, file_name: &str) { let z = vec![vec![1, 20, 30], vec![20, 1, 60], vec![30, 60, 1]]; - let trace = HeatMap::new_z(z).zmin(1.0).zmax(60.0); + let trace = HeatMap::new_z(z) + .zmin(1.0) + .zmax(60.0) + .hover_info(HoverInfo::Text) + .hover_text_matrix(vec![ + vec!["A", "B", "C"], + vec!["D", "E", "F"], + vec!["G", "H", "I"], + ]); let mut plot = Plot::new(); plot.add_trace(trace); diff --git a/plotly/src/traces/heat_map.rs b/plotly/src/traces/heat_map.rs index 4f3e45d7..b5514784 100644 --- a/plotly/src/traces/heat_map.rs +++ b/plotly/src/traces/heat_map.rs @@ -86,7 +86,8 @@ where #[serde(rename = "hovertemplate")] hover_template: Option>, #[serde(rename = "hovertext")] - hover_text: Option>, + #[field_setter(with_matrix)] + hover_text: Option>, #[serde(rename = "legendgroup")] legend_group: Option, #[serde(rename = "legendgrouptitle")] @@ -99,7 +100,8 @@ where show_legend: Option, #[serde(rename = "showscale")] show_scale: Option, - text: Option>, + #[field_setter(with_matrix)] + text: Option>, transpose: Option, visible: Option, x: Option>, @@ -214,7 +216,7 @@ mod tests { .hover_on_gaps(true) .hover_template("tmpl") .hover_template_array(vec!["tmpl1", "tmpl2"]) - .hover_text(vec!["hov", "er"]) + .hover_text_array(vec!["hov", "er"]) .legend_group("1") .legend_group_title("Legend Group Title") .name("name") @@ -222,7 +224,7 @@ mod tests { .reverse_scale(false) .show_legend(true) .show_scale(false) - .text(vec!["te", "xt"]) + .text_array(vec!["te", "xt"]) .transpose(true) .visible(Visible::LegendOnly) .x_axis("x")