Skip to content

Commit b74eec0

Browse files
author
Ritika Mishra
committed
enhance beta candle responsiveness across all screen sizes
1 parent 13cfcae commit b74eec0

File tree

3 files changed

+139
-55
lines changed

3 files changed

+139
-55
lines changed

src/components/BandPowerGraph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ const Graph: React.FC<GraphProps> = ({
255255
return (
256256
<div
257257
ref={containerRef}
258-
className={`w-full h-full min-h-0 min-w-0 px-4`}
258+
className={`w-full h-full min-h-0 min-w-0 py-2`}
259259
>
260260
<canvas
261261
ref={canvasRef}

src/components/CandleLit.tsx

Lines changed: 84 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,39 @@ type FFTData = FFTChannel[];
66
interface BrightCandleViewProps {
77
fftData?: FFTData;
88
betaPower: number;
9+
fullscreen?: boolean;
910
}
1011

1112
interface CandleLitProps {
1213
betaPower: number;
1314
}
1415

15-
const BrightCandleView: React.FC<BrightCandleViewProps> = ({ fftData = [], betaPower }) => {
16+
const BrightCandleView: React.FC<BrightCandleViewProps> = ({ fftData = [], betaPower, fullscreen }) => {
1617
const brightness = Math.max(0, betaPower / 100); // Normalize brightness
1718
// Add smoothing and minimum brightness
1819
const [displayBrightness, setDisplayBrightness] = useState(0.1); // Start with small flame
20+
const [screenSize, setScreenSize] = useState('normal'); // 'normal', 'large' (150%), 'xlarge' (175%)
21+
22+
useEffect(() => {
23+
// Detect screen size
24+
const detectScreenSize = () => {
25+
const width = window.innerWidth;
26+
if (width >= 1920) { // Assuming 1920px is 175% of standard size
27+
setScreenSize('xlarge');
28+
} else if (width >= 1680) { // Assuming 1680px is 150% of standard size
29+
setScreenSize('large');
30+
} else {
31+
setScreenSize('normal');
32+
}
33+
};
34+
35+
// Set initial size
36+
detectScreenSize();
37+
38+
// Update on resize
39+
window.addEventListener('resize', detectScreenSize);
40+
return () => window.removeEventListener('resize', detectScreenSize);
41+
}, []);
1942

2043
useEffect(() => {
2144
// Always show at least a small flame (0.1) and cap at 1.0
@@ -53,10 +76,10 @@ const BrightCandleView: React.FC<BrightCandleViewProps> = ({ fftData = [], betaP
5376
// Generate a slightly randomized organic flame path
5477
const generateFlamePath = () => {
5578
const basePoints = [
56-
{ x: 100, y: 50 },
57-
{ x: 70, y: 100 },
58-
{ x: 100, y: 180 },
59-
{ x: 130, y: 100 }
79+
{ x: 100, y: 30 }, // Adjusted Y positions
80+
{ x: 60, y: 80 }, // Increased vertical spread
81+
{ x: 100, y: 200 }, // Increased height
82+
{ x: 140, y: 80 } // Wider horizontal spread
6083
];
6184
const controlPoints = basePoints.map(point => ({
6285
x: point.x + (Math.random() - 0.5) * (10 * brightness),
@@ -69,28 +92,59 @@ const BrightCandleView: React.FC<BrightCandleViewProps> = ({ fftData = [], betaP
6992
`;
7093
};
7194

72-
return (
73-
<div className="w-full h-full flex items-center justify-center min-h-0 min-w-0 ">
74-
{/* Candle Container with reduced width */}
75-
<div className="relative w-32 h-64 group">
76-
{/* Candle Holder with a glassy, frosted look */}
77-
<div className="absolute bottom-0 w-full h-32
78-
bg-gradient-to-b from-gray-100 to-gray-200 dark:from-stone-600 dark:to-stone-700
79-
rounded-b-xl rounded-t-md
80-
border border-gray-300 dark:border-white/20
81-
backdrop-blur-md shadow-xl
82-
transition-transform duration-300
83-
before:absolute before:inset-0 before:bg-white/10 before:opacity-40 before:rounded-b-xl before:rounded-t-md
84-
"
85-
>
95+
// Calculate candle size based on screen size and fullscreen state
96+
const getCandleWidthClass = () => {
97+
if (fullscreen) {
98+
return screenSize === 'xlarge' ? 'w-40' : screenSize === 'large' ? 'w-36' : 'w-32';
99+
} else {
100+
return screenSize === 'xlarge' ? 'w-28' : screenSize === 'large' ? 'w-24' : 'w-20';
101+
}
102+
};
86103

87-
<div className="absolute inset-0 overflow-hidden rounded-b-xl rounded-t-md bg-gradient-to-b from-cyan-300 via-blue-400 to-blue-400
88-
">
104+
const getCandleHeightClass = () => {
105+
if (fullscreen) {
106+
return 'h-96';
107+
} else {
108+
return screenSize === 'xlarge' ? 'h-56' : screenSize === 'large' ? 'h-48' : 'h-40';
109+
}
110+
};
89111

90-
<div className="absolute top-2 left-2 right-2 h-0.5 bg-gray-300/30"></div>
112+
const getCandleHolderHeightClass = () => {
113+
if (fullscreen) {
114+
return 'h-48';
115+
} else {
116+
return screenSize === 'xlarge' ? 'h-28' : screenSize === 'large' ? 'h-24' : 'h-20';
117+
}
118+
};
91119

120+
const getFlameHeightClass = () => {
121+
if (fullscreen) {
122+
return 'h-64'; // Increased from h-48
123+
} else {
124+
return screenSize === 'xlarge' ? 'h-56' : // Increased from h-40
125+
screenSize === 'large' ? 'h-48' : // Increased from h-36
126+
'h-40'; // Increased from h-32
127+
}
128+
};
129+
return (
130+
<div className={`w-full h-full flex items-end justify-center min-h-0 min-w-0 ${fullscreen ? 'pb-4' : ''}`}>
131+
{/* Candle Container with dynamic width based on screen size and fullscreen mode */}
132+
<div className={`relative ${getCandleWidthClass()} ${getCandleHeightClass()} group`}>
133+
{/* Candle Holder with a glassy, frosted look */}
134+
<div
135+
className={`
136+
absolute bottom-0 w-full ${getCandleHolderHeightClass()}
137+
bg-gradient-to-b from-gray-100 to-gray-200 dark:from-stone-600 dark:to-stone-700
138+
rounded-t-md
139+
border border-gray-900 dark:border-gray-800 border-b-0
140+
backdrop-blur-md
141+
transition-transform duration-300
142+
before:absolute before:inset-0 before:bg-white/10 before:opacity-40 before:rounded-b-xl before:rounded-t-md
143+
`}
144+
>
145+
<div className="absolute inset-0 overflow-hidden rounded-t-md bg-gradient-to-b from-cyan-300 via-blue-400 to-gray-900">
92146
<div className="absolute top-2 left-1/2 transform -translate-x-1/2 text-center">
93-
<div className="text-sm font-semibold text-gray-500 px-2 py-1 rounded-md ">
147+
<div className={`${fullscreen ? 'text-3xl' : screenSize === 'xlarge' ? 'text-2xl' : 'text-xl'} font-semibold text-[#030c21] px-2 py-1 rounded-md opacity-70`}>
94148
{String(Math.floor(betaPower)).padStart(2, '0')}
95149
</div>
96150
</div>
@@ -100,20 +154,20 @@ const BrightCandleView: React.FC<BrightCandleViewProps> = ({ fftData = [], betaP
100154
{/* Yellow-Themed Animated Flame */}
101155
<svg
102156
xmlns="http://www.w3.org/2000/svg"
103-
viewBox="0 0 200 300"
104-
className="absolute top-0 left-1/2 transform -translate-x-1/2 w-full h-48 z-10 drop-shadow-xl"
157+
viewBox={`0 0 200 ${fullscreen ? 200 : 400}`} // Increased viewBox height
158+
className={`absolute top-0 left-1/2 transform -translate-x-1/2 w-full ${getFlameHeightClass()} z-10 drop-shadow-xl`}
105159
>
106160
<defs>
107161
{/* Outer Flame Gradient: Rich, Realistic Candle Flame Colors */}
108162
<linearGradient id="outerFlameGradient" x1="0%" y1="0%" x2="0%" y2="100%">
109-
<stop offset="0%" stopColor={`rgba(255,140,0, ${brightness * 0.6})`} />
110-
<stop offset="100%" stopColor={`rgba(255,69,0, ${brightness * 0.3})`} />
163+
<stop offset="0%" stopColor={`rgba(255,140,0, ${brightness * 1})`} />
164+
<stop offset="100%" stopColor={`rgba(255,69,0, ${brightness * 0.6})`} />
111165
</linearGradient>
112166

113167
{/* Inner Flame Gradient: Warm, Luminous Colors */}
114168
<linearGradient id="innerFlameGradient" x1="0%" y1="0%" x2="0%" y2="100%">
115-
<stop offset="0%" stopColor={`rgba(255,165,0, ${brightness * 0.8})`} />
116-
<stop offset="100%" stopColor={`rgba(255,99,71, ${brightness * 0.5})`} />
169+
<stop offset="0%" stopColor={`rgba(255,165,0, ${brightness * 1.2})`} />
170+
<stop offset="100%" stopColor={`rgba(255,99,71, ${brightness * 0.8})`} />
117171
</linearGradient>
118172

119173
{/* Filters for Enhanced Realism */}
@@ -129,7 +183,6 @@ const BrightCandleView: React.FC<BrightCandleViewProps> = ({ fftData = [], betaP
129183
</filter>
130184
</defs>
131185

132-
133186
{/* Outer Flame Layer */}
134187
<path
135188
d={generateFlamePath()}
@@ -145,23 +198,10 @@ const BrightCandleView: React.FC<BrightCandleViewProps> = ({ fftData = [], betaP
145198
filter="url(#innerGlow)"
146199
className="transition-all duration-300 animate-flicker"
147200
/>
148-
149-
{/* White Hot Core */}
150-
<ellipse
151-
cx="100"
152-
cy="150"
153-
rx={`${12 * brightness}`}
154-
ry={`${24 * brightness}`}
155-
fill={`rgba(255,255,255, ${brightness * 0.6})`}
156-
filter="url(#innerGlow)"
157-
className="transition-all duration-300"
158-
/>
159201
</svg>
160-
161-
162202
</div>
163203
</div>
164204
);
165205
};
166206

167-
export default BrightCandleView;
207+
export default BrightCandleView;

src/components/FFT.tsx

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ const FFT = forwardRef(
5353
const wglPlotsref = useRef<WebglPlot[]>([]);
5454
const linesRef = useRef<WebglLine[]>([]);
5555
const sweepPositions = useRef<number[]>(new Array(6).fill(0));
56+
const [screenSize, setScreenSize] = useState<'normal' | 'large' | 'xlarge'>('normal');
57+
58+
// Detect screen size on mount and resize
59+
useEffect(() => {
60+
const detectScreenSize = () => {
61+
const width = window.innerWidth;
62+
if (width >= 1920) { // Assuming 1920px is 175% of standard size
63+
setScreenSize('xlarge');
64+
} else if (width >= 1680) { // Assuming 1680px is 150% of standard size
65+
setScreenSize('large');
66+
} else {
67+
setScreenSize('normal');
68+
}
69+
};
70+
71+
// Set initial size
72+
detectScreenSize();
73+
74+
// Update on resize
75+
window.addEventListener('resize', detectScreenSize);
76+
return () => window.removeEventListener('resize', detectScreenSize);
77+
}, []);
5678

5779
// Extend views to include 'fullcandle'
5880
const [activeBandPowerView, setActiveBandPowerView] = useState<
@@ -134,6 +156,18 @@ const FFT = forwardRef(
134156
[currentSamplingRate, fftSize]
135157
);
136158

159+
// Get the appropriate scale class based on screen size for fullcandle view
160+
const getFullCandleScaleClass = () => {
161+
switch (screenSize) {
162+
case 'xlarge':
163+
return 'scale-150';
164+
case 'large':
165+
return 'scale-125';
166+
default:
167+
return 'scale-100';
168+
}
169+
};
170+
137171
const renderBandPowerView = () => {
138172
switch (activeBandPowerView) {
139173
case 'bandpower':
@@ -149,27 +183,37 @@ const FFT = forwardRef(
149183
);
150184
case 'brightcandle':
151185
return (
152-
<BrightCandleView
153-
betaPower={betaPower}
154-
fftData={fftData}
155-
/>
186+
<div className="flex items-center justify-center h-full w-full">
187+
<BrightCandleView
188+
betaPower={betaPower}
189+
fftData={fftData}
190+
/>
191+
</div>
156192
);
193+
// In the renderBandPowerView function in FFT.tsx
157194
case 'fullcandle':
158195
return (
159-
<div className="fixed inset-0 bg-gradient-to-b from-gray-900 to-black z-50 flex flex-col items-center justify-center p-4">
196+
<div className="fixed inset-0 bg-highlight z-50 flex flex-col items-center justify-end">
160197
<button
161198
onClick={() => setActiveBandPowerView('brightcandle')}
162199
className="absolute top-4 right-4 p-2 bg-transparent text-white hover:text-gray-300 transition-all duration-300"
163200
>
164201
<Shrink />
165202
</button>
166-
<div className="w-full max-w-4xl h-full flex items-center justify-center">
167-
<div className="transform scale-150 filter drop-shadow-2xl">
168-
<BrightCandleView betaPower={betaPower} fftData={fftData} />
203+
204+
{/* Candle Container with responsive sizing based on screen size */}
205+
<div className="w-full max-w-4xl h-full flex justify-center pb-20">
206+
<div className={`transform ${getFullCandleScaleClass()} filter drop-shadow-2xl`}>
207+
<BrightCandleView
208+
betaPower={betaPower}
209+
fftData={fftData}
210+
fullscreen
211+
/>
169212
</div>
170213
</div>
171214
</div>
172215
);
216+
173217
default:
174218
return (
175219
<BandPowerGraph
@@ -494,13 +538,13 @@ const FFT = forwardRef(
494538
</div>
495539
<div
496540
className="
497-
relative /* ← make this container the positioning context */
541+
relative
498542
flex-1 flex flex-col
499543
overflow-hidden min-h-0 min-w-0
500544
ml-4 bg-highlight rounded-2xl
501545
"
502546
>
503-
{/* only show when were on the Beta Candle view */}
547+
{/* only show when we're on the Beta Candle view */}
504548
{activeBandPowerView === 'brightcandle' && (
505549
<button
506550
onClick={() => setActiveBandPowerView('fullcandle')}

0 commit comments

Comments
 (0)