From 106dee13ac04dec06653010d379748c0f4e7bedf Mon Sep 17 00:00:00 2001 From: Nulo Date: Sat, 23 Dec 2023 21:13:06 -0300 Subject: [PATCH] mostrar colores y nombres de supermercados --- sitio/src/routes/ean/[ean]/Chart.svelte | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sitio/src/routes/ean/[ean]/Chart.svelte b/sitio/src/routes/ean/[ean]/Chart.svelte index f2905a2..07f9cda 100644 --- a/sitio/src/routes/ean/[ean]/Chart.svelte +++ b/sitio/src/routes/ean/[ean]/Chart.svelte @@ -5,10 +5,29 @@ export let precios: Precio[]; + enum Supermercado { + Dia = "Dia", + Carrefour = "Carrefour", + Coto = "Coto", + } + + const hosts: { [host: string]: Supermercado } = { + "diaonline.supermercadosdia.com.ar": Supermercado.Dia, + "www.carrefour.com.ar": Supermercado.Carrefour, + "www.cotodigital3.com.ar": Supermercado.Coto, + }; + const colorBySupermercado: { [supermercado in Supermercado]: string } = { + [Supermercado.Dia]: "#d52b1e", + [Supermercado.Carrefour]: "#19549d", + [Supermercado.Coto]: "#e20025", + }; + $: datasets = precios .map((p) => new URL(p.url!).hostname) .filter(onlyUnique) .map((host) => { + const supermercado = hosts[host]; + const ps = precios .filter((p) => new URL(p.url!).hostname === host) .filter( @@ -16,7 +35,7 @@ p.precioCentavos !== null, ); return { - label: host, + label: supermercado, data: [ ...ps.map((p) => ({ x: p.fetchedAt, @@ -30,7 +49,7 @@ ], fill: false, - borderColor: `${host}`, + borderColor: colorBySupermercado[supermercado], tension: 0.1, }; });