TimelineWidget¶
TimelineWidget is a component for displaying time-series events in emails. It can display project progress, system logs, historical records, and other information in chronological order, supporting status markers, timestamp display, and flexible style configuration.
🎯 Widget Preview¶
时间线组件预览
1. 时间线组件展示
项目开发时间线
✓
2024-01-01
完成项目立项和团队组建
✓
2024-02-15
完成用户需求调研和分析
✓
2024-03-01
完成UI/UX设计和架构设计
!
2024-04-01
正在进行核心功能开发
i
2024-05-01
计划进行全面测试
i
2024-06-01
计划正式上线发布
✨ Core Features¶
- ⏰ Time Ordering: Automatically arranges events in chronological order, supports ascending and descending order
- 🎨 Status Themes: Theme color configuration based on StatusType, such as success, warning, error, etc.
- 📅 Time Parsing: Intelligently parses multiple time formats, including dates and timestamps
- ⚙️ Flexible Configuration: Supports showing/hiding timestamps, reverse ordering, and other options
- 📧 Email Compatible: Implemented using email client-compatible HTML and CSS
🚀 Quick Start¶
Basic Usage¶
Python
from email_widget import Email
from email_widget.widgets import TimelineWidget
# 创建基础时间线
timeline = TimelineWidget()
timeline.set_title("项目历程")
timeline.add_event("项目启动", "2024-01-01", "项目正式开始")
timeline.add_event("需求确认", "2024-01-15", "完成需求分析")
timeline.add_event("设计评审", "2024-02-01", "UI设计通过评审")
email = Email("项目进展报告")
email.add_widget(timeline)
Advanced Usage¶
Python
# 带状态和时间戳的详细时间线
timeline = TimelineWidget()
timeline.set_title("系统监控日志")
timeline.add_event("系统启动", "2024-01-01 09:00:00", "服务器启动成功", "success")
timeline.add_event("用户登录", "2024-01-01 09:15:30", "管理员用户登录", "info")
timeline.add_event("发现警告", "2024-01-01 10:30:00", "CPU使用率过高", "warning")
timeline.add_event("问题解决", "2024-01-01 11:00:00", "系统性能恢复正常", "success")
timeline.show_timestamps(True)
timeline.set_reverse_order(True)
email.add_widget(timeline)
📚 Complete API Documentation: TimelineWidget API
🎨 Style Guide¶
Status Types and Theme Colors¶
- success: Green (#107c10) - Successfully completed tasks, milestone achievements
- warning: Orange (#ff8c00) - Events requiring attention, performance warnings
- error: Red (#d13438) - Errors, failures, exception events
- info: Blue (#0078d4) - Informational events, notifications, releases
- primary: Blue (#0078d4) - Important events, key milestones
📱 Best Practices¶
1. Project Progress Timeline¶
Python
from email_widget import Email
from email_widget.widgets.timeline_widget import TimelineWidget
# 创建项目进展报告邮件
email = Email("项目进展报告")
# 项目关键里程碑
timeline1 = TimelineWidget()
timeline1.set_title("项目里程碑")
timeline1.add_event("项目启动", "2024-01-01", "项目正式启动", "success")
timeline1.add_event("需求确认", "2024-01-15", "需求文档确认完成", "success")
timeline1.add_event("设计评审", "2024-02-01", "技术架构设计通过", "success")
timeline1.add_event("开发阶段", "2024-02-15", "进入开发阶段", "info")
timeline1.add_event("测试阶段", "2024-03-15", "功能测试开始", "warning")
timeline1.show_timestamps(True)
email.add_widget(timeline1)
# 导出HTML文件
email.export_html("project_progress_report.html")
项目进展报告
项目里程碑
✓
项目启动
2024-01-01项目正式启动
✓
需求确认
2024-01-15需求文档确认完成
✓
设计评审
2024-02-01技术架构设计通过
i
开发阶段
2024-02-15进入开发阶段
!
测试阶段
2024-03-15功能测试开始
●
上线部署
2024-04-01预计上线时间
本周进展
i
集成测试
2024-02-23 16:00集成测试进行中
!
BUG修复
2024-02-22 10:15修复密码验证问题
✓
代码审查
2024-02-21 14:30登录模块代码审查通过
✓
功能开发
2024-02-20 09:00完成用户登录模块
2. System Operations Log¶
Python
from email_widget import Email
from email_widget.widgets.timeline_widget import TimelineWidget
# 创建系统运维日报邮件
email = Email("系统运维日报")
# 系统事件时间线
timeline = TimelineWidget()
timeline.set_title("系统事件日志")
timeline.add_event("系统启动", "2024-01-01 08:00:00", "服务器重启完成", "success")
timeline.add_event("定时备份", "2024-01-01 12:00:00", "数据库自动备份", "info")
timeline.add_event("内存警告", "2024-01-01 14:30:00", "内存使用率达到85%", "warning")
timeline.add_event("服务异常", "2024-01-01 15:45:00", "Redis连接超时", "error")
timeline.add_event("问题修复", "2024-01-01 16:15:00", "Redis服务重启,连接恢复", "success")
timeline.show_timestamps(True)
timeline.set_reverse_order(True)
email.add_widget(timeline)
系统运维日报
系统事件日志
i
性能优化
2024-01-01 18:00:00优化数据库查询
✓
问题修复
2024-01-01 16:15:00Redis服务重启,连接恢复
✗
服务异常
2024-01-01 15:45:00Redis连接超时
!
内存警告
2024-01-01 14:30:00内存使用率达到85%
i
定时备份
2024-01-01 12:00:00数据库自动备份
✓
系统启动
2024-01-01 08:00:00服务器重启完成
部署记录
✓
重新部署
2024-01-02 14:00修复后重新部署v1.2.1
✗
回滚操作
2024-01-02 10:00回滚到v1.1.9
!
热修复
2024-01-02 09:30修复登录问题
✓
v1.2.0部署
2024-01-01 20:00生产环境部署完成
⚡ Shortcut Methods¶
The Email class provides the add_timeline
shortcut method:
Python
# 带参数的快捷方法
email.add_timeline(
title="项目时间线",
events=[
("事件1", "2024-01-01", "描述1"),
("事件2", "2024-01-02", "描述2", "success"),
("事件3", "2024-01-03", "描述3", "warning")
],
show_time=True,
reverse_order=True
)
🐛 Common Issues¶
Q: What are the requirements for time formats?¶
A: Supports multiple time formats with automatic parsing:
Python
timeline.add_event("事件1", "2024-01-01") # 日期
timeline.add_event("事件2", "2024-01-01 15:30") # 日期时间
timeline.add_event("事件3", datetime.now()) # datetime对象
Q: How to handle events with the same time?¶
A: Events with the same time are arranged in the order they were added.
Q: What's the difference between reverse and normal order?¶
A: - Normal order (False): Earliest events at top, latest events at bottom - Reverse order (True): Latest events at top, earliest events at bottom
🔗 Related Widgets¶
- ChecklistWidget - Task progress display
- ProgressWidget - Progress bar display
- StatusWidget - Status information display
- LogWidget - Log information display
- CardWidget - Cards that can contain timelines