Skip to content

Commit d5d9ab0

Browse files
yaooqinndongjoon-hyun
authored andcommitted
[SPARK-54320][UI] Fix Job DAG overlapping
### What changes were proposed in this pull request? Fix the Job DAG overlapping ### Why are the changes needed? A job with multiple stages might generate SVGs with overlapping ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? <img width="2956" height="1306" alt="image" src="https://github.com/user-attachments/assets/9ccfdc22-fa8d-4c9a-a8f2-5758b5382e08" /> ### Was this patch authored or co-authored using generative AI tooling? no Closes #53015 from yaooqinn/SPARK-54320. Authored-by: Kent Yao <yao@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org> (cherry picked from commit 1a802e3) Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent 51d7a20 commit d5d9ab0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

core/src/main/resources/org/apache/spark/ui/static/spark-dag-viz.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ function renderDagVizForJob(svgContainer) {
295295
.append("g")
296296
}
297297

298+
// Now we need to shift the container for this stage so it doesn't overlap with
299+
// existing ones, taking into account the position and width of the last stage's
300+
// container. We do not need to do this for the first stage of this job.
301+
if (i > 0) {
302+
const lastStage = svgContainer.selectAll("g.cluster.stage")
303+
.filter((d, i, nodes) => i === nodes.length - 1);
304+
if (lastStage) {
305+
const lastStageWidth = toFloat(lastStage.select("rect").attr("width"));
306+
const lastStagePosition = getAbsolutePosition(lastStage);
307+
const offset = lastStagePosition.x + lastStageWidth + VizConstants.stageSep;
308+
container.attr("transform", `translate(${offset}, 0)`);
309+
}
310+
}
311+
298312
var g = graphlibDot.read(dot);
299313
// Actually render the stage
300314
renderDot(g, container, true);
@@ -312,20 +326,6 @@ function renderDagVizForJob(svgContainer) {
312326
.attr("rx", "4")
313327
.attr("ry", "4");
314328

315-
// Now we need to shift the container for this stage so it doesn't overlap with
316-
// existing ones, taking into account the position and width of the last stage's
317-
// container. We do not need to do this for the first stage of this job.
318-
if (i > 0) {
319-
var existingStages = svgContainer.selectAll("g.cluster.stage").nodes();
320-
if (existingStages.length > 0) {
321-
var lastStage = d3.select(existingStages.pop());
322-
var lastStageWidth = toFloat(lastStage.select("rect").attr("width"));
323-
var lastStagePosition = getAbsolutePosition(lastStage);
324-
var offset = lastStagePosition.x + lastStageWidth + VizConstants.stageSep;
325-
container.attr("transform", "translate(" + offset + ", 0)");
326-
}
327-
}
328-
329329
// If there are any incoming edges into this graph, keep track of them to render
330330
// them separately later. Note that we cannot draw them now because we need to
331331
// put these edges in a separate container that is on top of all stage graphs.

0 commit comments

Comments
 (0)