Files
Timeline_Generator/frontend/static/index.html
beabigegg 2d37d23bcf v9.5: 實作標籤完全不重疊算法
- 新增 _calculate_lane_conflicts_v2() 分開返回標籤重疊和線穿框分數
- 修改泳道選擇算法,優先選擇無標籤重疊的泳道
- 兩階段搜尋:優先側別無可用泳道則嘗試另一側
- 增強日誌輸出,顯示標籤範圍和詳細衝突分數

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 11:35:29 +08:00

435 lines
14 KiB
HTML

<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TimeLine Designer</title>
<script src="https://cdn.plot.ly/plotly-2.27.0.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1400px;
margin: 0 auto;
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
overflow: hidden;
}
header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
h1 {
font-size: 2.5rem;
margin-bottom: 10px;
}
.subtitle {
opacity: 0.9;
font-size: 1.1rem;
}
.content {
padding: 30px;
}
.section {
margin-bottom: 30px;
}
.section-title {
font-size: 1.5rem;
color: #667eea;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 2px solid #667eea;
}
.file-upload-area {
border: 3px dashed #667eea;
border-radius: 10px;
padding: 40px;
text-align: center;
cursor: pointer;
transition: all 0.3s;
}
.file-upload-area:hover {
background: #f0f4ff;
border-color: #764ba2;
}
.file-upload-area input[type="file"] {
display: none;
}
.upload-icon {
font-size: 3rem;
margin-bottom: 10px;
}
.button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 12px 30px;
border-radius: 8px;
font-size: 1rem;
cursor: pointer;
transition: transform 0.2s;
margin: 5px;
}
.button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}
.button:active {
transform: translateY(0);
}
.button.secondary {
background: #6c757d;
}
#eventsCount {
display: inline-block;
background: #10b981;
color: white;
padding: 5px 15px;
border-radius: 20px;
font-weight: bold;
}
#timelineContainer {
width: 100%;
height: 600px;
border: 1px solid #e5e7eb;
border-radius: 10px;
overflow: hidden;
}
.controls {
display: flex;
gap: 10px;
flex-wrap: wrap;
align-items: center;
}
.alert {
padding: 15px;
border-radius: 8px;
margin: 10px 0;
}
.alert-success {
background: #d1fae5;
color: #065f46;
border: 1px solid #10b981;
}
.alert-error {
background: #fee2e2;
color: #991b1b;
border: 1px solid #ef4444;
}
.alert-info {
background: #dbeafe;
color: #1e40af;
border: 1px solid #3b82f6;
}
.spinner {
border: 3px solid #f3f3f3;
border-top: 3px solid #667eea;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
display: inline-block;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.hidden {
display: none !important;
}
select {
padding: 10px;
border: 2px solid #667eea;
border-radius: 8px;
font-size: 1rem;
cursor: pointer;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>📊 TimeLine Designer</h1>
<p class="subtitle">輕鬆建立專業的時間軸圖表</p>
</header>
<div class="content">
<!-- 檔案上傳區 -->
<div class="section">
<h2 class="section-title">1. 匯入資料</h2>
<div class="file-upload-area" id="uploadArea">
<div class="upload-icon">📁</div>
<p>點擊或拖曳 CSV/XLSX 檔案至此處</p>
<p style="color: #6c757d; margin-top: 10px;">支援格式: .csv, .xlsx, .xls</p>
<input type="file" id="fileInput" accept=".csv,.xlsx,.xls">
</div>
<div id="uploadMessage"></div>
</div>
<!-- 事件資訊 -->
<div class="section">
<h2 class="section-title">2. 事件資料</h2>
<p>目前事件數量: <span id="eventsCount">0</span></p>
<div class="controls" style="margin-top: 15px;">
<button class="button" onclick="renderTimeline()">🎨 生成時間軸</button>
<button class="button secondary" onclick="clearEvents()">🗑️ 清空事件</button>
</div>
</div>
<!-- 時間軸預覽 -->
<div class="section">
<h2 class="section-title">3. 時間軸預覽</h2>
<div id="renderMessage"></div>
<div id="loadingSpinner" class="hidden" style="text-align: center;">
<div class="spinner"></div>
<p>渲染中...</p>
</div>
<div id="timelineContainer"></div>
</div>
<!-- 匯出選項 -->
<div class="section">
<h2 class="section-title">4. 匯出圖表</h2>
<div class="controls">
<select id="exportFormat">
<option value="png">PNG 圖片</option>
<option value="pdf">PDF 文件</option>
<option value="svg">SVG 向量圖</option>
</select>
<select id="exportDPI">
<option value="150">150 DPI (螢幕)</option>
<option value="300" selected>300 DPI (標準印刷)</option>
<option value="600">600 DPI (高品質印刷)</option>
</select>
<button class="button" onclick="exportTimeline()">💾 匯出</button>
</div>
</div>
</div>
</div>
<script>
const API_BASE = 'http://localhost:8000/api';
let currentPlotlyData = null;
let currentPlotlyLayout = null;
// 檔案上傳區域點擊事件
document.getElementById('uploadArea').onclick = () => {
document.getElementById('fileInput').click();
};
// 檔案選擇事件
document.getElementById('fileInput').onchange = async (e) => {
const file = e.target.files[0];
if (!file) return;
const formData = new FormData();
formData.append('file', file);
showMessage('uploadMessage', '上傳中...', 'info');
try {
const response = await fetch(`${API_BASE}/import`, {
method: 'POST',
body: formData
});
const result = await response.json();
if (result.success) {
showMessage('uploadMessage',
`✅ 成功匯入 ${result.imported_count} 筆事件!`,
'success');
updateEventsCount();
} else {
showMessage('uploadMessage',
`❌ 匯入失敗: ${result.errors.join(', ')}`,
'error');
}
} catch (error) {
showMessage('uploadMessage', `❌ 錯誤: ${error.message}`, 'error');
}
};
// 更新事件計數
async function updateEventsCount() {
try {
const response = await fetch(`${API_BASE}/events`);
const events = await response.json();
document.getElementById('eventsCount').textContent = events.length;
} catch (error) {
console.error('無法取得事件數量:', error);
}
}
// 渲染時間軸
async function renderTimeline() {
document.getElementById('loadingSpinner').classList.remove('hidden');
showMessage('renderMessage', '渲染中...', 'info');
try {
const response = await fetch(`${API_BASE}/render`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
config: {
direction: 'horizontal',
theme: 'modern',
show_grid: true,
show_tooltip: true,
enable_zoom: true,
enable_drag: true
}
})
});
const result = await response.json();
if (result.success) {
currentPlotlyData = result.data;
currentPlotlyLayout = result.layout;
Plotly.newPlot('timelineContainer',
result.data.data,
result.layout,
result.config || {responsive: true}
);
showMessage('renderMessage', '✅ 時間軸已生成!', 'success');
} else {
showMessage('renderMessage', '❌ 渲染失敗', 'error');
}
} catch (error) {
showMessage('renderMessage', `❌ 錯誤: ${error.message}`, 'error');
} finally {
document.getElementById('loadingSpinner').classList.add('hidden');
}
}
// 匯出時間軸
async function exportTimeline() {
if (!currentPlotlyData || !currentPlotlyLayout) {
alert('請先生成時間軸預覽!');
return;
}
const format = document.getElementById('exportFormat').value;
const dpi = parseInt(document.getElementById('exportDPI').value);
try {
const response = await fetch(`${API_BASE}/export`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
plotly_data: currentPlotlyData,
plotly_layout: currentPlotlyLayout,
options: {
fmt: format,
dpi: dpi,
width: 1920,
height: 1080,
transparent_background: false
}
})
});
if (response.ok) {
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `timeline.${format}`;
a.click();
window.URL.revokeObjectURL(url);
alert('✅ 匯出成功!');
} else {
alert('❌ 匯出失敗');
}
} catch (error) {
alert(`❌ 錯誤: ${error.message}`);
}
}
// 清空事件
async function clearEvents() {
if (!confirm('確定要清空所有事件嗎?')) return;
try {
await fetch(`${API_BASE}/events`, {
method: 'DELETE'
});
updateEventsCount();
document.getElementById('timelineContainer').innerHTML = '';
currentPlotlyData = null;
currentPlotlyLayout = null;
alert('✅ 已清空所有事件');
} catch (error) {
alert(`❌ 錯誤: ${error.message}`);
}
}
// 顯示訊息
function showMessage(elementId, message, type) {
const element = document.getElementById(elementId);
element.innerHTML = `<div class="alert alert-${type}">${message}</div>`;
setTimeout(() => {
element.innerHTML = '';
}, 5000);
}
// 初始化
updateEventsCount();
</script>
</body>
</html>