Spaces:
Running
Running
Download components/MarketChart.js from powerllm/anycoder-cf48624d: direct link, hf CLI and curl.
- Browser
- Download file 3.07 kB
-
https://huggingface.co/spaces/powerllm/anycoder-cf48624d/resolve/main/components/MarketChart.js
- Command line
-
hf download hf://spaces/powerllm/anycoder-cf48624d/components/MarketChart.js
-
curl -L -o MarketChart.js https://huggingface.co/spaces/powerllm/anycoder-cf48624d/resolve/main/components/MarketChart.js
3.07 kB
| import { AreaChart, Area, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts' | |
| export default function MarketChart({ data, symbol }) { | |
| if (!data || data.length === 0) { | |
| return ( | |
| <div className="card h-80 p-4 flex items-center justify-center flex-col space-y-2"> | |
| <div className="text-danger text-sm font-medium">Waiting for valid data stream...</div> | |
| <div className="text-dark-500 text-xs">Ensure connection is active</div> | |
| </div> | |
| ) | |
| } | |
| const isUp = data[data.length-1].price >= data[0].price | |
| return ( | |
| <div className="card h-80 p-6 flex flex-col relative"> | |
| <div className="absolute top-6 right-6 flex items-center space-x-2"> | |
| <span className="w-2 h-2 rounded-full bg-success animate-pulse"></span> | |
| <span className="text-xs font-medium text-success">Live Market</span> | |
| </div> | |
| <div className="mb-6"> | |
| <h3 className="text-sm font-medium text-dark-400 uppercase tracking-wider">{symbol} Price Action</h3> | |
| <div className="flex items-baseline space-x-2 mt-1"> | |
| <span className="text-2xl font-bold text-white"> | |
| ${data[data.length-1].price.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})} | |
| </span> | |
| <span className={`text-sm font-medium ${isUp ? 'text-success' : 'text-danger'}`}> | |
| {isUp ? '+' : ''}{((data[data.length-1].price - data[0].price) / data[0].price * 100).toFixed(2)}% | |
| </span> | |
| </div> | |
| </div> | |
| <div className="flex-1 w-full min-h-0"> | |
| <ResponsiveContainer width="100%" height="100%"> | |
| <AreaChart data={data}> | |
| <defs> | |
| <linearGradient id="colorPrice" x1="0" y1="0" x2="0" y2="1"> | |
| <stop offset="5%" stopColor={isUp ? "#10b981" : "#ef4444"} stopOpacity={0.3}/> | |
| <stop offset="95%" stopColor={isUp ? "#10b981" : "#ef4444"} stopOpacity={0}/> | |
| </linearGradient> | |
| </defs> | |
| <XAxis dataKey="time" hide={true} /> | |
| <YAxis | |
| domain={['auto', 'auto']} | |
| orientation="right" | |
| tick={{fontSize: 10, fill: '#64748b'}} | |
| axisLine={false} | |
| tickLine={false} | |
| tickFormatter={(value) => `$${value.toLocaleString()}`} | |
| /> | |
| <Tooltip | |
| contentStyle={{ backgroundColor: '#0f172a', border: '1px solid #334155', borderRadius: '8px', boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1)' }} | |
| itemStyle={{ color: '#fff' }} | |
| labelStyle={{ display: 'none' }} | |
| formatter={(value) => [`$${value.toLocaleString()}`, 'Price']} | |
| /> | |
| <Area | |
| type="monotone" | |
| dataKey="price" | |
| stroke={isUp ? "#10b981" : "#ef4444"} | |
| strokeWidth={2} | |
| fillOpacity={1} | |
| fill="url(#colorPrice)" | |
| isAnimationActive={false} | |
| /> | |
| </AreaChart> | |
| </ResponsiveContainer> | |
| </div> | |
| </div> | |
| ) | |
| } |