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.
This commit is contained in:
parent
212cf8f950
commit
3530489761
1 changed files with 7 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue