2022-04-12 04:18:42 +08:00
|
|
|
<script lang="ts">
|
2022-08-31 04:56:59 +08:00
|
|
|
//@ts-ignore
|
|
|
|
import { csvParseRows, tsvParseRows } from "d3-dsv";
|
|
|
|
export let value: Array<Array<string | number>> | string;
|
|
|
|
export let samples_dir: string;
|
|
|
|
let hovered = false;
|
2022-12-27 23:48:32 +08:00
|
|
|
let loaded_value: Array<Array<string | number>> | string = value;
|
|
|
|
let loaded = Array.isArray(loaded_value);
|
2022-08-31 04:56:59 +08:00
|
|
|
|
|
|
|
$: if (!loaded && typeof value === "string" && /\.[a-zA-Z]+$/.test(value)) {
|
|
|
|
fetch(samples_dir + value)
|
|
|
|
.then((v) => v.text())
|
|
|
|
.then((v) => {
|
|
|
|
try {
|
|
|
|
if ((value as string).endsWith("csv")) {
|
|
|
|
const small_df = v
|
|
|
|
.split("\n")
|
|
|
|
.slice(0, 4)
|
|
|
|
.map((v) => v.split(",").slice(0, 4).join(","))
|
|
|
|
.join("\n");
|
|
|
|
|
2022-12-27 23:48:32 +08:00
|
|
|
loaded_value = csvParseRows(small_df);
|
2022-08-31 04:56:59 +08:00
|
|
|
} else if ((value as string).endsWith("tsv")) {
|
|
|
|
const small_df = v
|
|
|
|
.split("\n")
|
|
|
|
.slice(0, 4)
|
|
|
|
.map((v) => v.split("\t").slice(0, 4).join("\t"))
|
|
|
|
.join("\n");
|
|
|
|
|
2022-12-27 23:48:32 +08:00
|
|
|
loaded_value = tsvParseRows(small_df);
|
2022-08-31 04:56:59 +08:00
|
|
|
} else {
|
|
|
|
throw new Error(
|
|
|
|
"Incorrect format, only CSV and TSV files are supported"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
loaded = true;
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-04-12 04:18:42 +08:00
|
|
|
</script>
|
|
|
|
|
2022-08-31 04:56:59 +08:00
|
|
|
{#if loaded}
|
|
|
|
<div
|
|
|
|
class="gr-sample-dataframe"
|
|
|
|
on:mouseenter={() => (hovered = true)}
|
|
|
|
on:mouseleave={() => (hovered = false)}
|
|
|
|
>
|
|
|
|
<table class="gr-sample-dataframe relative">
|
2022-12-27 23:48:32 +08:00
|
|
|
{#each loaded_value.slice(0, 3) as row, i}
|
2022-08-31 04:56:59 +08:00
|
|
|
<tr>
|
|
|
|
{#each row.slice(0, 3) as cell, j}
|
|
|
|
<td
|
|
|
|
class="p-2 {i < 3
|
|
|
|
? 'border-b border-b-slate-300 dark:border-b-slate-700'
|
|
|
|
: ''}
|
|
|
|
{j < 3 ? 'border-r border-r-slate-300 dark:border-r-slate-700 ' : ''}"
|
|
|
|
>{cell}</td
|
|
|
|
>
|
|
|
|
{/each}
|
|
|
|
{#if row.length > 3}
|
|
|
|
<td
|
|
|
|
class="p-2 border-r border-b border-r-slate-300 dark:border-r-slate-700 border-b-slate-300 dark:border-b-slate-700"
|
|
|
|
>…</td
|
|
|
|
>
|
|
|
|
{/if}
|
|
|
|
</tr>
|
2022-04-12 04:18:42 +08:00
|
|
|
{/each}
|
2022-08-31 04:56:59 +08:00
|
|
|
{#if value.length > 3}
|
|
|
|
<div
|
2022-09-01 01:56:18 +08:00
|
|
|
class="absolute w-full h-[50%] bottom-0 bg-gradient-to-b from-[rgba(255,255,255,0)] dark:from-[rgba(0,0,0,0)] to-white"
|
2022-08-31 04:56:59 +08:00
|
|
|
class:dark:to-gray-950={!hovered}
|
|
|
|
class:dark:to-gray-800={hovered}
|
|
|
|
class:to-gray-50={hovered}
|
|
|
|
/>
|
2022-04-12 04:18:42 +08:00
|
|
|
{/if}
|
2022-08-31 04:56:59 +08:00
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
{/if}
|