|
| 1 | +<script lang="ts"> |
| 2 | + import { goto } from '$app/navigation'; |
| 3 | + import Alert from '$lib/components/Alert.svelte'; |
| 4 | + import Spinner from '$lib/components/Spinner.svelte'; |
| 5 | + import PairsSelector from './PairsSelector.svelte'; |
| 6 | +
|
| 7 | + let { data } = $props(); |
| 8 | + let { strategy, chartRegistrations, selectedChart, tradingPairs, selectedPairIds, contentPromise } = $derived(data); |
| 9 | +
|
| 10 | + function updateAnalysis({ chart_id, pair_ids }: { chart_id?: string; pair_ids?: number[] }) { |
| 11 | + const params = new URLSearchParams({ |
| 12 | + chart_id: chart_id ?? selectedChart?.id ?? '', |
| 13 | + pair_ids: (pair_ids ?? selectedPairIds).join(',') |
| 14 | + }); |
| 15 | + goto(`?${params}`, { noScroll: true }); |
| 16 | + } |
| 17 | +</script> |
| 18 | + |
| 19 | +<svelte:head> |
| 20 | + <title>Analysis | {strategy.name} | Trading Strategy</title> |
| 21 | + <meta name="description" content="Analysis charts and tables for {strategy.name} strategy" /> |
| 22 | +</svelte:head> |
| 23 | + |
| 24 | +<section class="analysis"> |
| 25 | + <div class="controls"> |
| 26 | + <select onchange={(e) => updateAnalysis({ chart_id: e.currentTarget.value })}> |
| 27 | + <option value="">Select analysis</option> |
| 28 | + {#each chartRegistrations as { id, name } (id)} |
| 29 | + <option value={id} selected={id === selectedChart?.id}>{name}</option> |
| 30 | + {/each} |
| 31 | + </select> |
| 32 | + <PairsSelector |
| 33 | + {selectedPairIds} |
| 34 | + {tradingPairs} |
| 35 | + disabled={selectedChart?.kind !== 'indicator_multi_pair'} |
| 36 | + onchange={(pair_ids) => updateAnalysis({ pair_ids })} |
| 37 | + /> |
| 38 | + </div> |
| 39 | + |
| 40 | + <div class="content"> |
| 41 | + {#await contentPromise} |
| 42 | + <div class="loading"> |
| 43 | + <Spinner size="60" /> |
| 44 | + </div> |
| 45 | + {:then content} |
| 46 | + {#if !content} |
| 47 | + <p>Select analysis from the drop-down above.</p> |
| 48 | + {:else if content.type === 'image/png'} |
| 49 | + <img src={URL.createObjectURL(content.data)} alt="Analysis content" /> |
| 50 | + {:else if content.type === 'text/html'} |
| 51 | + <!-- eslint-disable-next-line svelte/no-at-html-tags --> |
| 52 | + {@html content.data} |
| 53 | + {/if} |
| 54 | + {:catch error} |
| 55 | + <Alert size="md" status="error" title="Error loading analysis"> |
| 56 | + <pre class="error-detail">{error}</pre> |
| 57 | + </Alert> |
| 58 | + {/await} |
| 59 | + </div> |
| 60 | +</section> |
| 61 | + |
| 62 | +<style> |
| 63 | + .analysis { |
| 64 | + position: relative; |
| 65 | + display: grid; |
| 66 | + gap: 1.5rem; |
| 67 | +
|
| 68 | + select { |
| 69 | + border-radius: var(--radius-sm); |
| 70 | + padding: 0.5rem; |
| 71 | + margin-bottom: 1rem; |
| 72 | + } |
| 73 | +
|
| 74 | + .controls { |
| 75 | + display: grid; |
| 76 | + grid-template-columns: auto 1fr; |
| 77 | + align-items: center; |
| 78 | + gap: 1rem; |
| 79 | +
|
| 80 | + select { |
| 81 | + margin: 0; |
| 82 | + } |
| 83 | + } |
| 84 | +
|
| 85 | + .content { |
| 86 | + min-height: 500px; |
| 87 | + overflow: auto; |
| 88 | +
|
| 89 | + p { |
| 90 | + padding: 1rem 0.5rem; |
| 91 | + } |
| 92 | +
|
| 93 | + :global(table) { |
| 94 | + width: 100%; |
| 95 | + border-collapse: collapse; |
| 96 | + color: inherit; |
| 97 | + background: var(--c-box-1); |
| 98 | + font: var(--f-mono-sm-regular); |
| 99 | + line-height: 1.2; |
| 100 | + letter-spacing: var(--f-mono-sm-spacing, normal); |
| 101 | +
|
| 102 | + @media (--viewport-xs) { |
| 103 | + font-size: 12px; |
| 104 | + } |
| 105 | +
|
| 106 | + :global(:is(td, th)) { |
| 107 | + padding: 0.25em 0.5em; |
| 108 | + border-block: 1px solid var(--c-text-ultra-light); |
| 109 | + vertical-align: top; |
| 110 | +
|
| 111 | + &:first-child { |
| 112 | + padding-left: 0.25em; |
| 113 | + } |
| 114 | +
|
| 115 | + &:last-child { |
| 116 | + padding-right: 0.25em; |
| 117 | + } |
| 118 | + } |
| 119 | +
|
| 120 | + :global(tbody :is(td, th)) { |
| 121 | + /* Alternating column colors */ |
| 122 | + &:nth-child(even) { |
| 123 | + background-color: var(--c-box-3); |
| 124 | + } |
| 125 | +
|
| 126 | + &:nth-child(odd) { |
| 127 | + background-color: var(--c-box-1); |
| 128 | + } |
| 129 | + } |
| 130 | +
|
| 131 | + :global(thead th) { |
| 132 | + background: var(--c-box-3); |
| 133 | + font-weight: 900; |
| 134 | + border-bottom: 2px solid currentColor; |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | +
|
| 139 | + .loading { |
| 140 | + display: grid; |
| 141 | + place-content: center; |
| 142 | + min-height: inherit; |
| 143 | + } |
| 144 | +
|
| 145 | + .error-detail { |
| 146 | + white-space: pre-wrap; |
| 147 | + font: var(--f-code-md-regular); |
| 148 | + } |
| 149 | + } |
| 150 | +</style> |
0 commit comments