|
| 1 | +<script lang="ts"> |
| 2 | + import { Modal, modalStore, RangeSlider, SlideToggle } from '@skeletonlabs/skeleton'; |
| 3 | + import { |
| 4 | + pageState, |
| 5 | + cubeHelixParameters, |
| 6 | + cubeHelixLookup, |
| 7 | + cubeHelixMapFunction, |
| 8 | + currentMemoryRegion |
| 9 | + } from '../lib/stores'; |
| 10 | + import { derived, writable } from 'svelte/store'; |
| 11 | + import { cubehelix } from 'cubehelix'; |
| 12 | +
|
| 13 | + export let parent: Modal; |
| 14 | + const localCubeHelixParameters = writable(Object.assign({}, $cubeHelixParameters)); |
| 15 | + const localCubeHelixLookup = derived(localCubeHelixParameters, ($localCubeHelixParameters) => { |
| 16 | + const colorArray = new Array(1000); |
| 17 | +
|
| 18 | + const func = cubehelix($localCubeHelixParameters); |
| 19 | +
|
| 20 | + // Fill the color array with the correct colors |
| 21 | + for (let i = 0; i < 1000; i++) { |
| 22 | + const color = func(i / 1000); |
| 23 | + colorArray[i] = `rgb(${color.r[0] * 255}, ${color.g[0] * 255}, ${color.b[0] * 255})`; |
| 24 | + } |
| 25 | +
|
| 26 | + return (index: number) => { |
| 27 | + // Clamp index between 0 and 1 |
| 28 | + index = Math.max(0, Math.min(1, index)); |
| 29 | + return colorArray[Math.floor(index * (1000 - 1))]; |
| 30 | + }; |
| 31 | + }); |
| 32 | +
|
| 33 | + let gradientWidth: number; |
| 34 | + let multiplier = 1; |
| 35 | + let parametersUnchanged = true; |
| 36 | +
|
| 37 | + $: { |
| 38 | + if ('name' in $currentMemoryRegion && $pageState.customTotalAccessCount) { |
| 39 | + multiplier = $currentMemoryRegion.highestTotalCount / $pageState.customTotalAccessCount; |
| 40 | + } else { |
| 41 | + multiplier = 1; |
| 42 | + } |
| 43 | +
|
| 44 | + parametersUnchanged = JSON.stringify($cubeHelixParameters) !== JSON.stringify($localCubeHelixParameters); |
| 45 | + } |
| 46 | +</script> |
| 47 | + |
| 48 | +<div> |
| 49 | + <div class="w-full h-full flex flex-col align-middle justify-center items-center gap-2"> |
| 50 | + <SlideToggle bind:checked={$pageState.useCustomColorScheme} |
| 51 | + >Use a cube helix color scheme for the combined view</SlideToggle |
| 52 | + > |
| 53 | + <div class="flex align-middle items-center justify-evenly"> |
| 54 | + <div class="mr-4">Overwrite reference maximum number:</div> |
| 55 | + <div class=""><input type="number" class="w-8" bind:value={$pageState.customTotalAccessCount} /></div> |
| 56 | + </div> |
| 57 | + <div class="variant-soft rounded-3xl w-full h-full my-4 mx-2 p-3"> |
| 58 | + <div class="font-black text-center mb-4">Cube Helix Settings</div> |
| 59 | + |
| 60 | + <div class="flex flex-col gap-4"> |
| 61 | + <div class="flex"> |
| 62 | + <div class="flex-1"> |
| 63 | + <RangeSlider bind:value={$localCubeHelixParameters.start} min={0} max={5} step={0.05} ticked> |
| 64 | + <div class="flex justify-between items-center"> |
| 65 | + <div class="move-down text-xs">0</div> |
| 66 | + <div class="flex-1 text-center">Start Parameter</div> |
| 67 | + <div class="move-down text-xs">5</div> |
| 68 | + </div> |
| 69 | + </RangeSlider> |
| 70 | + </div> |
| 71 | + <div class="flex align-middle items-center justify-center ml-6"> |
| 72 | + <div class="mr-4">Value:</div> |
| 73 | + <input |
| 74 | + class="max-w-[64px] text-xs p-2" |
| 75 | + min="0" |
| 76 | + max="5" |
| 77 | + type="number" |
| 78 | + bind:value={$localCubeHelixParameters.start} |
| 79 | + /> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + <div class="flex"> |
| 83 | + <div class="flex-1"> |
| 84 | + <RangeSlider bind:value={$localCubeHelixParameters.r} min={-10} max={30} step={0.1} ticked> |
| 85 | + <div class="flex justify-between items-center"> |
| 86 | + <div class="move-down text-xs">-10</div> |
| 87 | + <div class="flex-1 text-center">Rotation Parameter</div> |
| 88 | + <div class="move-down text-xs">30</div> |
| 89 | + </div> |
| 90 | + </RangeSlider> |
| 91 | + </div> |
| 92 | + <div class="flex align-middle items-center justify-center ml-6"> |
| 93 | + <div class="mr-4">Value:</div> |
| 94 | + <input |
| 95 | + class="max-w-[64px] text-xs p-2" |
| 96 | + min="-10" |
| 97 | + max="30" |
| 98 | + type="number" |
| 99 | + bind:value={$localCubeHelixParameters.r} |
| 100 | + /> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + <div class="flex"> |
| 104 | + <div class="flex-1"> |
| 105 | + <RangeSlider bind:value={$localCubeHelixParameters.hue} min={0} max={10} step={0.05} ticked> |
| 106 | + <div class="flex justify-between items-center"> |
| 107 | + <div class="move-down text-xs">0</div> |
| 108 | + <div class="flex-1 text-center">Hue Parameter</div> |
| 109 | + <div class="move-down text-xs">10</div> |
| 110 | + </div> |
| 111 | + </RangeSlider> |
| 112 | + </div> |
| 113 | + <div class="flex align-middle items-center justify-center ml-6"> |
| 114 | + <div class="mr-4">Value:</div> |
| 115 | + <input |
| 116 | + class="max-w-[64px] text-xs p-2" |
| 117 | + min="0.00" |
| 118 | + max="10" |
| 119 | + type="number" |
| 120 | + bind:value={$localCubeHelixParameters.hue} |
| 121 | + /> |
| 122 | + </div> |
| 123 | + </div> |
| 124 | + <div class="flex"> |
| 125 | + <div class="flex-1"> |
| 126 | + <RangeSlider bind:value={$localCubeHelixParameters.gamma} min={0.0} max={5} step={0.05} ticked> |
| 127 | + <div class="flex justify-between items-center"> |
| 128 | + <div class="move-down text-xs">0</div> |
| 129 | + <div class="flex-1 text-center">Gamma Parameter</div> |
| 130 | + <div class="move-down text-xs">5</div> |
| 131 | + </div> |
| 132 | + </RangeSlider> |
| 133 | + </div> |
| 134 | + <div class="flex align-middle items-center justify-center ml-6"> |
| 135 | + <div class="mr-4">Value:</div> |
| 136 | + <input |
| 137 | + class="max-w-[64px] text-xs p-2" |
| 138 | + min="0.01" |
| 139 | + max="5" |
| 140 | + type="number" |
| 141 | + bind:value={$localCubeHelixParameters.gamma} |
| 142 | + /> |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + </div> |
| 146 | + |
| 147 | + <div class="font-mono text-center mt-4">Preview</div> |
| 148 | + <div class="flex rounded-3xl overflow-hidden" bind:clientWidth={gradientWidth}> |
| 149 | + {#each Array.from({ length: Math.floor(gradientWidth / 2) }) as _, i} |
| 150 | + <div |
| 151 | + class="h-8 flex-1" |
| 152 | + style={`background-color: ${$localCubeHelixLookup((i / (gradientWidth / 2)) * multiplier)}`} |
| 153 | + /> |
| 154 | + {/each} |
| 155 | + </div> |
| 156 | + <div class="font-mono text-center mt-4">Presets</div> |
| 157 | + <div class="flex justify-evenly items-center"> |
| 158 | + <button |
| 159 | + class="btn variant-soft" |
| 160 | + on:click={() => { |
| 161 | + $localCubeHelixParameters = { start: 0, r: 0.6, hue: 3.0, gamma: 1.0 }; |
| 162 | + }} |
| 163 | + > |
| 164 | + Heat |
| 165 | + </button> |
| 166 | + <button |
| 167 | + class="btn variant-soft" |
| 168 | + on:click={() => { |
| 169 | + $localCubeHelixParameters = { start: 0.75, r: -0.4, hue: 4.2, gamma: 1.55 }; |
| 170 | + }} |
| 171 | + > |
| 172 | + Winter |
| 173 | + </button> |
| 174 | + <button |
| 175 | + class="btn variant-soft" |
| 176 | + on:click={() => { |
| 177 | + $localCubeHelixParameters = { start: 2.55, r: 0.1, hue: 5.9, gamma: 1.55 }; |
| 178 | + }} |
| 179 | + > |
| 180 | + Blue |
| 181 | + </button> |
| 182 | + <button |
| 183 | + class="btn variant-soft" |
| 184 | + on:click={() => { |
| 185 | + $localCubeHelixParameters = { start: 5, r: 1.6, hue: 2.15, gamma: 7 }; |
| 186 | + }} |
| 187 | + > |
| 188 | + Peak |
| 189 | + </button> |
| 190 | + </div> |
| 191 | + </div> |
| 192 | + </div> |
| 193 | + |
| 194 | + <div class="h-[1px] w-full bg-surface-400/30 mb-4" /> |
| 195 | + <footer class="modal-footer {parent.regionFooter}"> |
| 196 | + <button class="btn {parent.buttonNeutral}" on:click={parent.onClose}>Close</button> |
| 197 | + <button |
| 198 | + class="btn {parent.buttonPositive}" |
| 199 | + on:click={() => { |
| 200 | + $cubeHelixParameters = Object.assign({}, $localCubeHelixParameters); |
| 201 | + }} |
| 202 | + disabled={!parametersUnchanged}>Apply</button |
| 203 | + > |
| 204 | + </footer> |
| 205 | +</div> |
| 206 | + |
| 207 | +<style> |
| 208 | + .move-down { |
| 209 | + transform: translateY(0.5rem); |
| 210 | + } |
| 211 | +</style> |
0 commit comments