File size: 1,686 Bytes
a18645a
a0194e7
a18645a
bdf2455
29d6ac1
a18645a
 
a0194e7
 
fcd804b
a0194e7
29d6ac1
 
 
 
 
 
 
 
 
a18645a
 
 
a0194e7
 
dc3ebef
 
eda8f97
 
 
 
 
 
29d6ac1
eda8f97
 
 
fcd804b
a18645a
a0194e7
d994c06
 
 
 
 
a18645a
 
 
 
 
 
 
fcd804b
a18645a
eda8f97
 
 
a18645a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<script lang="ts">
  import { useNodes, type NodeProps } from '@xyflow/svelte';
  import LynxKiteNode from './LynxKiteNode.svelte';
  import Table from './Table.svelte';
  import SvelteMarkdown from 'svelte-markdown'
  type $$Props = NodeProps;
  export let data: $$Props['data'];
  const nodes = useNodes(); // We don't properly get updates to "data". This is a hack.
  $: D = $nodes && data;
  const open = {};
  $: single = D.display?.value?.dataframes && Object.keys(D.display.value.dataframes).length === 1;
  function toMD(v) {
    if (typeof v === 'string') {
      return v;
    }
    if (Array.isArray(v)) {
      return v.map(toMD).join('\n\n');
    }
    return JSON.stringify(v);
  }
</script>

<LynxKiteNode {...$$props}>
  {#if D?.display?.value}
    {#each Object.entries(D.display.value.dataframes || {}) as [name, df]}
      {#if !single}<div class="df-head" on:click={() => open[name] = !open[name]}>{name}</div>{/if}
      {#if single || open[name]}
        {#if df.data.length > 1}
          <Table columns={df.columns} data={df.data} />
        {:else}
          <dl>
          {#each df.columns as c, i}
            <dt>{c}</dt>
            <dd><SvelteMarkdown source={toMD(df.data[0][i])} /></dd>
          {/each}
          </dl>
        {/if}
      {/if}
    {/each}
    {#each Object.entries(D.display.value.others || {}) as [name, o]}
      <div class="df-head" on:click={() => open[name] = !open[name]}>{name}</div>
      {#if open[name]}
      <pre>{o}</pre>
      {/if}
    {/each}
  {/if}
</LynxKiteNode>
<style>
  .df-head {
    font-weight: bold;
    padding: 8px;
    background: #f0f0f0;
    cursor: pointer;
  }
  dl {
    margin: 10px;
  }
</style>