astro-component-kit 0.3.0 → 0.4.0
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 +159 -176
- package/package.json +2 -2
- package/src/components/index.ts +16 -202
- 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/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/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/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/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/layout/DiagonalSectionDivider.astro +69 -0
- package/src/components/lib/layout/HolyGrailGrid.astro +125 -0
- 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/BlogGridSection.astro +131 -0
- package/src/components/lib/sections/CareersOpenings.astro +139 -0
- package/src/components/lib/sections/ChangelogSection.astro +144 -0
- package/src/components/lib/sections/ContactSplitMap.astro +139 -0
- package/src/components/lib/sections/CtaNewsletterSection.astro +163 -0
- package/src/components/lib/sections/CtaSplitImage.astro +147 -0
- package/src/components/lib/sections/FaqTwoColumn.astro +119 -0
- package/src/components/lib/sections/FeatureAlternatingRows.astro +190 -0
- package/src/components/lib/sections/FeatureIconGrid.astro +155 -0
- package/src/components/lib/sections/FeatureTabsShowcase.astro +180 -0
- package/src/components/lib/sections/FooterMegaSection.astro +155 -0
- package/src/components/lib/sections/HeroDashboardPreview.astro +180 -0
- package/src/components/lib/sections/HeroMinimalCentered.astro +175 -0
- package/src/components/lib/sections/HeroShowcaseSplit.astro +304 -0
- package/src/components/lib/sections/HeroTerminal.astro +251 -0
- package/src/components/lib/sections/HeroWaitlist.astro +229 -0
- package/src/components/lib/sections/HowItWorksSteps.astro +178 -0
- package/src/components/lib/sections/IntegrationsGrid.astro +167 -0
- package/src/components/lib/sections/LogoCloudSection.astro +96 -0
- package/src/components/lib/sections/LogoWallGrid.astro +91 -0
- package/src/components/lib/sections/PricingSinglePlan.astro +157 -0
- package/src/components/lib/sections/PricingToggleCards.astro +171 -0
- package/src/components/lib/sections/StatsCounterBand.astro +122 -0
- package/src/components/lib/sections/StatsDashboardSection.astro +83 -0
- package/src/components/lib/sections/TestimonialCarousel.astro +165 -0
- package/src/components/lib/sections/TestimonialFeatured.astro +120 -0
- package/src/components/lib/sections/TestimonialGridSection.astro +188 -0
- package/src/components/lib/sections/index.ts +29 -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 +18 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* ActivityRings — Concentric closed rings tracking daily goals (move, exercise,
|
|
4
|
+
* stand style). Values over 100% wrap with a stronger overlap stroke.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<{label: string, value: number, goal: number, unit?: string}>} rings - Up to 4 goals.
|
|
7
|
+
* @param {string[]} colors - Optional per-ring colors.
|
|
8
|
+
* @param {string} variant - Card style (glass|solid|ghost).
|
|
9
|
+
* @param {string} size - Density (sm|md|lg).
|
|
10
|
+
*/
|
|
11
|
+
import ChartFrame from './ChartFrame.astro';
|
|
12
|
+
import { arcStroke, colorAt } from './chart-utils';
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
title?: string;
|
|
16
|
+
subtitle?: string;
|
|
17
|
+
rings?: Array<{ label: string; value: number; goal: number; unit?: string }>;
|
|
18
|
+
colors?: string[];
|
|
19
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
20
|
+
size?: 'sm' | 'md' | 'lg';
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
title = 'Today',
|
|
26
|
+
subtitle = 'Daily goals',
|
|
27
|
+
rings = [
|
|
28
|
+
{ label: 'Focus time', value: 5.2, goal: 6, unit: 'h' },
|
|
29
|
+
{ label: 'Tasks done', value: 11, goal: 8 },
|
|
30
|
+
{ label: 'Reviews', value: 3, goal: 5 },
|
|
31
|
+
],
|
|
32
|
+
colors = ['var(--chart-5, #d55181)', 'var(--chart-3, #199e70)', 'var(--chart-1, #3987e5)'],
|
|
33
|
+
variant = 'glass',
|
|
34
|
+
size = 'md',
|
|
35
|
+
className = '',
|
|
36
|
+
} = Astro.props;
|
|
37
|
+
|
|
38
|
+
const S = 220;
|
|
39
|
+
const c = S / 2;
|
|
40
|
+
const stroke = 20;
|
|
41
|
+
const items = rings.slice(0, 4).map((r, i) => {
|
|
42
|
+
const radius = c - stroke / 2 - 4 - i * (stroke + 4);
|
|
43
|
+
const pct = r.value / (r.goal || 1);
|
|
44
|
+
return { ...r, radius, pct, color: colorAt(i, colors) };
|
|
45
|
+
});
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
<ChartFrame
|
|
49
|
+
title={title}
|
|
50
|
+
subtitle={subtitle}
|
|
51
|
+
variant={variant}
|
|
52
|
+
size={size}
|
|
53
|
+
className={className}
|
|
54
|
+
table={{ headers: ['Goal', 'Value', 'Target', 'Progress'], rows: items.map((r) => [r.label, `${r.value}${r.unit ?? ''}`, `${r.goal}${r.unit ?? ''}`, `${Math.round(r.pct * 100)}%`]) }}
|
|
55
|
+
>
|
|
56
|
+
<div class="ar">
|
|
57
|
+
<svg viewBox={`0 0 ${S} ${S}`} role="img" aria-label={`${title}: ${items.map((r) => `${r.label} ${Math.round(r.pct * 100)}%`).join(', ')}`}>
|
|
58
|
+
{items.map((r) => {
|
|
59
|
+
const main = Math.min(r.pct, 0.9999);
|
|
60
|
+
const extra = r.pct > 1 ? Math.min(r.pct - 1, 0.9999) : 0;
|
|
61
|
+
return (
|
|
62
|
+
<g>
|
|
63
|
+
<circle cx={c} cy={c} r={r.radius} fill="none" stroke={r.color} stroke-opacity="0.16" stroke-width={stroke} />
|
|
64
|
+
{main > 0 && <path class="ar__arc" d={arcStroke(c, c, r.radius, 0, Math.PI * 2 * main)} fill="none" stroke={r.color} stroke-width={stroke} stroke-linecap="round" />}
|
|
65
|
+
{extra > 0 && <path d={arcStroke(c, c, r.radius, 0, Math.PI * 2 * extra)} fill="none" stroke={r.color} stroke-width={stroke} stroke-linecap="round" style="filter: drop-shadow(0 0 3px rgba(0,0,0,0.6)) brightness(1.15)" />}
|
|
66
|
+
</g>
|
|
67
|
+
);
|
|
68
|
+
})}
|
|
69
|
+
</svg>
|
|
70
|
+
<ul class="ar__list">
|
|
71
|
+
{items.map((r) => (
|
|
72
|
+
<li>
|
|
73
|
+
<span class="ar__label"><i style={`background:${r.color}`} aria-hidden="true"></i>{r.label}</span>
|
|
74
|
+
<span class="ar__value">{r.value}{r.unit ?? ''}<small>/{r.goal}{r.unit ?? ''}</small></span>
|
|
75
|
+
<span class="ar__pct">{Math.round(r.pct * 100)}%{r.pct >= 1 && <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" aria-label="goal met"><path d="M20 6 9 17l-5-5" /></svg>}</span>
|
|
76
|
+
</li>
|
|
77
|
+
))}
|
|
78
|
+
</ul>
|
|
79
|
+
</div>
|
|
80
|
+
</ChartFrame>
|
|
81
|
+
|
|
82
|
+
<style>
|
|
83
|
+
.ar {
|
|
84
|
+
display: grid;
|
|
85
|
+
grid-template-columns: minmax(0, 220px) 1fr;
|
|
86
|
+
gap: 2rem;
|
|
87
|
+
align-items: center;
|
|
88
|
+
}
|
|
89
|
+
.ar__arc {
|
|
90
|
+
stroke-dasharray: 800;
|
|
91
|
+
stroke-dashoffset: 800;
|
|
92
|
+
animation: ar-draw 1.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
93
|
+
}
|
|
94
|
+
@keyframes ar-draw { to { stroke-dashoffset: 0; } }
|
|
95
|
+
.ar__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
|
|
96
|
+
.ar__list li { display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 1rem; }
|
|
97
|
+
.ar__label { display: flex; align-items: center; gap: 0.45rem; font-size: 0.8125rem; color: var(--c-text-2, #a3a3a3); grid-column: 1 / -1; }
|
|
98
|
+
.ar__label i { width: 10px; height: 10px; border-radius: 50%; }
|
|
99
|
+
.ar__value { font-size: 1.25rem; font-weight: 700; color: var(--c-text-1, #fff); font-variant-numeric: tabular-nums; }
|
|
100
|
+
.ar__value small { font-size: 0.8rem; color: var(--c-text-3, #8a8a8a); font-weight: 500; }
|
|
101
|
+
.ar__pct { display: inline-flex; align-items: center; gap: 0.3rem; align-self: end; font-size: 0.8125rem; color: var(--c-text-2, #a3a3a3); font-variant-numeric: tabular-nums; }
|
|
102
|
+
.ar__pct svg { color: var(--chart-pos, #34c38f); }
|
|
103
|
+
@media (max-width: 520px) { .ar { grid-template-columns: 1fr; justify-items: center; } .ar__list { width: 100%; } .ar svg { max-width: 200px; } }
|
|
104
|
+
@media (prefers-reduced-motion: reduce) { .ar__arc { animation: none; stroke-dashoffset: 0; } }
|
|
105
|
+
</style>
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* BoxPlotChart — Distribution summary per group: median, interquartile box,
|
|
4
|
+
* 1.5×IQR whiskers and outlier dots. Computes stats from raw values.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<{label: string, values: number[]}>} groups - Raw observations per group.
|
|
7
|
+
* @param {string} suffix - Value suffix.
|
|
8
|
+
* @param {string} color - Box color.
|
|
9
|
+
* @param {string} variant - Card style (glass|solid|ghost).
|
|
10
|
+
* @param {string} size - Density (sm|md|lg).
|
|
11
|
+
*/
|
|
12
|
+
import ChartFrame from './ChartFrame.astro';
|
|
13
|
+
import { scaleLinear, niceTicks, quantile } from './chart-utils';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
title?: string;
|
|
17
|
+
subtitle?: string;
|
|
18
|
+
groups?: Array<{ label: string; values: number[] }>;
|
|
19
|
+
suffix?: string;
|
|
20
|
+
height?: number;
|
|
21
|
+
color?: string;
|
|
22
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
23
|
+
size?: 'sm' | 'md' | 'lg';
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const rand = (seed: number, n: number, mean: number, spread: number) =>
|
|
28
|
+
Array.from({ length: n }, (_, i) => {
|
|
29
|
+
const a = Math.sin((i + 1) * seed) * 9999;
|
|
30
|
+
const b = Math.sin((i + 3) * seed * 1.7) * 9999;
|
|
31
|
+
return Math.round(mean + ((a - Math.floor(a)) + (b - Math.floor(b)) - 1) * spread);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
title = 'Response time by region',
|
|
36
|
+
subtitle = 'Distribution of p50 latency, ms',
|
|
37
|
+
groups = [
|
|
38
|
+
{ label: 'us-east', values: [...rand(1.3, 40, 82, 40), 190] },
|
|
39
|
+
{ label: 'us-west', values: rand(2.7, 40, 95, 45) },
|
|
40
|
+
{ label: 'eu-central', values: [...rand(4.1, 40, 70, 30), 160, 172] },
|
|
41
|
+
{ label: 'ap-south', values: rand(5.9, 40, 140, 70) },
|
|
42
|
+
{ label: 'sa-east', values: rand(8.3, 40, 160, 55) },
|
|
43
|
+
],
|
|
44
|
+
suffix = 'ms',
|
|
45
|
+
height = 290,
|
|
46
|
+
color = 'var(--chart-1, #3987e5)',
|
|
47
|
+
variant = 'glass',
|
|
48
|
+
size = 'md',
|
|
49
|
+
className = '',
|
|
50
|
+
} = Astro.props;
|
|
51
|
+
|
|
52
|
+
const stats = groups.map((g) => {
|
|
53
|
+
const s = [...g.values].sort((a, b) => a - b);
|
|
54
|
+
const q1 = quantile(s, 0.25);
|
|
55
|
+
const med = quantile(s, 0.5);
|
|
56
|
+
const q3 = quantile(s, 0.75);
|
|
57
|
+
const iqr = q3 - q1;
|
|
58
|
+
const lo = s.find((v) => v >= q1 - 1.5 * iqr) ?? s[0];
|
|
59
|
+
const hi = [...s].reverse().find((v) => v <= q3 + 1.5 * iqr) ?? s[s.length - 1];
|
|
60
|
+
const outliers = s.filter((v) => v < lo || v > hi);
|
|
61
|
+
return { label: g.label, q1, med, q3, lo, hi, outliers, n: s.length };
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const W = 640;
|
|
65
|
+
const H = height;
|
|
66
|
+
const m = { t: 14, r: 12, b: 30, l: 48 };
|
|
67
|
+
const allV = groups.flatMap((g) => g.values);
|
|
68
|
+
const ticks = niceTicks(Math.min(...allV), Math.max(...allV), 4);
|
|
69
|
+
const y = scaleLinear(ticks[0], ticks[ticks.length - 1], H - m.b, m.t);
|
|
70
|
+
const band = (W - m.l - m.r) / groups.length;
|
|
71
|
+
const bw = Math.min(56, band * 0.45);
|
|
72
|
+
const f = (v: number) => `${Math.round(v)}${suffix}`;
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
<ChartFrame
|
|
76
|
+
title={title}
|
|
77
|
+
subtitle={subtitle}
|
|
78
|
+
variant={variant}
|
|
79
|
+
size={size}
|
|
80
|
+
className={className}
|
|
81
|
+
table={{ headers: ['Group', 'Min', 'Q1', 'Median', 'Q3', 'Max', 'Outliers'], rows: stats.map((s) => [s.label, f(s.lo), f(s.q1), f(s.med), f(s.q3), f(s.hi), s.outliers.length]) }}
|
|
82
|
+
>
|
|
83
|
+
<svg viewBox={`0 0 ${W} ${H}`} role="img" aria-label={`${title}: box plot of ${groups.length} groups`}>
|
|
84
|
+
{ticks.map((t) => (
|
|
85
|
+
<g>
|
|
86
|
+
<line class="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">{f(t)}</text>
|
|
88
|
+
</g>
|
|
89
|
+
))}
|
|
90
|
+
{stats.map((s, i) => {
|
|
91
|
+
const cx = m.l + i * band + band / 2;
|
|
92
|
+
return (
|
|
93
|
+
<g class="cf-mark cf-dim" tabindex="0" role="img"
|
|
94
|
+
aria-label={`${s.label}: median ${f(s.med)}, IQR ${f(s.q1)}–${f(s.q3)}, range ${f(s.lo)}–${f(s.hi)}, ${s.outliers.length} outliers`}
|
|
95
|
+
data-tip-title={s.label} data-tip={`Max: ${f(s.hi)}|Q3: ${f(s.q3)}|${color}::Median: ${f(s.med)}|Q1: ${f(s.q1)}|Min: ${f(s.lo)}${s.outliers.length ? `|Outliers: ${s.outliers.length}` : ''}`}>
|
|
96
|
+
<rect x={cx - band / 2} y={m.t} width={band} height={H - m.t - m.b} fill="transparent" />
|
|
97
|
+
<line x1={cx} x2={cx} y1={y(s.hi)} y2={y(s.q3)} stroke="var(--c-text-2, #a3a3a3)" stroke-width="1.5" />
|
|
98
|
+
<line x1={cx} x2={cx} y1={y(s.q1)} y2={y(s.lo)} stroke="var(--c-text-2, #a3a3a3)" stroke-width="1.5" />
|
|
99
|
+
<line x1={cx - bw / 4} x2={cx + bw / 4} y1={y(s.hi)} y2={y(s.hi)} stroke="var(--c-text-2, #a3a3a3)" stroke-width="1.5" />
|
|
100
|
+
<line x1={cx - bw / 4} x2={cx + bw / 4} y1={y(s.lo)} y2={y(s.lo)} stroke="var(--c-text-2, #a3a3a3)" stroke-width="1.5" />
|
|
101
|
+
<rect x={cx - bw / 2} y={y(s.q3)} width={bw} height={Math.max(1, y(s.q1) - y(s.q3))} rx="4" fill={color} fill-opacity="0.3" stroke={color} stroke-width="1.5" />
|
|
102
|
+
<line x1={cx - bw / 2} x2={cx + bw / 2} y1={y(s.med)} y2={y(s.med)} stroke="var(--c-text-1, #fff)" stroke-width="2.5" />
|
|
103
|
+
{s.outliers.map((o) => <circle cx={cx} cy={y(o)} r="3.5" fill="none" stroke={color} stroke-width="1.5" />)}
|
|
104
|
+
<text class="cf-label" x={cx} y={H - 10} text-anchor="middle">{s.label}</text>
|
|
105
|
+
</g>
|
|
106
|
+
);
|
|
107
|
+
})}
|
|
108
|
+
</svg>
|
|
109
|
+
</ChartFrame>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* BubbleChart — Three-variable scatter: x, y and bubble area (z). Larger
|
|
4
|
+
* bubbles are drawn first so small ones stay visible on top.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<{label: string, x: number, y: number, z: number, group?: number}>} items - Bubbles.
|
|
7
|
+
* @param {string[]} groups - Group names (max 3) mapped to color slots.
|
|
8
|
+
* @param {string} xLabel - X-axis title.
|
|
9
|
+
* @param {string} yLabel - Y-axis title.
|
|
10
|
+
* @param {string} zLabel - Bubble size meaning.
|
|
11
|
+
* @param {string[]} colors - Optional per-group colors.
|
|
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 { scaleLinear, niceTicks, colorAt, formatCompact } from './chart-utils';
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
title?: string;
|
|
20
|
+
subtitle?: string;
|
|
21
|
+
items?: Array<{ label: string; x: number; y: number; z: number; group?: number }>;
|
|
22
|
+
groups?: string[];
|
|
23
|
+
xLabel?: string;
|
|
24
|
+
yLabel?: string;
|
|
25
|
+
zLabel?: string;
|
|
26
|
+
height?: number;
|
|
27
|
+
colors?: string[];
|
|
28
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
29
|
+
size?: 'sm' | 'md' | 'lg';
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
title = 'Market opportunity',
|
|
35
|
+
subtitle = 'Growth vs margin, bubble = revenue',
|
|
36
|
+
items = [
|
|
37
|
+
{ label: 'Analytics', x: 34, y: 62, z: 120, group: 0 },
|
|
38
|
+
{ label: 'Payments', x: 18, y: 41, z: 260, group: 0 },
|
|
39
|
+
{ label: 'CRM', x: 9, y: 55, z: 180, group: 1 },
|
|
40
|
+
{ label: 'Hosting', x: 22, y: 28, z: 90, group: 1 },
|
|
41
|
+
{ label: 'AI tools', x: 71, y: 48, z: 70, group: 2 },
|
|
42
|
+
{ label: 'Security', x: 27, y: 72, z: 140, group: 2 },
|
|
43
|
+
{ label: 'Email', x: 6, y: 66, z: 60, group: 1 },
|
|
44
|
+
{ label: 'Design', x: 41, y: 58, z: 85, group: 0 },
|
|
45
|
+
],
|
|
46
|
+
groups = ['Core', 'Mature', 'Emerging'],
|
|
47
|
+
xLabel = 'YoY growth (%)',
|
|
48
|
+
yLabel = 'Gross margin (%)',
|
|
49
|
+
zLabel = 'Revenue ($M)',
|
|
50
|
+
height = 320,
|
|
51
|
+
colors,
|
|
52
|
+
variant = 'glass',
|
|
53
|
+
size = 'md',
|
|
54
|
+
className = '',
|
|
55
|
+
} = Astro.props;
|
|
56
|
+
|
|
57
|
+
const W = 640;
|
|
58
|
+
const H = height;
|
|
59
|
+
const m = { t: 20, r: 24, b: 40, l: 48 };
|
|
60
|
+
const xt = niceTicks(0, Math.max(...items.map((i) => i.x)), 5);
|
|
61
|
+
const yt = niceTicks(0, Math.max(...items.map((i) => i.y)), 4);
|
|
62
|
+
const x = scaleLinear(xt[0], xt[xt.length - 1], m.l, W - m.r);
|
|
63
|
+
const y = scaleLinear(yt[0], yt[yt.length - 1], H - m.b, m.t);
|
|
64
|
+
const zMax = Math.max(...items.map((i) => i.z)) || 1;
|
|
65
|
+
const r = (z: number) => 6 + Math.sqrt(z / zMax) * 30; // area-proportional radius
|
|
66
|
+
const sorted = [...items].sort((a, b) => b.z - a.z);
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
<ChartFrame
|
|
70
|
+
title={title}
|
|
71
|
+
subtitle={subtitle}
|
|
72
|
+
variant={variant}
|
|
73
|
+
size={size}
|
|
74
|
+
className={className}
|
|
75
|
+
legend={groups.slice(0, 3).map((g, i) => ({ label: g, color: colorAt(i, colors) }))}
|
|
76
|
+
table={{ headers: ['Item', 'Group', xLabel, yLabel, zLabel], rows: items.map((i) => [i.label, groups[i.group ?? 0] ?? '—', i.x, i.y, i.z]) }}
|
|
77
|
+
>
|
|
78
|
+
<svg viewBox={`0 0 ${W} ${H}`} role="img" aria-label={`${title}: bubble chart of ${items.length} items`}>
|
|
79
|
+
{yt.map((t) => (
|
|
80
|
+
<g>
|
|
81
|
+
<line class="cf-grid" x1={m.l} x2={W - m.r} y1={y(t)} y2={y(t)} />
|
|
82
|
+
<text class="cf-label" x={m.l - 8} y={y(t) + 4} text-anchor="end">{formatCompact(t)}</text>
|
|
83
|
+
</g>
|
|
84
|
+
))}
|
|
85
|
+
{xt.map((t) => <text class="cf-label" x={x(t)} y={H - m.b + 16} text-anchor="middle">{formatCompact(t)}</text>)}
|
|
86
|
+
<text class="cf-label" x={(m.l + W - m.r) / 2} y={H - 4} text-anchor="middle">{xLabel}</text>
|
|
87
|
+
<text class="cf-label" transform={`translate(12 ${(m.t + H - m.b) / 2}) rotate(-90)`} text-anchor="middle">{yLabel}</text>
|
|
88
|
+
|
|
89
|
+
{sorted.map((it) => {
|
|
90
|
+
const col = colorAt(it.group ?? 0, colors);
|
|
91
|
+
const rad = r(it.z);
|
|
92
|
+
return (
|
|
93
|
+
<g class="cf-mark cf-dim" tabindex="0" role="img" aria-label={`${it.label}: ${xLabel} ${it.x}, ${yLabel} ${it.y}, ${zLabel} ${it.z}`}
|
|
94
|
+
data-tip-title={it.label} data-tip={`${col}::${groups[it.group ?? 0] ?? ''}|${xLabel}: ${it.x}|${yLabel}: ${it.y}|${zLabel}: ${it.z}`}>
|
|
95
|
+
<circle cx={x(it.x)} cy={y(it.y)} r={rad} fill={col} fill-opacity="0.55" stroke={col} stroke-width="1.5" />
|
|
96
|
+
{rad > 18 && <text x={x(it.x)} y={y(it.y) + 4} text-anchor="middle" fill="#fff" font-size="11" font-weight="600">{it.label}</text>}
|
|
97
|
+
</g>
|
|
98
|
+
);
|
|
99
|
+
})}
|
|
100
|
+
</svg>
|
|
101
|
+
</ChartFrame>
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* BulletChart — Compact KPI-vs-target bars with qualitative bands
|
|
4
|
+
* (poor / ok / good), a measure bar and a target tick. Stack several for a grid.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<{label: string, value: number, target: number, ranges: [number, number, number], unit?: string}>} metrics
|
|
7
|
+
* - Each metric with its qualitative band thresholds (ascending).
|
|
8
|
+
* @param {string} color - Measure bar color.
|
|
9
|
+
* @param {string} variant - Card style (glass|solid|ghost).
|
|
10
|
+
* @param {string} size - Density (sm|md|lg).
|
|
11
|
+
*/
|
|
12
|
+
import ChartFrame from './ChartFrame.astro';
|
|
13
|
+
|
|
14
|
+
interface Metric {
|
|
15
|
+
label: string;
|
|
16
|
+
value: number;
|
|
17
|
+
target: number;
|
|
18
|
+
ranges: [number, number, number];
|
|
19
|
+
unit?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
title?: string;
|
|
24
|
+
subtitle?: string;
|
|
25
|
+
metrics?: Metric[];
|
|
26
|
+
color?: string;
|
|
27
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
28
|
+
size?: 'sm' | 'md' | 'lg';
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
title = 'Quarterly targets',
|
|
34
|
+
subtitle = 'Measure vs target with performance bands',
|
|
35
|
+
metrics = [
|
|
36
|
+
{ label: 'Revenue ($k)', value: 270, target: 250, ranges: [150, 225, 300] },
|
|
37
|
+
{ label: 'Profit', value: 23, target: 26, ranges: [20, 25, 30], unit: '%' },
|
|
38
|
+
{ label: 'New customers', value: 1650, target: 2100, ranges: [1400, 2000, 2500] },
|
|
39
|
+
{ label: 'NPS', value: 54, target: 50, ranges: [30, 50, 70] },
|
|
40
|
+
],
|
|
41
|
+
color = 'var(--c-text-1, #fff)',
|
|
42
|
+
variant = 'glass',
|
|
43
|
+
size = 'md',
|
|
44
|
+
className = '',
|
|
45
|
+
} = Astro.props;
|
|
46
|
+
|
|
47
|
+
const pct = (v: number, max: number) => `${Math.min(100, (v / max) * 100)}%`;
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
<ChartFrame
|
|
51
|
+
title={title}
|
|
52
|
+
subtitle={subtitle}
|
|
53
|
+
variant={variant}
|
|
54
|
+
size={size}
|
|
55
|
+
className={className}
|
|
56
|
+
table={{ headers: ['Metric', 'Value', 'Target', 'Status'], rows: metrics.map((mt) => [mt.label, `${mt.value}${mt.unit ?? ''}`, `${mt.target}${mt.unit ?? ''}`, mt.value >= mt.target ? 'On target' : 'Below target']) }}
|
|
57
|
+
>
|
|
58
|
+
<div class="bc">
|
|
59
|
+
{metrics.map((mt) => {
|
|
60
|
+
const max = mt.ranges[2];
|
|
61
|
+
const met = mt.value >= mt.target;
|
|
62
|
+
return (
|
|
63
|
+
<div
|
|
64
|
+
class="bc__row cf-mark"
|
|
65
|
+
tabindex="0"
|
|
66
|
+
role="meter"
|
|
67
|
+
aria-valuemin={0}
|
|
68
|
+
aria-valuemax={max}
|
|
69
|
+
aria-valuenow={mt.value}
|
|
70
|
+
aria-label={`${mt.label}: ${mt.value}${mt.unit ?? ''} of target ${mt.target}${mt.unit ?? ''}`}
|
|
71
|
+
data-tip-title={mt.label}
|
|
72
|
+
data-tip={`Value: ${mt.value}${mt.unit ?? ''}|Target: ${mt.target}${mt.unit ?? ''}|${met ? 'var(--chart-pos)::On target' : 'var(--chart-neg)::Below target'}`}
|
|
73
|
+
>
|
|
74
|
+
<div class="bc__meta">
|
|
75
|
+
<span class="bc__label">{mt.label}</span>
|
|
76
|
+
<span class="bc__value">
|
|
77
|
+
{mt.value}{mt.unit ?? ''}
|
|
78
|
+
<span class={`bc__status ${met ? 'bc__status--ok' : 'bc__status--bad'}`}>
|
|
79
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" aria-hidden="true">
|
|
80
|
+
{met ? <path d="M20 6 9 17l-5-5" /> : <><circle cx="12" cy="12" r="9" /><path d="M12 8v4M12 16h.01" /></>}
|
|
81
|
+
</svg>
|
|
82
|
+
{met ? 'On target' : 'Below'}
|
|
83
|
+
</span>
|
|
84
|
+
</span>
|
|
85
|
+
</div>
|
|
86
|
+
<div class="bc__track" aria-hidden="true">
|
|
87
|
+
<span class="bc__band" style={`width:${pct(mt.ranges[2], max)}; opacity:0.07`}></span>
|
|
88
|
+
<span class="bc__band" style={`width:${pct(mt.ranges[1], max)}; opacity:0.11`}></span>
|
|
89
|
+
<span class="bc__band" style={`width:${pct(mt.ranges[0], max)}; opacity:0.16`}></span>
|
|
90
|
+
<span class="bc__measure" style={`width:${pct(mt.value, max)}; background:${color}`}></span>
|
|
91
|
+
<span class="bc__target" style={`left:${pct(mt.target, max)}`}></span>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
})}
|
|
96
|
+
</div>
|
|
97
|
+
</ChartFrame>
|
|
98
|
+
|
|
99
|
+
<style>
|
|
100
|
+
.bc { display: grid; gap: 1rem; }
|
|
101
|
+
.bc__row {
|
|
102
|
+
display: grid;
|
|
103
|
+
gap: 0.45rem;
|
|
104
|
+
padding: 0.35rem;
|
|
105
|
+
border-radius: 8px;
|
|
106
|
+
}
|
|
107
|
+
.bc__row:focus-visible { outline: 2px solid var(--c-primary-light, #d4a017); }
|
|
108
|
+
.bc__meta { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
|
|
109
|
+
.bc__label { font-size: 0.8125rem; color: var(--c-text-2, #a3a3a3); }
|
|
110
|
+
.bc__value {
|
|
111
|
+
display: inline-flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
gap: 0.6rem;
|
|
114
|
+
font-weight: 650;
|
|
115
|
+
color: var(--c-text-1, #fff);
|
|
116
|
+
font-variant-numeric: tabular-nums;
|
|
117
|
+
}
|
|
118
|
+
.bc__status {
|
|
119
|
+
display: inline-flex;
|
|
120
|
+
align-items: center;
|
|
121
|
+
gap: 0.25rem;
|
|
122
|
+
font-size: 0.6875rem;
|
|
123
|
+
font-weight: 600;
|
|
124
|
+
color: var(--c-text-2, #a3a3a3);
|
|
125
|
+
white-space: nowrap;
|
|
126
|
+
}
|
|
127
|
+
.bc__status--ok svg { color: var(--chart-pos, #34c38f); }
|
|
128
|
+
.bc__status--bad svg { color: var(--chart-neg, #f06a6a); }
|
|
129
|
+
.bc__track {
|
|
130
|
+
position: relative;
|
|
131
|
+
height: 22px;
|
|
132
|
+
border-radius: 4px;
|
|
133
|
+
overflow: hidden;
|
|
134
|
+
}
|
|
135
|
+
.bc__band {
|
|
136
|
+
position: absolute;
|
|
137
|
+
inset: 0 auto 0 0;
|
|
138
|
+
background: #fff;
|
|
139
|
+
}
|
|
140
|
+
.bc__measure {
|
|
141
|
+
position: absolute;
|
|
142
|
+
left: 0;
|
|
143
|
+
top: 7px;
|
|
144
|
+
height: 8px;
|
|
145
|
+
border-radius: 0 3px 3px 0;
|
|
146
|
+
transform-origin: left;
|
|
147
|
+
animation: bc-grow 0.8s cubic-bezier(0.4, 0, 0.2, 1) both;
|
|
148
|
+
}
|
|
149
|
+
.bc__target {
|
|
150
|
+
position: absolute;
|
|
151
|
+
top: 3px;
|
|
152
|
+
bottom: 3px;
|
|
153
|
+
width: 3px;
|
|
154
|
+
margin-left: -1.5px;
|
|
155
|
+
border-radius: 2px;
|
|
156
|
+
background: var(--chart-4, #c98500);
|
|
157
|
+
}
|
|
158
|
+
@keyframes bc-grow { from { transform: scaleX(0); } }
|
|
159
|
+
@media (prefers-reduced-motion: reduce) { .bc__measure { animation: none; } }
|
|
160
|
+
</style>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* BumpChart — Rank-over-time chart. Each line tracks one entity's position
|
|
4
|
+
* (1 = top) across periods, with labels at both ends.
|
|
5
|
+
*
|
|
6
|
+
* @param {string[]} periods - X-axis labels.
|
|
7
|
+
* @param {Array<{name: string, ranks: number[]}>} series - Rank per period (1-based), max 8.
|
|
8
|
+
* @param {string[]} colors - Optional per-series colors.
|
|
9
|
+
* @param {string} variant - Card style (glass|solid|ghost).
|
|
10
|
+
* @param {string} size - Density (sm|md|lg).
|
|
11
|
+
*/
|
|
12
|
+
import ChartFrame from './ChartFrame.astro';
|
|
13
|
+
import { colorAt, smoothPath, type Point } from './chart-utils';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
title?: string;
|
|
17
|
+
subtitle?: string;
|
|
18
|
+
periods?: string[];
|
|
19
|
+
series?: Array<{ name: string; ranks: number[] }>;
|
|
20
|
+
colors?: string[];
|
|
21
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
22
|
+
size?: 'sm' | 'md' | 'lg';
|
|
23
|
+
className?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
title = 'Framework popularity rank',
|
|
28
|
+
subtitle = 'Developer survey position by year',
|
|
29
|
+
periods = ['2021', '2022', '2023', '2024', '2025', '2026'],
|
|
30
|
+
series = [
|
|
31
|
+
{ name: 'Astro', ranks: [5, 4, 3, 2, 1, 1] },
|
|
32
|
+
{ name: 'Next', ranks: [1, 1, 1, 1, 2, 2] },
|
|
33
|
+
{ name: 'Svelte', ranks: [3, 2, 2, 3, 3, 4] },
|
|
34
|
+
{ name: 'Nuxt', ranks: [2, 3, 4, 4, 5, 3] },
|
|
35
|
+
{ name: 'Remix', ranks: [4, 5, 5, 5, 4, 5] },
|
|
36
|
+
],
|
|
37
|
+
colors,
|
|
38
|
+
variant = 'glass',
|
|
39
|
+
size = 'md',
|
|
40
|
+
className = '',
|
|
41
|
+
} = Astro.props;
|
|
42
|
+
|
|
43
|
+
const W = 640;
|
|
44
|
+
const maxRank = Math.max(...series.flatMap((s) => s.ranks));
|
|
45
|
+
const rowH = 44;
|
|
46
|
+
const H = maxRank * rowH + 36;
|
|
47
|
+
const m = { t: 30, l: 80, r: 80 };
|
|
48
|
+
const n = periods.length;
|
|
49
|
+
const x = (i: number) => m.l + (i / Math.max(1, n - 1)) * (W - m.l - m.r);
|
|
50
|
+
const y = (r: number) => m.t + (r - 1) * rowH + 8;
|
|
51
|
+
const lines = series.slice(0, 8).map((s, si) => ({
|
|
52
|
+
...s,
|
|
53
|
+
color: colorAt(si, colors),
|
|
54
|
+
pts: s.ranks.map((r, i): Point => [x(i), y(r)]),
|
|
55
|
+
}));
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
<ChartFrame
|
|
59
|
+
title={title}
|
|
60
|
+
subtitle={subtitle}
|
|
61
|
+
variant={variant}
|
|
62
|
+
size={size}
|
|
63
|
+
className={className}
|
|
64
|
+
legend={lines.map((l) => ({ label: l.name, color: l.color }))}
|
|
65
|
+
table={{ headers: ['Name', ...periods], rows: series.map((s) => [s.name, ...s.ranks.map((r) => `#${r}`)]) }}
|
|
66
|
+
>
|
|
67
|
+
<svg viewBox={`0 0 ${W} ${H}`} role="img" aria-label={`${title}: bump chart of ranks over ${n} periods`}>
|
|
68
|
+
{periods.map((p, i) => (
|
|
69
|
+
<g>
|
|
70
|
+
<line class="cf-grid" x1={x(i)} x2={x(i)} y1={m.t - 6} y2={H - 10} />
|
|
71
|
+
<text class="cf-label" x={x(i)} y={14} text-anchor="middle">{p}</text>
|
|
72
|
+
</g>
|
|
73
|
+
))}
|
|
74
|
+
{lines.map((l) => (
|
|
75
|
+
<g class="cf-mark cf-dim" tabindex="0" role="img"
|
|
76
|
+
aria-label={`${l.name}: ${l.ranks.map((r, i) => `${periods[i]} #${r}`).join(', ')}`}
|
|
77
|
+
data-tip-title={l.name}
|
|
78
|
+
data-tip={l.ranks.map((r, i) => `${periods[i]}: #${r}`).join('|')}>
|
|
79
|
+
<path d={smoothPath(l.pts)} fill="none" stroke={l.color} stroke-width="3" stroke-linecap="round" />
|
|
80
|
+
<path d={smoothPath(l.pts)} fill="none" stroke="transparent" stroke-width="16" />
|
|
81
|
+
{l.pts.map(([px, py], i) => (
|
|
82
|
+
<g>
|
|
83
|
+
<circle cx={px} cy={py} r="11" fill={l.color} stroke="var(--chart-surface, #0d0d0f)" stroke-width="2" />
|
|
84
|
+
<text x={px} y={py + 4} text-anchor="middle" font-size="10" font-weight="700" fill="#fff">{l.ranks[i]}</text>
|
|
85
|
+
</g>
|
|
86
|
+
))}
|
|
87
|
+
<text class="cf-label cf-label--strong" x={m.l - 18} y={l.pts[0][1] + 4} text-anchor="end">{l.name}</text>
|
|
88
|
+
<text class="cf-label cf-label--strong" x={W - m.r + 18} y={l.pts[n - 1][1] + 4}>{l.name}</text>
|
|
89
|
+
</g>
|
|
90
|
+
))}
|
|
91
|
+
</svg>
|
|
92
|
+
</ChartFrame>
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* CandlestickChart — OHLC price chart. Bodies span open→close, wicks span
|
|
4
|
+
* low→high. Up candles are hollow, down candles filled, so direction is
|
|
5
|
+
* readable without color.
|
|
6
|
+
*
|
|
7
|
+
* @param {Array<{label: string, open: number, high: number, low: number, close: number}>} candles - OHLC data.
|
|
8
|
+
* @param {string} prefix - Price prefix.
|
|
9
|
+
* @param {number} height - SVG height in viewBox units (width is 640).
|
|
10
|
+
* @param {string} variant - Card style (glass|solid|ghost).
|
|
11
|
+
* @param {string} size - Density (sm|md|lg).
|
|
12
|
+
*/
|
|
13
|
+
import ChartFrame from './ChartFrame.astro';
|
|
14
|
+
import { scaleLinear, niceTicks, POSITIVE, NEGATIVE } from './chart-utils';
|
|
15
|
+
|
|
16
|
+
interface Candle { label: string; open: number; high: number; low: number; close: number }
|
|
17
|
+
interface Props {
|
|
18
|
+
title?: string;
|
|
19
|
+
subtitle?: string;
|
|
20
|
+
candles?: Candle[];
|
|
21
|
+
prefix?: string;
|
|
22
|
+
height?: number;
|
|
23
|
+
variant?: 'glass' | 'solid' | 'ghost';
|
|
24
|
+
size?: 'sm' | 'md' | 'lg';
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const demo: Candle[] = (() => {
|
|
29
|
+
let p = 182;
|
|
30
|
+
return Array.from({ length: 22 }, (_, i) => {
|
|
31
|
+
const r1 = Math.sin(i * 4.7) * 0.5 + Math.sin(i * 1.3) * 0.5;
|
|
32
|
+
const r2 = Math.abs(Math.sin(i * 9.1));
|
|
33
|
+
const open = p;
|
|
34
|
+
const close = Math.round((p + r1 * 6 + 0.6) * 100) / 100;
|
|
35
|
+
const high = Math.round((Math.max(open, close) + r2 * 3 + 0.4) * 100) / 100;
|
|
36
|
+
const low = Math.round((Math.min(open, close) - (1 - r2) * 3 - 0.4) * 100) / 100;
|
|
37
|
+
p = close;
|
|
38
|
+
return { label: `Oct ${i + 6}`, open, high, low, close };
|
|
39
|
+
});
|
|
40
|
+
})();
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
title = 'ACME / USD',
|
|
44
|
+
subtitle = 'Daily candles',
|
|
45
|
+
candles = demo,
|
|
46
|
+
prefix = '$',
|
|
47
|
+
height = 300,
|
|
48
|
+
variant = 'glass',
|
|
49
|
+
size = 'md',
|
|
50
|
+
className = '',
|
|
51
|
+
} = Astro.props;
|
|
52
|
+
|
|
53
|
+
const W = 640;
|
|
54
|
+
const H = height;
|
|
55
|
+
const m = { t: 12, r: 52, b: 28, l: 12 };
|
|
56
|
+
const ticks = niceTicks(Math.min(...candles.map((c) => c.low)), Math.max(...candles.map((c) => c.high)), 5);
|
|
57
|
+
const y = scaleLinear(ticks[0], ticks[ticks.length - 1], H - m.b, m.t);
|
|
58
|
+
const band = (W - m.l - m.r) / candles.length;
|
|
59
|
+
const bw = Math.max(3, band * 0.6);
|
|
60
|
+
const f = (v: number) => `${prefix}${v.toFixed(2)}`;
|
|
61
|
+
const last = candles[candles.length - 1];
|
|
62
|
+
const first = candles[0];
|
|
63
|
+
const change = ((last.close - first.open) / first.open) * 100;
|
|
64
|
+
const labelEvery = Math.ceil(candles.length / 6);
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
<ChartFrame
|
|
68
|
+
title={title}
|
|
69
|
+
subtitle={subtitle}
|
|
70
|
+
value={f(last.close)}
|
|
71
|
+
delta={`${change >= 0 ? '+' : ''}${change.toFixed(2)}%`}
|
|
72
|
+
deltaPositive={change >= 0}
|
|
73
|
+
variant={variant}
|
|
74
|
+
size={size}
|
|
75
|
+
className={className}
|
|
76
|
+
legend={[{ label: 'Up (hollow)', color: POSITIVE }, { label: 'Down (filled)', color: NEGATIVE }]}
|
|
77
|
+
table={{ headers: ['Date', 'Open', 'High', 'Low', 'Close'], rows: candles.map((c) => [c.label, f(c.open), f(c.high), f(c.low), f(c.close)]) }}
|
|
78
|
+
>
|
|
79
|
+
<svg viewBox={`0 0 ${W} ${H}`} role="img" aria-label={`${title}: candlestick chart, ${candles.length} periods, ${change.toFixed(1)}% change`}>
|
|
80
|
+
{ticks.map((t) => (
|
|
81
|
+
<g>
|
|
82
|
+
<line class="cf-grid" x1={m.l} x2={W - m.r} y1={y(t)} y2={y(t)} />
|
|
83
|
+
<text class="cf-label" x={W - m.r + 8} y={y(t) + 4}>{f(t)}</text>
|
|
84
|
+
</g>
|
|
85
|
+
))}
|
|
86
|
+
{candles.map((c, i) => {
|
|
87
|
+
const cx = m.l + i * band + band / 2;
|
|
88
|
+
const up = c.close >= c.open;
|
|
89
|
+
const col = up ? POSITIVE : NEGATIVE;
|
|
90
|
+
const top = y(Math.max(c.open, c.close));
|
|
91
|
+
const h = Math.max(1.5, Math.abs(y(c.open) - y(c.close)));
|
|
92
|
+
return (
|
|
93
|
+
<g class="cf-mark cf-dim" tabindex="0" role="img"
|
|
94
|
+
aria-label={`${c.label}: open ${f(c.open)}, high ${f(c.high)}, low ${f(c.low)}, close ${f(c.close)}`}
|
|
95
|
+
data-tip-title={c.label} data-tip={`${col}::${up ? 'Up' : 'Down'} ${(((c.close - c.open) / c.open) * 100).toFixed(2)}%|O ${f(c.open)} · H ${f(c.high)}|L ${f(c.low)} · C ${f(c.close)}`}>
|
|
96
|
+
<rect x={cx - band / 2} y={m.t} width={band} height={H - m.t - m.b} fill="transparent" />
|
|
97
|
+
<line x1={cx} x2={cx} y1={y(c.high)} y2={y(c.low)} stroke={col} stroke-width="1.5" />
|
|
98
|
+
<rect x={cx - bw / 2} y={top} width={bw} height={h} rx="1.5" fill={up ? 'var(--chart-surface, #0d0d0f)' : col} stroke={col} stroke-width="1.5" />
|
|
99
|
+
{i % labelEvery === 0 && <text class="cf-label" x={cx} y={H - 8} text-anchor="middle">{c.label}</text>}
|
|
100
|
+
</g>
|
|
101
|
+
);
|
|
102
|
+
})}
|
|
103
|
+
<line x1={m.l} x2={W - m.r} y1={y(last.close)} y2={y(last.close)} stroke="var(--c-text-1, #fff)" stroke-opacity="0.3" stroke-dasharray="3 4" aria-hidden="true" />
|
|
104
|
+
</svg>
|
|
105
|
+
</ChartFrame>
|