Skip to content

Commit acba924

Browse files
authored
fix hovertext dimension to be matrix / 2d array type (#387)
Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
1 parent 8a8dab9 commit acba924

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

examples/scientific_charts/src/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::f64::consts::PI;
44

5-
use plotly::common::{ColorScale, ColorScalePalette, Font};
5+
use plotly::common::{ColorScale, ColorScalePalette, Font, HoverInfo};
66
use plotly::contour::Contours;
77
use plotly::{Contour, HeatMap, Layout, Plot};
88
use plotly_utils::write_example_to_html;
@@ -124,7 +124,15 @@ fn customizing_spacing_between_x_and_y_ticks(show: bool, file_name: &str) {
124124
// ANCHOR: basic_heat_map
125125
fn basic_heat_map(show: bool, file_name: &str) {
126126
let z = vec![vec![1, 20, 30], vec![20, 1, 60], vec![30, 60, 1]];
127-
let trace = HeatMap::new_z(z).zmin(1.0).zmax(60.0);
127+
let trace = HeatMap::new_z(z)
128+
.zmin(1.0)
129+
.zmax(60.0)
130+
.hover_info(HoverInfo::Text)
131+
.hover_text_matrix(vec![
132+
vec!["A", "B", "C"],
133+
vec!["D", "E", "F"],
134+
vec!["G", "H", "I"],
135+
]);
128136
let mut plot = Plot::new();
129137
plot.add_trace(trace);
130138

plotly/src/traces/heat_map.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ where
8686
#[serde(rename = "hovertemplate")]
8787
hover_template: Option<Dim<String>>,
8888
#[serde(rename = "hovertext")]
89-
hover_text: Option<Vec<String>>,
89+
#[field_setter(with_matrix)]
90+
hover_text: Option<Dim<String>>,
9091
#[serde(rename = "legendgroup")]
9192
legend_group: Option<String>,
9293
#[serde(rename = "legendgrouptitle")]
@@ -99,7 +100,8 @@ where
99100
show_legend: Option<bool>,
100101
#[serde(rename = "showscale")]
101102
show_scale: Option<bool>,
102-
text: Option<Vec<String>>,
103+
#[field_setter(with_matrix)]
104+
text: Option<Dim<String>>,
103105
transpose: Option<bool>,
104106
visible: Option<Visible>,
105107
x: Option<Vec<X>>,
@@ -214,15 +216,15 @@ mod tests {
214216
.hover_on_gaps(true)
215217
.hover_template("tmpl")
216218
.hover_template_array(vec!["tmpl1", "tmpl2"])
217-
.hover_text(vec!["hov", "er"])
219+
.hover_text_array(vec!["hov", "er"])
218220
.legend_group("1")
219221
.legend_group_title("Legend Group Title")
220222
.name("name")
221223
.opacity(0.99)
222224
.reverse_scale(false)
223225
.show_legend(true)
224226
.show_scale(false)
225-
.text(vec!["te", "xt"])
227+
.text_array(vec!["te", "xt"])
226228
.transpose(true)
227229
.visible(Visible::LegendOnly)
228230
.x_axis("x")

0 commit comments

Comments
 (0)