Skip to content

Fix dynamic graph centering in Generate page#1764

Open
r-weng wants to merge 6 commits into
Courseography:masterfrom
r-weng:centre-dynamic-graph-v2
Open

Fix dynamic graph centering in Generate page#1764
r-weng wants to merge 6 commits into
Courseography:masterfrom
r-weng:centre-dynamic-graph-v2

Conversation

@r-weng

@r-weng r-weng commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

This pull request introduces the computeShapesBbox method in js/components/graph/Graph.js to 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 name computeShapesBbox.

...

Screenshots of your changes (if applicable) Screenshot 2026-07-18 at 2 14 33 PM (before) Screenshot 2026-07-18 at 2 15 04 PM (after)

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue) X
🎨 User interface change (change to user interface; provide screenshots) X
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

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:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.
  • I have updated the project Changelog (this is required for all changes).

After opening your pull request:

  • I have verified that the CircleCI checks have passed.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

@coveralls

coveralls commented Jul 18, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 0

Coverage decreased (-0.5%) to 58.113%

Details

  • Coverage decreased (-0.5%) from the base build.
  • Patch coverage: 30 uncovered changes across 1 file (7 of 37 lines covered, 18.92%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
js/components/graph/Graph.js 37 7 18.92%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
js/components/graph/Graph.js 1 75.53%

Coverage Stats

Coverage Status
Relevant Lines: 4242
Covered Lines: 2520
Line Coverage: 59.41%
Relevant Branches: 984
Covered Branches: 517
Branch Coverage: 52.54%
Branches in Coverage %: Yes
Coverage Strength: 150.47 hits per line

💛 - Coveralls

@r-weng
r-weng requested a review from david-yz-liu July 18, 2026 18:45
Comment thread js/components/graph/Graph.js Outdated
let maxX = -Infinity
let maxY = -Infinity

shapes.forEach(shape => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fairly standard loop accumulation so I would just use a for loop rather than calling forEach

Comment thread js/components/graph/Graph.js Outdated
if (bbox !== null) {
viewboxCentreX = (bbox.minX + bbox.maxX) / 2
viewboxCentreY = (bbox.minY + bbox.maxY) / 2
shapesWidth = bbox.width

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants