Skip to content

Conversation

@mp-v2
Copy link
Contributor

@mp-v2 mp-v2 commented Dec 23, 2023

This MR adds the ability to change graph forces in the graph view, under a new dropdown menu item called "Forces"

image

This resolves requests for a customisable/better graph algorithm:

This should also resolve some a number of user issues related to the graph layout being messy/not being very useful:

Users resorted to manually dragging nodes to where they want them to be, and then requesting that the graph does not reset/re-render each time you click back to it. The ability to change graph forces means users can now customise the default force values, thus the default layout of their graph, using the config.edn default parameters. This indirectly resolves the requests to have a layout-persistant graph option:

To not overload the number of options, although more are possible using the same structure, I implemented the key ones:

  • link distance (The link force pushes linked nodes together or apart according to the desired link distance)
  • charge strength (The many-body (or n-body) force applies mutually amongst all nodes. A positive value causes nodes to attract each other, similar to gravity, while a negative value causes nodes to repel each other, similar to electrostatic charge)
  • charge range (The maximum distance between nodes over which this force is considered)

image

The graph is reactive to the sliders, and the graph forces can be reset back to defaults using the "Reset forces" button, similar to "Reset graph" for the n-hops slider.

Force values, in general, default to the same value they were previously, so that the default experience is the same as it was before. Exceptions;

I set the sliders to have a stepsize proportional to the value size (e.g. 5, 10 or 100), to prevent too much rendering of large graphs. It would be more efficient to have the graph render on slider release (instead of on value change), however I would need someone more familiar with Clojure to assist with this.

Cheers,
mp-v2

Here is my personal graph using the master branch:
image

Here is the same graph with default forces in this branch (with lower velocity decay, allowing better convergence on a clean solution):
image

Now with adjusted forces based on personal preference. These changes are persistant, even when changing to note pages and returning to the graph view:
image

Examples from a large graph are much more exciting, but some examples below show options now available

Small link distance:
image

Large link distance:
image

Default negative charge (repulsion) changed to positive (gravity) causes orphan pages to come to the centre:
image

A positive charge strength, and long link distance, will group chuild nodes together from one node:
image

@mp-v2
Copy link
Contributor Author

mp-v2 commented Dec 27, 2023

Added commit 10305d6 to fix the failing lint test

@mp-v2
Copy link
Contributor Author

mp-v2 commented Jan 4, 2024

@tiensonqin

You ran the CICD workflow and it failed on a lint test, so I added an extra commit to the PR already to resolve that issue
Is there anything more needed from me to enable a code review?

@mp-v2
Copy link
Contributor Author

mp-v2 commented Jan 25, 2024

@xyhp915 is anything needed from me to allow one of the logseq team to review this PR? I spent a lot of time on it, and on providing a clear PR. I haven't heard anything for a month. It's not particularly encouraging towards contributing to the project.. Could you or @tiensonqin communicate what I can expect?

@xyhp915 xyhp915 added the graph Graph view label Jan 25, 2024
@tiensonqin
Copy link
Contributor

@mp-v2 Sorry for the late response, the team has been busy with some other changes such as #10933 and #10897,
reviewing this PR now.

Copy link
Contributor

@tiensonqin tiensonqin left a comment

Choose a reason for hiding this comment

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

@mp-v2 Thanks for looking into all the discussions related to graph view and your amazing work on those exciting enhancements! 👍

I QAed it on my local graph and it works as you described, I'll merge this PR and open another PR to adjust ui/slider to trigger on-change when the mouse is released.

(.distanceMax (if (> nodes-count 500) 4000 600))
;; The minimum distance between nodes over which this force is considered.
;; A minimum distance establishes an upper bound on the strength of the force between two nearby nodes, avoiding instability.
(.distanceMin 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

(.force "y" (-> (forceY 0) (.strength 0.02)))
(.force "center" (forceCenter))
(.velocityDecay 0.8))
;; The decay factor is akin to atmospheric friction; after the application of any forces during a tick,
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense.

@tiensonqin tiensonqin merged commit 7938022 into logseq:master Feb 5, 2024
@mp-v2
Copy link
Contributor Author

mp-v2 commented Feb 5, 2024

@tiensonqin thanks for the reply and for the review - happy to see it worked well enough to merge already!

@tiensonqin
Copy link
Contributor

@mp-v2 I just opened #10972 which tweaks the on-change behaviour for ui/slider and introduces a toggle for force simulation.

@mp-v2
Copy link
Contributor Author

mp-v2 commented Feb 6, 2024

Great to see this in the 0.10.6 release! And good effort with that slider mouse release efficiency improvement

@turtaf turtaf mentioned this pull request Feb 8, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

graph Graph view

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants