Skip to content

Commit

Permalink
Merge branch 'master' into node-cluster-position
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl authored Oct 28, 2024
2 parents 20f517a + 138dcb1 commit 19259c6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 4.19.4 - 10/17/24
- [chore] Add ability to customise Label font size and offset #285

# 4.19.3 - 8/20/24
- [fix] fixed labelType none still shows label when hovering over node
- [chore] replace react-use-gesture to @use-gesture/react #257
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reagraph",
"version": "4.19.3",
"version": "4.19.4",
"description": "WebGL Node-based Graph for React",
"scripts": {
"build": "vite build --mode library",
Expand Down
4 changes: 4 additions & 0 deletions src/useGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const useGraph = ({
const camera = useThree(state => state.camera) as PerspectiveCamera;
const dragRef = useRef<DragReferences>(drags);

// Calculate the visible entities
const { visibleEdges, visibleNodes } = useMemo(
() =>
getVisibleEntities({
Expand Down Expand Up @@ -138,6 +139,7 @@ export const useGraph = ({
}, [drags, clusterAttribute, updateLayout]);

useEffect(() => {
// When the camera position/zoom changes, update the label visibility
const nodes = stateNodes.map(node => ({
...node,
labelVisible: calcLabelVisibility({
Expand All @@ -148,10 +150,12 @@ export const useGraph = ({
})('node', node?.size)
}));

// Determine if the label visibility has changed
const isVisibilityUpdated = nodes.some(
(node, i) => node.labelVisible !== stateNodes[i].labelVisible
);

// Update the nodes if the label visibility has changed
if (isVisibilityUpdated) {
setNodes(nodes);
}
Expand Down
11 changes: 11 additions & 0 deletions src/utils/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ export function buildClusterGroups(
}

export interface CalculateClustersInput {
/**
* The nodes to calculate clusters for.
*/
nodes: InternalGraphNode[];
/**
* The attribute to use for clustering.
*/
clusterAttribute?: string;
}

Expand All @@ -45,6 +51,11 @@ export interface ClusterGroup {

/**
* Builds the cluster map.
*
* This function:
* - Builds the cluster groups
* - Calculates the center position of each cluster group
* - Creates a cluster object for each group
*/
export function calculateClusters({
nodes,
Expand Down

0 comments on commit 19259c6

Please sign in to comment.