Commit 35304897 authored by Georg G's avatar Georg G

Use defined colour for a language when available

This commit changes the colours of languages in the language graph to
the ones Linguist has defined.  When there is no colour defined for a
language in Linguist, it will fall back to the old method of finding
a colour.
parent 212cf8f9
......@@ -35,15 +35,19 @@ class Projects::GraphsController < Projects::ApplicationController
def languages
@languages = Linguist::Repository.new(@repository.rugged, @repository.rugged.head.target_id).languages
total = @languages.map(&:last).sum
colors = Linguist::Language.colors.
select { |lang| @languages.include? lang.name }.
map { |lang| [lang.name, lang.color] }.
to_h
@languages = @languages.map do |language|
name, share = language
color = Digest::SHA256.hexdigest(name)[0...6]
color = colors[name] || "##{Digest::SHA256.hexdigest(name)[0...6]}"
{
value: (share.to_f * 100 / total).round(2),
label: name,
color: "##{color}",
highlight: "##{color}"
color: color,
highlight: color
}
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment