diff options
author | Georg G <nilsding@nilsding.org> | 2016-10-07 19:15:14 +0200 |
---|---|---|
committer | Georg G <nilsding@nilsding.org> | 2016-10-07 19:16:18 +0200 |
commit | 3530489761fbf892adbf335fe65c0c73b978da39 (patch) | |
tree | 109d2a6b97f49a42dcecf930fce6163676014ead /app/controllers/projects | |
parent | 212cf8f950610570d3d2fb946ea57defd6fc04f3 (diff) | |
download | gitlab-ce-3530489761fbf892adbf335fe65c0c73b978da39.tar.gz |
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.
Diffstat (limited to 'app/controllers/projects')
-rw-r--r-- | app/controllers/projects/graphs_controller.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/app/controllers/projects/graphs_controller.rb b/app/controllers/projects/graphs_controller.rb index 092ef32e6e3..f4f2e5841a0 100644 --- a/app/controllers/projects/graphs_controller.rb +++ b/app/controllers/projects/graphs_controller.rb @@ -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 |