Skip to content

Commit

Permalink
add some more interesting examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Jan 16, 2024
1 parent f9abd5f commit a7477c3
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 121 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ To raise the sliders, you need to click on one of the examples that are displaye
- [ ] Once this is done, it make sense to show a tooltip that displays a pair of values as you hover over the graph. (maybe also the hex?)
- [ ] There should be an add color button that adds the current state of the sliders.
- [ ] A single selection sets the sliders. Multi-select does not
- [ ] Might then make sense to move the graph colorspace, range and background color controls into this area.
- [ ] As a short term improvement, raise the sliders when you click on a color in the graphs.
- [x] Might then make sense to move the graph colorspace, range and background color controls into this area.
- [x] As a short term improvement, raise the sliders when you click on a color in the graphs.

## TODOS

- [ ] Make keyboard short cut (option+up/down) for the z-direction
- [ ] Polar stuff
- [ ] Chore: Extract some common types into a top level location (like types.ts type thing)
- [ ] Examples: A (default) example showing annotated math stuff
- [x] Examples: A (default) example showing annotated math stuff
- [ ] Examples: SVG Upload
- [ ] Examples: Vega/Vega-Lite Specification
- [ ] Examples: Examples held as assets somewhere that are downloaded rather than components (for consistency)
Expand Down
160 changes: 160 additions & 0 deletions public/HolyGrail.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions public/fourier.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions public/r2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions public/vis-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 34 additions & 25 deletions src/content-modules/Examples.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import colorStore from "../stores/color-store";
import { charts, idxToKey } from "../lib/charts";
import Vega from "../components/Vega.svelte";
import TinyWebpage from "../content-modules/TinyWebpage.svelte";
import TextBlock from "../content-modules/TextBlock.svelte";
import Modal from "../components/Modal.svelte";
import { buttonStyle } from "../lib/styles";
import { xml } from "@codemirror/lang-xml";
Expand All @@ -24,7 +22,9 @@
function detectColorsInSvgString(svgString: string) {
const colors = new Set<string>();
const regex = /#[0-9a-f]{6}/gi;
// match hex or rgb(255, 255, 255)
const regex = /#(?:[0-9a-fA-F]{3}){1,2}|rgb\((?:\d{1,3},\s*){2}\d{1,3}\)/g;
let match;
while ((match = regex.exec(svgString))) {
colors.add(match[0]);
Expand Down Expand Up @@ -60,6 +60,13 @@
};
colorStore.createNewPal(newPal);
}
const DEMOS = [
{ title: "Mondrian", filename: "./mondrian.svg" },
{ title: "Annotated R2", filename: "./r2.svg" },
{ title: "Annotated Fourier", filename: "./fourier.svg" },
{ title: "VIS Logo", filename: "./vis-logo.svg" },
{ title: "Holy Grail Layout", filename: "./HolyGrail.svg" },
];
</script>

<div class="flex items-center bg-slate-200 px-4">
Expand Down Expand Up @@ -128,10 +135,6 @@
{#if $exampleStore.sections["swatches"]}
<Swatches />
{/if}
{#if $exampleStore.sections.pages}
<TinyWebpage />
<TextBlock />
{/if}
{#each charts as { chart, group }}
{#if sections[group]}
<div class="flex flex-col border-2 border-dashed rounded w-min mr-4">
Expand All @@ -150,34 +153,40 @@
<div slot="header">
<div class="flex justify-between">
<div>Add an Example</div>
{#if modalState === "input-svg"}
<button
class={buttonStyle}
on:click={() => {
fetch("./mondrian.svg")
.then((response) => response.text())
.then((text) => {
value = text;
modalState = "input-svg";
})
.catch((e) => {
console.error(e);
});
}}
>
Demo: Add a Mondrian
</button>
{/if}
</div>
</div>
<div class="h-96 overflow-auto" style="width: 700px;">
<div>
Demos:
{#if modalState === "input-svg"}
{#each DEMOS as demo}
<button
class={buttonStyle}
on:click={() => {
fetch(demo.filename)
.then((response) => response.text())
.then((text) => {
value = text;
modalState = "input-svg";
})
.catch((e) => {
console.error(e);
});
}}
>
{demo.title}
</button>
{/each}
{/if}
</div>
{#if modalState === "input-svg"}
<CodeMirror
bind:value
lang={xml()}
placeholder={"Paste in some SVG text here"}
/>
{/if}

{#if modalState === "edit-colors"}
<div>
<h3>
Expand Down
13 changes: 8 additions & 5 deletions src/content-modules/Swatches.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
{
className: `${common} w-8 h-8 `,
styleMap: (color: Color): string => `background-color: ${color.toHex()};`,
selectionClass: "rotate-12",
},
{
className: `${common} w-6 h-6`,
styleMap: (color: Color): string => `background-color: ${color.toHex()};`,
selectionClass: "rotate-12",
},
{
className: `${common} w-4 h-4 rounded-full`,
styleMap: (color: Color): string => `border: 2px solid ${color.toHex()};`,
selectionClass: "relative top-1 left-1",
},
];
</script>
Expand All @@ -38,7 +41,7 @@
<span>Hold shift to select multiple</span>
</span> -->
</div>
{#each classes as { className, styleMap }}
{#each classes as { className, styleMap, selectionClass }}
<div class="flex justify-center flex-wrap">
{#each colors as color, idx}
<Tooltip top={"100px"} allowDrag={true}>
Expand All @@ -49,7 +52,7 @@
let:toggle
let:tooltipOpen
slot="target"
class={className}
class={`${className} ${focusSet.has(idx) ? selectionClass : ""}`}
style={`${styleMap(color)}`}
on:click={(e) => {
const isFocused = focusSet.has(idx);
Expand Down Expand Up @@ -82,7 +85,6 @@
}
}
}}
class:rotate-45={focusSet.has(idx)}
></button>
</Tooltip>
{/each}
Expand All @@ -91,9 +93,10 @@
<div class="flex flex-wrap justify-center">
{#each colors as color, i}
<div
style={`color: ${color.toHex()}`}
style={`color: ${color.toHex()}; transform: rotate(${
focusSet.has(i) ? 10 : 0
}deg)`}
class="mr-2"
class:mt-2={focusSet.has(i)}
>
{color.toHex()}
</div>
Expand Down
34 changes: 0 additions & 34 deletions src/content-modules/TextBlock.svelte

This file was deleted.

54 changes: 0 additions & 54 deletions src/content-modules/TinyWebpage.svelte

This file was deleted.

0 comments on commit a7477c3

Please sign in to comment.