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

Jamie adjust petrinet transition matrix rectangle widths #3113

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
9a7d769
made transition matrices responsive
jamiewaese-uncharted Mar 21, 2024
6adf633
Update nested-petrinet-renderer.ts
jamiewaese-uncharted Mar 21, 2024
3abd4d5
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
jamiewaese-uncharted Mar 21, 2024
79e1258
Merge remote-tracking branch 'origin/main' into jamie-adjust-petrinet…
mwdchang Mar 22, 2024
6f67667
Added aspectRatio as part of the type
YohannParis Mar 22, 2024
0e46106
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
YohannParis Mar 22, 2024
f115af0
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
jamiewaese-uncharted Mar 22, 2024
1715f0e
fixed distortion when cols are less than rows
jamiewaese-uncharted Mar 22, 2024
bc0a6d3
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
jamiewaese-uncharted Mar 22, 2024
0496214
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
jamiewaese-uncharted Mar 22, 2024
deecc94
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
jamiewaese-uncharted Mar 22, 2024
c7abb45
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
jamiewaese-uncharted Mar 23, 2024
c2c1084
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
YohannParis Mar 23, 2024
90b3fc4
Fix... again the type changes
YohannParis Mar 23, 2024
3e1ea49
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
jamiewaese-uncharted Mar 25, 2024
a175eb1
Merge branch 'main' into jamie-adjust-petrinet-transition-matrix-rect…
mwdchang Mar 27, 2024
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
3 changes: 3 additions & 0 deletions packages/client/graph-scaffolder/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export interface INode<T> {
height: number;
data: T;
nodes: INode<T>[];
aspectRatio?: number;
matrixCols?: number;
matrixRows?: number;
}

export interface IEdge<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,49 @@ export class NestedPetrinetRenderer extends PetrinetRenderer {
strataTypes.push(strataType as string);
}
});

// Calculate aspect ratio for each node based on the transition matrix
selection.each((d) => {
const BASE_SIZE = 50;

const transitionMatrix = this.transitionMatrices?.[d.id] ?? [];
const matrixRowLen = transitionMatrix?.length ?? 0;
const matrixColLen = transitionMatrix[0]?.length ?? 0;

d.matrixRows = matrixRowLen;
d.matrixCols = matrixColLen;

// Initialize aspectRatio to 1 in case the matrix is square or empty
d.aspectRatio = 1;

// Check and set the aspect ratio based on the dimensions of the matrix
if (matrixRowLen > matrixColLen) {
d.aspectRatio = matrixColLen / matrixRowLen;
d.width = BASE_SIZE * d.aspectRatio;
d.height = BASE_SIZE;
} else if (matrixRowLen < matrixColLen) {
d.aspectRatio = matrixColLen / matrixRowLen;
d.width = BASE_SIZE;
d.height = BASE_SIZE / d.aspectRatio;
}

// If either dimension is 0, it could mean that the matrix is not properly formed
if (matrixRowLen === 0 || matrixColLen === 0 || d.aspectRatio === 1) {
d.width = BASE_SIZE;
d.height = BASE_SIZE;
}
});

// transitions
transitions
.append('rect')
.classed('shape selectableNode', true)
.attr('width', (d) => d.width)
.attr('height', (d) => d.height)
.attr('width', (d) => ((d.aspectRatio ?? 1) >= 1 ? d.width : d.width))
.attr('height', (d) => ((d.aspectRatio ?? 1) >= 1 ? d.height : d.height))
.attr('x', (d) => ((d.aspectRatio ?? 1) >= 1 ? -d.width * 0.5 : -d.width * 0.5))
.attr('y', (d) => -d.height * 0.5)
.attr('x', (d) => -d.width * 0.5)
.attr('rx', 6)
.attr('ry', 6)
// .attr('rx', 6)
// .attr('ry', 6)
.style('fill', (d) => (d.data.strataType ? getNodeTypeColor(d.data.strataType) : '#ffffff'))
.style('cursor', 'pointer')
.attr('stroke', 'var(--petri-nodeBorder)')
Expand Down Expand Up @@ -144,30 +177,8 @@ export class NestedPetrinetRenderer extends PetrinetRenderer {

const matrixRowLen = transitionMatrix.length;
const matrixColLen = transitionMatrix[0].length;

const transitionNode = select(g[idx]);

for (let i = 1; i < matrixRowLen; i++) {
const position = (d.width / matrixColLen) * i;

transitionNode
.append('line')
.attr('class', 'gridline')
.attr('x1', -d.width * 0.5)
.attr('y1', -d.width * 0.5 + position)
.attr('x2', d.width * 0.5)
.attr('y2', -d.width * 0.5 + position)
.attr('stroke', '#ffffffcf');
transitionNode
.append('line')
.attr('class', 'gridline')
.attr('y1', -d.width * 0.5)
.attr('x1', -d.width * 0.5 + position)
.attr('y2', d.width * 0.5)
.attr('x2', -d.width * 0.5 + position)
.attr('stroke', '#ffffffcf');
}

transitionMatrix.forEach((row, ridx) => {
const rowIdx = ridx;
row.forEach((col, cidx) => {
Expand All @@ -176,16 +187,35 @@ export class NestedPetrinetRenderer extends PetrinetRenderer {
transitionNode
.append('rect')
.attr('width', d.width / matrixColLen)
.attr('height', d.width / matrixRowLen)
.attr('height', d.height / matrixRowLen)
.attr('x', -d.width * 0.5 + (d.width / matrixColLen) * colIdx)
.attr('y', -d.width * 0.5 + (d.width / matrixRowLen) * rowIdx)
.attr('rx', 2)
.attr('ry', 2)
.attr('y', -d.height * 0.5 + (d.height / matrixRowLen) * rowIdx)
// .attr('rx', 2)
// .attr('ry', 2)
.style('fill', d.data.strataType ? getNodeTypeColor(d.data.strataType) : '#8692a4')
.style('cursor', 'pointer')
.attr('stroke', '#ffffff')
.attr('stroke-width', 1);
}
// Draw label for number of columns
// transitionNode
// .append('text')
// .attr('x', 0)
// .attr('y', -d.height * 0.6)
// .attr('text-anchor', 'middle') // This will center-align the text horizontally
// .text(matrixColLen)
// .style('fill', '#cccccc')
// .style('font-size', '7px');

// Draw label for number of rows
// transitionNode
// .append('text')
// .attr('x', (-d.width * d.aspectRatio!) / 2 - 8)
// .attr('y', (-d.height * d.aspectRatio!) / 2 + 12)
// .attr('text-anchor', 'right') // This will center-align the text horizontally
// .text(matrixRowLen)
// .style('fill', '#cccccc')
// .style('font-size', '7px');
});
});
});
Expand Down
Loading