Skip to content
Snippets Groups Projects
Unverified Commit 86c2ec28 authored by Mahatthana (Kelvin) Nomsawadi's avatar Mahatthana (Kelvin) Nomsawadi Committed by GitHub
Browse files

Fix whitelabeled colors aren't respected in x-rays (#22458)

parent 1357f3c3
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
[metabase.automagic-dashboards.filters :as filters]
[metabase.models.card :as card]
[metabase.models.collection :as collection]
[metabase.public-settings :as public-settings]
[metabase.query-processor.util :as qp.util]
[metabase.util.i18n :refer [trs]]
[toucan.db :as db]))
......@@ -43,9 +44,20 @@
:location "/")
(create-collection! "Automatically Generated Dashboards" "#509EE3" nil nil)))
(def colors
"Colors used for coloring charts and collections."
["#509EE3" "#9CC177" "#A989C5" "#EF8C8C" "#f9d45c" "#F1B556" "#A6E7F3" "#7172AD"])
(defn colors
"A vector of colors used for coloring charts and collections. Uses [[public-settings/application-colors]] for user choices."
[]
(let [order [:brand :accent1 :accent2 :accent3 :accent4 :accent5 :accent6 :accent7]
colors-map (merge {:brand "#509EE3"
:accent1 "#88BF4D"
:accent2 "#A989C5"
:accent3 "#EF8C8C"
:accent4 "#F9D45C"
:accent5 "#F2A86F"
:accent6 "#98D9D9"
:accent7 "#7172AD"}
(public-settings/application-colors))]
(into [] (map colors-map) order)))
(defn- ensure-distinct-colors
[candidates]
......@@ -55,14 +67,14 @@
(fn [acc color count]
(if (= count 1)
(conj acc color)
(concat acc [color (first (drop-while (conj (set acc) color) colors))])))
(concat acc [color (first (drop-while (conj (set acc) color) (colors)))])))
[])))
(defn map-to-colors
"Map given objects to distinct colors."
[objs]
(->> objs
(map (comp colors #(mod % (count colors)) hash))
(map (comp (colors) #(mod % (count (colors))) hash))
ensure-distinct-colors))
(defn- colorize
......
......@@ -350,7 +350,7 @@
dashcards (:ordered_cards dashboard)
collection (populate/create-collection!
(ensure-unique-collection-name (:name dashboard) parent-collection-id)
(rand-nth populate/colors)
(rand-nth (populate/colors))
"Automatically generated cards."
parent-collection-id)
dashboard (db/insert! Dashboard
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment