Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save textnode movement nad #126

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

souissimai
Copy link
Contributor

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?

What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

If yes, please check if the following requirements are fulfilled

  • The Breaking Change or Deprecated label has been added
  • The migration steps are described in the following section

What changes might users need to make in their application due to this PR? (migration steps)

Other information:

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

textNodeMoves[1].xOrig,
textNodeMoves[1].yOrig
);
if (callMoveTextNodeCallback) {
Copy link
Contributor

Choose a reason for hiding this comment

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

move test over this.onMoveTextNodeCallback here

if (this.onMoveTextNodeCallback != null && callMoveTextNodeCallback) {

Copy link
Contributor

Choose a reason for hiding this comment

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

This should create another bug I think. If you don't define a onMoveTextNodeCallback function then moving textNode should not work at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why? still able to move node even if onMoveTextNodeCallback (tested)

textNodeMoves[1].yNew,
textNodeMoves[1].xOrig,
textNodeMoves[1].yOrig,
mousePosition
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need mousePosition here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mousePosition to save the newPosition of dragged text node

@souissimai souissimai requested a review from sBouzols December 16, 2024 13:08
@@ -208,6 +228,7 @@ export class NetworkAreaDiagramViewer {
}

const dimensions: DIMENSIONS | null = this.getDimensionsFromSvg();
console.log(' ======== dimensions ', dimensions);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this

Comment on lines +211 to +213
//Update css rules to diplay labels
const firstChild: HTMLElement = <HTMLElement>this.svgDraw?.node.firstChild;
this.injectDisplayCssRules(firstChild);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the purpose is to reapply css rules to display labels

let styleTag = htmlElementSvg.querySelector('style');
if (!styleTag) {
htmlElementSvg.appendChild(document.createElement('style'));
console.debug('[injectDynamicCssRules] Style tag missing from SVG file. It has been created.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Bad copy paste

styleTags.forEach((styleTag) => {
styleTag.textContent =
styleTag?.textContent !== null
? styleTag?.textContent.replace(`{display: none;}`, `{display: block;}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

This line bothers me : there is an unnecessary "?", and if the css rule is slightly different, it will not work.

Copy link
Contributor

Choose a reason for hiding this comment

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

if using a ternary operator impacts readability then switch to if..else code format I think

Copy link

sonarqubecloud bot commented Jan 2, 2025


// update the styles to display labels if needed
cssSelectors.forEach((selector) => {
const styleTags = [...document.querySelectorAll('style')].filter((styleTag) =>
Copy link
Contributor

@sBouzols sBouzols Jan 2, 2025

Choose a reason for hiding this comment

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

You could optimize this code a lot
You should call document.querySelectorAll('style') only once
Then filter styles nullish values .filter(Boolean) and not matching cssSelectors.
and finally loop over to set textContent.

This way you could avoid optional chaining operator elsewhere styleTag?.

By the way you have a problem because you have 2 local variables with the same name styleTag in injectDisplayCssRules and it's confusing...

Do you want to update the style on the given HTMLElement ? or on all Elements of the document ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants