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

Parse all transform #1475

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

elescogna
Copy link
Contributor

Proposed Changes

This PR adds new parsers for all types of transformations in SVG files, specifically it adds parsers for matrix, rotate, scale, skewX, and skewY. After parsing the SVG transformations, they are represented as matrices.

How I tested my changes:

  • for rotate, scale, skewX, and skewY, I added some arbitrary transformations to the existing Computer Science graph, and I checked that they were displayed accordingly on the courseography graph page after parsing them
  • for matrix, I checked that the result remained unvaried when I substituted each of the of the other transformations for their corresponding matrix equivalent.

...

Screenshots of your changes (if applicable)

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)
🎨 User interface change (change to user interface; provide screenshots)
♻️ 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) X

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.)

app/Svg/Parser.hs Outdated Show resolved Hide resolved
Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@elescogna the code looks good. I left one comment about handling optional arguments, since you seem to have made good progress on that front. Make sure to update the changelog as well.

Keep me posted on your debugging the issues you found through manual testing 👍

app/Svg/Parser.hs Outdated Show resolved Hide resolved
@elescogna elescogna force-pushed the parse-all-transform branch from 57b7d75 to a02b873 Compare December 7, 2024 15:19
@@ -177,6 +177,7 @@ rectToSVG styled courseMap rect
_ -> ""

in S.g ! A.id_ (textValue $ sanitizeId $ shapeId_ rect)
! A.transform (stringValue . show . formatTransform $ shapeTransform rect)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the line I added to add the transformation to the new SVG file. It made sense to me looking at how the other attributes were added, though it does not appear to be working as it is now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry I didn't clue into this earlier! This module is used to generate the SVG for the static images (produced when "exporting"), but not the front-end graph rendering. So you should keep these changes, but also I added one commit which adds the changes for the front-end to get the transform attribute properly applied.

@@ -263,6 +266,7 @@ edgeToSVG styled path =
S.path ! A.id_ (textValue . T.append "path" . pathId_ $ path)
! A.class_ "path"
! A.d (textValue . T.cons 'M' . buildPathString . pathPoints $ path)
! A.transform (stringValue . show . formatTransform $ pathTransform path)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am unsure this is the right place to add this line since it is not included in a tag.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear what you mean by "not included in a tag"

Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@elescogna I did some digging here, but it's a tough problem! First, I added one commit to this branch to incorporate some front-end changes to get the transform attribute to be properly applied. (So you'll need to pull from this branch to get my latest commit.)

As for the actual intersection issues: I wasn't able to pinpoint the source. There's a problem even for just the raw graph (just translations!). I believe the issue is in how the text and shape intersection code is working (e.g. buildRect); when I reverted those changes specifically, the original graph looked better, but still not perfect.

One thing I noticed in Svg.Parser: in parseGraph, a globalTransform is being applied to each point in the associated shape/text/path. This is logically incorrect, and this transform should instead be applied to each entitie's individual transform attribute. I'm not sure if this will itself solve the problem, but you should make this change!

@@ -263,6 +266,7 @@ edgeToSVG styled path =
S.path ! A.id_ (textValue . T.append "path" . pathId_ $ path)
! A.class_ "path"
! A.d (textValue . T.cons 'M' . buildPathString . pathPoints $ path)
! A.transform (stringValue . show . formatTransform $ pathTransform path)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear what you mean by "not included in a tag"

@@ -177,6 +177,7 @@ rectToSVG styled courseMap rect
_ -> ""

in S.g ! A.id_ (textValue $ sanitizeId $ shapeId_ rect)
! A.transform (stringValue . show . formatTransform $ shapeTransform rect)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry I didn't clue into this earlier! This module is used to generate the SVG for the static images (produced when "exporting"), but not the front-end graph rendering. So you should keep these changes, but also I added one commit which adds the changes for the front-end to get the transform attribute properly applied.

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.

2 participants