
Company News
Socket Partners with Replit to Block Malicious Packages in AI-Powered Development
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.
@nx/graph
Advanced tools
@nx/graph/legacyThis entry point is mainly for migration purposes. This contains the entire old @nx/graph library.
@nx/graphCore of Nx Graph that contains base styles, basic types, and logic to render Cytoscape elements.
useRenderGraphEventA custom hook that allows consumers to listen for various events on the RenderGraph: the nodes, the edges, the background click
const { graphClient, send } = useProjectGraphClient({
/*...*/
});
useRenderGraphEvent(graphClient, 'CompositeNodeDblClick', (event) => {
if (event.isExpanded) {
send({ type: 'collapseCompositeNode', compositeNodeId: event.id });
} else {
send({
type: 'expandCompositeNode',
compositeNodeId: event.id,
mode: 'affected-only',
});
}
});
export interface CompositeProjectNodeDblClickEvent {
type: 'CompositeNodeDblClick';
id: string;
isExpanded: boolean;
}
export interface ProjectNodeContextMenuEvent {
type: 'ProjectNodeContextMenu';
id: string;
data: ProjectNodeElementData;
virtualElement: VirtualElement;
}
export interface CompositeProjectNodeContextMenuEvent {
type: 'CompositeNodeContextMenu';
id: string;
isExpanded: boolean;
data: CompositeProjectNodeElementData;
virtualElement: VirtualElement;
}
export interface ProjectEdgeContextMenuEvent {
type: 'ProjectEdgeContextMenu';
id: string;
data: ProjectEdgeElementData;
virtualElement: VirtualElement;
}
export interface CompositeProjectEdgeContextMenuEvent {
type: 'CompositeProjectEdgeContextMenu';
id: string;
data: CompositeProjectEdgeElementData;
virtualElement: VirtualElement;
}
export interface EmptyClickEvent {
type: 'EmptyClick';
}
export interface PostRenderEvent {
type: 'PostRender';
cy: Core;
}
export type RenderGraphEvent = CompositeProjectNodeDblClickEvent | ProjectNodeContextMenuEvent | CompositeProjectNodeContextMenuEvent | ProjectEdgeContextMenuEvent | CompositeProjectEdgeContextMenuEvent | EmptyClickEvent | PostRenderEvent;
@nx/graph/projectsThis entry point deals with handling ProjectGraph information.
const { containerRef, graphClient, send } = useProjectGraphClient({ renderPlatform: 'nx-cloud' });
containerRef is used to assign to a div element where the graph will be rendered.graphClient can be used with other graph components like useRenderGraphEventsend is a function that can send events that the ProjectGraphClient handles@nx/graph/tasksThis entry point deals with handling TaskGraph information.
const { containerRef, graphClient, send } = useTaskGraphClient({ renderPlatform: 'nx-cloud' });
containerRef is used to assign to a div element where the graph will be rendered.graphClient can be used with other graph components like useRenderGraphEventsend is a function that can send events that the TaskGraphClient handles@nx/graph/uiThis entry point contains various graph UI components
NxGraphBackgroundA static background component.
<div className="graph-container relative overflow-hidden">
<NxGraphBackground />
<div className="h-full" ref={containerRef} />
</div>
NxGraphControlsA container that holds the graph controls; usually in form of icons
<div className="graph-container relative overflow-hidden">
<div className="h-full" ref={containerRef} />
<NxGraphControls>
<ResetGraphLayoutControl onClick={() => send({ type: 'resetLayout' })} />
<ResetGraphStateControl onClick={() => send({ type: 'resetGraph', autoExpand: true, mode: 'affected-only' })} />
</NxGraphControls>
</div>
NxGraphLegendsA collapsible element that renders graph legends
<NxGraphLegends>
{{
nodes: (
<>
<NodeLegend />
<CompositeNodeLegend />
<AffectedNodeLegend />
{touchedProjects.length > 0 && <TouchedNodeLegend />}
</>
),
edges: (
<>
<EdgeLegend />
<CompositeEdgeLegend />
</>
),
}}
</NxGraphLegends>
NodeLegend: legend for a regular nodeCompositeNodeLegend: legend for a composite nodeAffectedNodeLegend: legend for a node whose isAffected is trueTouchedNodeLegend: legend for a node whose isTouched is trueEdgeLegend: legend for a regular edgeCompositeEdgeLegend: legend for a composite edgeAll legends can be customized: colors, labels, etc...
@nx/graph/context-menuHandles context menu of the elements on the graph.
useGraphContextMenuTo enable context menu, useGraphContextMenu hook is required. This hook sets up listeners for various render events and return proper graphMenu object
const { graphMenu, closeMenu } = useGraphContextMenu({
/* require graphClient or any RenderGraphEventBus */
renderGraphEventBus: graphClient,
});
NxGraphContextMenugraphMenu object is used to render NxGraphContextMenu
{
graphMenu ? (
<NxGraphContextMenu menu={graphMenu.props} virtualElement={graphMenu.virtualElement} placement="bottom-start">
{/* {children goes here} */}
</NxGraphContextMenu>
) : null;
}
NxGraphContextMenu only handles the floating menu. To render the content, NxGraphContextMenu accepts a dictionary of children render props
{
project: ({ id: string, data: ProjectNodeElementData }) => ReactNode;
compositeProject: ({ id: string, isExpanded: boolean, data: CompositeProjectNodeElementData }) => ReactNode;
}
Each children render prop can render multiple NxGraphContextMenuSection
<NxGraphContextMenu>
{{
project: ({ id, data }) => (
<>
<NxGraphContextMenuSection>
<ViewDetailButton />
</NxGraphContextMenuSection>
<NxGraphContextMenuSection title="Actions">
<ExcludeNodeButton />
</NxGraphContextMenuSection>
</>
),
}}
</NxGraphContextMenu>
ViewDetailButtonandExcludeNodeButtonare implementation details. They can be anything that the consumers want to render in the Project Node's context menu.
@nx/graph/panelHandles panels in the graph.
NxGraphElementDetailPanelTo render a panel, capture a NodeElementData (via NxGraphContextMenu or useRenderGraphEvent) then use NxGraphElementDetailPanel
<NxGraphElementDetailPanel element={element} onClose={() => setElement(null)}>
{{
project: (projectNodeElementData) => <>{/* any content */}</>,
compositeProject: (compositeProjectNodeElementData) => <>{/* any content */}</>,
}}
</NxGraphElementDetailPanel>
FAQs
Internal utilities for Nx graph visualization, not intended for external use.
We found that @nx/graph demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.

Research
/Security News
Newer packages in this compromise use native extensions and .pth loaders to execute JavaScript stealers in developer environments.