-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ScatterPlot into TableInset showing periodicity trends when heat …
…map selected inspired by https://ptable.netlify.app (github.com/kadinzhang/Periodicity)
- Loading branch information
Showing
6 changed files
with
171 additions
and
1 deletion.
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
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,30 @@ | ||
<script lang="ts"> | ||
import { cubicOut } from 'svelte/easing' | ||
import { tweened } from 'svelte/motion' | ||
export let x: number | ||
export let y: number | ||
export let fill = `gray` | ||
const tX = tweened(0, { duration: 400, easing: cubicOut }) | ||
const tY = tweened(0, { duration: 400, easing: cubicOut }) | ||
$: tX.set(x) | ||
$: tY.set(y) | ||
</script> | ||
|
||
<g transform="translate({$tX} {$tY})" {fill} on:mouseenter> | ||
<circle cx="0" cy="0" r="3" /> | ||
</g> | ||
|
||
<style> | ||
circle { | ||
transition: 0.3s; | ||
stroke: transparent; | ||
stroke-width: 5px; | ||
} | ||
g:hover circle { | ||
fill: orange; | ||
transform: scale(2); | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<script lang="ts"> | ||
import { interpolatePath } from 'd3-interpolate-path' | ||
import { curveMonotoneX, line } from 'd3-shape' | ||
import { cubicOut } from 'svelte/easing' | ||
import { tweened } from 'svelte/motion' | ||
export let data: [number, number, ...unknown[]][] | ||
const lineGenerator = line() | ||
.x((point) => point[0]) | ||
.y((point) => point[1]) | ||
.curve(curveMonotoneX) | ||
const tLinePath = tweened(``, { | ||
duration: 400, | ||
easing: cubicOut, | ||
interpolate: interpolatePath, | ||
}) | ||
$: linePath = lineGenerator(data) | ||
$: tLinePath.set(linePath) | ||
</script> | ||
|
||
<path d={$tLinePath} /> | ||
|
||
<style> | ||
path { | ||
fill: none; | ||
stroke: teal; | ||
stroke-width: 2; | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<script lang="ts"> | ||
import { extent } from 'd3-array' | ||
import { scaleLinear } from 'd3-scale' | ||
import { active_element } from '../../stores' | ||
import { Element } from '../../types' | ||
import Datapoint from './Datapoint.svelte' | ||
import Line from './Line.svelte' | ||
export let data: [number, number, Element][] | ||
export let colorscale: (y: number) => string | undefined = () => undefined | ||
const padding = 10 // pixels | ||
let width: number | ||
let height: number | ||
$: xrange = extent(data.map((point) => point[0])) | ||
$: yrange = extent(data.map((point) => point[1])) | ||
$: x_scale = scaleLinear() | ||
.domain(xrange) | ||
.range([padding, width - padding]) | ||
$: y_scale = scaleLinear() | ||
.domain(yrange) | ||
.range([height - padding, padding]) | ||
$: scaled_data = data | ||
.filter(([x, y]) => !(isNaN(x) || isNaN(y) || x === null || y === null)) | ||
.map(([x, y, ...rest]) => [x_scale(x), y_scale(y), colorscale(y), ...rest]) | ||
</script> | ||
|
||
<div class="scatter" bind:clientWidth={width} bind:clientHeight={height}> | ||
{#if width && height} | ||
<svg {width} {height}> | ||
<Line data={scaled_data} /> | ||
{#each scaled_data as [x, y, fill, element]} | ||
<Datapoint {x} {y} {fill} on:mouseenter={() => ($active_element = element)} /> | ||
{/each} | ||
</svg> | ||
{/if} | ||
</div> | ||
|
||
<style> | ||
.scatter { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
overflow: hidden; | ||
} | ||
</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