Skip to content

Graph grouping/collapsing code tidy #2129

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

Open
wants to merge 4 commits into
base: graph-group-collapse
Choose a base branch
from

Conversation

MetRonnie
Copy link
Member

@MetRonnie MetRonnie commented Apr 7, 2025

Follow-up to #1810
Partly addresses #1130

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Tests are updated
  • Changelog entry not needed
  • No docs needed
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

@MetRonnie MetRonnie added this to the 2.x milestone Apr 7, 2025
@MetRonnie MetRonnie requested a review from oliver-sanders April 7, 2025 11:36
@MetRonnie MetRonnie self-assigned this Apr 7, 2025
@MetRonnie MetRonnie linked an issue Apr 7, 2025 that may be closed by this pull request
Comment on lines +1329 to +1331
const indexSearch = Object.values(this.cylcTree.$index).find(
(node) => node.name === family && node.tokens.cycle === cycle
)
Copy link
Member

Choose a reason for hiding this comment

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

(unrelated) Walking over the full index is really slow, it can contain nodes from other workflows.

const indexSearch = Object.values(this.cylcTree.$index).find(
(node) => node.name === family && node.tokens.cycle === cycle
)
if (!indexSearch) continue
Copy link
Member

Choose a reason for hiding this comment

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

Does linting really allow omitting the braces?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes for control statements on the same line as the condition

Comment on lines +917 to +918
for (const { $edges } of this.workflows) {
for (const { tokens } of $edges || []) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a bit to clever, the previous syntax is much more obvious.

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh, destructuring is a core feature of JS that IMO everyone should get used to

}
}
return ret
return new Map(ret)
Copy link
Member

Choose a reason for hiding this comment

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

Why build an array then convert to a map?

Copy link
Member Author

@MetRonnie MetRonnie Apr 11, 2025

Choose a reason for hiding this comment

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

Good question... made this a Map from the start

nodes.map(n => n.id).reduce((x, y) => { return x + y }) +
(edges || []).map(n => n.id).reduce((x, y) => { return x + y }, 1)
nodes.map(n => n.id).reduce((x, y) => x + y) +
Array.from(edges.keys()).reduce((x, y) => x + y, 1)
Copy link
Member

Choose a reason for hiding this comment

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

Turning the map into an array might be a bit expensive.

Copy link
Member Author

@MetRonnie MetRonnie Apr 11, 2025

Choose a reason for hiding this comment

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

Seeing as originally it was doing an Array.prototype.map() followed by an Array.prototype.reduce(), it shouldn't be any more expensive as there were 2 loops before. However, newer browsers support edges.keys().reduce() directly, so we could do something like

const edgesReducer = (x, y) => x + y
// If browser supports Iterator.prototype.reduce(), use it:
edges.keys().reduce?.(edgesReducer) ?? Array.from(edges.keys()).reduce(edgesReducer)

to take advantage of it on the browsers that support it?

Adds ugliness to code however

@oliver-sanders
Copy link
Member

LGTM, but doesn't work right.

I tested with the complex workflow, the graph didn't produce any errors, but it also didn't layout and left all of the tasks in a long line.

When I tried to group by cycle I got this error in the console:

TypeError: this.allParentLookUp[l] is undefined

@MetRonnie MetRonnie marked this pull request as draft April 9, 2025 09:56
@MetRonnie
Copy link
Member Author

As discussed in person, I can't reproduce the problem with the same workflow

@MetRonnie MetRonnie marked this pull request as ready for review April 11, 2025 14:10
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.

graph: family collapsing
2 participants