Fix: component value label on canvas doesn't update after editing#27
Open
ImranFarhat01 wants to merge 1 commit into
Open
Fix: component value label on canvas doesn't update after editing#27ImranFarhat01 wants to merge 1 commit into
ImranFarhat01 wants to merge 1 commit into
Conversation
Component value label on the canvas did not update after using SET PARAMETERS in the Component Properties panel. The Redux state was updated, but nothing told mxGraph to refresh the displayed cell label. A previous attempt at fixing this called model.setValue() with just the raw VALUE field, which did make the canvas update immediately, but replaced the entire label (e.g. 'R1\n1k' became just '10k'), losing the component name. The canvas label is actually built from per-component-type rules (plain VALUE for R/L/C, 'DC value' phrasing only affects the netlist string not the label, no value line at all for transistors/MOSFETs, EXTRA_EXPRESSION appended with a space, etc), and that logic already existed inside buildNetlistFromGraph() in NetlistExporter.js, just duplicated across every branch. Fix: - Extracted the label-building rules into a single shared function, buildComponentCanvasLabel(baseName, properties) - buildNetlistFromGraph() now calls this function once instead of repeating 'component.value = component.value + ...' in 7 places - ComponentProperties.js's setProps() now looks up the edited cell directly via the graph model (not via canvas selection, which can be stale or include unrelated cells), splits its current label to preserve the base name, calls the shared function to rebuild the value portion, and applies it via model.setValue() - Added a small getGraph() export from ComponentDrag.js so ComponentProperties.js can access the live graph instance Testing: - Resistor: edited VALUE, canvas immediately shows 'R1' / new value on two lines, name preserved - Capacitor: same, name preserved - Voltage source (PWL waveform): edited VALUE, canvas immediately shows 'V1' / new waveform expression, name preserved - Generated a netlist after these edits: output is correct and unaffected by the refactor (same SPICE syntax as before)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Component value label on the canvas did not update after using SET
PARAMETERS in the Component Properties panel.
Root Cause
The Redux state was updated correctly, but nothing told mxGraph to
refresh the displayed cell label. The canvas label is built from
per-component-type rules (plain value for resistors/inductors/
capacitors, no value line for transistors/MOSFETs, an extra
expression appended with a space, etc), and that logic only existed
inside the netlist generation function, never wired up to the
Properties panel.
Fix
buildComponentCanvasLabel(baseName, properties)repeating the same label-building line across 7 different branches
graph model, preserves the component's base name, rebuilds the
value portion using the shared function, and applies it
immediately to the canvas
Testing
and new value together, name preserved
canvas immediately shows the name and new expression together
simulation output is unaffected by the refactor