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

add option to removeDimensions #58

Merged
merged 8 commits into from Mar 8, 2018
Merged

add option to removeDimensions #58

merged 8 commits into from Mar 8, 2018

Conversation

lifeiscontent
Copy link
Contributor

@lifeiscontent lifeiscontent commented Mar 5, 2018

I'd like to be able to specify width/height within props, this lets me do that.

@neoziro

I also took the liberty to sort the config options/defaults/docs. Let me know if you want me to pull that out.

I made them separate commits, so you don't get overloaded with a diff when reviewing.

@codecov
Copy link

codecov bot commented Mar 5, 2018

Codecov Report

Merging #58 into master will increase coverage by 0.46%.
The diff coverage is 77.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #58      +/-   ##
==========================================
+ Coverage   46.27%   46.74%   +0.46%     
==========================================
  Files          19       20       +1     
  Lines         255      261       +6     
  Branches       52       54       +2     
==========================================
+ Hits          118      122       +4     
- Misses        116      117       +1     
- Partials       21       22       +1
Impacted Files Coverage Δ
src/cli/index.js 0% <ø> (ø) ⬆️
src/configToOptions.js 88% <100%> (+0.5%) ⬆️
src/h2x/removeDimensions.js 60% <60%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ecf61a3...4666d39. Read the comment docs.

@wuweiweiwu
Copy link
Contributor

wuweiweiwu commented Mar 6, 2018

@lifeiscontent

the svgo implementation used doesn't remove dimension attributes if viewBox attribute does not exist.

https://github.com/svg/svgo/blob/master/plugins/removeDimensions.js

This is a good article explaining those properties. https://www.sarasoueidan.com/blog/svg-coordinate-systems/

And also you don't need the viewBox attribute in order to specify height and width. You can also have viewBox without height and width (in which case viewBox is irrelevant and height and width are both 100%) 😄

Copy link
Owner

@gregberge gregberge left a comment

Choose a reason for hiding this comment

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

@lifeiscontent thanks!

Can you please speak with @wuweiweiwu to decide which PR is the most relevant. For me you are the first so you are legit, but if you prefer to let @wuweiweiwu it is your choice.

  • Documented option is still missing in README (you updated only CLI)

@@ -57,6 +58,7 @@ function configToOptions(config = {}) {
const svgoConfig = { plugins }
if (!config.title || config.icon) plugins.push({ removeTitle: {} })
else if (config.title) plugins.push({ removeTitle: false })
if (!config.dimensions) plugins.push({ removeDimensions: true })
Copy link
Owner

Choose a reason for hiding this comment

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

As @wuweiweiwu this seems to not be sufficient.

@lifeiscontent
Copy link
Contributor Author

@neoziro updating now, please stand by. 👍

@lifeiscontent
Copy link
Contributor Author

@neoziro do you mind that I'm sorting the options/docs? If not, I'll do that, but I don't think I'll be able to do it in 1 commit. I've already done it, but I can revert if necessary.

@lifeiscontent
Copy link
Contributor Author

@neoziro also added docs for some undocumented stuff, please review.

@wuweiweiwu
Copy link
Contributor

wuweiweiwu commented Mar 7, 2018

@neoziro @lifeiscontent I think you should have it! :)

config.replaceAttrValues.forEach(([oldValue, newValue]) => {
plugins.push(replaceAttrValue(oldValue, newValue))
})
if (!config.dimensions) {
plugins.push(...['width', 'height'].map(stripAttribute))
Copy link
Contributor

Choose a reason for hiding this comment

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

@lifeiscontent

@neoziro addressed this in my PR but this will remove all height and width attributes. Regardless if its in an svg or not.

I think the best way is to actually implement a h2x plugin similar to emSize

Something like:

const removeDimensions = () => ({
  visitor: {
    JSXElement: {
      enter(path) {
        // Skip if not svg node
        if (path.node.name !== 'svg') return

        const otherAttributes = []
        path.node.attributes.forEach(attr => {
          if (attr.name === 'width' || attr.name === 'height'){
          // NO OP
          } 
          else otherAttributes.push(attr)
        })

        path.node.attributes = otherAttributes
      },
    },
  },
})

I've tested this and it works :)

@wuweiweiwu
Copy link
Contributor

wuweiweiwu commented Mar 7, 2018

@lifeiscontent

Also I think its best practices to not change stuff outside the scope of the PR. For example. Your doc edits should probably be in another PR. cc: @neoziro

README.md Outdated

### JSX Brackets
### Version
Copy link
Owner

Choose a reason for hiding this comment

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

Should not appear in options

README.md Outdated

### Quotes
### Help
Copy link
Owner

Choose a reason for hiding this comment

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

Should not appear in options

README.md Outdated

### Dimensions

Remove width and height.
Copy link
Owner

Choose a reason for hiding this comment

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

Remove width and height from root SVG tag.

@gregberge
Copy link
Owner

@lifeiscontent your documentation reordering is OK for me in that PR, it is not optimal but it is OK. Thanks for taking care of it.

  • Can you please remove help and version from options, this is CLI relative and should not appear in that section
  • Can you please change the description of the option and use @wuweiweiwu suggested strategy to be sure that only root width and height are removed?

Thanks!

@lifeiscontent
Copy link
Contributor Author

@wuweiweiwu I agree with you about the scope, I kinda went down a small rabbit hole, but I figured since this project had given me a lot of benefit, I might as well knock out some cleanup work as well, and as you can see in my previous post to @neoziro I told him I'd happily pull it out.

anyway, @neoziro I've updated the docs and reimplemented @wuweiweiwu's implementation for removeDimensions.

@gregberge
Copy link
Owner

@lifeiscontent thanks you!!

@gregberge gregberge merged commit 7357e7c into gregberge:master Mar 8, 2018
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.

None yet

3 participants