Skip to content

Commit

Permalink
[AIRFLOW-6613] center dag on graph view load (#7238)
Browse files Browse the repository at this point in the history
  • Loading branch information
QP Hou authored Feb 2, 2020
1 parent 7527edd commit fe686e5
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions airflow/www/templates/airflow/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,27 @@
"scale(" + d3.event.scale + ")");
});
svg.call(zoom);
}

// Centering the DAG on load (Not implemented yet)
// https://github.com/dagrejs/dagre-d3/issues/245
// Centering the DAG on load
// Get Dagre Graph dimensions
var graphWidth = g.graph().width;
var graphHeight = g.graph().height;
// Get SVG dimensions
var padding = 20;
var svgBb = svg.node().getBoundingClientRect();
var width = svgBb.width - padding*2;
var height = svgBb.height - padding; // we are not centering the dag vertically

// Calculate applicable scale for zoom
zoomScale = Math.min(
Math.min(width / graphWidth, height / graphHeight),
1.5, // cap zoom level to 1.5 so nodes are not too large
);

zoom.translate([(width/2) - ((graphWidth*zoomScale)/2) + padding, padding]);
zoom.scale(zoomScale);
zoom.event(innerSvg);
}

setUpZoomSupport();
inject_node_ids(tasks);
Expand Down

0 comments on commit fe686e5

Please sign in to comment.