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

Request for an SVG Version with Border Support #137

Open
wickdynex opened this issue Dec 19, 2024 · 4 comments
Open

Request for an SVG Version with Border Support #137

wickdynex opened this issue Dec 19, 2024 · 4 comments

Comments

@wickdynex
Copy link

Background:

First of all, thank you for developing and maintaining this fun and useful project! While using the GitHub Snake contribution graph, I encountered a small issue:

Currently, the generated SVG file does not have a border, while other components in my GitHub README (such as GitHub Stats and Streak Stats) have borders by default. This creates a visual inconsistency, as the elements look mismatched due to different border styles.

Request:

I would like to have an option to generate an SVG version with a border, so that it aligns with other GitHub components that already have borders, improving the overall consistency and visual appeal of the page.

My Questions:

  1. Is there already a way to generate an SVG version with a border?

    • If so, could you provide guidance on how to use this feature? For example, is there a specific configuration or option to enable borders on the SVG?
  2. If this feature is not currently available, could you consider adding it in a future version?

    • Ideally, I would like to customize the border style (e.g., color, width), or at least have a simple default border.

Conclusion:

I would greatly appreciate it if this feature could be added in future versions, as it would make GitHub profile presentations more consistent and visually appealing.

Thanks again for your work on this project, and I look forward to your response!😊

@Platane
Copy link
Owner

Platane commented Dec 20, 2024

Hi, I don't plan to add that as an option, however you can manipulate the generated svg

There is likely nice way to do it by parsing the svg and manipulating svg element,

I wrote a hacky script to manipulate the svg string instead

// read the svg file as string 
// [...]

// extract the svg viewBox values
const [, vb] = svgContent.match(/viewBox="([^"]*)"/);
const [minX, minY, width, height] = vb
  .trim()
  .split(" ")
  .map((x) => +x);
const viewBox = { minX, minY, width, height };

// generate the border as rect
const strokeWidth = 1;
const svgBorder = `<rect
        x="${viewBox.minX + strokeWidth / 2}"
        y="${viewBox.minY + strokeWidth / 2}"
        width="${viewBox.width - strokeWidth}"
        height="${viewBox.height - strokeWidth}"
        rx="12"
        stroke="#e4e2e2"
        stroke-width="${strokeWidth}"
        fill="none"
        />`;

// append the rect at the end of the svg
const svgContentWithBorder = svgContent.replace("</svg>", svgBorder + "</svg>");

// write the svg file
// [...]

it looks like this

download

you might want to add some more padding by manipulating the viewBox param

@wickdynex
Copy link
Author

Hi @Platane,

I'm a beginner in front-end development, so please excuse any mistakes in my question.

Your response seems to suggest using JavaScript to add a border to the SVG image. However, I want to use this SVG in my GitHub Profile, and GitHub doesn't support JavaScript. I also tried using the <html> tag for this, but it didn't work as expected.

Could you help me add a border directly to the SVG? Also, this action can provide a manual or steps that other users can follow to do like this.

Code in GitHub Profile

<h3 align="center"><strong>GitHub Activity Tracker</strong></h3>

<picture>
  <!-- If the user prefers dark mode, show snake-dark.svg -->
  <source media="(prefers-color-scheme: dark)" srcset="https://github.com/wickdynex/wickdynex/blob/gh-pages/snake-dark.svg" />
  
  <!-- If the user prefers light mode, show snake.svg -->
  <source media="(prefers-color-scheme: light)" srcset="https://github.com/wickdynex/wickdynex/blob/gh-pages/snake-light.svg" />
  
  <!-- Default image if media queries are not supported -->
  <img src="https://github.com/wickdynex/wickdynex/blob/gh-pages/snake-dark.svg" alt="Snake animation" />
</picture>

I've used different param to generate 2 version of sig image to invert in different system settings.

Source Code

Link: README.md

Additional Notes

I understand this may not be part of your responsibilities, and if you're too busy or unable to help, I completely understand. However, I would be truly grateful if you could take some time to help me figure out this problem, which has been confusing me for several days. Thank you so much in advance! 🥺

@Platane
Copy link
Owner

Platane commented Dec 21, 2024

what you can do is manipulate the svg when it's created: when the github action runs

I think the cleanest way to achieve that would be to fork this action.

Or you can insert a step to the github action workflow. For example with github-script which allows to run js code

@wickdynex
Copy link
Author

Genius! I was stuck in HTML format which didn't support JS and CSS. But now I can use JS in GitHub Actions! Thanks for the tip, truly!

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

No branches or pull requests

2 participants