|
|
@@ -447,6 +447,39 @@ function getCategoryLabels($categoryIds)
|
|
|
return $labels;
|
|
|
}
|
|
|
|
|
|
+function getCategoryChipPalette($categoryId)
|
|
|
+{
|
|
|
+ $categoryId = normalizeCategoryId($categoryId);
|
|
|
+ if ($categoryId === "") {
|
|
|
+ return [
|
|
|
+ "background" => "#ebe8df",
|
|
|
+ "border" => "#d0c8b5",
|
|
|
+ "text" => "#4b4b4b",
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $hash = crc32($categoryId);
|
|
|
+ if ($hash < 0) {
|
|
|
+ $hash = $hash * -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Spread hues across a distinct red -> blue range.
|
|
|
+ $hueSteps = [0, 16, 32, 48, 66, 84, 104, 128, 152, 176, 200, 224];
|
|
|
+ $hue = $hueSteps[$hash % count($hueSteps)];
|
|
|
+ $saturation = 44 + (($hash >> 8) % 10);
|
|
|
+ $lightness = 84 + (($hash >> 16) % 7);
|
|
|
+
|
|
|
+ $background = "hsl(" . $hue . ", " . $saturation . "%, " . $lightness . "%)";
|
|
|
+ $border = "hsl(" . $hue . ", " . ($saturation + 8) . "%, " . ($lightness - 16) . "%)";
|
|
|
+ $text = "hsl(" . $hue . ", " . ($saturation + 18) . "%, 24%)";
|
|
|
+
|
|
|
+ return [
|
|
|
+ "background" => $background,
|
|
|
+ "border" => $border,
|
|
|
+ "text" => $text,
|
|
|
+ ];
|
|
|
+}
|
|
|
+
|
|
|
function generateCategoryIdFromLabel($label, $existingCategories = [])
|
|
|
{
|
|
|
$baseId = normalizeCategoryId($label);
|