buildLegend(
		colorPalette,
		arrayOfStringValues,
		minValue,
		maxValue,
		legendType,
		valueFmt,
		chartType,
		legendId,
		value,
		legend
	) {
		const createLegendObject = () => ({
			colorPalette,
			values: arrayOfStringValues,
			minValue,
			maxValue,
			legendType,
			valueFmt,
			chartType,
			legendId,
			value,
			legend
		});

		this.#legendData.update((legendData) => {
			const existingIndex = legendData.findIndex((data) => data.legendId === legendId);

			if (existingIndex !== -1) {
				// Update existing legend
				return legendData.map((data, index) =>
					index === existingIndex ? { ...legend, ...createLegendObject() } : data
				);
			} else if (legendId !== undefined) {
				// Add new legend if legendId is defined
				return [...legendData, createLegendObject()];
			}
			// If legendId is undefined, return the original array
			return legendData;
		});
	}
@type {import('svelte/store').Writable<
{ values: string[], colorPalette: string[], minValue: number, maxValue: number, legendType: string, valueFmt: string, chartType: string, legendId: string, value: string, legend: boolean }[]
>}