Fix dynamic graph centering in Generate page#1764
Conversation
Coverage Report for CI Build 0Coverage decreased (-0.5%) to 58.113%Details
Uncovered Changes
Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
| let maxX = -Infinity | ||
| let maxY = -Infinity | ||
|
|
||
| shapes.forEach(shape => { |
There was a problem hiding this comment.
This is a fairly standard loop accumulation so I would just use a for loop rather than calling forEach
| if (bbox !== null) { | ||
| viewboxCentreX = (bbox.minX + bbox.maxX) / 2 | ||
| viewboxCentreY = (bbox.minY + bbox.maxY) / 2 | ||
| shapesWidth = bbox.width |
There was a problem hiding this comment.
Overall I do not think we should be recalculating the width and height, and instead just rely on what is computed by Graphviz on the Courseography back-end. (If there's an issue with the width/height data, that's a bug on the back-end that can be fixed there.)
|
|
||
| /** | ||
| * Compute the dimensions of the bounding box (bbox) that encloses every valid shape (node, hybrid, and bool) in the graph. | ||
| * @returns {?{minX, minY, maxX, maxY, width, height}} The bbox dimensions (minimum xy-coordinates, maximum |
There was a problem hiding this comment.
Make sure to update the docstring as well.
However as I was thinking about this further, I realized that I think you can just retrieve the minX and minY values from here, and then use the graph-provided width and height for the rest of the viewbox setting further below.
Proposed Changes
This pull request introduces the
computeShapesBboxmethod injs/components/graph/Graph.jsto centre the dynamic graph in the Generate page. Previously, the SVG viewBox was set to a region below the graph, causing the graph to appear to load in at the top of the page. This PR fixes this, centering the viewBox on the newly computed bounding box (bbox) instead. Note that this bbox is computed solely using valid shapes (nodes, hybrids, and bools) in the graph, hence the namecomputeShapesBbox....
Screenshots of your changes (if applicable)
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)