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 background color support #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ For example, I personally think it would really spiff up a [personal website](ht

# Color Schemes

We also support custom color schemes! You can provide any base color and we will make shades for the chart. Just visit `https://ghchart.rshah.org/<HEX-COLOR>/2016rshah` and replace `<HEX-COLOR>` with your hex color code, not including the leading hashtag. For example if you want a blue-themed chart that is based around the hex color `#409ba5`, you can visit the following route:
We also support custom color schemes! You can provide any base color and we will make shades for the chart.

```
https://ghchart.rshah.org/<BASE-COLOR>/2016rshah
```
Replace ```BASE-COLOR``` with a hex string eg: ```ff0000```

```
https://ghchart.rshah.org/<BASE-COLOR>/<BG-COLOR>/2016rshah
```
Replace ```BASE-COLOR``` & ```BG-COLOR``` with a hex string eg: ```ff0000```


<img src="https://ghchart.rshah.org/409ba5/2016rshah" alt="2016rshah's Github chart" />

<img src="https://ghchart.rshah.org/409ba5/222222/2016rshah" alt="2016rshah's Github chart" />

<img src="https://ghchart.rshah.org/409ba5/2016rshah" alt="2016rshah's Blue Github Chart" />

![2016rshah's Blue Github Chart](https://ghchart.rshah.org/409ba5/2016rshah)


# Contributing
Expand Down
26 changes: 26 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
end
end


get '/:base/:username' do
# Custom color scheme, with default background
headers 'Cache-Control' => "max-age=#{60*60*24}"
headers 'Content-Type' => "image/svg+xml"

Expand All @@ -44,3 +46,27 @@
out << svg
end
end


get '/:base/:background/:username' do
# Custom color scheme, with custom background
headers 'Cache-Control' => "max-age=#{60*60*24}"
headers 'Content-Type' => "image/svg+xml"

username = params[:username].chomp('.svg')

#Makes API backwards compatible
if(params[:base] == "teal" || params[:base] == "halloween" || params[:base] == "default")
scheme = COLOR_SCHEMES[params[:base].to_sym]
else
#this case will be executed a majority of the time
base_color = '#'+params[:base]
background_color = '#'+params[:background]
scheme = [background_color, lighten_color(base_color, 0.3), lighten_color(base_color, 0.2), base_color, darken_color(base_color, 0.8)]
end

svg = GithubChart.new(user: username, colors: scheme).render('svg')
stream do |out|
out << svg
end
end