Skip to content

Commit 978424c

Browse files
authored
plot: add hovertemplate to ScatterTrace (#233)
* plot: add hovertemplate to ScatterTrace adds a hovertemplate string @[omitempty] field to ScatterTrace in the plot module. Several trace types already expose Plotly’s hovertemplate (for example HeatmapTrace, ContourTrace, SurfaceTrace, ChoroplethTrace, ScatterMapboxTrace, and SankeyLink). This change brings the scatter trace in line with those APIs and with Plotly’s own scatter trace options. A small test (test_scatter_hovertemplate_in_traces_json) verifies that the hovertemplate field is emitted in the traces JSON when set. * v fmt * make hovertemplate test less brittle to json changes
1 parent b259f32 commit 978424c

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

plot/plot_test.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,16 @@ fn test_bar() {
1212
)
1313
plt.show()!
1414
}
15+
16+
fn test_scatter_hovertemplate_in_json() {
17+
mut plt := Plot.new()
18+
mut tr := ScatterTrace{
19+
x: [1.0]
20+
y: [2.0]
21+
hovertemplate: 'x=%{x}, y=%{y}<extra></extra>'
22+
}
23+
plt.add_trace(tr)
24+
traces, _ := plt.to_json()
25+
assert traces.contains('"hovertemplate":')
26+
assert traces.contains('x=%{x}, y=%{y}<extra></extra>')
27+
}

plot/trace.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub mut:
6868
@[params]
6969
pub struct ScatterTrace {
7070
CommonTrace
71+
pub mut:
72+
hovertemplate string @[omitempty]
7173
}
7274

7375
// PieTrace is a struct for Pie trace type

0 commit comments

Comments
 (0)