File: DemoApp.svelte

package info (click to toggle)
python-pyinstrument 5.1.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,672 kB
  • sloc: python: 6,907; ansic: 897; makefile: 46; sh: 26; javascript: 18
file content (111 lines) | stat: -rw-r--r-- 2,385 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<script lang="ts">
  import pyinstrumentHTMLRenderer from "../src/main";

  const fileURLs = import.meta.glob("../demo-data/*.json", {import: "default"})

  const files = Object.entries(fileURLs).map(([srcURL, promiseFn]) => {
    const filename = srcURL.split("/").pop()!;
    const stem = filename.split(".").slice(0, -1).join(".");
    return { name: stem, promiseFn };
  });

  let file = files[0];

  let data: any = null;
  let error: Error | null = null;
  let loading = false;
  $: {
    loading = true;
    error = null;
    data = null;
    file.promiseFn()
      .then((json) => {
        data = json;
        error = null;
      })
      .catch((e) => {
        error = e;
      })
      .finally(() => {
        loading = false;
      });
  }

  let appComponent: ReturnType<
    (typeof pyinstrumentHTMLRenderer)["render"]
  > | null = null;
  let resultElement: HTMLElement | undefined;

  $: if (resultElement && data) {
    if (appComponent) {
      appComponent.$destroy();
    }
    appComponent = pyinstrumentHTMLRenderer.render(resultElement, data);
  }
</script>

<div class="demo-app">
  <div class="header">
    <div class="left"></div>
    <div class="right">
      Choose a demo profile:
      <select bind:value={file}>
        {#each files as optionFile}
          <option value={optionFile}>{optionFile.name}</option>
        {/each}
      </select>
    </div>
  </div>
  <div class="body">
    {#if loading}
      <div>Loading...</div>
    {:else if error}
      <div>Error loading file: {error.message}</div>
    {/if}

    <div class="result-element" style={!data ? 'display: none' : ''} bind:this={resultElement}></div>
  </div>
</div>

<style lang="scss">
  .demo-app {
    background-color: #111;
    color: white;
    font-size: 11px;
    font-family:
      system-ui,
      -apple-system,
      BlinkMacSystemFont,
      "Segoe UI",
      Roboto,
      Oxygen,
      Ubuntu,
      Cantarell,
      "Open Sans",
      "Helvetica Neue",
      sans-serif;

    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
  }
  .header {
    // background: #292f32;
    // font-size: 14px;
    padding: 5px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .body {
    position: relative;
    flex: 1;
  }
  select {
    font: inherit;
  }
</style>