Skip to content

fix: consider default style when computing effective style properties - #152

Merged
tbouffard merged 6 commits into
developmentfrom
fix/use_default_style_when_accumulate_all_styles
Dec 17, 2022
Merged

fix: consider default style when computing effective style properties#152
tbouffard merged 6 commits into
developmentfrom
fix/use_default_style_when_accumulate_all_styles

Conversation

@tbouffard

@tbouffard tbouffard commented Dec 13, 2022

Copy link
Copy Markdown
Member

Summary

StyleSheet.getCellStyle didn't keep the properties of the default style when baseStyleNames was set in the cellStyle parameter.

The JSDoc was incorrect (it came from mxGraph) about how the style is computed, in particular about the default style. It probably leads to the erroneous implementation during migration. It is now fixed and clearly describe the rules followed to merge style properties.

The 'Stylesheet' story has been updated to correctly use the maxGraph API (with the help of #88). It also includes more examples involving baseStyleNames to show the 'properties merge' in action.
The following screenshots of the story show what happened prior the fix

  • the vertex with the 'Interval 1' label was missing the properties from the default (vertex) style: fillColor (including gradient), font properties, perimeter (so the edges start from the center of the vertex), rounded
  • and the edge with the 'Transfer 2' label as well: edgeStyle (we see a bend point instead of using of a vertical segment passing by this point - Elbow connector), endArrow (so no arrow was displayed)
prior the fix now (with fix)
storybook_01_before_fix storybook_02_after_fix

As a reminder, here is how the example looks with mxGraph:

mxGraph_example

Description for the changelog

StyleSheet.getCellStyle merges all the properties of the default style when baseStyleNames is set in the cellStyle parameter.

Possible root cause of the issue

The API documentation of mxGraph and typed-mxgraph used during the maxGraph migration was wrong and didn't reflect what the code does.
The change of the style from a string representation (#82) to an object probably introduced the regression, especially because the API doc was incomplete and wrong.
I reviewed the PR myself and didn't notice the problem. There were no example to demonstrate the feature and to test it.
We now have automatic unit tests and examples, so this situation shouldn't appear again.

Other info

Introduce jest to test the fix and the whole implementation of the changed method. Types check support is provided by ts-jest. As maxGraph uses a lot of browser objects, also setup jest-jsdom-environment.

This is a starting point. I created a discussion about a test strategy and choosing the test framework: #153.
In the short term, I would like to see this PR merged as is to move forward (see discussion for details).

The StyleSheet.getCellStyle didn't keep the properties of the default style when `baseStyleNames` was set in the
`cellStyle` parameter.

The JSDoc was incorrect (it came from mxGraph) about how the style is computed, in particular about the default style.
It probably leads to the erroneous implementation during migration. It is now fixed and clearly describe the rules
followed to merge style properties.

The 'Stylesheet' has been updated to correctly use the maxGraph API. It also includes more examples involving
`baseStyleNames` to show the 'properties merge' in action.

Introduce `jest` to test the fix and the whole implementation of the changed method.
Types check support is provided by `ts-jest`. As maxGraph uses a lot of browser objects, also setup
`jest-jsdom-environment`.
@tbouffard
tbouffard marked this pull request as ready for review December 13, 2022 15:19

@junsikshim junsikshim left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great step forward.
Testing a few examples from the storybook was definitely not enough to ensure the robustness of the change.

@tbouffard
tbouffard merged commit 5a34607 into development Dec 17, 2022
@tbouffard
tbouffard deleted the fix/use_default_style_when_accumulate_all_styles branch December 17, 2022 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants