Github user andrewor14 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7774#discussion_r36117128
  
    --- Diff: 
sql/core/src/main/resources/org/apache/spark/sql/ui/static/spark-sql-viz.js ---
    @@ -0,0 +1,160 @@
    +/*
    + * 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.
    + */
    +
    +var PlanVizConstants = {
    +  svgMarginX: 16,
    +  svgMarginY: 16
    +};
    +
    +function renderPlanViz() {
    +  var svg = planVizContainer().append("svg");
    +  var metadata = d3.select("#plan-viz-metadata");
    +  var dot = metadata.select(".dot-file").text().trim();
    +  var graph = svg.append("g");
    +
    +  var g = graphlibDot.read(dot);
    +  preprocessGraphLayout(g);
    +  var renderer = new dagreD3.render();
    +  renderer(graph, g);
    +
    +  // Round corners on rectangles
    +  svg
    +    .selectAll("rect")
    +    .attr("rx", "5")
    +    .attr("ry", "5");
    +
    +  var nodeSize = parseInt($("#plan-viz-metadata-size").text());
    +  for (var i = 0; i < nodeSize; i++) {
    +    setupTooltipForSparkPlanNode(i);
    +  }
    +
    +  resizeSvg(svg)
    +}
    +
    +/* -------------------- *
    + * | Helper functions | *
    + * -------------------- */
    +
    +function planVizContainer() { return d3.select("#plan-viz-graph"); }
    +
    +/*
    + * Set up the tooltip for a SparkPlan node using metadata. When the user 
moves the mouse on the
    + * node, it will display the details of this SparkPlan node in the right.
    + */
    +function setupTooltipForSparkPlanNode(nodeId) {
    +  var nodeTooltip = d3.select("#plan-meta-data-" + nodeId).text()
    +  d3.select("svg g .node_" + nodeId)
    +    .on('mouseover', function(d) {
    +      var domNode = d3.select(this).node();
    +      $(domNode).tooltip({
    +        title: nodeTooltip, trigger: "manual", container: "body", 
placement: "right"
    +      });
    +      $(domNode).tooltip("show");
    +    })
    +    .on('mouseout', function(d) {
    +      var domNode = d3.select(this).node();
    +      $(domNode).tooltip("destroy");
    +    })
    +}
    +
    +/*
    + * Helper function to pre-process the graph layout.
    + * This step is necessary for certain styles that affect the positioning
    + * and sizes of graph elements, e.g. padding, font style, shape.
    + */
    +function preprocessGraphLayout(g) {
    --- End diff --
    
    There's a lot of duplicated code between this file and the dag viz one. Can 
you add a TODO somewhere in this file to make a `viz-utils.js` that holds the 
common methods? I would recommend that we do this in a follow-up patch so as 
not to delay this patch further.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to