Skip to content

Commit

Permalink
blerp blerp blerp
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Jan 19, 2024
1 parent 6175d6a commit d23a016
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/lib/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d23a016

Please sign in to comment.