Skip to content

Commit

Permalink
interpolant fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Jan 19, 2024
1 parent e76c0ed commit 5680be1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 45 deletions.
23 changes: 8 additions & 15 deletions src/content-modules/contextual-tools/InterpolatePoints.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import PalPreview from "../../components/PalPreview.svelte";
$: focusedColors = $focusStore.focusedColors;
$: focusSet = new Set(focusedColors);
$: colors = $colorStore.currentPal.colors;
let colorSpace = "lab";
let numPoints = 1;
Expand Down Expand Up @@ -41,21 +42,15 @@
}
return points;
}
function createInterpolation(forPreview: boolean): Color[] {
function createInterpolation(): Color[] {
const newColors = [];
for (let idx = 0; idx < focusedColors.length - 1; idx++) {
const pointA = colors[focusedColors[idx]];
const pointB = colors[focusedColors[idx + 1]];
const newPoints = createInterpolatedPoints(pointA, pointB);
if (forPreview) {
newColors.push(pointA, ...newPoints);
} else {
newColors.push(...newPoints);
}
}
if (forPreview) {
newColors.push(colors[focusedColors[focusedColors.length - 1]]);
newColors.push(pointA, ...newPoints);
}
newColors.push(colors[focusedColors[focusedColors.length - 1]]);
return newColors;
}
</script>
Expand Down Expand Up @@ -94,15 +89,13 @@
<button
class="{buttonStyle} mt-5"
on:click={() => {
let newColors = [...colors];
const newPoints = createInterpolation(false);
let newColors = [...colors].filter((_, idx) => !focusSet.has(idx));
const offset = newColors.length;
const newPoints = createInterpolation();
newColors = [...newColors, ...newPoints];
colorStore.setCurrentPalColors(newColors);
// also focus all of the new points
focusStore.setColors([
...focusedColors,
...newPoints.map((_, idx) => colors.length + idx),
]);
focusStore.setColors([...newPoints.map((_, idx) => offset + idx)]);
}}
>
Add points
Expand Down
32 changes: 2 additions & 30 deletions src/lib/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,6 @@ export function buildTheme(pal: Palette): any {
};
}

// const groupedBarChart = () => ();
// const scatterPlot = () => ();

// const map = () => ();

// const areaChart = () => ();

// const stackedAreaChart = () => ();
// url: !location.href.includes("localhost")
// ? "https://vega.github.io/editor/data/penguins.json"
// : "data/penguins.json",

// const scatterPlotOrdinal = () => ();

// const heatmap = () => ();

export const charts = [
// groupedBarChart, //
// { group: "categorical", chart: scatterPlot },
// { group: "categorical", chart: map },
// { group: "categorical", chart: areaChart },
// { group: "categorical", chart: stackedAreaChart },
// { group: "ordinal", chart: scatterPlotOrdinal },
// { group: "ordinal", chart: heatmap },
];

const vegaDatasets = [
"7zip.png",
"airports.csv",
Expand Down Expand Up @@ -231,11 +205,9 @@ export async function getSVG(localSpec: string, pal: Palette) {
// : "data/penguins.json",
const matchedDataset = vegaDatasets.find((x) => spec.data?.url?.includes(x));
if (matchedDataset) {
const isLocal = location.href.includes("localhost");
if (isLocal) {
if (location.href.includes("localhost")) {
spec.data.url = `data/${matchedDataset}`;
}
if (!isLocal && spec.data.url === `data/${matchedDataset}`) {
} else {
spec.data.url = `https://vega.github.io/editor/data/${matchedDataset}`;
}
}
Expand Down

0 comments on commit 5680be1

Please sign in to comment.