forked from alteryx/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement rendering with dagre-d3 instead of viz.js
Before this commit, this patch relies on a JavaScript version of GraphViz that was compiled from C. Even the minified version of this resource was ~2.5M. The main motivation for switching away from this library, however, is that this is a complete black box of which we have absolutely no control. It is not at all extensible, and if something breaks we will have a hard time understanding why. The new library, dagre-d3, is not perfect either. It does not officially support clustering of nodes; for certain large graphs, the clusters will have a lot of unnecessary whitespace. A few in the dagre-d3 community are looking into a solution, but until then we will have to live with this (minor) inconvenience.
- Loading branch information
Andrew Or
committed
Apr 23, 2015
1 parent
5e22946
commit 205f838
Showing
8 changed files
with
158 additions
and
1,336 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
core/src/main/resources/org/apache/spark/ui/static/dagre-d3.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
core/src/main/resources/org/apache/spark/ui/static/graphlib-dot.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
core/src/main/resources/org/apache/spark/ui/static/spark-stage-viz.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* Render a DAG that describes the RDDs for a given stage. | ||
* | ||
* Input: The content of a dot file, stored in the text of the "#viz-dot-file" element | ||
* Output: An SVG that visualizes the DAG, stored in the "#viz-graph" element | ||
* | ||
* This relies on a custom implementation of dagre-d3, which can be found under | ||
* http://github.com/andrewor14/dagre-d3/dist/dagre-d3.js. For more detail, please | ||
* track the changes in that project after it was forked. | ||
*/ | ||
function renderStageViz() { | ||
|
||
// Parse the dot file and render it in an SVG | ||
var dot = d3.select("#viz-dot-file").text(); | ||
var escaped_dot = dot | ||
.replace(/</g, "<") | ||
.replace(/>/g, ">") | ||
.replace(/"/g, "\""); | ||
var g = graphlibDot.read(escaped_dot); | ||
var render = new dagreD3.render(); | ||
var svg = d3.select("#viz-graph"); | ||
svg.call(render, g); | ||
|
||
// Set the appropriate SVG dimensions to ensure that all elements are displayed | ||
var svgMargin = 20; | ||
var boundingBox = svg.node().getBBox(); | ||
svg.style("width", (boundingBox.width + svgMargin) + "px"); | ||
svg.style("height", (boundingBox.height + svgMargin) + "px"); | ||
|
||
// Add style to clusters, nodes and edges | ||
d3.selectAll("svg g.cluster rect") | ||
.style("fill", "none") | ||
.style("stroke", "#AADFFF") | ||
.style("stroke-width", "4px") | ||
.style("stroke-opacity", "0.5"); | ||
d3.selectAll("svg g.node rect") | ||
.style("fill", "white") | ||
.style("stroke", "black") | ||
.style("stroke-width", "2px") | ||
.style("fill-opacity", "0.8") | ||
.style("stroke-opacity", "0.9"); | ||
d3.selectAll("svg g.edgePath path") | ||
.style("stroke", "black") | ||
.style("stroke-width", "2px"); | ||
|
||
// Add labels to clusters | ||
d3.selectAll("svg g.cluster").each(function(cluster_data) { | ||
var cluster = d3.select(this); | ||
cluster.selectAll("rect").each(function(rect_data) { | ||
var rect = d3.select(this); | ||
// Shift the boxes up a little | ||
rect.attr("y", toFloat(rect.attr("y")) - 10); | ||
rect.attr("height", toFloat(rect.attr("height")) + 10); | ||
var labelX = toFloat(rect.attr("x")) + toFloat(rect.attr("width")) - 5; | ||
var labelY = toFloat(rect.attr("y")) + 15; | ||
var labelText = cluster.attr("id").replace(/^cluster/, "").replace(/_.*$/, ""); | ||
cluster.append("text") | ||
.attr("x", labelX) | ||
.attr("y", labelY) | ||
.attr("fill", "#AAAAAA") | ||
.attr("font-size", "11px") | ||
.attr("text-anchor", "end") | ||
.text(labelText); | ||
}); | ||
}); | ||
|
||
// We have shifted a few elements upwards, so we should fix the SVG views | ||
var startX = -svgMargin; | ||
var startY = -svgMargin; | ||
var endX = toFloat(svg.style("width")) + svgMargin; | ||
var endY = toFloat(svg.style("height")) + svgMargin; | ||
var newViewBox = startX + " " + startY + " " + endX + " " + endY; | ||
svg.attr("viewBox", newViewBox); | ||
|
||
} | ||
|
||
/* Helper method to convert attributes to numeric values. */ | ||
function toFloat(f) { | ||
return parseFloat(f.replace(/px$/, "")) | ||
} | ||
|
1,302 changes: 0 additions & 1,302 deletions
1,302
core/src/main/resources/org/apache/spark/ui/static/viz.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters