Price Trend Embeddable Component - 用于 AI 对话中的航班价格展示
PriceTrendEmbed.jsx 组件renderPriceChart()[[timestamp, price], ...]// 数据转换函数
function convertPriceInsights(priceInsights, searchParams) {
const data = priceInsights.priceHistory.map(([ts, price]) => ({
date: new Date(ts * 1000).toISOString().split('T')[0],
price
}));
const prices = data.map(d => d.price);
return {
data,
currentPrice: priceInsights.lowestPrice,
analysis: {
min: Math.min(...prices),
max: Math.max(...prices),
average: Math.round(prices.reduce((a,b) => a+b) / prices.length),
pctDiff: Math.round(((currentPrice - avg) / avg) * 100),
level: priceInsights.priceLevel === 'typical' ? 'mid' : priceInsights.priceLevel,
trend: calculateTrend(data)
}
};
}
// 渲染图表
renderPriceChart('price-chart-container', chartData);