|
1 | 1 | <script lang="ts"> |
2 | | - import { onDestroy, onMount } from 'svelte'; |
3 | | - import { page } from '$app/state'; |
| 2 | + import { onMount } from 'svelte'; |
4 | 3 | import SettingsCard from '$lib/components/SettingsCard.svelte'; |
5 | 4 | import { slide } from 'svelte/transition'; |
6 | 5 | import { cubicOut } from 'svelte/easing'; |
|
11 | 10 |
|
12 | 11 | Chart.register(...registerables); |
13 | 12 |
|
14 | | - let heapChartElement: HTMLCanvasElement = $state(); |
| 13 | + let heapChartElement: HTMLCanvasElement | undefined = $state(); |
15 | 14 | let heapChart: Chart; |
16 | 15 |
|
17 | | - let psramChartElement: HTMLCanvasElement = $state(); |
| 16 | + let psramChartElement: HTMLCanvasElement | undefined = $state(); |
18 | 17 | let psramChart: Chart; |
19 | 18 |
|
20 | | - let filesystemChartElement: HTMLCanvasElement = $state(); |
| 19 | + let filesystemChartElement: HTMLCanvasElement | undefined = $state(); |
21 | 20 | let filesystemChart: Chart; |
22 | 21 |
|
23 | | - let temperatureChartElement: HTMLCanvasElement = $state(); |
| 22 | + let temperatureChartElement: HTMLCanvasElement | undefined = $state(); |
24 | 23 | let temperatureChart: Chart; |
25 | 24 |
|
| 25 | + // Check if PSRAM data is available |
| 26 | + let hasPsramData = $derived(Math.max(...$analytics.psram_size) > 0); |
| 27 | +
|
26 | 28 | onMount(() => { |
27 | 29 | heapChart = new Chart(heapChartElement, { |
28 | 30 | type: 'line', |
|
97 | 99 | } |
98 | 100 | } |
99 | 101 | }); |
100 | | - psramChart = new Chart(psramChartElement, { |
| 102 | + |
| 103 | + // Only create PSRAM chart if PSRAM data is available |
| 104 | + if (hasPsramData) { |
| 105 | + psramChart = new Chart(psramChartElement, { |
101 | 106 | type: 'line', |
102 | 107 | data: { |
103 | 108 | labels: $analytics.uptime, |
|
107 | 112 | borderColor: daisyColor('--color-primary'), |
108 | 113 | backgroundColor: daisyColor('--color-primary', 50), |
109 | 114 | borderWidth: 2, |
110 | | - data: $analytics.free_psram, |
| 115 | + data: $analytics.used_psram, |
111 | 116 | yAxisID: 'y' |
112 | 117 | } |
113 | 118 | ] |
|
162 | 167 | } |
163 | 168 | } |
164 | 169 | }); |
| 170 | + } |
| 171 | + |
165 | 172 | filesystemChart = new Chart(filesystemChartElement, { |
166 | 173 | type: 'line', |
167 | 174 | data: { |
|
304 | 311 | heapChart.update('none'); |
305 | 312 | heapChart.options.scales.y.max = Math.round(Math.max(...$analytics.total_heap)); |
306 | 313 |
|
307 | | - if (Math.max(...$analytics.psram_size)) { |
| 314 | + if (hasPsramData) { |
308 | 315 | psramChart.data.labels = $analytics.uptime; |
309 | 316 | psramChart.data.datasets[0].data = $analytics.used_psram; |
310 | 317 | psramChart.update('none'); |
|
365 | 372 | <canvas bind:this={heapChartElement}></canvas> |
366 | 373 | </div> |
367 | 374 | </div> |
368 | | - {#if Math.max(...$analytics.psram_size)} |
| 375 | + {#if hasPsramData} |
369 | 376 | <div class="w-full overflow-x-auto"> |
370 | 377 | <div |
371 | 378 | class="flex w-full flex-col space-y-1 h-60" |
|
0 commit comments