Skip to content

Commit

Permalink
add precision prop to ColorBar
Browse files Browse the repository at this point in the history
fix ElementScatter max-height applying to element detail pages
set container-type: inline-size on TableInset wrapper
  • Loading branch information
janosh committed Mar 20, 2023
1 parent 15a5d9d commit b9bc392
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/lib/ColorBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
export let tick_side: 'top' | 'bottom' | 'center' = `bottom`
// TODO vertical not fully implemented yet
export let orientation: 'horizontal' | 'vertical' = `horizontal`
export let precision: number = 1
$: if (
tick_labels?.length == 0 ||
Expand Down Expand Up @@ -64,7 +65,7 @@
<div style:background="linear-gradient({grad_dir}, {ramped})" {style}>
{#each tick_labels || [] as tick_label, idx}
<span style="left: calc(100% * {idx} / {tick_labels?.length - 1}); {tick_pos}">
{pretty_num(tick_label, 1)}
{pretty_num(tick_label, precision)}
</span>
{/each}
</div>
Expand Down
5 changes: 1 addition & 4 deletions src/lib/ElementScatter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
}
</script>

<!-- set max-height to ensure ScatterPlot is never taller than 3 Ptable rows
so it doesn't stretch the table. assumes Ptable has 18 rows -->
<ScatterPlot
{y}
x={[...Array(y.length + 1).keys()].slice(1)}
Expand All @@ -32,7 +30,6 @@
{x_label}
on:change
{...$$props}
style="max-height: calc(100cqw / 18 * 3);"
>
<div slot="tooltip" let:x let:y>
{#if $active_element}
Expand All @@ -50,6 +47,6 @@
width: max-content;
box-sizing: border-box;
border-radius: 3pt;
font-size: 2.3cqw;
font-size: min(2.3cqw, 12pt);
}
</style>
2 changes: 1 addition & 1 deletion src/lib/ScatterPlot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
font-weight: lighter;
overflow: visible;
z-index: 1;
font-size: 2.3cqw;
font-size: min(2.3cqw, 12pt);
}
line {
stroke: gray;
Expand Down
1 change: 1 addition & 0 deletions src/lib/TableInset.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
box-sizing: border-box;
grid-row: 1 / span 3;
grid-column: 3 / span 10;
container-type: inline-size;
}
</style>
2 changes: 0 additions & 2 deletions src/routes/(demos)/element-tile/+page.svx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
`ElementTile.svelte` automatically changes text color to ensure high contrast with its background. If its background is transparent, it traverses up the DOM tree to find the first element with non-transparent background color. This an, of course, go wrong e.g. if the tile is absolutely positioned outside its parent element. In that case, pass an explicit `text_color` prop and `text_color_threshold={null}` to `ElementTile` to override the automatic color selection.

```svelte example stackblitz code_above

```svelte example stackblitz code_above
<script>
import { ElementTile, element_data } from '$lib'
Expand Down
3 changes: 3 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
bind:active_category={$active_category}
links="name"
>
<!-- set max-height to ensure ScatterPlot is never taller than 3 PeriodicTable
rows so it doesn't stretch the table. assumes PeriodicTable has 18 rows -->
<TableInset slot="inset">
{#if heatmap_key}
<ElementScatter
Expand All @@ -73,6 +75,7 @@
on:change={(e) => ($active_element = element_data[e.detail.x - 1])}
x_label_yshift={42}
{color_scale}
style="max-height: calc(100cqw / 10 * 3);"
/>
{:else}
<ElementStats --font-size="1vw" element={$last_element} />
Expand Down
7 changes: 1 addition & 6 deletions src/routes/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,7 @@
>
<a href={item.name.toLowerCase()} style="display: flex; flex-direction: column;">
<h3>
{#if kind == `next`}
Next
<Icon icon="carbon:next-filled" inline />
{:else}
<Icon icon="carbon:previous-filled" inline />Previous
{/if}
{@html kind == `next` ? `Next &rarr;` : `&larr; Previous`}
</h3>
<ElementPhoto element={item} style="width: 200px; border-radius: 4pt;" />
<ElementTile
Expand Down

0 comments on commit b9bc392

Please sign in to comment.