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