Skip to content

Commit 972e1f3

Browse files
Release 0.0.27 (#85)
1 parent a5f94e5 commit 972e1f3

5 files changed

Lines changed: 155 additions & 157 deletions

File tree

dist/build.js

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -93624,7 +93624,6 @@ azdataQueryPlan.prototype.renderPolygons = function () {
9362493624
azdataQueryPlan.prototype.getPolygonPerimeter = function (cell) {
9362593625
let points = [];
9362693626
points = points.concat(this.getLeftSidePoints(cell));
93627-
9362893627
let rightSidePoints = this.getRightSidePoints(cell);
9362993628
points = points.concat(this.getBottomSidePoints(cell, rightSidePoints[0].x));
9363093629
points = points.concat(rightSidePoints);
@@ -93642,9 +93641,13 @@ const NODE_WIDTH = 100;
9364293641
*/
9364393642
azdataQueryPlan.prototype.getLeftSidePoints = function (cell) {
9364493643
let points = [];
93644+
93645+
// let additionalLeftSideSpacing = longestSubLabel % 10 * 25;
93646+
let additionalLeftSideSpacing = this.calcAdditionalSpacingForNode(cell);
93647+
9364593648
let xPosition = cell.geometry.x - 15; // subtracting to push the x coordinate to the left.
93646-
points.push({ x: xPosition, y: cell.geometry.y });
93647-
points.push({ x: xPosition, y: cell.geometry.y + NODE_HEIGHT });
93649+
points.push({ x: xPosition - additionalLeftSideSpacing, y: cell.geometry.y });
93650+
points.push({ x: xPosition - additionalLeftSideSpacing, y: cell.geometry.y + NODE_HEIGHT });
9364893651

9364993652
return points;
9365093653
}
@@ -93656,64 +93659,51 @@ azdataQueryPlan.prototype.getLeftSidePoints = function (cell) {
9365693659
*/
9365793660
azdataQueryPlan.prototype.getBottomSidePoints = function (cell, polygonRightSideConstraint) {
9365893661
let points = [];
93659-
let bottomSideLeafNodes = this.getBottomSideLeafNodes(cell, polygonRightSideConstraint);
93662+
let bottomSideNodes = this.getBottomSideNodes(cell, polygonRightSideConstraint);
9366093663

93661-
for (let index = 0; index < bottomSideLeafNodes.length; ++index) {
93662-
let leafNode = bottomSideLeafNodes[index].value;
93663-
let leftOfLeafNode = leafNode;
93664+
bottomSideNodes.forEach(node => {
93665+
let lastPoint = points.length > 0 ? points[points.length - 1] : null;
9366493666

93665-
// Finds the left most node directly to the left of the leaf node.
93666-
while (leftOfLeafNode.position.y === leftOfLeafNode.parent.position.y) {
93667-
leftOfLeafNode = leftOfLeafNode.parent;
93668-
}
93667+
let newPoint = { x: node.geometry.x, y: node.geometry.y + NODE_HEIGHT };
9366993668

93670-
if (points.length === 0) {
93671-
let parent = leftOfLeafNode.parent;
93672-
let auxiliaryPoint = { x: leftOfLeafNode.position.x - NODE_WIDTH, y: parent.position.y + NODE_HEIGHT };
93673-
points.push(auxiliaryPoint);
93674-
}
93675-
else if (points.length !== 0 && points[points.length - 1].y - NODE_HEIGHT !== leftOfLeafNode.position.y) {
93676-
let auxiliaryPoint = { x: leftOfLeafNode.position.x - NODE_WIDTH, y: points[points.length - 1].y };
93669+
if (lastPoint && newPoint.y !== lastPoint.y) {
93670+
let auxiliaryPoint = { x: lastPoint.x, y: newPoint.y };
9367793671
points.push(auxiliaryPoint);
9367893672
}
9367993673

93680-
points.push({ x: leftOfLeafNode.position.x - NODE_WIDTH, y: leftOfLeafNode.position.y + NODE_HEIGHT });
93674+
let cell = this.graph.model.getCell(node.id);
93675+
let additionalSpacing = Math.max(...(cell.value.label.split(/\r\n|\n/).map(str => str.length))) > 20 ? this.calcAdditionalSpacingForNode(cell) : 0;
9368193676

93682-
if (leftOfLeafNode.position.x < leafNode.position.x) {
93683-
points.push({ x: leafNode.position.x + NODE_WIDTH, y: leafNode.position.y + NODE_HEIGHT});
93684-
}
93685-
}
93677+
points.push({ x: node.geometry.x, y: node.geometry.y + NODE_HEIGHT });
93678+
points.push({ x: node.geometry.x + NODE_WIDTH + additionalSpacing, y: node.geometry.y + NODE_HEIGHT });
93679+
});
9368693680

9368793681
return points;
9368893682
}
9368993683

93690-
azdataQueryPlan.prototype.getBottomSideLeafNodes = function (cell, polygonRightSideConstraint) {
93691-
let leafNodeTable = {};
93692-
let stack = [cell];
93684+
azdataQueryPlan.prototype.getBottomSideNodes = function (cell, polygonRightSideConstraint) {
93685+
let queue = [cell];
93686+
let nodes = [];
9369393687

93694-
while (stack.length !== 0) {
93695-
let entry = stack.pop();
93688+
while (queue.length !== 0) {
93689+
let levelNodeCount = queue.length;
9369693690

93697-
if (entry.value.children.length === 0 && entry.geometry.x <= polygonRightSideConstraint) {
93698-
if (entry.geometry.x in leafNodeTable) {
93699-
let previouslyCachedEntry = leafNodeTable[entry.geometry.x];
93700-
if (entry.geometry.y > previouslyCachedEntry.geometry.y) {
93701-
leafNodeTable[entry.geometry.x] = entry;
93702-
}
93703-
}
93704-
else {
93705-
leafNodeTable[entry.geometry.x] = entry;
93691+
for (let nodeIndex = 0; nodeIndex < levelNodeCount; ++nodeIndex) {
93692+
let entry = queue.shift();
93693+
93694+
if (nodeIndex === levelNodeCount - 1 && entry.geometry.x < polygonRightSideConstraint) {
93695+
nodes.push(entry)
9370693696
}
93707-
}
9370893697

93709-
for (let nodeIndex = 0; nodeIndex < entry.value.children.length; ++nodeIndex) {
93710-
stack.push(this.graph.model.getCell(entry.value.children[nodeIndex].id));
93698+
for (let childIndex = 0; childIndex < entry.value.children.length; ++childIndex) {
93699+
if (entry.geometry.x < polygonRightSideConstraint) {
93700+
queue.push(this.graph.model.getCell(entry.value.children[childIndex].id));
93701+
}
93702+
}
9371193703
}
9371293704
}
9371393705

93714-
let leafNodes = Object.keys(leafNodeTable).map(key => leafNodeTable[key])
93715-
93716-
return leafNodes;
93706+
return nodes;
9371793707
}
9371893708

9371993709
/**
@@ -93723,22 +93713,26 @@ azdataQueryPlan.prototype.getBottomSideLeafNodes = function (cell, polygonRightS
9372393713
*/
9372493714
azdataQueryPlan.prototype.getRightSidePoints = function (cell) {
9372593715
let points = [];
93726-
let leafNodes = this.getLeafNodes(cell);
93716+
let leafs = this.getLeafNodes(cell);
9372793717

93728-
for (let nodeIndex = 0; nodeIndex < leafNodes.length; ++nodeIndex) {
93729-
let leafNode = leafNodes[nodeIndex];
93718+
for (let leafIndex = 0; leafIndex < leafs.length; ++leafIndex) {
93719+
let leaf = leafs[leafIndex];
9373093720

93731-
let longestSubLabel = Math.max(...(leafNode.value.label.split(/\r\n|\n/).map(str => str.length)));
93732-
// These values to work best for drawing regions around labels of different lengths, so the label is always inside the polygon.
93733-
let additionalRightSideSpacing = longestSubLabel % 10 * 25;
93721+
let additionalRightSideSpacing = this.calcAdditionalSpacingForNode(leaf);
9373493722

93735-
points.push({ x: leafNode.geometry.x + NODE_WIDTH + additionalRightSideSpacing, y: leafNode.geometry.y + NODE_HEIGHT });
93736-
points.push({ x: leafNode.geometry.x + NODE_WIDTH + additionalRightSideSpacing, y: leafNode.geometry.y });
93723+
points.push({ x: leaf.geometry.x + NODE_WIDTH + additionalRightSideSpacing, y: leaf.geometry.y + NODE_HEIGHT });
93724+
points.push({ x: leaf.geometry.x + NODE_WIDTH + additionalRightSideSpacing, y: leaf.geometry.y });
9373793725
}
9373893726

9373993727
return points;
9374093728
}
9374193729

93730+
azdataQueryPlan.prototype.calcAdditionalSpacingForNode = function(cell) {
93731+
let longestSubLabel = Math.max(...(cell.value.label.split(/\r\n|\n/).map(str => str.length)));
93732+
// These values to work best for drawing regions around labels of different lengths, so the label is always inside the polygon.
93733+
return longestSubLabel / 10 * 15;
93734+
}
93735+
9374293736
/**
9374393737
* Helper function to get the right most nodes of the polygon in a execution plan
9374493738
* @param {*} cell The root node that will be used to find all of the leaf nodes

dist/js/azdata/azdataQueryPlan.js

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,6 @@ azdataQueryPlan.prototype.renderPolygons = function () {
775775
azdataQueryPlan.prototype.getPolygonPerimeter = function (cell) {
776776
let points = [];
777777
points = points.concat(this.getLeftSidePoints(cell));
778-
779778
let rightSidePoints = this.getRightSidePoints(cell);
780779
points = points.concat(this.getBottomSidePoints(cell, rightSidePoints[0].x));
781780
points = points.concat(rightSidePoints);
@@ -793,9 +792,13 @@ const NODE_WIDTH = 100;
793792
*/
794793
azdataQueryPlan.prototype.getLeftSidePoints = function (cell) {
795794
let points = [];
795+
796+
// let additionalLeftSideSpacing = longestSubLabel % 10 * 25;
797+
let additionalLeftSideSpacing = this.calcAdditionalSpacingForNode(cell);
798+
796799
let xPosition = cell.geometry.x - 15; // subtracting to push the x coordinate to the left.
797-
points.push({ x: xPosition, y: cell.geometry.y });
798-
points.push({ x: xPosition, y: cell.geometry.y + NODE_HEIGHT });
800+
points.push({ x: xPosition - additionalLeftSideSpacing, y: cell.geometry.y });
801+
points.push({ x: xPosition - additionalLeftSideSpacing, y: cell.geometry.y + NODE_HEIGHT });
799802

800803
return points;
801804
}
@@ -807,64 +810,51 @@ azdataQueryPlan.prototype.getLeftSidePoints = function (cell) {
807810
*/
808811
azdataQueryPlan.prototype.getBottomSidePoints = function (cell, polygonRightSideConstraint) {
809812
let points = [];
810-
let bottomSideLeafNodes = this.getBottomSideLeafNodes(cell, polygonRightSideConstraint);
813+
let bottomSideNodes = this.getBottomSideNodes(cell, polygonRightSideConstraint);
811814

812-
for (let index = 0; index < bottomSideLeafNodes.length; ++index) {
813-
let leafNode = bottomSideLeafNodes[index].value;
814-
let leftOfLeafNode = leafNode;
815+
bottomSideNodes.forEach(node => {
816+
let lastPoint = points.length > 0 ? points[points.length - 1] : null;
815817

816-
// Finds the left most node directly to the left of the leaf node.
817-
while (leftOfLeafNode.position.y === leftOfLeafNode.parent.position.y) {
818-
leftOfLeafNode = leftOfLeafNode.parent;
819-
}
818+
let newPoint = { x: node.geometry.x, y: node.geometry.y + NODE_HEIGHT };
820819

821-
if (points.length === 0) {
822-
let parent = leftOfLeafNode.parent;
823-
let auxiliaryPoint = { x: leftOfLeafNode.position.x - NODE_WIDTH, y: parent.position.y + NODE_HEIGHT };
824-
points.push(auxiliaryPoint);
825-
}
826-
else if (points.length !== 0 && points[points.length - 1].y - NODE_HEIGHT !== leftOfLeafNode.position.y) {
827-
let auxiliaryPoint = { x: leftOfLeafNode.position.x - NODE_WIDTH, y: points[points.length - 1].y };
820+
if (lastPoint && newPoint.y !== lastPoint.y) {
821+
let auxiliaryPoint = { x: lastPoint.x, y: newPoint.y };
828822
points.push(auxiliaryPoint);
829823
}
830824

831-
points.push({ x: leftOfLeafNode.position.x - NODE_WIDTH, y: leftOfLeafNode.position.y + NODE_HEIGHT });
825+
let cell = this.graph.model.getCell(node.id);
826+
let additionalSpacing = Math.max(...(cell.value.label.split(/\r\n|\n/).map(str => str.length))) > 20 ? this.calcAdditionalSpacingForNode(cell) : 0;
832827

833-
if (leftOfLeafNode.position.x < leafNode.position.x) {
834-
points.push({ x: leafNode.position.x + NODE_WIDTH, y: leafNode.position.y + NODE_HEIGHT});
835-
}
836-
}
828+
points.push({ x: node.geometry.x, y: node.geometry.y + NODE_HEIGHT });
829+
points.push({ x: node.geometry.x + NODE_WIDTH + additionalSpacing, y: node.geometry.y + NODE_HEIGHT });
830+
});
837831

838832
return points;
839833
}
840834

841-
azdataQueryPlan.prototype.getBottomSideLeafNodes = function (cell, polygonRightSideConstraint) {
842-
let leafNodeTable = {};
843-
let stack = [cell];
835+
azdataQueryPlan.prototype.getBottomSideNodes = function (cell, polygonRightSideConstraint) {
836+
let queue = [cell];
837+
let nodes = [];
844838

845-
while (stack.length !== 0) {
846-
let entry = stack.pop();
839+
while (queue.length !== 0) {
840+
let levelNodeCount = queue.length;
847841

848-
if (entry.value.children.length === 0 && entry.geometry.x <= polygonRightSideConstraint) {
849-
if (entry.geometry.x in leafNodeTable) {
850-
let previouslyCachedEntry = leafNodeTable[entry.geometry.x];
851-
if (entry.geometry.y > previouslyCachedEntry.geometry.y) {
852-
leafNodeTable[entry.geometry.x] = entry;
853-
}
854-
}
855-
else {
856-
leafNodeTable[entry.geometry.x] = entry;
842+
for (let nodeIndex = 0; nodeIndex < levelNodeCount; ++nodeIndex) {
843+
let entry = queue.shift();
844+
845+
if (nodeIndex === levelNodeCount - 1 && entry.geometry.x < polygonRightSideConstraint) {
846+
nodes.push(entry)
857847
}
858-
}
859848

860-
for (let nodeIndex = 0; nodeIndex < entry.value.children.length; ++nodeIndex) {
861-
stack.push(this.graph.model.getCell(entry.value.children[nodeIndex].id));
849+
for (let childIndex = 0; childIndex < entry.value.children.length; ++childIndex) {
850+
if (entry.geometry.x < polygonRightSideConstraint) {
851+
queue.push(this.graph.model.getCell(entry.value.children[childIndex].id));
852+
}
853+
}
862854
}
863855
}
864856

865-
let leafNodes = Object.keys(leafNodeTable).map(key => leafNodeTable[key])
866-
867-
return leafNodes;
857+
return nodes;
868858
}
869859

870860
/**
@@ -874,22 +864,26 @@ azdataQueryPlan.prototype.getBottomSideLeafNodes = function (cell, polygonRightS
874864
*/
875865
azdataQueryPlan.prototype.getRightSidePoints = function (cell) {
876866
let points = [];
877-
let leafNodes = this.getLeafNodes(cell);
867+
let leafs = this.getLeafNodes(cell);
878868

879-
for (let nodeIndex = 0; nodeIndex < leafNodes.length; ++nodeIndex) {
880-
let leafNode = leafNodes[nodeIndex];
869+
for (let leafIndex = 0; leafIndex < leafs.length; ++leafIndex) {
870+
let leaf = leafs[leafIndex];
881871

882-
let longestSubLabel = Math.max(...(leafNode.value.label.split(/\r\n|\n/).map(str => str.length)));
883-
// These values to work best for drawing regions around labels of different lengths, so the label is always inside the polygon.
884-
let additionalRightSideSpacing = longestSubLabel % 10 * 25;
872+
let additionalRightSideSpacing = this.calcAdditionalSpacingForNode(leaf);
885873

886-
points.push({ x: leafNode.geometry.x + NODE_WIDTH + additionalRightSideSpacing, y: leafNode.geometry.y + NODE_HEIGHT });
887-
points.push({ x: leafNode.geometry.x + NODE_WIDTH + additionalRightSideSpacing, y: leafNode.geometry.y });
874+
points.push({ x: leaf.geometry.x + NODE_WIDTH + additionalRightSideSpacing, y: leaf.geometry.y + NODE_HEIGHT });
875+
points.push({ x: leaf.geometry.x + NODE_WIDTH + additionalRightSideSpacing, y: leaf.geometry.y });
888876
}
889877

890878
return points;
891879
}
892880

881+
azdataQueryPlan.prototype.calcAdditionalSpacingForNode = function(cell) {
882+
let longestSubLabel = Math.max(...(cell.value.label.split(/\r\n|\n/).map(str => str.length)));
883+
// These values to work best for drawing regions around labels of different lengths, so the label is always inside the polygon.
884+
return longestSubLabel / 10 * 15;
885+
}
886+
893887
/**
894888
* Helper function to get the right most nodes of the polygon in a execution plan
895889
* @param {*} cell The root node that will be used to find all of the leaf nodes

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "azdataGraph",
33
"description": "azdataGraph is a derivative of mxGraph, which is a fully client side JavaScript diagramming library that uses SVG and HTML for rendering.",
4-
"version": "0.0.26",
4+
"version": "0.0.27",
55
"homepage": "https://github.com/microsoft/azdataGraph",
66
"author": "Microsoft",
77
"license": "Apache-2.0",
@@ -17,7 +17,7 @@
1717
"prepare": "grunt build --base ./ --gruntfile etc/build/Gruntfile.js"
1818
},
1919
"devDependencies": {
20-
"grunt": "^1.0.1",
20+
"grunt": "^1.5.3",
2121
"grunt-contrib-concat": "^1.0.1",
2222
"grunt-contrib-copy": "^1.0.0",
2323
"grunt-webpack": "^2.0.1",

0 commit comments

Comments
 (0)