Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed Oct 18, 2024
1 parent 13e89de commit 138dcb1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/useGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const useGraph = ({
const layout = useRef<LayoutStrategy | null>(null);
const camera = useThree(state => state.camera) as PerspectiveCamera;

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

useEffect(() => {
// When the camera position/zoom changes, update the label visibility
const nodes = stateNodes.map(node => ({
...node,
labelVisible: calcLabelVisibility({
Expand All @@ -147,10 +149,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
20 changes: 20 additions & 0 deletions src/utils/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,38 @@ export function buildClusterGroups(
}

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

export interface ClusterGroup {
/**
* The nodes in the cluster.
*/
nodes: InternalGraphNode[];
/**
* The position of the cluster.
*/
position: CenterPositionVector;
/**
* The label of the cluster.
*/
label: string;
}

/**
* 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 138dcb1

Please sign in to comment.