-
Notifications
You must be signed in to change notification settings - Fork 187
Fix: usage shifts #2345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: usage shifts #2345
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -197,3 +197,30 @@ function generateSingleValue(column: Columns): string | number | boolean | null | |||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
function seededRandom(seed: number) { | ||||||||||||||||||||||||||||||||||||||||||||||
const x = Math.sin(seed) * 10000; | ||||||||||||||||||||||||||||||||||||||||||||||
return x - Math.floor(x); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
export function generateFakeBarChartData(seed = 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
const fakeData: [number, number][] = []; | ||||||||||||||||||||||||||||||||||||||||||||||
const now = Date.now(); | ||||||||||||||||||||||||||||||||||||||||||||||
for (let i = 23; i >= 0; i--) { | ||||||||||||||||||||||||||||||||||||||||||||||
const val = seededRandom(seed + i) * 1_000_000; | ||||||||||||||||||||||||||||||||||||||||||||||
fakeData.push([now - i * 60 * 60 * 1000, Math.round(val)]); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
return fakeData; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
export function generateFakeLineChartData(seed = 2) { | ||||||||||||||||||||||||||||||||||||||||||||||
const fakeData: [number, number][] = []; | ||||||||||||||||||||||||||||||||||||||||||||||
const now = Date.now(); | ||||||||||||||||||||||||||||||||||||||||||||||
let value = seededRandom(seed) * 5000 + 5000; | ||||||||||||||||||||||||||||||||||||||||||||||
for (let i = 23; i >= 0; i--) { | ||||||||||||||||||||||||||||||||||||||||||||||
value += (seededRandom(seed + i) - 0.5) * 1000; | ||||||||||||||||||||||||||||||||||||||||||||||
value = Math.max(0, value); | ||||||||||||||||||||||||||||||||||||||||||||||
fakeData.push([now - i * 60 * 60 * 1000, Math.round(value)]); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
return fakeData; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+216
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Same stabilization for line data. -export function generateFakeLineChartData(seed = 2) {
+export function generateFakeLineChartData(seed = 2, baseTimeMs = Date.now()) {
const fakeData: [number, number][] = [];
- const now = Date.now();
+ const now = baseTimeMs;
let value = seededRandom(seed) * 5000 + 5000;
for (let i = 23; i >= 0; i--) {
value += (seededRandom(seed + i) - 0.5) * 1000;
value = Math.max(0, value);
fakeData.push([now - i * 60 * 60 * 1000, Math.round(value)]);
}
return fakeData;
} Follow-up: Pass a single 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<script lang="ts"> | ||
import { fade } from 'svelte/transition'; | ||
import { Layout, Skeleton, Typography } from '@appwrite.io/pink-svelte'; | ||
|
||
let { | ||
loading = false, | ||
metricName, | ||
resourceMetric = null | ||
}: { | ||
loading: boolean; | ||
metricName: string; | ||
resourceMetric?: | ||
| string | ||
| { | ||
value: string; | ||
unit: string; | ||
} | ||
| null; | ||
} = $props(); | ||
|
||
function isMetricObject( | ||
metric: typeof resourceMetric | ||
): metric is { value: string; unit: string } { | ||
return metric !== null && typeof metric === 'object'; | ||
} | ||
</script> | ||
|
||
<Layout.Stack gap="xxxs"> | ||
<Typography.Title> | ||
<div class="overlay-container"> | ||
{#if loading} | ||
<div class="overlay-item skeleton" transition:fade={{ duration: 300 }}> | ||
<Skeleton height="100%" width="7.5rem" variant="line" style="opacity: 0.35" /> | ||
</div> | ||
{:else if resourceMetric !== null} | ||
<div class="overlay-item" transition:fade={{ duration: 300 }}> | ||
{#if isMetricObject(resourceMetric)} | ||
{resourceMetric.value} | ||
<span style:line-height="0%" style:font-size="var(--font-size-0)"> | ||
{resourceMetric.unit} | ||
</span> | ||
{:else} | ||
{resourceMetric} | ||
{/if} | ||
</div> | ||
{/if} | ||
</div> | ||
</Typography.Title> | ||
|
||
<Typography.Text>{metricName}</Typography.Text> | ||
</Layout.Stack> | ||
|
||
<style lang="scss"> | ||
.overlay-container { | ||
display: grid; | ||
min-height: 1lh; | ||
align-items: stretch; | ||
grid-template-areas: 'content'; | ||
} | ||
|
||
.overlay-item { | ||
grid-area: content; | ||
|
||
&.skeleton { | ||
display: flex; | ||
align-items: center; | ||
} | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script lang="ts"> | ||
import { fade } from 'svelte/transition'; | ||
import { Skeleton, Typography } from '@appwrite.io/pink-svelte'; | ||
|
||
let { | ||
value, | ||
resource, | ||
unit = null, | ||
loading = false | ||
}: { | ||
loading: boolean; | ||
resource: string; | ||
unit?: string; | ||
value: string | number | boolean; | ||
} = $props(); | ||
</script> | ||
|
||
<Typography.Title> | ||
<div class="overlay-container"> | ||
{#if loading} | ||
<div class="overlay-item skeleton" transition:fade={{ duration: 300 }}> | ||
<Skeleton | ||
height="100%" | ||
width="5rem" | ||
variant="line" | ||
style="opacity: 0.35; margin-bottom: 1rem; margin-inline-start: -2px" /> | ||
</div> | ||
{:else} | ||
<div class="overlay-item" transition:fade={{ duration: 300, delay: 150 }}> | ||
{value} | ||
{#if unit} | ||
<span style:line-height="0%" style:font-size="var(--font-size-0)"> | ||
{unit} | ||
</span> | ||
{/if} | ||
</div> | ||
{/if} | ||
</div> | ||
</Typography.Title> | ||
|
||
<Typography.Text> | ||
{resource} | ||
</Typography.Text> | ||
|
||
<style lang="scss"> | ||
.overlay-container { | ||
display: grid; | ||
min-height: 1lh; | ||
align-items: stretch; | ||
grid-template-areas: 'content'; | ||
} | ||
|
||
.overlay-item { | ||
grid-area: content; | ||
|
||
&.skeleton { | ||
display: flex; | ||
align-items: center; | ||
} | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Stabilize timestamps to prevent loading-state chart reflows.
Using
Date.now()
on each render can shift x-axis and trigger re-layout. Accept abaseTimeMs
parameter (defaulted once) so repeated calls during the same loading session produce consistent timestamps.📝 Committable suggestion
🤖 Prompt for AI Agents