Skip to content

plot: add hovertemplate to ScatterTrace#233

Open
holder66 wants to merge 3 commits intovlang:mainfrom
holder66:scatter-hovertemplate
Open

plot: add hovertemplate to ScatterTrace#233
holder66 wants to merge 3 commits intovlang:mainfrom
holder66:scatter-hovertemplate

Conversation

@holder66
Copy link
Copy Markdown

@holder66 holder66 commented Mar 15, 2026

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.

Summary by CodeRabbit

  • New Features

    • Support for configurable hover templates in scatter plots, letting users customize tooltip content shown when hovering over points.
  • Tests

    • Added test coverage to verify hover template settings are correctly serialized and retained in JSON output.

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.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 79b13ac2-e767-4745-a72a-f82d79f22464

📥 Commits

Reviewing files that changed from the base of the PR and between ea2bd8a and d4be1c3.

📒 Files selected for processing (1)
  • plot/plot_test.v
🚧 Files skipped from review as they are similar to previous changes (1)
  • plot/plot_test.v

📝 Walkthrough

Walkthrough

Adds a new public mutable string field hovertemplate (omitempty) to ScatterTrace and a unit test test_scatter_hovertemplate_in_json that verifies the field is present in the plot JSON output.

Changes

Cohort / File(s) Summary
ScatterTrace Field Addition
plot/trace.v
Adds hovertemplate string (pub mut, @[omitempty]) to the ScatterTrace struct.
Serialization Test
plot/plot_test.v
Adds test_scatter_hovertemplate_in_json which builds a Plot with a ScatterTrace containing hovertemplate, calls to_json, and asserts the JSON contains the hovertemplate value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hop through code with a bright little grin,
A string called hovertemplate tucked softly within.
I nibble the JSON, then dance on the line,
Per-trace whispers in output — how fine! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the main change: adding a hovertemplate field to ScatterTrace.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
plot/plot_test.v (1)

25-25: Make Line 25 assertion less brittle to JSON formatting differences.

Exact substring matching with key+value formatting can break on serializer formatting changes (e.g., spacing). Consider splitting into key/value presence checks.

♻️ Suggested tweak
-	assert traces.contains('"hovertemplate":"x=%{x}, y=%{y}<extra></extra>"')
+	assert traces.contains('"hovertemplate"')
+	assert traces.contains('x=%{x}, y=%{y}<extra></extra>')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plot/plot_test.v` at line 25, The assertion on traces is brittle because it
matches an exact JSON substring; instead update the test in plot_test.v to check
the hovertemplate key and its value separately (e.g., assert
traces.contains('"hovertemplate"') && traces.contains('x=%{x},
y=%{y}<extra></extra>')) or better: parse the JSON in traces and assert the
hovertemplate field equals "x=%{x}, y=%{y}<extra></extra>" so spacing/formatting
changes in serialization won't break the test; locate the assertion that uses
traces.contains in the test and replace it with the split-presence checks or
JSON-parse+field check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@plot/plot_test.v`:
- Line 25: The assertion on traces is brittle because it matches an exact JSON
substring; instead update the test in plot_test.v to check the hovertemplate key
and its value separately (e.g., assert traces.contains('"hovertemplate"') &&
traces.contains('x=%{x}, y=%{y}<extra></extra>')) or better: parse the JSON in
traces and assert the hovertemplate field equals "x=%{x}, y=%{y}<extra></extra>"
so spacing/formatting changes in serialization won't break the test; locate the
assertion that uses traces.contains in the test and replace it with the
split-presence checks or JSON-parse+field check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 077b0ec3-c011-4c58-8938-6e153a555df5

📥 Commits

Reviewing files that changed from the base of the PR and between e4299c0 and ea2bd8a.

📒 Files selected for processing (1)
  • plot/plot_test.v

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant