Skip to content

[fix] Prevent Overlapping of Clusters in netjsongraph.js #171 #349

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 82 commits into
base: master
Choose a base branch
from

Conversation

cestercian
Copy link
Contributor

@cestercian cestercian commented Mar 12, 2025

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #171

Description of Changes

This PR addresses issue #171 by preventing the overlapping of clusters in the netjsongraph.js visualization.

Changes Implemented:

  • Introduced spatial indexing using KDBush to optimize clustering performance.
  • Implemented grouping of nodes based on proximity and clustering attributes.
  • Modified cluster assignment logic to prevent overlapping.
  • Updated centroid calculations for accurate cluster placement.
  • Ensured better handling of non-clustered nodes.

Testing

A test file (cluster_overlap_test.html) was created to visualize and verify the clustering behavior. The test file simulates overlapping nodes with different statuses and ensures they are properly clustered without overlaps.

Screenshot

image

- Remove redundant font-family declarations on the body and standardize to "sans-serif"
- Update .iconfont declarations to include a serif fallback for better compatibility
- Replace "0px" with "0" for margin properties for consistency
- Improve overall formatting and structure for maintainability
This file is for testing purposes only and helps in identifying and reproducing the problem so that potential solutions can be explored.
@niteshsinha17 niteshsinha17 self-requested a review March 17, 2025 15:06
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

This has slipped my attention, the notification for this was buried among many other notifications. That's why it's good to let us know about your work in the dev chat.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

In the PR description you mention a test file called cluster_overlap_test.html, which I see you have removed. What type of problem where you having with this? I think such a test file to compare the behavior of this branch with master and verify whether the situation really improves is quite useful.

@cestercian
Copy link
Contributor Author

Thanks for the review @nemesifier! The cluster_overlap_test.html file was initially created to visualize the issue, but I removed it since I thought it wasn't necessary after fixing the overlap problem. However, I see your point—it could be useful for verifying improvements. I can reintroduce it and ensure it effectively compares the branch behavior with master. Let me know if you'd like any specific tests included!

@cestercian
Copy link
Contributor Author

Hi @nemesifier ,

I've made the requested changes:

✅ Moved netjson-cluster-overlap.html to /public/example_templates for consistency.
✅ Updated index.html to include a link to the new example, styled like the others.

Let me know if you need any further modifications or if you'd like me to proceed with replacing the current clustering example with this one. Thanks for your feedback!

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

This is what I see when I try to open the example, do you see a different situation?

Cannot GET /example_templates/netjson-cluster-overlap.html.

Screenshot from 2025-03-19 19-01-01

@cestercian
Copy link
Contributor Author

hey @nemesifier

I’ve fixed the issue. The error occurred because the requested file was not being served correctly. I’ve updated netjson-cluster-overlap.html and changed the file location in index.html my latest commit, which should resolve it.

Let me know if you still encounter any issues!

@cestercian cestercian requested a review from nemesifier March 20, 2025 08:03
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

I don't know if I am doing something wrong but this isn't working for me, here's what I see:

netjsongraphjs-clustering-pr.webm

@niteshsinha17 do you see a different situation or do you get the same result I get?

@cestercian
Copy link
Contributor Author

image

It looks like the NetJSONGraph library isn't being recognized. This often happens when the project isn't started properly.

@nemesifier, are you running yarn start, or are you just opening the index.html file directly? If you're just opening the file, the dependencies might not be loading correctly. Try starting the project with yarn start and let me know if the issue persists.

@niteshsinha17
Copy link
Member

I don't know if I am doing something wrong but this isn't working for me, here's what I see:

netjsongraphjs-clustering-pr.webm
@niteshsinha17 do you see a different situation or do you get the same result I get?

@nemesifier I am getting this result. Seems something is wrong. I will look into PR in detail.

Screenshot 2025-03-22 at 8 58 06 PM

Copy link
Member

@niteshsinha17 niteshsinha17 left a comment

Choose a reason for hiding this comment

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

I have done a very basic review for now. The graph is not rendering properly.

Check this comment, here @nemesifier
has mentioned about an example that needs to be added. #239 (review)

@cestercian
Copy link
Contributor Author

Screen.Recording.2025-04-23.at.4.54.24.PM.mov

Applied Node Coloring based on node status

@nemesifier nemesifier changed the title [Fix] Prevent Overlapping of Clusters in netjsongraph.js (#171) [Fix] Prevent Overlapping of Clusters in netjsongraph.js #171 Apr 23, 2025
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Looks good @cestercian! The test coverage has went down considerably, can you please fix that? Look at the CI build configuration to see how to calculate test coverage locally so you can see which lines are not being executed during tests.

See also my comments below. Tomorrow I will do more code review, now I only had time to do a quick test.

@cestercian cestercian requested a review from nemesifier April 26, 2025 14:18
@cestercian cestercian requested a review from niteshsinha17 May 5, 2025 09:36
@cestercian
Copy link
Contributor Author

Hey @niteshsinha17 ,
I moved overlap prevention logic from lib/js/clusterUtils.js to src/js/cluster-utils.js, updated imports, and removed the old file.
and optimized getNodeStyle() usage in netjsongraph.render.js by properly using all returned style configs.

let me know if any other changes are needed 😁

@niteshsinha17
Copy link
Member

@cestercian It's really good you are putting efforts. But I am interested in knowing your observations and reasoning behind your changes.

@nemesifier nemesifier changed the title [Fix] Prevent Overlapping of Clusters in netjsongraph.js #171 [fix] Prevent Overlapping of Clusters in netjsongraph.js #171 May 6, 2025
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

I would group all the clustering docs into a single section coming just before "Example Usage". The rest looks good to me but I'm trying to spare some time to do a complete round of testing before merging.

Comment on lines 269 to +279
const series = [
Object.assign(configs.mapOptions.nodeConfig, {
{
type:
configs.mapOptions.nodeConfig.type === "effectScatter"
? "effectScatter"
: "scatter",
name: "nodes",
coordinateSystem: "leaflet",
data: nodesData,
animationDuration: 1000,
}),
label: configs.mapOptions.nodeConfig.label,
Copy link
Member

@niteshsinha17 niteshsinha17 May 6, 2025

Choose a reason for hiding this comment

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

@cestercian By looking at your code and spending some time in debugging. I think now I know the reason why u are adding an extra object in the series array. You have added this because getNodeStyle is returning {} as size for some nodes (may be because of config) and you wanted to provide your custom functions so that nodes get correct styles? Please correct if I am wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

[change] Prevent overlapping of clusters
3 participants