From 3530489761fbf892adbf335fe65c0c73b978da39 Mon Sep 17 00:00:00 2001 From: Georg G Date: Fri, 7 Oct 2016 19:15:14 +0200 Subject: [PATCH] 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. --- app/controllers/projects/graphs_controller.rb | 10 +++++++--- 1 file 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 -- GitLab