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
|
def languages
|
||||||
@languages = Linguist::Repository.new(@repository.rugged, @repository.rugged.head.target_id).languages
|
@languages = Linguist::Repository.new(@repository.rugged, @repository.rugged.head.target_id).languages
|
||||||
total = @languages.map(&:last).sum
|
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|
|
@languages = @languages.map do |language|
|
||||||
name, share = 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),
|
value: (share.to_f * 100 / total).round(2),
|
||||||
label: name,
|
label: name,
|
||||||
color: "##{color}",
|
color: color,
|
||||||
highlight: "##{color}"
|
highlight: color
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue