({});
+
+ // Update the config when layoutAlgorithm changes via the panel options
+ useEffect(() => {
+ if (layoutAlgorithm) {
+ setConfig((prevConfig) => {
+ return {
+ ...prevConfig,
+ gridLayout: layoutAlgorithm === LayoutAlgorithm.Grid,
+ layoutAlgorithm,
+ };
+ });
+ }
+ }, [layoutAlgorithm]);
+
const firstNodesDataFrame = nodesDataFrames[0];
const firstEdgesDataFrame = edgesDataFrames[0];
@@ -166,7 +193,8 @@ export function NodeGraph({ getLinks, dataFrames, nodeLimit, panelId, zoomMode }
nodeCountLimit,
width,
focusedNodeId,
- processed.hasFixedPositions
+ processed.hasFixedPositions,
+ layoutCacheRef.current
);
// If we move from grid to graph layout, and we have focused node lets get its position to center there. We want to
@@ -199,6 +227,18 @@ export function NodeGraph({ getLinks, dataFrames, nodeLimit, panelId, zoomMode }
const highlightId = useHighlight(focusedNodeId);
+ const handleLayoutChange = (cfg: Config) => {
+ if (cfg.layoutAlgorithm !== config.layoutAlgorithm) {
+ setFocusedNodeId(undefined);
+ }
+ setConfig(cfg);
+ };
+
+ // Clear the layout cache when data changes
+ useEffect(() => {
+ layoutCacheRef.current = {};
+ }, [firstNodesDataFrame, firstEdgesDataFrame]);
+
return (
{loading ? (
@@ -208,6 +248,27 @@ export function NodeGraph({ getLinks, dataFrames, nodeLimit, panelId, zoomMode }
) : null}
+ {!panelId && (
+
+ {
+ handleLayoutChange({
+ ...config,
+ gridLayout: value === LayoutAlgorithm.Grid,
+ layoutAlgorithm: value,
+ });
+ }}
+ />
+
+ )}
+
{dataFrames.length && processed.nodes.length ? (