Add nice-scale chart axes, dual-axis ping chart with loss overlay, and auth-gated period selector#1
Merged
Conversation
…th-gated period selector - Introduce chartScale.ts: d3-style nice tick calculation, auto-baseline, loss/delay/speed presets, axis width budgeting - Rework PingChart to ComposedChart with delay Y-axis + loss area overlay, P95-trimmed scale, and per-monitor packet loss from nezha-dash algorithm - Add 1d/7d/30d period selector; 7d and 30d gated behind login (matching official theme behavior) - Add useIsLogin hook via /api/v1/profile with periodic refetch - Apply nice-scale Y-axes to HistoryChart and RealtimeCharts with unit labels in chart headers - Edge-aware X-axis ticks (first left-aligned, last right-aligned) - ServerCard: traffic limit progress bar with bidirectional traffic support, billing badge redesign - OsIcon: use brand hex colors from simple-icons instead of fill-current - Sparkline: decouple viewBox from container size, add showDot prop - ServerDetail: truncate long CPU/GPU strings, billing badge style update - Mock server: period-aware data, deterministic failure windows, auth simulation via cookie
- Use template literal over string concatenation in ServerDetail - Replace 1.414 with Math.SQRT2 in chartScale - Reformat inline comments in mock server - Fix formatting in OsIcon, ServerCard, Sparkline
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TL;DR
Charts had ugly default ticks (e.g. 333.33ms), no loss visualization, and no way to view 7d/30d history. This PR adds a d3-style nice-scale engine for clean axis ticks, dual-axis ping charts (delay + loss overlay), period selection with auth gating, and traffic-limit progress bars on server cards.
Files to review
src/components/detail/chartScale.tssrc/components/detail/PingChart.tsxsrc/lib/auth.tsuseIsLogin()hook, probes/api/v1/profileto gate 7d/30d periodssrc/components/ServerCard.tsxsrc/components/detail/HistoryChart.tsxsrc/components/detail/RealtimeCharts.tsxsrc/components/detail/ChartTheme.tsxEdgeTickX),X_AXIS_PROPSsrc/components/Sparkline.tsxshowDotpropsrc/components/OsIcon.tsxfill-currentsrc/pages/ServerDetail.tsxsrc/lib/api.tsfetchProfile,fetchServerMonitoracceptsMonitorPeriodsrc/types/nezha.tsMonitorPeriodtype,ProfileResponseinterfacesrc/lib/i18n.tsxloginToViewi18n key (zh/en)src/index.cssmock/server.mjsWhy
How
chartScale.tsimplements a standalone nice-scale engine:niceStep(sqrt-threshold 1/2/5/10 selector),niceScale(auto-baseline with configurable ratio, min-span guard, headroom), plus domain-specific helpers (PERCENT_SCALE,lossScale,speedScale,delayTickFormatter,axisWidthFor).LineCharttoComposedChartwith two Y-axes: left for delay (P95-trimmed + auto-baseline), right for loss (preset-tier scale). Packet loss is computed per-point using the nezha-dash EWMA algorithm when backendpacket_lossis absent.useIsLogin()polls/api/v1/profileevery 5min; 7d/30d buttons are disabled and auto-revert to 1d on logout.trafficVol(e.g. "500GB") into bytes, computes percentage, renders a color-coded 2px progress bar (green → amber → red at 75%/90%).Reviewer notes
chartScale.tsis ~280 lines of pure math with no React deps — easy to unit-test if desired.PingChart.tsxis ported verbatim from hamster1963/nezha-dash; the EWMA smoothing and coefficient-of-variation thresholds match upstream.document.cookie = "nz-jwt=mock"— documented in a comment inserver.mjs.Visual aids
fill-current