Improve and fix issues with color generation
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { GenerateColor } from "$lib/utils";
|
||||
import { GenerateColor, RemoveExistingColors } from "$lib/utils";
|
||||
import { main } from "$wails/models";
|
||||
import EmptyFoodComp from "./EmptyFoodComp.svelte";
|
||||
import FoodComp from "./FoodComp.svelte";
|
||||
|
||||
export let items: main.Food[] = [];
|
||||
RemoveExistingColors();
|
||||
|
||||
let minCal = 1e5;
|
||||
let maxCal = 0;
|
||||
|
@@ -1,10 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { GenerateColor } from "$lib/utils";
|
||||
import { GenerateColor, RemoveExistingColors } from "$lib/utils";
|
||||
import EmptyWeightComp from "$components/Weight/EmptyWeightComp.svelte";
|
||||
import WeightComp from "$components/Weight/WeightComp.svelte";
|
||||
import { main } from "$wails/models";
|
||||
|
||||
export let items: main.Weight[] = [];
|
||||
RemoveExistingColors();
|
||||
|
||||
const dateColors: Map<string, string> = new Map<string, string>();
|
||||
|
||||
|
@@ -68,8 +68,11 @@ function GenerateRandomHSL(): Color {
|
||||
|
||||
const existingColors: Color[] = [];
|
||||
|
||||
function RemoveExistingColors() {
|
||||
existingColors.length = 0;
|
||||
}
|
||||
function GenerateColor(): string {
|
||||
const minDistance = 15;
|
||||
const minDistance = 5;
|
||||
|
||||
let newColor: Color;
|
||||
let isDistinct = false;
|
||||
@@ -89,8 +92,10 @@ function GenerateColor(): string {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isDistinct) {
|
||||
existingColors.push(newColor);
|
||||
}
|
||||
}
|
||||
|
||||
// We can not reach this point without having a color generated
|
||||
// @ts-ignore
|
||||
@@ -104,5 +109,5 @@ function LerpColor(color1: Color, color2: Color, t: number): Color {
|
||||
return { h, s, l };
|
||||
}
|
||||
|
||||
export { GenerateColor, LerpColor };
|
||||
export { GenerateColor, LerpColor, RemoveExistingColors };
|
||||
export type { Color };
|
||||
|
Reference in New Issue
Block a user