fix(label): improve editing position and 'label changed" event#567
Conversation
| position: [100, 60], | ||
| size: [120, 80], | ||
| style: { overflow: 'fill' }, | ||
| style: { overflow: 'fill', editable: true }, |
There was a problem hiding this comment.
note: Once #570 has been merged, this should no longer be necessary.
There was a problem hiding this comment.
#570 has been merged, so merging main into the branch of this PR should allow to remove the "editable" configuration
There was a problem hiding this comment.
Updated this branch to be up to date with main, works properly without having to add editable:true when inserting vertex. I've removed the property from story example
tbouffard
left a comment
There was a problem hiding this comment.
Thanks @HalilFocic for this PR
I've only had time to do a static review and it looks promising. ✨
I'll do more testing later.
| } | ||
|
|
||
| this.textarea.style.position = 'relative'; | ||
| this.textarea.style.position = 'absolute'; |
There was a problem hiding this comment.
question: Have you checked this change outside the StoryBook stories to see if there's any change in behavior? In the js-example or ts-example applications provided in this repository, for example?
In mxGraph, the position was calculated dynamically: https://github.com/jgraph/mxgraph/blob/v4.2.2/javascript/src/js/view/mxCellEditor.js#L281
It seems to have been removed during migration and I don't know why. Probably because of the name of the function and its comments, even though it seems to have had an impact on modern browsers (and not only in IE 8).
Here, we could at least introduce a way to set the value with a new property and let people decide what they want to use as a position.
I haven't thought this through any further, so feel free to suggest alternatives or contradict the proposal. 😸
There was a problem hiding this comment.
I checked right now, and on main I have this issue where if i just add cellsEditable and try to dobuleclick, the tooltip goes to bottom like this:
This image maybe doesn't show much detail, but I double click on the topleft blue rectangle and it scrolled the graph down and focused on textarea which is misplaced.
Switching to my branch and clicking on it seemed to work as intented.
I am pretty sure reason for this behaviour is that textarea is being added like this:
this.graph.container.appendChild(textarea);
If we put relative it will go to the bottom of the graph, then move but its still taking same space.
There was a problem hiding this comment.
Yes you are right, I also tested with ts-example and other standalone applications.
I reproduce the problem for both the vertices and the edges.
In the mxGraph code, a check was done on the SVG node in the container. Generally, no style is applied to it so isLegacyEditor returned true and the absolute position was then used for the "text edition div". See https://github.com/jgraph/mxgraph/blob/v4.2.2/javascript/src/js/view/mxCellEditor.js#L750
The relative position was applied to the "text edition div" when the SVG node had a position explicitly set to absolute.
I tested the main branch (064c349) by applying an absolute position to the SVG. Using the relative position correctly position the "text edition div" in this case. But using the absolute position works as well, so I guess we can always set the absolute position.
| }); | ||
| } | ||
|
|
||
| this.trigger = null; |
There was a problem hiding this comment.
question: do you know why this statement must be moved?
In mxGraph, it was at the former place and it worked: https://github.com/jgraph/mxgraph/blob/v4.2.2/javascript/src/js/view/mxCellEditor.js#L968
There was a problem hiding this comment.
Okay, so this trigger is inside stopEditing function. We change the label inside the if statement if innerHTML is not equal to initial which is okay and we call the applyValue function which takes state and the value, which also seemed fine.
Problem arised because the applyValue function used this.trigger when calling labelChanged function and labelChanged always received null. This is because no matter what, we set the trigger to null even before checking if values has changed. I can look up logic inside the mxGraph for this aswell, but I since the editing of value doesn't work in the example, I would assume they had the bug too.
There was a problem hiding this comment.
OK thanks for the information I got what you mean 😄
I didn't understand why this change was needed at a first glance, because most stories and examples work without this change.
The Editing story relies on the triggered event in the overridden Graph.labelChanged method. It needs the event to be correctly set to correctly assign the label (using the custom Cell.value which is an object and not a string, which stores the 2 label values). See https://github.com/maxGraph/maxGraph/blob/v0.13.1/packages/html/stories/Editing.stories.js#L116
Here is video showing the problem (i.e. the labels are not updated) without the change 👇🏿
PR_567_Editing_story_required_change_in_trigger_management.webm
The regular Graph.labelChanged method doesn't directly used the event (except to send another event which is not used in stories). That is why, most of the time, the existing code was working. 😸
ℹ️ Notice that such a fix has been proposed in the past in 4a63940#diff-470b5171fde7755241a36fb45a75aec1a323913b5088e08646d182cfda9dc86c
ℹ️ For the record, the mxGraph "Editing" example doesn't work: https://jgraph.github.io/mxgraph/javascript/examples/editing.html. It doesn't set the label correctly after edition, for all reasons explained in this thread.
Properly editable is not being set by default for cells, hence the editing was never allowed to start. Major issue that was also present inside the mxGraph old example was that the value doesn't actually get updated. This commit fixes that as well. Furthermore, the container for the textarea editing had position relative instead of absolute which caused snappy behaviour while editing.
c96a2fa to
f629053
Compare
tbouffard
left a comment
There was a problem hiding this comment.
LGTM, good job @HalilFocic and thanks for the additional explanations which helped during the review 👍🏿 .
✔️ The position of the label editing area is now is for both vertices and edges
✔️ The edition of the 2 custom labels in the Editing story is now working (see #567 (comment) for more explanations)
Tested with various stories, ts-example, js-example and personal applications with both Firefox and Chrome on Ubuntu 22.04.


Updated the Editing story and CellMixing to make Editing storywork. Vertex is now editable and value is saved after stopEditing has been called.
PR Checklist
maxGraph, and you are assigned to the issue.packages/core/_tests_or a new or altered Storybook story inpackages/html/stories(an existing story may also demonstrate the change).or no docs changes are needed.Overview
Editing story functionality after this change:
Screen.Recording.2024-11-09.at.17.23.27.mov
Notes
fixes #544