v9.5: 實作標籤完全不重疊算法

- 新增 _calculate_lane_conflicts_v2() 分開返回標籤重疊和線穿框分數
- 修改泳道選擇算法,優先選擇無標籤重疊的泳道
- 兩階段搜尋:優先側別無可用泳道則嘗試另一側
- 增強日誌輸出,顯示標籤範圍和詳細衝突分數

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
beabigegg
2025-11-06 11:35:29 +08:00
commit 2d37d23bcf
83 changed files with 22971 additions and 0 deletions

72
SDD.md Normal file
View File

@@ -0,0 +1,72 @@
# 📗 System Design Document (SDD)
## 1. 架構概述
```
PyWebview Host
├── FastAPI Backend
│ ├── importer.pyCSV/XLSX 處理)
│ ├── renderer.pyPlotly/kaleido 渲染)
│ ├── schemas.py資料模型定義
│ └── export.pyPDF/SVG/PNG 輸出)
└── Frontend (React + Tailwind)
├── TimelineCanvasvis-timeline 封裝)
├── EventForm / ThemePanel / ExportDialog
└── api.tsAPI 呼叫)
```
## 2. 資料模型
```python
class Event(BaseModel):
id: str
title: str
start: datetime
end: Optional[datetime]
group: Optional[str]
description: Optional[str]
color: Optional[str]
class TimelineConfig(BaseModel):
direction: Literal['horizontal', 'vertical'] = 'horizontal'
theme: str = 'modern'
show_grid: bool = True
class ExportOptions(BaseModel):
fmt: Literal['png', 'pdf', 'svg']
dpi: int = 300
```
## 3. API 定義
| Method | Endpoint | 功能 | 輸入 | 輸出 |
|---------|-----------|------|------|------|
| POST | /import | 匯入事件資料 | CSV/XLSX | Event[] |
| GET | /events | 取得事件列表 | None | Event[] |
| POST | /render | 生成時間軸 JSON | TimelineConfig | Plotly JSON |
| POST | /export | 導出時間軸圖 | ExportOptions | 圖檔 |
| GET | /themes | 主題列表 | None | Theme[] |
## 4. 視覺化邏輯
- 自動調整時間刻度(日/週/月)
- 重疊節點避碰算法
- 拖曳吸附Snap to Grid
- Hover 顯示 Tooltip 詳細資訊
## 5. 前端契約
```tsx
<TimelineCanvas
events={Event[]}
config={TimelineConfig}
onSelect={(id)=>{}}
onMove={(id,newStart)=>{}}
/>
```
## 6. 系統相依性
| 模組 | 用途 |
|------|------|
| PyWebview | 原生 GUI 容器 |
| FastAPI | 後端 API 框架 |
| React | 前端 UI |
| Tailwind | 樣式系統 |
| Plotly/kaleido | 圖表渲染與輸出 |
| Playwright | 截圖與測試 |