|
134 | 134 | }; |
135 | 135 | }); |
136 | 136 |
|
137 | | - // Format time for axis |
| 137 | + // Format time for axis - include date if range spans multiple days |
138 | 138 | function formatTime(time: Date): string { |
| 139 | + const { minTime, maxTime } = chartBounds; |
| 140 | + const rangeMs = maxTime - minTime; |
| 141 | + const dayMs = 24 * 60 * 60 * 1000; |
| 142 | +
|
| 143 | + if (rangeMs > dayMs) { |
| 144 | + // Show date + time for multi-day ranges |
| 145 | + return time.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }) + |
| 146 | + ' ' + time.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }); |
| 147 | + } |
139 | 148 | return time.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }); |
140 | 149 | } |
141 | 150 |
|
| 151 | + // Calculate full totals (all chart data) |
| 152 | + const fullTotals = $derived.by(() => { |
| 153 | + const tx = chartData.reduce((sum, d) => sum + d.txBytes, 0); |
| 154 | + const rx = chartData.reduce((sum, d) => sum + d.rxBytes, 0); |
| 155 | + return { tx, rx, total: tx + rx }; |
| 156 | + }); |
| 157 | +
|
142 | 158 | // Calculate totals for selected range only (in historical mode) or all data |
143 | 159 | const totals = $derived.by(() => { |
144 | 160 | const selectedStart = $dataSourceStore.selectedStart; |
145 | 161 | const selectedEnd = $dataSourceStore.selectedEnd; |
146 | 162 | const mode = $dataSourceStore.mode; |
147 | 163 |
|
148 | | - let dataToSum = chartData; |
149 | | -
|
150 | | - // In historical mode, only sum data within selected range |
151 | | - if (mode === 'historical' && selectedStart && selectedEnd) { |
152 | | - dataToSum = chartData.filter((d) => { |
153 | | - const t = d.time.getTime(); |
154 | | - return t >= selectedStart.getTime() && t <= selectedEnd.getTime(); |
155 | | - }); |
| 164 | + // In live mode or if no selection, use full totals |
| 165 | + if (mode !== 'historical' || !selectedStart || !selectedEnd) { |
| 166 | + return fullTotals; |
156 | 167 | } |
157 | 168 |
|
| 169 | + // In historical mode, sum data within selected range |
| 170 | + const dataToSum = chartData.filter((d) => { |
| 171 | + const t = d.time.getTime(); |
| 172 | + return t >= selectedStart.getTime() && t <= selectedEnd.getTime(); |
| 173 | + }); |
| 174 | +
|
158 | 175 | const tx = dataToSum.reduce((sum, d) => sum + d.txBytes, 0); |
159 | 176 | const rx = dataToSum.reduce((sum, d) => sum + d.rxBytes, 0); |
160 | 177 | return { tx, rx, total: tx + rx }; |
161 | 178 | }); |
162 | 179 |
|
| 180 | + // Check if we're showing a subset of data |
| 181 | + const isShowingSubset = $derived( |
| 182 | + $dataSourceStore.mode === 'historical' && |
| 183 | + $dataSourceStore.selectedStart !== null && |
| 184 | + $dataSourceStore.selectedEnd !== null && |
| 185 | + totals.total !== fullTotals.total |
| 186 | + ); |
| 187 | +
|
163 | 188 | // Generate time axis ticks |
164 | 189 | const timeAxisTicks = $derived.by(() => { |
165 | 190 | if (chartData.length === 0) return []; |
|
193 | 218 | <div class="flex items-center gap-4"> |
194 | 219 | <span class="text-xs font-medium text-muted-foreground"> |
195 | 220 | Bandwidth Over Time |
196 | | - {#if $dataSourceStore.mode === 'historical'} |
| 221 | + {#if isShowingSubset} |
197 | 222 | <span class="text-primary/70">(selected range)</span> |
198 | 223 | {/if} |
199 | 224 | </span> |
|
209 | 234 | <span class="text-muted-foreground"> |
210 | 235 | Total: {formatBytes(totals.total)} |
211 | 236 | </span> |
| 237 | + {#if isShowingSubset} |
| 238 | + <span class="text-muted-foreground/60"> |
| 239 | + | All: {formatBytes(fullTotals.total)} |
| 240 | + </span> |
| 241 | + {/if} |
212 | 242 | </div> |
213 | 243 | </div> |
214 | 244 | {#if chartData.length > 0} |
|
0 commit comments