astro-component-kit 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -36
- package/package.json +17 -4
- package/src/components/index.ts +18 -202
- package/src/components/lib/Galaxy3D.astro +249 -137
- package/src/components/lib/app/AppSidebar.astro +249 -0
- package/src/components/lib/app/AppTopbar.astro +284 -0
- package/src/components/lib/app/ArrivalsBoard.astro +176 -0
- package/src/components/lib/app/AuthCard.astro +213 -0
- package/src/components/lib/app/DataTable.astro +346 -0
- package/src/components/lib/app/GuestProfileCard.astro +133 -0
- package/src/components/lib/app/HousekeepingBoard.astro +189 -0
- package/src/components/lib/app/PageHeader.astro +157 -0
- package/src/components/lib/app/PlanUsageCard.astro +112 -0
- package/src/components/lib/app/RoomRack.astro +207 -0
- package/src/components/lib/app/SettingsSection.astro +96 -0
- package/src/components/lib/app/SwitchRow.astro +71 -0
- package/src/components/lib/app/TeamMembers.astro +190 -0
- package/src/components/lib/app/app-icons.ts +52 -0
- package/src/components/lib/app/index.ts +19 -0
- package/src/components/lib/buttons/NeonBorderButton.astro +162 -0
- package/src/components/lib/buttons/RippleButton.astro +199 -0
- package/src/components/lib/buttons/SlideRevealButton.astro +159 -0
- package/src/components/lib/buttons/index.ts +4 -0
- package/src/components/lib/cards/GithubRepoCard.astro +176 -0
- package/src/components/lib/cards/PricingCompareMiniCard.astro +196 -0
- package/src/components/lib/cards/StatsTrendCard.astro +149 -0
- package/src/components/lib/cards/index.ts +3 -0
- package/src/components/lib/charts/ActivityRings.astro +105 -0
- package/src/components/lib/charts/AreaChart.astro +4 -4
- package/src/components/lib/charts/BarChart.astro +3 -3
- package/src/components/lib/charts/BoxPlotChart.astro +109 -0
- package/src/components/lib/charts/BubbleChart.astro +101 -0
- package/src/components/lib/charts/BulletChart.astro +160 -0
- package/src/components/lib/charts/BumpChart.astro +92 -0
- package/src/components/lib/charts/CandlestickChart.astro +105 -0
- package/src/components/lib/charts/ChartFrame.astro +373 -0
- package/src/components/lib/charts/DivergingBarChart.astro +98 -0
- package/src/components/lib/charts/DonutChart.astro +2 -2
- package/src/components/lib/charts/DumbbellChart.astro +92 -0
- package/src/components/lib/charts/ForecastLineChart.astro +125 -0
- package/src/components/lib/charts/FunnelChart.astro +122 -0
- package/src/components/lib/charts/GaugeChart.astro +111 -0
- package/src/components/lib/charts/GoalProgressChart.astro +97 -0
- package/src/components/lib/charts/GroupedBarChart.astro +125 -0
- package/src/components/lib/charts/HeatmapChart.astro +131 -0
- package/src/components/lib/charts/HistogramChart.astro +111 -0
- package/src/components/lib/charts/HorizontalBarChart.astro +155 -0
- package/src/components/lib/charts/KpiStatTile.astro +116 -0
- package/src/components/lib/charts/KpiTrendGrid.astro +60 -0
- package/src/components/lib/charts/LineChart.astro +160 -0
- package/src/components/lib/charts/LinearProgressGauge.astro +136 -0
- package/src/components/lib/charts/LollipopChart.astro +100 -0
- package/src/components/lib/charts/MeterGauge.astro +122 -0
- package/src/components/lib/charts/MetricDeltaTable.astro +125 -0
- package/src/components/lib/charts/PieChart.astro +135 -0
- package/src/components/lib/charts/PolarAreaChart.astro +85 -0
- package/src/components/lib/charts/PopulationPyramid.astro +122 -0
- package/src/components/lib/charts/PunchCardChart.astro +89 -0
- package/src/components/lib/charts/RadarChart.astro +94 -0
- package/src/components/lib/charts/RadarMetricChart.astro +168 -0
- package/src/components/lib/charts/RadialBarChart.astro +124 -0
- package/src/components/lib/charts/RangeAreaChart.astro +113 -0
- package/src/components/lib/charts/RetentionCohortTable.astro +126 -0
- package/src/components/lib/charts/SankeyChart.astro +128 -0
- package/src/components/lib/charts/ScatterPlot.astro +139 -0
- package/src/components/lib/charts/SegmentedBarChart.astro +119 -0
- package/src/components/lib/charts/SlopeChart.astro +105 -0
- package/src/components/lib/charts/SparklineChart.astro +87 -0
- package/src/components/lib/charts/StackedAreaChart.astro +130 -0
- package/src/components/lib/charts/StackedBarChart.astro +136 -0
- package/src/components/lib/charts/SunburstChart.astro +103 -0
- package/src/components/lib/charts/TreemapChart.astro +94 -0
- package/src/components/lib/charts/WaffleChart.astro +121 -0
- package/src/components/lib/charts/WaterfallChart.astro +118 -0
- package/src/components/lib/charts/chart-tooltip.ts +75 -0
- package/src/components/lib/charts/chart-utils.ts +271 -0
- package/src/components/lib/charts/index.ts +46 -0
- package/src/components/lib/data/ActivityHeatmapGrid.astro +157 -0
- package/src/components/lib/data/MetricComparisonRow.astro +109 -0
- package/src/components/lib/data/StatusTimelineFeed.astro +168 -0
- package/src/components/lib/data/index.ts +3 -0
- package/src/components/lib/ecommerce/CartDrawer.astro +483 -0
- package/src/components/lib/ecommerce/CartPageList.astro +290 -0
- package/src/components/lib/ecommerce/CartToast.astro +276 -0
- package/src/components/lib/ecommerce/CategoryTiles.astro +143 -0
- package/src/components/lib/ecommerce/CheckoutForm.astro +423 -0
- package/src/components/lib/ecommerce/CountdownBanner.astro +230 -0
- package/src/components/lib/ecommerce/FilterBar.astro +278 -0
- package/src/components/lib/ecommerce/FilterSidebar.astro +405 -0
- package/src/components/lib/ecommerce/LiveActivityToast.astro +213 -0
- package/src/components/lib/ecommerce/OrderSummary.astro +295 -0
- package/src/components/lib/ecommerce/ProductBuyBox.astro +247 -0
- package/src/components/lib/ecommerce/ProductCardMinimal.astro +229 -0
- package/src/components/lib/ecommerce/ProductGallery.astro +145 -0
- package/src/components/lib/ecommerce/ProductGrid.astro +118 -0
- package/src/components/lib/ecommerce/ProductMedia.astro +113 -0
- package/src/components/lib/ecommerce/ProductRating.astro +78 -0
- package/src/components/lib/ecommerce/ProductToolbar.astro +93 -0
- package/src/components/lib/ecommerce/PromoBar.astro +145 -0
- package/src/components/lib/ecommerce/StockIndicator.astro +127 -0
- package/src/components/lib/ecommerce/StoreHeader.astro +446 -0
- package/src/components/lib/ecommerce/StoreHero.astro +260 -0
- package/src/components/lib/ecommerce/StoreProductCard.astro +307 -0
- package/src/components/lib/ecommerce/TrustBadges.astro +101 -0
- package/src/components/lib/ecommerce/VariantPicker.astro +145 -0
- package/src/components/lib/ecommerce/cart-store.ts +151 -0
- package/src/components/lib/ecommerce/catalog-filter.ts +62 -0
- package/src/components/lib/ecommerce/index.ts +34 -0
- package/src/components/lib/ecommerce/product-icons.ts +28 -0
- package/src/components/lib/ecommerce/types.ts +70 -0
- package/src/components/lib/feedback/ProgressRingCounter.astro +118 -0
- package/src/components/lib/feedback/ToastNotificationGroup.astro +173 -0
- package/src/components/lib/feedback/index.ts +2 -0
- package/src/components/lib/forms/AnimatedInput.astro +4 -2
- package/src/components/lib/forms/CustomRadioGroup.astro +3 -1
- package/src/components/lib/forms/GlassInlineToggleGroup.astro +161 -0
- package/src/components/lib/forms/PasswordStrengthInput.astro +242 -0
- package/src/components/lib/forms/PhoneCountryInput.astro +145 -0
- package/src/components/lib/forms/TagsAutocompleteInput.astro +249 -0
- package/src/components/lib/forms/index.ts +5 -0
- package/src/components/lib/index.ts +2 -0
- package/src/components/lib/layout/BentoGrid3.astro +6 -4
- package/src/components/lib/layout/CenterFixedBox.astro +2 -2
- package/src/components/lib/layout/CenteredContainer.astro +4 -2
- package/src/components/lib/layout/ClusterHorizontal.astro +2 -2
- package/src/components/lib/layout/DiagonalSectionDivider.astro +69 -0
- package/src/components/lib/layout/FeatureHero.astro +4 -2
- package/src/components/lib/layout/FooterCenteredMinimal.astro +4 -2
- package/src/components/lib/layout/FullBleedSection.astro +2 -2
- package/src/components/lib/layout/GalleryGrid4.astro +2 -2
- package/src/components/lib/layout/HolyGrailGrid.astro +127 -0
- package/src/components/lib/layout/LandingSectionSplit.astro +5 -3
- package/src/components/lib/layout/MasonryGrid.astro +2 -2
- package/src/components/lib/layout/MinimalFooterGrid.astro +1 -1
- package/src/components/lib/layout/ScrollSnapSection.astro +1 -1
- package/src/components/lib/layout/SidebarLayoutWrapper.astro +4 -2
- package/src/components/lib/layout/SplitScreenLayout.astro +3 -3
- package/src/components/lib/layout/StepLayoutVertical.astro +1 -1
- package/src/components/lib/layout/StickySidebarWrapper.astro +4 -2
- package/src/components/lib/layout/index.ts +3 -1
- package/src/components/lib/navigation/QuickJumpDock.astro +125 -0
- package/src/components/lib/navigation/StepBreadcrumbBar.astro +151 -0
- package/src/components/lib/navigation/SubNavbarPills.astro +102 -0
- package/src/components/lib/navigation/index.ts +3 -0
- package/src/components/lib/overlays/CookiePreferencesDrawer.astro +226 -0
- package/src/components/lib/overlays/FloatingFeedbackWidget.astro +203 -0
- package/src/components/lib/overlays/ImageCompareSlider.astro +172 -0
- package/src/components/lib/overlays/index.ts +3 -0
- package/src/components/lib/sections/AgencyContactBrief.astro +194 -0
- package/src/components/lib/sections/AgencyFooterCta.astro +94 -0
- package/src/components/lib/sections/AgencyHeader.astro +161 -0
- package/src/components/lib/sections/AgencyHeroKinetic.astro +172 -0
- package/src/components/lib/sections/AgencyServicesList.astro +113 -0
- package/src/components/lib/sections/AgencyTeamGrid.astro +111 -0
- package/src/components/lib/sections/AgencyWorkGrid.astro +147 -0
- package/src/components/lib/sections/BlogGridSection.astro +133 -0
- package/src/components/lib/sections/ButtonsShowcase.astro +20 -18
- package/src/components/lib/sections/CardsShowcase.astro +28 -26
- package/src/components/lib/sections/CareersOpenings.astro +141 -0
- package/src/components/lib/sections/ChangelogSection.astro +151 -0
- package/src/components/lib/sections/ContactGlassForm.astro +10 -8
- package/src/components/lib/sections/ContactSplitMap.astro +141 -0
- package/src/components/lib/sections/CtaAppDownload.astro +13 -11
- package/src/components/lib/sections/CtaGlowBanner.astro +12 -10
- package/src/components/lib/sections/CtaNewsletterSection.astro +165 -0
- package/src/components/lib/sections/CtaSplitImage.astro +149 -0
- package/src/components/lib/sections/DataShowcase.astro +23 -21
- package/src/components/lib/sections/FaqAccordionSection.astro +8 -8
- package/src/components/lib/sections/FaqTwoColumn.astro +121 -0
- package/src/components/lib/sections/FeatureAlternatingRows.astro +192 -0
- package/src/components/lib/sections/FeatureBentoGrid.astro +13 -11
- package/src/components/lib/sections/FeatureIconGrid.astro +155 -0
- package/src/components/lib/sections/FeatureTabsShowcase.astro +182 -0
- package/src/components/lib/sections/FeatureTimelineFlow.astro +8 -6
- package/src/components/lib/sections/FeedbackShowcase.astro +15 -13
- package/src/components/lib/sections/FooterMegaSection.astro +157 -0
- package/src/components/lib/sections/FormsShowcase.astro +22 -20
- package/src/components/lib/sections/HeroDashboardPreview.astro +182 -0
- package/src/components/lib/sections/HeroGlass.astro +22 -20
- package/src/components/lib/sections/HeroGradient.astro +15 -13
- package/src/components/lib/sections/HeroMinimalCentered.astro +175 -0
- package/src/components/lib/sections/HeroShowcaseSplit.astro +306 -0
- package/src/components/lib/sections/HeroSplit.astro +13 -11
- package/src/components/lib/sections/HeroTerminal.astro +253 -0
- package/src/components/lib/sections/HeroWaitlist.astro +231 -0
- package/src/components/lib/sections/HowItWorksSteps.astro +180 -0
- package/src/components/lib/sections/IntegrationsGrid.astro +167 -0
- package/src/components/lib/sections/LayoutShowcase.astro +21 -19
- package/src/components/lib/sections/LogoCloudSection.astro +96 -0
- package/src/components/lib/sections/LogoWallGrid.astro +93 -0
- package/src/components/lib/sections/NavigationShowcase.astro +15 -13
- package/src/components/lib/sections/OverlaysShowcase.astro +21 -19
- package/src/components/lib/sections/PricingComparisonMatrix.astro +15 -13
- package/src/components/lib/sections/PricingSinglePlan.astro +159 -0
- package/src/components/lib/sections/PricingTierCards.astro +11 -9
- package/src/components/lib/sections/PricingToggleCards.astro +171 -0
- package/src/components/lib/sections/ShopCategoryHero.astro +103 -0
- package/src/components/lib/sections/ShopCollectionMosaic.astro +131 -0
- package/src/components/lib/sections/ShopFooterWordmark.astro +100 -0
- package/src/components/lib/sections/ShopHeaderEditorial.astro +396 -0
- package/src/components/lib/sections/ShopHeroEditorial.astro +151 -0
- package/src/components/lib/sections/ShopLookbook.astro +250 -0
- package/src/components/lib/sections/ShopNewsletterEditorial.astro +128 -0
- package/src/components/lib/sections/ShopProductRail.astro +150 -0
- package/src/components/lib/sections/ShopReviewsEditorial.astro +133 -0
- package/src/components/lib/sections/ShopValuesMarquee.astro +91 -0
- package/src/components/lib/sections/StatsCounterBand.astro +124 -0
- package/src/components/lib/sections/StatsDashboardSection.astro +85 -0
- package/src/components/lib/sections/StatsMetricShowcase.astro +9 -7
- package/src/components/lib/sections/TeamGridSection.astro +12 -10
- package/src/components/lib/sections/TestimonialCarousel.astro +167 -0
- package/src/components/lib/sections/TestimonialFeatured.astro +122 -0
- package/src/components/lib/sections/TestimonialGridSection.astro +188 -0
- package/src/components/lib/sections/TestimonialWallGlass.astro +11 -9
- package/src/components/lib/sections/TypographyShowcase.astro +10 -8
- package/src/components/lib/sections/index.ts +39 -0
- package/src/components/lib/templates/ecommerce/StoreCategoryPage.astro +160 -0
- package/src/components/lib/templates/ecommerce/StoreCheckoutPage.astro +98 -0
- package/src/components/lib/templates/ecommerce/StoreHomePage.astro +191 -0
- package/src/components/lib/templates/ecommerce/StoreLayout.astro +169 -0
- package/src/components/lib/templates/ecommerce/StoreProductPage.astro +165 -0
- package/src/components/lib/templates/ecommerce/data.ts +187 -0
- package/src/components/lib/templates/ecommerce/index.ts +14 -0
- package/src/components/lib/templates/ecommerce-editorial/EditorialBagPage.astro +52 -0
- package/src/components/lib/templates/ecommerce-editorial/EditorialCheckoutPage.astro +123 -0
- package/src/components/lib/templates/ecommerce-editorial/EditorialHomePage.astro +102 -0
- package/src/components/lib/templates/ecommerce-editorial/EditorialLayout.astro +216 -0
- package/src/components/lib/templates/ecommerce-editorial/EditorialProductPage.astro +205 -0
- package/src/components/lib/templates/ecommerce-editorial/EditorialShopPage.astro +112 -0
- package/src/components/lib/templates/ecommerce-editorial/data.ts +125 -0
- package/src/components/lib/templates/ecommerce-editorial/index.ts +16 -0
- package/src/components/lib/templates/saas-hotel/AppLayout.astro +83 -0
- package/src/components/lib/templates/saas-hotel/DashboardPage.astro +66 -0
- package/src/components/lib/templates/saas-hotel/GuestsPage.astro +65 -0
- package/src/components/lib/templates/saas-hotel/LandingPage.astro +213 -0
- package/src/components/lib/templates/saas-hotel/ReportsPage.astro +63 -0
- package/src/components/lib/templates/saas-hotel/ReservationsPage.astro +49 -0
- package/src/components/lib/templates/saas-hotel/RoomsPage.astro +48 -0
- package/src/components/lib/templates/saas-hotel/SettingsPage.astro +115 -0
- package/src/components/lib/templates/saas-hotel/SignInPage.astro +50 -0
- package/src/components/lib/templates/saas-hotel/data.ts +229 -0
- package/src/components/lib/templates/saas-hotel/index.ts +19 -0
- package/src/components/lib/templates/saas-hotel/lobby-theme.css +90 -0
- package/src/components/lib/typography/AnimatedCounterText.astro +102 -0
- package/src/components/lib/typography/CurvedPathHeading.astro +86 -0
- package/src/components/lib/typography/GradientTextMarquee.astro +105 -0
- package/src/components/lib/typography/HackerDecodeText.astro +85 -0
- package/src/components/lib/typography/index.ts +4 -0
- package/src/styles/global.css +113 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* HistogramChart — Bins raw values into equal-width buckets and draws the
|
|
4
|
+
* distribution, with optional mean and median markers.
|
|
5
|
+
*
|
|
6
|
+
* @param {number[]} values - Raw observations.
|
|
7
|
+
* @param {number} bins - Number of buckets.
|
|
8
|
+
* @param {boolean} showStats - Draw mean & median reference lines.
|
|
9
|
+
* @param {string} unit - Unit suffix for bucket edges.
|
|
10
|
+
* @param {string} color - Bar color.
|
|
11
|
+
* @param {string} variant - Card style (glass|solid|ghost).
|
|
12
|
+
* @param {string} size - Density (sm|md|lg).
|
|
13
|
+
*/
|
|
14
|
+
import ChartFrame from './ChartFrame.astro';
|
|
15
|
+
import { scaleLinear, niceTicks, quantile, sum } from './chart-utils';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
title?: string;
|
|
19
|
+
subtitle?: string;
|
|
20
|
+
values?: number[];
|
|
21
|
+
bins?: number;
|
|
22
|
+
showStats?: boolean;
|
|
23
|
+
unit?: string;
|
|
24
|
+
height?: number;
|
|
25
|
+
color?: string;
|
|
26
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
27
|
+
size?: 'sm' | 'md' | 'lg';
|
|
28
|
+
className?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Deterministic sample: a right-skewed page-load distribution.
|
|
32
|
+
const sample = Array.from({ length: 240 }, (_, i) => {
|
|
33
|
+
const a = Math.sin(i * 12.9898) * 43758.5453;
|
|
34
|
+
const b = Math.sin(i * 78.233) * 12345.678;
|
|
35
|
+
const u = a - Math.floor(a);
|
|
36
|
+
const v = b - Math.floor(b);
|
|
37
|
+
return Math.round((0.6 + Math.abs(Math.sqrt(-2 * Math.log(u + 1e-9)) * Math.cos(2 * Math.PI * v)) * 0.9) * 100) / 100;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
title = 'Page load time',
|
|
42
|
+
subtitle = '240 sessions, seconds',
|
|
43
|
+
values = sample,
|
|
44
|
+
bins = 14,
|
|
45
|
+
showStats = true,
|
|
46
|
+
unit = 's',
|
|
47
|
+
height = 260,
|
|
48
|
+
color = 'var(--chart-1, #3987e5)',
|
|
49
|
+
variant = 'glass',
|
|
50
|
+
size = 'md',
|
|
51
|
+
className = '',
|
|
52
|
+
} = Astro.props;
|
|
53
|
+
|
|
54
|
+
const W = 640;
|
|
55
|
+
const H = height;
|
|
56
|
+
const m = { t: 22, r: 12, b: 30, l: 40 };
|
|
57
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
58
|
+
const lo = sorted[0];
|
|
59
|
+
const hi = sorted[sorted.length - 1];
|
|
60
|
+
const width = (hi - lo) / bins || 1;
|
|
61
|
+
const counts = Array.from({ length: bins }, () => 0);
|
|
62
|
+
values.forEach((v) => {
|
|
63
|
+
counts[Math.min(bins - 1, Math.floor((v - lo) / width))] += 1;
|
|
64
|
+
});
|
|
65
|
+
const yTicks = niceTicks(0, Math.max(...counts), 4);
|
|
66
|
+
const y = scaleLinear(0, yTicks[yTicks.length - 1], H - m.b, m.t);
|
|
67
|
+
const x = scaleLinear(lo, hi, m.l, W - m.r);
|
|
68
|
+
const mean = sum(values) / values.length;
|
|
69
|
+
const median = quantile(sorted, 0.5);
|
|
70
|
+
const edge = (i: number) => (lo + i * width).toFixed(1);
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
<ChartFrame
|
|
74
|
+
title={title}
|
|
75
|
+
subtitle={subtitle}
|
|
76
|
+
value={`${median.toFixed(2)}${unit}`}
|
|
77
|
+
delta="median"
|
|
78
|
+
variant={variant}
|
|
79
|
+
size={size}
|
|
80
|
+
className={className}
|
|
81
|
+
table={{ headers: ['Bucket', 'Count'], rows: counts.map((c, i) => [`${edge(i)}–${edge(i + 1)}${unit}`, c]) }}
|
|
82
|
+
>
|
|
83
|
+
<svg viewBox={`0 0 ${W} ${H}`} role="img" aria-label={`${title}: histogram of ${values.length} values, median ${median.toFixed(2)}${unit}`}>
|
|
84
|
+
{yTicks.map((t) => (
|
|
85
|
+
<g>
|
|
86
|
+
<line class={t === 0 ? 'cf-axis' : 'cf-grid'} x1={m.l} x2={W - m.r} y1={y(t)} y2={y(t)} />
|
|
87
|
+
<text class="cf-label" x={m.l - 8} y={y(t) + 4} text-anchor="end">{t}</text>
|
|
88
|
+
</g>
|
|
89
|
+
))}
|
|
90
|
+
{counts.map((c, i) => {
|
|
91
|
+
const bx = x(lo + i * width) + 1;
|
|
92
|
+
const bw = x(lo + (i + 1) * width) - x(lo + i * width) - 2;
|
|
93
|
+
return (
|
|
94
|
+
<rect class="cf-mark cf-dim" x={bx} y={y(c)} width={Math.max(1, bw)} height={Math.max(0, y(0) - y(c))} rx="2" fill={color}
|
|
95
|
+
tabindex="0" role="img" aria-label={`${edge(i)} to ${edge(i + 1)}${unit}: ${c} values`}
|
|
96
|
+
data-tip-title={`${edge(i)}–${edge(i + 1)}${unit}`} data-tip={`${color}::${c} values · ${((c / values.length) * 100).toFixed(1)}%`} />
|
|
97
|
+
);
|
|
98
|
+
})}
|
|
99
|
+
{Array.from({ length: bins + 1 }, (_, i) => i).filter((i) => i % 2 === 0).map((i) => (
|
|
100
|
+
<text class="cf-label" x={x(lo + i * width)} y={H - 10} text-anchor="middle">{edge(i)}</text>
|
|
101
|
+
))}
|
|
102
|
+
{showStats && (
|
|
103
|
+
<g aria-hidden="true">
|
|
104
|
+
<line x1={x(median)} x2={x(median)} y1={m.t - 6} y2={H - m.b} stroke="var(--c-text-1, #fff)" stroke-width="1.5" />
|
|
105
|
+
<text class="cf-label cf-label--strong" x={x(median) + 5} y={m.t}>Median</text>
|
|
106
|
+
<line x1={x(mean)} x2={x(mean)} y1={m.t + 10} y2={H - m.b} stroke="var(--chart-2, #d95926)" stroke-width="1.5" />
|
|
107
|
+
<text class="cf-label" x={x(mean) + 5} y={m.t + 16}>Mean {mean.toFixed(2)}{unit}</text>
|
|
108
|
+
</g>
|
|
109
|
+
)}
|
|
110
|
+
</svg>
|
|
111
|
+
</ChartFrame>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* HorizontalBarChart — Ranked horizontal bars with labels on the left and values
|
|
4
|
+
* on the right. One series → one color; optionally highlight a single bar.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<{label: string, value: number}>} items - Bars to draw.
|
|
7
|
+
* @param {boolean} sort - Sort descending by value.
|
|
8
|
+
* @param {string} highlight - Label to emphasise; other bars recede.
|
|
9
|
+
* @param {string} prefix - Value prefix.
|
|
10
|
+
* @param {string} suffix - Value suffix.
|
|
11
|
+
* @param {string} color - Bar color.
|
|
12
|
+
* @param {string} variant - Card style (glass|solid|ghost).
|
|
13
|
+
* @param {string} size - Density (sm|md|lg).
|
|
14
|
+
*/
|
|
15
|
+
import ChartFrame from './ChartFrame.astro';
|
|
16
|
+
import { formatValue } from './chart-utils';
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
title?: string;
|
|
20
|
+
subtitle?: string;
|
|
21
|
+
items?: Array<{ label: string; value: number }>;
|
|
22
|
+
sort?: boolean;
|
|
23
|
+
highlight?: string;
|
|
24
|
+
prefix?: string;
|
|
25
|
+
suffix?: string;
|
|
26
|
+
color?: string;
|
|
27
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
28
|
+
size?: 'sm' | 'md' | 'lg';
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
title = 'Top pages',
|
|
34
|
+
subtitle = 'Unique visitors, last 30 days',
|
|
35
|
+
items = [
|
|
36
|
+
{ label: '/pricing', value: 18420 },
|
|
37
|
+
{ label: '/docs/getting-started', value: 15210 },
|
|
38
|
+
{ label: '/', value: 12980 },
|
|
39
|
+
{ label: '/blog/astro-5', value: 9340 },
|
|
40
|
+
{ label: '/components', value: 7120 },
|
|
41
|
+
{ label: '/changelog', value: 4310 },
|
|
42
|
+
],
|
|
43
|
+
sort = true,
|
|
44
|
+
highlight,
|
|
45
|
+
prefix = '',
|
|
46
|
+
suffix = '',
|
|
47
|
+
color = 'var(--chart-1, #3987e5)',
|
|
48
|
+
variant = 'glass',
|
|
49
|
+
size = 'md',
|
|
50
|
+
className = '',
|
|
51
|
+
} = Astro.props;
|
|
52
|
+
|
|
53
|
+
const rows = sort ? [...items].sort((a, b) => b.value - a.value) : items;
|
|
54
|
+
const max = Math.max(...rows.map((r) => r.value)) || 1;
|
|
55
|
+
const fmt = (v: number) => formatValue(v, prefix, suffix);
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
<ChartFrame
|
|
59
|
+
title={title}
|
|
60
|
+
subtitle={subtitle}
|
|
61
|
+
variant={variant}
|
|
62
|
+
size={size}
|
|
63
|
+
className={className}
|
|
64
|
+
table={{ headers: ['Item', 'Value'], rows: rows.map((r) => [r.label, fmt(r.value)]) }}
|
|
65
|
+
>
|
|
66
|
+
<ol class="hb" aria-label={title}>
|
|
67
|
+
{rows.map((r, i) => {
|
|
68
|
+
const dim = highlight && highlight !== r.label;
|
|
69
|
+
return (
|
|
70
|
+
<li
|
|
71
|
+
class="hb__row cf-mark"
|
|
72
|
+
tabindex="0"
|
|
73
|
+
style={`--hb-w:${(r.value / max) * 100}%; --hb-c:${color}; --hb-o:${dim ? 0.35 : 1}; --hb-i:${i}`}
|
|
74
|
+
data-tip-title={r.label}
|
|
75
|
+
data-tip={`${color}::${fmt(r.value)} · ${((r.value / max) * 100).toFixed(0)}% of top`}
|
|
76
|
+
aria-label={`${i + 1}. ${r.label}: ${fmt(r.value)}`}
|
|
77
|
+
>
|
|
78
|
+
<span class="hb__label">{r.label}</span>
|
|
79
|
+
<span class="hb__track" aria-hidden="true"><span class="hb__bar"></span></span>
|
|
80
|
+
<span class="hb__value">{fmt(r.value)}</span>
|
|
81
|
+
</li>
|
|
82
|
+
);
|
|
83
|
+
})}
|
|
84
|
+
</ol>
|
|
85
|
+
</ChartFrame>
|
|
86
|
+
|
|
87
|
+
<style>
|
|
88
|
+
.hb {
|
|
89
|
+
list-style: none;
|
|
90
|
+
margin: 0;
|
|
91
|
+
padding: 0;
|
|
92
|
+
display: grid;
|
|
93
|
+
gap: 0.35rem;
|
|
94
|
+
}
|
|
95
|
+
.hb__row {
|
|
96
|
+
display: grid;
|
|
97
|
+
grid-template-columns: minmax(6rem, 34%) 1fr auto;
|
|
98
|
+
align-items: center;
|
|
99
|
+
gap: 0.75rem;
|
|
100
|
+
min-height: 32px;
|
|
101
|
+
padding: 0.15rem 0.35rem;
|
|
102
|
+
border-radius: 8px;
|
|
103
|
+
cursor: default;
|
|
104
|
+
}
|
|
105
|
+
.hb__row:hover,
|
|
106
|
+
.hb__row:focus-visible {
|
|
107
|
+
background: rgb(var(--ink-rgb, 255 255 255) / 0.04);
|
|
108
|
+
}
|
|
109
|
+
.hb__row:focus-visible {
|
|
110
|
+
outline: 2px solid var(--c-primary-light, #d4a017);
|
|
111
|
+
outline-offset: 1px;
|
|
112
|
+
}
|
|
113
|
+
.hb__label {
|
|
114
|
+
font-size: 0.8125rem;
|
|
115
|
+
color: var(--c-text-2, #a3a3a3);
|
|
116
|
+
overflow: hidden;
|
|
117
|
+
text-overflow: ellipsis;
|
|
118
|
+
white-space: nowrap;
|
|
119
|
+
}
|
|
120
|
+
.hb__track {
|
|
121
|
+
height: 10px;
|
|
122
|
+
border-radius: 4px;
|
|
123
|
+
background: rgb(var(--ink-rgb, 255 255 255) / 0.04);
|
|
124
|
+
overflow: hidden;
|
|
125
|
+
}
|
|
126
|
+
.hb__bar {
|
|
127
|
+
display: block;
|
|
128
|
+
height: 100%;
|
|
129
|
+
width: var(--hb-w);
|
|
130
|
+
border-radius: 0 4px 4px 0;
|
|
131
|
+
background: var(--hb-c);
|
|
132
|
+
opacity: var(--hb-o);
|
|
133
|
+
transform-origin: left;
|
|
134
|
+
animation: hb-grow 0.7s cubic-bezier(0.4, 0, 0.2, 1) both;
|
|
135
|
+
animation-delay: calc(var(--hb-i) * 60ms);
|
|
136
|
+
}
|
|
137
|
+
.hb__value {
|
|
138
|
+
font-size: 0.8125rem;
|
|
139
|
+
font-weight: 600;
|
|
140
|
+
color: var(--c-text-1, #fff);
|
|
141
|
+
font-variant-numeric: tabular-nums;
|
|
142
|
+
min-width: 3.5rem;
|
|
143
|
+
text-align: right;
|
|
144
|
+
}
|
|
145
|
+
@keyframes hb-grow {
|
|
146
|
+
from { transform: scaleX(0); }
|
|
147
|
+
}
|
|
148
|
+
@media (max-width: 480px) {
|
|
149
|
+
.hb__row { grid-template-columns: 1fr auto; }
|
|
150
|
+
.hb__track { grid-column: 1 / -1; grid-row: 2; }
|
|
151
|
+
}
|
|
152
|
+
@media (prefers-reduced-motion: reduce) {
|
|
153
|
+
.hb__bar { animation: none; }
|
|
154
|
+
}
|
|
155
|
+
</style>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* KpiStatTile — Hero-number statistic tile: label, big value, change vs previous
|
|
4
|
+
* period (icon + text, never color alone) and an optional sparkline.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} label - Metric name.
|
|
7
|
+
* @param {string} value - Formatted value.
|
|
8
|
+
* @param {number} change - Percentage change vs comparison period.
|
|
9
|
+
* @param {string} period - Comparison period label (e.g. 'vs last month').
|
|
10
|
+
* @param {boolean} invert - Treat a decrease as good (e.g. churn, latency).
|
|
11
|
+
* @param {number[]} trend - Optional sparkline data.
|
|
12
|
+
* @param {string} variant - Visual style (glass|solid|ghost).
|
|
13
|
+
* @param {string} size - Density (sm|md|lg).
|
|
14
|
+
* @param {string} className - Extra CSS class.
|
|
15
|
+
*/
|
|
16
|
+
import SparklineChart from './SparklineChart.astro';
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
label?: string;
|
|
20
|
+
value?: string;
|
|
21
|
+
change?: number;
|
|
22
|
+
period?: string;
|
|
23
|
+
invert?: boolean;
|
|
24
|
+
trend?: number[];
|
|
25
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
26
|
+
size?: 'sm' | 'md' | 'lg';
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
label = 'Monthly recurring revenue',
|
|
32
|
+
value = '$84,210',
|
|
33
|
+
change = 12.4,
|
|
34
|
+
period = 'vs last month',
|
|
35
|
+
invert = false,
|
|
36
|
+
trend = [52, 55, 54, 60, 63, 61, 68, 72, 70, 76, 80, 84],
|
|
37
|
+
variant = 'glass',
|
|
38
|
+
size = 'md',
|
|
39
|
+
className = '',
|
|
40
|
+
} = Astro.props;
|
|
41
|
+
|
|
42
|
+
const up = change >= 0;
|
|
43
|
+
const good = invert ? !up : up;
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
<article class={`kpi kpi--${variant} kpi--${size} ${className}`} aria-label={`${label}: ${value}, ${up ? 'up' : 'down'} ${Math.abs(change)}% ${period}`}>
|
|
47
|
+
<header class="kpi__head">
|
|
48
|
+
<h3 class="kpi__label">{label}</h3>
|
|
49
|
+
<span class={`kpi__chip ${good ? 'kpi__chip--good' : 'kpi__chip--bad'}`}>
|
|
50
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
51
|
+
{up ? <path d="M7 17 17 7M9 7h8v8" /> : <path d="M7 7l10 10M17 9v8H9" />}
|
|
52
|
+
</svg>
|
|
53
|
+
{up ? '+' : '−'}{Math.abs(change)}%
|
|
54
|
+
</span>
|
|
55
|
+
</header>
|
|
56
|
+
<p class="kpi__value">{value}</p>
|
|
57
|
+
<div class="kpi__foot">
|
|
58
|
+
<span class="kpi__period">{period}</span>
|
|
59
|
+
{trend.length > 1 && (
|
|
60
|
+
<SparklineChart data={trend} size={size === 'lg' ? 'lg' : 'md'} color={good ? 'var(--chart-pos, #34c38f)' : 'var(--chart-neg, #f06a6a)'} label={`${label} trend`} />
|
|
61
|
+
)}
|
|
62
|
+
</div>
|
|
63
|
+
</article>
|
|
64
|
+
|
|
65
|
+
<style>
|
|
66
|
+
.kpi {
|
|
67
|
+
--kpi-pad: var(--sp-6, 1.5rem);
|
|
68
|
+
--kpi-val: 2rem;
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-direction: column;
|
|
71
|
+
gap: 0.5rem;
|
|
72
|
+
padding: var(--kpi-pad);
|
|
73
|
+
border-radius: var(--r-lg, 20px);
|
|
74
|
+
min-width: 0;
|
|
75
|
+
transition: border-color 0.25s ease, transform 0.25s ease;
|
|
76
|
+
}
|
|
77
|
+
.kpi--glass {
|
|
78
|
+
background: linear-gradient(160deg, rgb(var(--ink-rgb, 255 255 255) / 0.05), rgb(var(--ink-rgb, 255 255 255) / 0.015));
|
|
79
|
+
border: 1px solid var(--c-border, rgb(var(--ink-rgb, 255 255 255) / 0.07));
|
|
80
|
+
backdrop-filter: blur(14px);
|
|
81
|
+
}
|
|
82
|
+
.kpi--solid { background: var(--chart-surface, #0d0d0f); border: 1px solid rgb(var(--ink-rgb, 255 255 255) / 0.08); }
|
|
83
|
+
.kpi--ghost { background: transparent; border: 1px solid transparent; padding-inline: 0; }
|
|
84
|
+
.kpi--glass:hover, .kpi--solid:hover { border-color: rgb(var(--ink-rgb, 255 255 255) / 0.16); transform: translateY(-2px); }
|
|
85
|
+
.kpi--sm { --kpi-pad: var(--sp-4, 1rem); --kpi-val: 1.5rem; }
|
|
86
|
+
.kpi--lg { --kpi-pad: var(--sp-8, 2rem); --kpi-val: 2.5rem; }
|
|
87
|
+
.kpi__head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }
|
|
88
|
+
.kpi__label { margin: 0; font-size: 0.8125rem; font-weight: 500; color: var(--c-text-2, #a3a3a3); letter-spacing: 0; }
|
|
89
|
+
.kpi__chip {
|
|
90
|
+
display: inline-flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
gap: 0.25rem;
|
|
93
|
+
padding: 0.2rem 0.5rem;
|
|
94
|
+
border-radius: var(--r-full, 999px);
|
|
95
|
+
font-size: 0.75rem;
|
|
96
|
+
font-weight: 650;
|
|
97
|
+
font-variant-numeric: tabular-nums;
|
|
98
|
+
color: var(--c-text-1, #fff);
|
|
99
|
+
}
|
|
100
|
+
.kpi__chip--good { background: color-mix(in srgb, var(--chart-pos, #34c38f) 18%, transparent); }
|
|
101
|
+
.kpi__chip--good svg { color: var(--chart-pos, #34c38f); }
|
|
102
|
+
.kpi__chip--bad { background: color-mix(in srgb, var(--chart-neg, #f06a6a) 18%, transparent); }
|
|
103
|
+
.kpi__chip--bad svg { color: var(--chart-neg, #f06a6a); }
|
|
104
|
+
.kpi__value {
|
|
105
|
+
margin: 0;
|
|
106
|
+
font-size: var(--kpi-val);
|
|
107
|
+
font-weight: 750;
|
|
108
|
+
color: var(--c-text-1, #fff);
|
|
109
|
+
letter-spacing: -0.02em;
|
|
110
|
+
font-variant-numeric: tabular-nums;
|
|
111
|
+
line-height: 1.1;
|
|
112
|
+
}
|
|
113
|
+
.kpi__foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; }
|
|
114
|
+
.kpi__period { font-size: 0.75rem; color: var(--c-text-3, #8a8a8a); }
|
|
115
|
+
@media (prefers-reduced-motion: reduce) { .kpi { transition: none; } }
|
|
116
|
+
</style>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* KpiTrendGrid — Responsive grid of KPI stat tiles with sparklines; the classic
|
|
4
|
+
* top row of an analytics dashboard.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<{label: string, value: string, change: number, trend?: number[], invert?: boolean}>} metrics - Tiles.
|
|
7
|
+
* @param {string} period - Shared comparison label.
|
|
8
|
+
* @param {string} variant - Tile style (glass|solid|ghost).
|
|
9
|
+
* @param {string} size - Density (sm|md|lg).
|
|
10
|
+
* @param {string} className - Extra CSS class.
|
|
11
|
+
*/
|
|
12
|
+
import KpiStatTile from './KpiStatTile.astro';
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
title?: string;
|
|
16
|
+
metrics?: Array<{ label: string; value: string; change: number; trend?: number[]; invert?: boolean }>;
|
|
17
|
+
period?: string;
|
|
18
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
19
|
+
size?: 'sm' | 'md' | 'lg';
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
title = 'Overview',
|
|
25
|
+
metrics = [
|
|
26
|
+
{ label: 'Revenue', value: '$128.4k', change: 9.2, trend: [80, 84, 90, 88, 96, 102, 110, 118, 128] },
|
|
27
|
+
{ label: 'Active users', value: '24,812', change: 4.1, trend: [20, 21, 21.5, 22, 22.8, 23.1, 23.9, 24.2, 24.8] },
|
|
28
|
+
{ label: 'Churn', value: '2.3%', change: -0.6, invert: true, trend: [3.1, 3, 2.9, 2.8, 2.7, 2.6, 2.5, 2.4, 2.3] },
|
|
29
|
+
{ label: 'Avg. response', value: '182ms', change: 7.8, invert: true, trend: [150, 160, 158, 170, 165, 175, 172, 180, 182] },
|
|
30
|
+
],
|
|
31
|
+
period = 'vs previous 30 days',
|
|
32
|
+
variant = 'glass',
|
|
33
|
+
size = 'md',
|
|
34
|
+
className = '',
|
|
35
|
+
} = Astro.props;
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
<section class={`kg ${className}`} aria-label={title}>
|
|
39
|
+
{title && <h2 class="kg__title">{title}</h2>}
|
|
40
|
+
<div class="kg__grid">
|
|
41
|
+
{metrics.map((mt) => (
|
|
42
|
+
<KpiStatTile label={mt.label} value={mt.value} change={mt.change} trend={mt.trend} invert={mt.invert} period={period} variant={variant} size={size} />
|
|
43
|
+
))}
|
|
44
|
+
</div>
|
|
45
|
+
</section>
|
|
46
|
+
|
|
47
|
+
<style>
|
|
48
|
+
.kg { width: 100%; }
|
|
49
|
+
.kg__title {
|
|
50
|
+
margin: 0 0 var(--sp-4, 1rem);
|
|
51
|
+
font-size: 1rem;
|
|
52
|
+
font-weight: 650;
|
|
53
|
+
color: var(--c-text-1, #fff);
|
|
54
|
+
}
|
|
55
|
+
.kg__grid {
|
|
56
|
+
display: grid;
|
|
57
|
+
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
|
58
|
+
gap: var(--sp-4, 1rem);
|
|
59
|
+
}
|
|
60
|
+
</style>
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* LineChart — Zero-dependency SVG line chart with smooth, linear or step curves,
|
|
4
|
+
* optional area fill, crosshair tooltip and a data-table fallback.
|
|
5
|
+
*
|
|
6
|
+
* @param {string[]} categories - X-axis labels.
|
|
7
|
+
* @param {Array<{name: string, data: number[]}>} series - One or more series (max 8).
|
|
8
|
+
* @param {string} curve - Interpolation (smooth|linear|step).
|
|
9
|
+
* @param {boolean} area - Fill a soft gradient under each line.
|
|
10
|
+
* @param {boolean} dots - Draw point markers.
|
|
11
|
+
* @param {string} prefix - Value prefix (e.g. '$').
|
|
12
|
+
* @param {string} suffix - Value suffix (e.g. '%').
|
|
13
|
+
* @param {number} height - SVG height in viewBox units (width is 640).
|
|
14
|
+
* @param {string[]} colors - Optional color overrides per series.
|
|
15
|
+
* @param {string} variant - Card style (glass|solid|ghost).
|
|
16
|
+
* @param {string} size - Density (sm|md|lg).
|
|
17
|
+
*/
|
|
18
|
+
import ChartFrame from './ChartFrame.astro';
|
|
19
|
+
import { colorAt, scaleLinear, niceTicks, curvePath, areaPath, formatValue, chartId, type Point } from './chart-utils';
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
title?: string;
|
|
23
|
+
subtitle?: string;
|
|
24
|
+
categories?: string[];
|
|
25
|
+
series?: Array<{ name: string; data: number[] }>;
|
|
26
|
+
curve?: 'smooth' | 'linear' | 'step';
|
|
27
|
+
area?: boolean;
|
|
28
|
+
dots?: boolean;
|
|
29
|
+
prefix?: string;
|
|
30
|
+
suffix?: string;
|
|
31
|
+
height?: number;
|
|
32
|
+
colors?: string[];
|
|
33
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
34
|
+
size?: 'sm' | 'md' | 'lg';
|
|
35
|
+
className?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
title = 'Weekly active users',
|
|
40
|
+
subtitle = 'Last 12 weeks, by platform',
|
|
41
|
+
categories = ['W1', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7', 'W8', 'W9', 'W10', 'W11', 'W12'],
|
|
42
|
+
series = [
|
|
43
|
+
{ name: 'Web', data: [4200, 4580, 4410, 5020, 5390, 5210, 5870, 6120, 6050, 6680, 7010, 7420] },
|
|
44
|
+
{ name: 'Mobile', data: [2100, 2350, 2600, 2550, 2980, 3310, 3240, 3620, 3900, 4150, 4080, 4560] },
|
|
45
|
+
],
|
|
46
|
+
curve = 'smooth',
|
|
47
|
+
area = true,
|
|
48
|
+
dots = false,
|
|
49
|
+
prefix = '',
|
|
50
|
+
suffix = '',
|
|
51
|
+
height = 280,
|
|
52
|
+
colors,
|
|
53
|
+
variant = 'glass',
|
|
54
|
+
size = 'md',
|
|
55
|
+
className = '',
|
|
56
|
+
} = Astro.props;
|
|
57
|
+
|
|
58
|
+
const W = 640;
|
|
59
|
+
const H = height;
|
|
60
|
+
const m = { t: 12, r: 16, b: 28, l: 44 };
|
|
61
|
+
const all = series.flatMap((s) => s.data);
|
|
62
|
+
const ticks = niceTicks(Math.min(0, ...all), Math.max(...all), 4);
|
|
63
|
+
const y = scaleLinear(ticks[0], ticks[ticks.length - 1], H - m.b, m.t);
|
|
64
|
+
const n = categories.length;
|
|
65
|
+
const x = (i: number) => m.l + (n <= 1 ? 0 : (i / (n - 1)) * (W - m.l - m.r));
|
|
66
|
+
const gid = chartId('line');
|
|
67
|
+
const step = n > 1 ? (W - m.l - m.r) / (n - 1) : W;
|
|
68
|
+
const labelEvery = Math.ceil(n / 8);
|
|
69
|
+
|
|
70
|
+
const lines = series.slice(0, 8).map((s, si) => {
|
|
71
|
+
const pts: Point[] = s.data.map((v, i) => [x(i), y(v)]);
|
|
72
|
+
return {
|
|
73
|
+
name: s.name,
|
|
74
|
+
color: colorAt(si, colors),
|
|
75
|
+
pts,
|
|
76
|
+
d: curvePath(pts, curve),
|
|
77
|
+
area: areaPath(pts, H - m.b, curve),
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const fmt = (v: number) => formatValue(v, prefix, suffix);
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
<ChartFrame
|
|
85
|
+
title={title}
|
|
86
|
+
subtitle={subtitle}
|
|
87
|
+
variant={variant}
|
|
88
|
+
size={size}
|
|
89
|
+
className={className}
|
|
90
|
+
legend={lines.map((l) => ({ label: l.name, color: l.color }))}
|
|
91
|
+
table={{
|
|
92
|
+
headers: ['Period', ...series.map((s) => s.name)],
|
|
93
|
+
rows: categories.map((c, i) => [c, ...series.map((s) => fmt(s.data[i]))]),
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<svg viewBox={`0 0 ${W} ${H}`} role="img" aria-label={`${title}: line chart with ${series.length} series over ${n} periods`}>
|
|
97
|
+
<defs>
|
|
98
|
+
{lines.map((l, i) => (
|
|
99
|
+
<linearGradient id={`${gid}-g${i}`} x1="0" y1="0" x2="0" y2="1">
|
|
100
|
+
<stop offset="0%" stop-color={l.color} stop-opacity="0.22" />
|
|
101
|
+
<stop offset="100%" stop-color={l.color} stop-opacity="0" />
|
|
102
|
+
</linearGradient>
|
|
103
|
+
))}
|
|
104
|
+
</defs>
|
|
105
|
+
|
|
106
|
+
{ticks.map((t) => (
|
|
107
|
+
<g>
|
|
108
|
+
<line class="cf-grid" x1={m.l} x2={W - m.r} y1={y(t)} y2={y(t)} />
|
|
109
|
+
<text class="cf-label" x={m.l - 8} y={y(t) + 4} text-anchor="end">{fmt(t)}</text>
|
|
110
|
+
</g>
|
|
111
|
+
))}
|
|
112
|
+
|
|
113
|
+
{categories.map((c, i) => i % labelEvery === 0 && (
|
|
114
|
+
<text class="cf-label" x={x(i)} y={H - 8} text-anchor="middle">{c}</text>
|
|
115
|
+
))}
|
|
116
|
+
|
|
117
|
+
{area && lines.map((l, i) => <path d={l.area} fill={`url(#${gid}-g${i})`} aria-hidden="true" />)}
|
|
118
|
+
{lines.map((l) => (
|
|
119
|
+
<path class="lc__line" d={l.d} fill="none" stroke={l.color} stroke-width="2" stroke-linejoin="round" stroke-linecap="round" aria-hidden="true" />
|
|
120
|
+
))}
|
|
121
|
+
{dots && lines.map((l) => l.pts.map(([px, py]) => (
|
|
122
|
+
<circle cx={px} cy={py} r="4" fill={l.color} stroke="var(--chart-surface, #0d0d0f)" stroke-width="2" aria-hidden="true" />
|
|
123
|
+
)))}
|
|
124
|
+
|
|
125
|
+
{categories.map((c, i) => (
|
|
126
|
+
<g class="cf-hit-group">
|
|
127
|
+
<line class="cf-cross" x1={x(i)} x2={x(i)} y1={m.t} y2={H - m.b} />
|
|
128
|
+
{lines.map((l) => (
|
|
129
|
+
<circle class="cf-cross" cx={l.pts[i]?.[0]} cy={l.pts[i]?.[1]} r="4.5" fill={l.color} stroke="#fff" stroke-width="1.5" />
|
|
130
|
+
))}
|
|
131
|
+
<rect
|
|
132
|
+
class="cf-hit"
|
|
133
|
+
x={x(i) - step / 2}
|
|
134
|
+
y={m.t}
|
|
135
|
+
width={step}
|
|
136
|
+
height={H - m.t - m.b}
|
|
137
|
+
tabindex="0"
|
|
138
|
+
role="img"
|
|
139
|
+
aria-label={`${c}: ${series.map((s) => `${s.name} ${fmt(s.data[i])}`).join(', ')}`}
|
|
140
|
+
data-tip-title={c}
|
|
141
|
+
data-tip={lines.map((l, si) => `${l.color}::${l.name}: ${fmt(series[si].data[i])}`).join('|')}
|
|
142
|
+
/>
|
|
143
|
+
</g>
|
|
144
|
+
))}
|
|
145
|
+
</svg>
|
|
146
|
+
</ChartFrame>
|
|
147
|
+
|
|
148
|
+
<style>
|
|
149
|
+
.lc__line {
|
|
150
|
+
stroke-dasharray: 2400;
|
|
151
|
+
stroke-dashoffset: 2400;
|
|
152
|
+
animation: lc-draw 1.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
153
|
+
}
|
|
154
|
+
@keyframes lc-draw {
|
|
155
|
+
to { stroke-dashoffset: 0; }
|
|
156
|
+
}
|
|
157
|
+
@media (prefers-reduced-motion: reduce) {
|
|
158
|
+
.lc__line { animation: none; stroke-dashoffset: 0; }
|
|
159
|
+
}
|
|
160
|
+
</style>
|