Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Canvas] Fix group layering #114346

Merged
merged 6 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,40 @@ const missingParentCheck = (groups) => {
};

export const shapesForNodes = (nodes) => {
// For a group, it's z-layer should be the same as the highest of it's children
// So we cache every nodes layer in this array so when we get to a group
// we can refer back to all of the elements and figure out the appropriate layer
// for the group
const nodeLayers = nodes.map(() => null);

const getNodeLayer = (nodeIndex) => {
if (nodeLayers[nodeIndex]) {
return nodeLayers[nodeIndex];
}

const node = nodes[nodeIndex];
const thisId = node.id;

const childrenIndexesOfThisNode = nodes
.map((n, i) => [n, i])
.filter(([node]) => node.position.parent === thisId)
.map(([, index]) => index);

if (childrenIndexesOfThisNode.length === 0) {
nodeLayers[nodeIndex] = nodeIndex;
} else {
const layer = Math.max(...childrenIndexesOfThisNode.map(getNodeLayer));
nodeLayers[nodeIndex] = layer;
}

return nodeLayers[nodeIndex];
};

const rawShapes = nodes
.map(elementToShape)
.map((node, index) => {
const layer = getNodeLayer(index);
return elementToShape(node, layer);
})
// filtering to eliminate residual element of a possible group that had been deleted in Redux
.filter((d, i, a) => !isGroupId(d.id) || a.find((s) => s.parent === d.id))
.filter(dedupe);
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/canvas/public/lib/aeroelastic/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ const planeTuple = (transformMatrix, x, y) => {
const x0 = rightPoint[0] - centerPoint[0];
const y0 = rightPoint[1] - centerPoint[1];
const x1 = upPoint[0] - centerPoint[0];
const y1 = upPoint[1] - centerPoint[1];
// If the shape is rotated so it's straight up or down (90 deg or -90 deg) then
// y1 is going to be zero here and cause divide by zero issues further down.
// The resulting planeVector accounts for this, but it's returning something incorrect that causes z
// to be calculated incorrectly.
// So instead we're going to set y1 to almost zero so we don't have to worry abou the divide by zeros
// and we still end up with an almost correct planeVector
const y1 = upPoint[1] - centerPoint[1] || 0.00000000001;
const rightSlope = y1 ? rightPoint[2] - centerPoint[2] : 0; // handle degenerate case: y1 === 0 (infinite slope)
const upSlope = y1 ? upPoint[2] - centerPoint[2] : 0; // handle degenerate case: y1 === 0 (infinite slope)
const inverseProjection = invert(transformMatrix);
Expand Down