-
Notifications
You must be signed in to change notification settings - Fork 4
feat(status): add KPI stat strip to the Health tab #1506
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/features/instance/status/analytics/tabs/kpi/KpiSparkline.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import type { KpiPoint } from './kpiMath'; | ||
|
|
||
| interface Props { | ||
| points: KpiPoint[]; | ||
| /** Full current-window bounds, so a half-empty window draws half a line | ||
| * instead of stretching the data to fill the tile. */ | ||
| xDomain: [number, number]; | ||
| } | ||
|
|
||
| const VIEW_W = 120; | ||
| const VIEW_H = 32; | ||
| /** Inset so the stroke isn't clipped at the extremes. */ | ||
| const PAD_Y = 2; | ||
|
|
||
| /** Axis-less inline-SVG sparkline for the KPI tiles. Decorative only | ||
| * (aria-hidden) — the tile's value + delta carry the information. Drawn in | ||
| * the muted de-emphasis hue with the final segment in the accent chart hue | ||
| * so "now" reads at a glance in both themes. */ | ||
| export function KpiSparkline({ points, xDomain }: Props) { | ||
| if (points.length < 2) { return <div className="h-8" aria-hidden="true" />; } | ||
|
|
||
| const [x0, x1] = xDomain; | ||
| const xSpan = x1 - x0 || 1; | ||
| let yMin = Infinity; | ||
| let yMax = -Infinity; | ||
| for (const p of points) { | ||
| if (p.y < yMin) { yMin = p.y; } | ||
| if (p.y > yMax) { yMax = p.y; } | ||
| } | ||
| // Flat series: center the line rather than dividing by zero. | ||
| const ySpan = yMax - yMin || 1; | ||
|
|
||
| const toXY = (p: KpiPoint): [number, number] => [ | ||
| ((p.x - x0) / xSpan) * VIEW_W, | ||
| yMax === yMin | ||
| ? VIEW_H / 2 | ||
| : PAD_Y + (1 - (p.y - yMin) / ySpan) * (VIEW_H - 2 * PAD_Y), | ||
| ]; | ||
|
|
||
| const coords = points.map(toXY); | ||
| const toPath = (cs: [number, number][]): string => | ||
| cs.map(([x, y], i) => `${i === 0 ? 'M' : 'L'}${x.toFixed(2)},${y.toFixed(2)}`).join(' '); | ||
|
|
||
| return ( | ||
| <svg | ||
| viewBox={`0 0 ${VIEW_W} ${VIEW_H}`} | ||
| preserveAspectRatio="none" | ||
| className="h-8 w-full text-muted-foreground/60" | ||
| aria-hidden="true" | ||
| focusable="false" | ||
| > | ||
| { | ||
| /* Two points = only the accent segment below; a one-coord path | ||
| would be an invisible MoveTo-only element. */ | ||
| } | ||
| {points.length > 2 && ( | ||
| <path | ||
| d={toPath(coords.slice(0, -1))} | ||
| fill="none" | ||
| stroke="currentColor" | ||
| strokeWidth={1.5} | ||
| vectorEffect="non-scaling-stroke" | ||
| strokeLinejoin="round" | ||
| strokeLinecap="round" | ||
| /> | ||
| )} | ||
| <path | ||
| d={toPath(coords.slice(-2))} | ||
| fill="none" | ||
| stroke="var(--chart-node-1)" | ||
| strokeWidth={1.5} | ||
| vectorEffect="non-scaling-stroke" | ||
| strokeLinejoin="round" | ||
| strokeLinecap="round" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/features/instance/status/analytics/tabs/kpi/KpiStrip.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { KpiTile } from './KpiTile'; | ||
| import { KPI_TILES } from './kpiTiles'; | ||
|
|
||
| /** The Health tab's at-a-glance vitals row: five stat tiles above the panel | ||
| * grid (see kpiTiles.ts for the metric definitions). */ | ||
| export function KpiStrip() { | ||
| return ( | ||
| <div className="grid grid-cols-2 gap-4 sm:grid-cols-3 xl:grid-cols-5" data-testid="kpi-strip"> | ||
| {KPI_TILES.map((def) => <KpiTile key={def.id} def={def} />)} | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.