Scott/combo chart fix - #428
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a stable Y-axis width calculation for charts by extracting measurement utilities into a shared measure_axis_width.ts file, and updates horizontal/vertical bar and line charts to use it. It also enhances the query provider, store, and comparison chart derivation to correctly support same-place, different-variable comparisons by merging and narrowing results appropriately. The review feedback points out that the helper functions niceNum and numericAxisLabels were duplicated in both data_chart_bar_vertical.tsx and data_chart_line.tsx instead of being imported from the new utility file.
7097b97 to
aa8960f
Compare
aa8960f to
6b08ae9
Compare
Code Review SuggestionsNice refactoring on this PR! Moving combine/style intents to the LLM query analyzer ( Will early approve to unblock, but below are a few edge cases and actionable suggestions to consider: 1.
|
Overview
Fixes combo (comparison) chart generation when multiple variables are selected for the same place, adds LLM-driven chart style changes and compare/combine intent detection, and stabilizes the Y-axis width across all chart types.
Previously, selecting cards like "Female Life Expectancy in Japan" and "Male Life Expectancy in Japan" would overwrite each other since they shared the same entity key, resulting in only one series appearing in the combined chart. Additionally, changing chart styles and triggering combine/compare flows relied on fragile client-side regex matching — both are now delegated to the LLM via the query parsing step.
Changes Made
LLM-driven chart style changes
chartStyleIntentin query parsing — the LLM can now detect when a user wants to change chart appearance (e.g. "make these horizontal", "switch to a line chart") and returns achartStyleIntentwith atargetStylevalue (bar-vertical|bar-horizontal|line). Unsupported chart types (pie, scatter, etc.) produce a follow-up with supported options instead (parse_query.md,parse_query.ts)chartStyleChangestream event — new stream event type lets the server signal a style change; the client applies it to all selected chart shapes and persists it in the store (types.ts,route.ts, query_provider.tsx)chartStyleon cards —ChartStyletype promoted from the local menu component toserver/types.ts; stored onCardEntry, the tldraw shape props, andAtlasContentso it survives across export/import and re-renders (types.ts, store.ts,helpers.ts,shapes/card.tsx,chart.tsx,menu_chart_options.tsx)cardSetChartStylestore action — new zustand action to update a card's persisted chart style (store.ts)LLM-driven combine/compare intent
combineIntentin query parsing — the LLM detects compare/combine requests (e.g. "combine these", "compare these charts") when multiple chart cards are selected, replacing the client-sideisCombineIntentregex. ReturnscombineIntent: truein the parsed query (parse_query.md,parse_query.ts)route.tshandlescombineIntentas an early exit: runs the comparison step directly with the selected results sent from the client, removing the separate/api/combineendpoint dependency for this pathhasChartSelection,chartSelectionCount, andselectedResultsare now included in the query request so the LLM and server have full context about what's selected (types.ts, query_provider.tsx,route.ts)Same-place multi-variable fix
variablesandtimeSeriesarrays instead of overwriting. Deduplicates bydcid/variableDcid+entityDcidso repeated entries are skipped (query_provider.tsx)deriveComparisonChartContentdetects same-place vs. different-place scenarios: when all results share one entity it overlays every variable as a separate series; otherwise it builds one series per place as before (sync_store.ts)deriveChartContentForVariablederives chart content targeting a specific variable DCID (and optionally entity DCID), used byderiveContentForCardwhen a card hasvariableDcidset (sync_store.ts)getResultsForSelectedCardsuses a compositeentityDcid::variableDcidkey so cards with the same place but different variables produce distinct results; narrows each result to only the targeted variable'stimeSeriesandvariableswhencard.variableDcidis set (store.ts)Stable Y-axis width
measureAxisWidthutility — new shared utility uses a cached off-screen<canvas>to measure the widest label in pixels; companionnumericAxisLabelsgenerates representative formatted tick strings. Applied to bar-vertical, bar-horizontal, and line charts, replacing Recharts'width="auto"with a pre-measured value that prevents layout jitter on resize (measure_axis_width.ts)Minor