-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plus new demo page src/routes/(demos)/color-bar/+page.md add support for objects as heatmap_values i.e. maps from element symbols to numbers, previous only number arrays were supported
- Loading branch information
Showing
9 changed files
with
180 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<script lang="ts"> | ||
import * as d3sc from 'd3-scale-chromatic' | ||
export let text: string = `` | ||
export let color_scale: ((x: number) => string) | null = null | ||
export let text_side: 'left' | 'right' | 'top' | 'bottom' = `left` | ||
export let style: string | null = null | ||
export let text_style: string | null = null | ||
export let wrapper_style: string | null = null | ||
$: if (color_scale === null) { | ||
color_scale = d3sc[`interpolate${text}`] | ||
if (color_scale === undefined) console.error(`Color scale not found: ${text}`) | ||
} | ||
$: ramped = [...Array(10).keys()].map((idx) => color_scale?.(idx / 10)) | ||
$: flex_dir = { | ||
left: `row`, | ||
right: `row-reverse`, | ||
top: `column`, | ||
bottom: `column-reverse`, | ||
}[text_side] | ||
</script> | ||
|
||
<div style:flex-direction={flex_dir} style={wrapper_style}> | ||
{#if text}<span style={text_style}>{text}</span>{/if} | ||
<div style:background="linear-gradient(to right, {ramped})" {style} /> | ||
</div> | ||
|
||
<style> | ||
div { | ||
display: flex; | ||
gap: 5pt; | ||
width: max-content; | ||
} | ||
div > div { | ||
border-radius: 2pt; | ||
height: 1em; | ||
width: 10em; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
`ColorBar.svelte` | ||
|
||
ColorBar supports <code>text_side = ['top', 'bottom', 'left', 'right']</code> | ||
|
||
```svelte example stackblitz | ||
<script> | ||
import { ColorBar } from '$lib' | ||
import * as d3sc from 'd3-scale-chromatic' | ||
const names = Object.keys(d3sc).filter((key) => key.startsWith(`interpolate`)) | ||
</script> | ||
<section> | ||
{#each [`top`, `bottom`, `left`, `right`] as text_side, idx} | ||
<ul> | ||
<code>{text_side}</code> | ||
{#each names.slice(idx * 5, 5 * idx + 5) as name} | ||
<li> | ||
<ColorBar | ||
text={name.replace(`interpolate`, ``)} | ||
{text_side} | ||
text_style="min-width: 5em;" | ||
/> | ||
</li> | ||
{/each} | ||
</ul> | ||
{/each} | ||
</section> | ||
<style> | ||
section { | ||
display: flex; | ||
overflow: scroll; | ||
gap: 2em; | ||
} | ||
section > ul { | ||
list-style: none; | ||
padding: 0; | ||
} | ||
section > ul > li { | ||
padding: 1ex; | ||
} | ||
section > ul > code { | ||
font-size: 16pt; | ||
} | ||
</style> | ||
``` | ||
|
||
You can also fat and skinny bars: | ||
|
||
```svelte example stackblitz | ||
<script> | ||
import { ColorBar } from '$lib' | ||
const wrapper_style = 'place-items: center;' | ||
</script> | ||
<ColorBar text="Viridis" {wrapper_style} style="width: 10em; height: 1ex;" /> | ||
<br /> | ||
<ColorBar text="Viridis" {wrapper_style} style="width: 3em; height: 2em;" /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters