diff --git a/src/lib/charts.ts b/src/lib/charts.ts index 5eb899f7..f2706a43 100644 --- a/src/lib/charts.ts +++ b/src/lib/charts.ts @@ -191,30 +191,22 @@ export async function getSVG(localSpec: string, pal: Palette) { if (results[newKey]) return results[newKey]; const theme = buildTheme(pal); let spec: any; + + const cleanSpec = vegaDatasets.reduce((acc, x) => { + const breakKey = `url": "data/${x}`; + const joinKey = `url": "https://vega.github.io/editor/data/${x}`; + return acc.split(breakKey).join(joinKey); + }, localSpec); + try { - spec = JSON.parse(localSpec); + spec = JSON.parse(cleanSpec); } catch (e) { - console.error(e, localSpec); + console.error(e, cleanSpec); return ""; } if (spec.$schema.includes("vega-lite")) { spec = vegaLite.compile(spec, { config: theme }).spec; } - // // url: !location.href.includes("localhost") - // ? "https://vega.github.io/editor/data/penguins.json" - // : "data/penguins.json", - const matchedDataset = vegaDatasets.find((x) => spec.data?.url?.includes(x)); - console.log("asd", matchedDataset, spec.data?.url, vegaDatasets); - if (matchedDataset) { - console.log("XXXX", matchedDataset); - if (location.href.includes("localhost")) { - console.log("a"); - spec.data.url = `data/${matchedDataset}`; - } else { - console.log("b"); - spec.data.url = `https://vega.github.io/editor/data/${matchedDataset}`; - } - } const runtime = vega.parse(spec, theme); const view = await new vega.View(runtime, { renderer: "svg" }).runAsync();