MCP-002 — Default chart tooltips
Goal
Line (and similar) charts emitted by get_viz_spec show hover tooltips by default for readability in embedded previews (e.g. chat ChartPreview).
Context
- Implementation likely in
src/data360/visualization.py and/or src/data360/viz_config.py where Vega-Lite spec is built.
- Frontend:
vercel-ai-chatbot renders spec via vega-embed in frontend/components/data360/chart-preview.tsx — no change required if spec includes tooltips.
Implementation hints
- Entry point (Draco path):
src/data360/visualization.py line 555–556 — tooltip_cols = list(viz_data.columns); chart = chart.encode(tooltip=tooltip_cols). This runs after Draco rendering.
- Entry point (fallback path):
src/data360/visualization.py line 603 — base = alt.Chart(viz_data).mark_line().encode(tooltip=fc). Fallback uses fc (field config) for tooltip.
- Current behavior: Tooltip is a flat list of all columns. Column names at this point are already renamed:
time_period → year, obs_value → value, ref_area → country (renaming happens at lines 414–434). Tooltip shows raw renamed columns with no formatting.
- Desired behavior: Structured tooltips per chart type — for line/area: show
year, value, country with human-readable labels and number formatting. Use alt.Tooltip(field, title, format) objects instead of raw column names.
- Chart types to cover: line (line 149), area (line 167) as minimum. bar (line 155), point (line 161), tick (line 173) as stretch.
- Test file:
tests/test_visualization.py — existing class TestGetVizSpecDracoFallbackWarning (lines 11–147). Add a new test class TestTooltipEncoding that asserts tooltip fields and titles on the returned spec dict.
- Gotchas: Tooltip encoding happens AFTER Draco (line 555) — this is intentional to allow override. Fallback path (line 603) hardcodes
mark_line() regardless of chart type — tooltip fix should handle both paths. Codelist mapping runs before viz (lines 421–431) so country column contains names not codes at tooltip time.
Acceptance criteria
Dependencies
Related
- MCP-003 often touches the same spec-building code; coordinate or sequence to reduce merge conflicts (soft dependency only).
Task file: TODO/MCP-002-vega-line-tooltips.md
MCP-002 — Default chart tooltips
Goal
Line (and similar) charts emitted by
get_viz_specshow hover tooltips by default for readability in embedded previews (e.g. chatChartPreview).Context
src/data360/visualization.pyand/orsrc/data360/viz_config.pywhere Vega-Lite spec is built.vercel-ai-chatbotrenders spec via vega-embed infrontend/components/data360/chart-preview.tsx— no change required if spec includes tooltips.Implementation hints
src/data360/visualization.pyline 555–556 —tooltip_cols = list(viz_data.columns); chart = chart.encode(tooltip=tooltip_cols). This runs after Draco rendering.src/data360/visualization.pyline 603 —base = alt.Chart(viz_data).mark_line().encode(tooltip=fc). Fallback usesfc(field config) for tooltip.time_period → year,obs_value → value,ref_area → country(renaming happens at lines 414–434). Tooltip shows raw renamed columns with no formatting.year,value,countrywith human-readable labels and number formatting. Usealt.Tooltip(field, title, format)objects instead of raw column names.tests/test_visualization.py— existing classTestGetVizSpecDracoFallbackWarning(lines 11–147). Add a new test classTestTooltipEncodingthat asserts tooltip fields and titles on the returned spec dict.mark_line()regardless of chart type — tooltip fix should handle both paths. Codelist mapping runs before viz (lines 421–431) socountrycolumn contains names not codes at tooltip time.Acceptance criteria
tooltipencoding or mark-level tooltip defaults.tests/test_visualization.pyupdated or added to assert tooltip presence in spec JSON.Dependencies
Related
Task file:
TODO/MCP-002-vega-line-tooltips.md