CODAP-166: graph responds dynamically to attribute type changes#2415
CODAP-166: graph responds dynamically to attribute type changes#2415
Conversation
codap-v3
|
||||||||||||||||||||||||||||
| Project |
codap-v3
|
| Branch Review |
main
|
| Run status |
|
| Run duration | 05m 14s |
| Commit |
|
| Committer | William Finzer |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
73
|
|
|
0
|
|
|
300
|
| View all changes introduced in this branch ↗︎ | |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2415 +/- ##
==========================================
- Coverage 85.50% 85.49% -0.01%
==========================================
Files 755 755
Lines 41908 41914 +6
Branches 9974 10368 +394
==========================================
+ Hits 35832 35834 +2
- Misses 6064 6068 +4
Partials 12 12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
When a user changes an attribute's type (e.g., numeric to categorical) via the case table or card view, the graph now reconfigures its axes and plot type accordingly. Also fixes stale D3 selection refs and inherited SVG attributes when transitioning between axis types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cc509b8 to
868e824
Compare
kswenson
left a comment
There was a problem hiding this comment.
👍 Looks good -- the following review was developed in conjunction with Claude Code 🤖.
PR Review Summary
Changes: 3 files, +21 / -6 lines
What it does
When a user changes an attribute's type (e.g., numeric to categorical) via the case table or card view, the graph now dynamically reconfigures its axes and plot type. Previously, the graph would not respond to attribute type changes — only to attribute assignment changes. This also fixes three crash/display bugs that surfaced when transitioning between axis types: stale D3 selection refs, inherited SVG attributes making categorical labels invisible, and dead MST model access during undo.
The approach
Three targeted fixes across three files:
-
use-plot.ts(line 207-208): The existingmstReactionthat watches attribute assignments now also watchesattributeType()for each role. When the type changes,syncModelWithAttributeConfigurationreconfigures the axes and plot type. This is the core fix — it makes the graph reactive to type changes, not just assignment changes. -
axis-helper.ts(lines 28, 35, 39-43, 47): CachesaxisModel.placein a private_axisPlacefield at construction time. TheaxisPlacegetter now reads from the cache instead of the live MST model. This prevents crashes during undo when the axis model may already be removed from the MST tree. Additionally, the constructor now clears inherited SVG attributes (fill,font-size,font-family,text-anchor) from the axis<g>element. D3's numeric axis setsfill="none"on the group, and when switching to a categorical axis, the text labels inherit thatfilland become invisible. -
use-sub-axis.ts(lines 287-288): ClearscategoriesSelectionRefandsubAxisSelectionRefbefore constructing a newCategoricalAxisHelper. TheAxisHelperconstructor removes all SVG children, which detaches DOM elements. Without clearing these refs, other MobX reactions that fire synchronously could crash on detached DOM nodes.
Assessment
This is a well-targeted fix. Each of the three changes addresses a distinct, clearly described problem. The approach is sound:
- Extending the existing
mstReactionto includeattributeTypeis the minimal, correct way to make the graph responsive to type changes. The reaction already callssyncModelWithAttributeConfiguration, which handles the full axis/plot reconfiguration. - Caching
axisPlaceis safe because axis place never changes after construction — it's determined by position in the document layout. - Clearing SVG attributes and stale refs are defensive fixes for real crash paths.
Issues
Fixed during review:
use-plot.ts: The attribute assignment/type reaction was missingequals: comparer.structural. The accessor returns a new array of[id, type]tuples on every call, so without structural comparison the reaction fires on every MobX transaction regardless of whether values actually changed. (This was a pre-existing issue — the original code also lacked it — but the PR made it slightly worse by nesting arrays.) Addedequals: comparer.structuralto the reaction options.
No other concerns.
…ction The mstReaction that watches attribute IDs and types returns a new array of tuples on every call. Without comparer.structural, the reaction fires on every MobX transaction regardless of whether values actually changed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR enables graphs to dynamically reconfigure when a user changes an attribute's type (e.g., from numeric to categorical) via the case table or card view. The changes fix crashes and rendering issues that occurred during these transitions.
Changes:
- Added tracking of attribute type changes in addition to attribute assignment changes, triggering graph reconfiguration when types change
- Fixed stale D3 selection references that caused crashes when transitioning between axis types by clearing refs before creating categorical axis helpers
- Fixed inherited SVG attributes and prevented dead MST model access during undo by caching axis place and clearing D3-set attributes
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| v3/src/components/graph/hooks/use-plot.ts | Added attribute type to the reaction that monitors attribute changes, enabling dynamic response when users change attribute types |
| v3/src/components/axis/hooks/use-sub-axis.ts | Clears stale D3 selection refs before creating CategoricalAxisHelper to prevent crashes from detached DOM nodes |
| v3/src/components/axis/helper-models/axis-helper.ts | Caches axis place to prevent dead MST model access during undo and clears inherited SVG attributes to fix rendering issues |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
fill="none") that made categorical labels invisible after switching from a numeric axisFixes CODAP-166
Test plan
🤖 Generated with Claude Code