zuozhiw commented on a change in pull request #2486:
URL: https://github.com/apache/calcite/pull/2486#discussion_r689665526
##########
File path: core/src/main/resources/volcano-viz/viz-template.html
##########
@@ -0,0 +1,323 @@
+<!doctype html>
+<html lang="en">
+<!--
+{% comment %}
+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.
+{% endcomment %}
+-->
+<meta charset="utf-8">
+<title>Calcite Rule Match Visualization</title>
+
+<script src="https://d3js.org/d3.v5.min.js" charset="utf-8"></script>
+<script
src="https://dagrejs.github.io/project/dagre-d3/latest/dagre-d3.min.js"></script>
+<script src="https://d3js.org/d3-zoom.v1.min.js"></script>
+<script src="https://unpkg.com/tippy.js@3/dist/tippy.all.min.js"></script>
+<script src="volcano-viz-data.js"></script>
+
+<style id="css">
+ body {
+ height: 100%;
+ margin: 0 0;
+ color: #333;
+ font-weight: 300;
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serf;
+ }
+
+ li a {
+ display: block;
+ /* and you can use padding for additional space if needs, as a
clickable area / or other styling */
+ padding: 5px 20px;
+ }
+
+ section {
+ margin-bottom: 3em;
+ }
+
+ section p {
+ text-align: justify;
+ }
+
+ svg {
+ border: 1px solid #ccc;
+ overflow: hidden;
+ margin: 0 auto;
+ }
+
+ pre {
+ border: 1px solid #ccc;
+ }
+
+ .clusters rect {
+ fill: #FFFFE0;
+ stroke: #999;
+ stroke-width: 1.5px;
+ }
+
+ text {
+ font-weight: 300;
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serf;
+ font-size: 2em;
+ }
+
+ .node rect {
+ stroke: #999;
+ fill: #fff;
+ stroke-width: 1.5px;
+ }
+
+ .edgePath path {
+ stroke: #333;
+ stroke-width: 2px;
+ }
+
+ .container {
+ display: flex;
+ align-items: center;
+ }
+
+ .column1 {
+ flex: 0 0 300px;
+ }
+
+ .column2 {
+ flex: 0 0 1000px;
+ }
+
+ .tippy-content {
+ word-break: break-all;
+ word-wrap: break-word;
+ }
+</style>
+
+<div class="container">
+ <div class="column1">
+ <div style="width: 100%; text-align: center">
+ <div id="current-rule" style="display: block"></div>
+ <button id="prev-button" style="width: 80px; height: 40px;
display:inline-block" disabled>prev </button>
+ <button id="next-button" style="width: 80px; height: 40px;
display:inline-block" disabled> next</button>
+ </div>
+ <ul id="rule-match-list" style="width: 300px; height: 600px; overflow:
auto">
+ </ul>
+ </div>
+ <div class="column2">
+ <svg id="svg-canvas" width="1200px" height="800px"></svg>
+ </div>
+</div>
+
+<script id="js">
+
+ var allNodes = data.allNodes;
+ var ruleMatchSequence = data.ruleMatchSequence;
+ var ruleMatchInfoMap = data.ruleMatchInfoMap;
+ var nodeAddedInRule = data.nodeAddedInRule;
+
+ /*
+ * Graph data and D3 JS render related variables
+ */
+
+ // Create the input graph
+ var g = new dagreD3.graphlib.Graph({
+ compound: true
+ })
+ .setGraph({
+ rankdir: 'LR'
+ })
+ .setDefaultEdgeLabel(function () {
+ return {};
+ });
+
+ // Create the renderer
+ var render = new dagreD3.render();
+
+ // Set up an SVG group so that we can translate the final graph.
+ var svg = d3.select("svg");
+ var svgGroup = svg.append("g");
+
+ // Set up zoom support
+ var svg = d3.select("svg")
+ .attr("width", "1200px")
+ .attr("height", "800px")
+ .call(d3.zoom().on("zoom", function () {
+ svgGroup.attr("transform", d3.event.transform)
+ }));
+
+ /*
+ * Global State
+ */
+
+ var currentRuleID = undefined;
+
+ /*
+ * Event Handler functions
+ */
+
+ var setCurrentRule = (ruleMatchID) => {
+ // un-highlight previous entry
+ var prevRuleID = currentRuleID;
+ if (prevRuleID !== undefined) {
+ var prevRuleElement = document.getElementById(prevRuleID);
+ prevRuleElement.style.backgroundColor = "#FFFFFF";
+ }
+
+ currentRuleID = ruleMatchID;
+ document.getElementById('current-rule').innerText = currentRuleID;
+
+ var currentRuleElement = document.getElementById(currentRuleID);
+ currentRuleElement.style.backgroundColor = "#D3D3D3";
+
+ var ruleIndex = ruleMatchSequence.indexOf(currentRuleID);
+
+ document.getElementById("prev-button").disabled = false;
+ document.getElementById("next-button").disabled = false;
+
+ if (ruleIndex === 0) {
+ document.getElementById("prev-button").disabled = true;
+ }
+ if (ruleIndex === ruleMatchSequence.length - 1) {
+ document.getElementById("next-button").disabled = true;
+ }
+
+ createGraph(ruleMatchID);
+ }
+
+ var createGraph = (ruleMatchID) => {
+ var ruleMatchInfo = ruleMatchInfoMap[ruleMatchID]
+ console.log(ruleMatchInfo);
+
+ // remove previous rendered view and clear graph model
+ d3.select("svg g").selectAll("*").remove();
+ g.nodes().slice().forEach(nodeID => g.removeNode(nodeID));
Review comment:
Agree, but we need to be careful and compare the old nodes with the new
nodes. This could be tricky especially when set merge happens: one set is
removed and relnodes from this set all go into another set. So re-drawing is
eaiser.
One more thing on performance. This tool runs slow when the plan is
ultra-large. I investigated and the major performance bottleneck is actually
doing the **layout** instead of drawing the nodes. I can't recall the exact
numbers but over 90% of the time is spent on the layout (`dagre`) for plans
with noticable delay in visualization.
I did an extensive investigation on different layout libraries, but `dagre`
remains the best-looking one, so I decided to keep it although it's slow. One
sad thing is that none of these layout libraries can calculate layout
incrementally. They all have to re-compute the whole thing every time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]