TimelineWidget API¶
TimelineWidget()
¶
Bases: BaseWidget
Timeline component for creating event timeline displays.
TimelineWidget is used to display a series of events arranged in chronological order, each event can have different states, descriptions, and timestamps. Suitable for project progress, history records, process steps, and other scenarios.
Attributes:
Name | Type | Description |
---|---|---|
events |
List[Dict[str, Any]]
|
Timeline events list |
title |
str
|
Timeline title |
show_time |
bool
|
Whether to show time information |
reverse_order |
bool
|
Whether to arrange in reverse chronological order |
Examples:
Basic usage:
timeline = TimelineWidget()
timeline.add_event("Project Launch", "2024-01-01", "Project officially started")
timeline.add_event("Requirements Confirmed", "2024-01-15", "Requirements analysis document completed")
timeline.add_event("Development Complete", "2024-02-28", "Code development completed")
Using method chaining:
timeline = (TimelineWidget()
.set_title("Project Milestones")
.add_event("Project Initiation", "2024-01-01", status_type="success")
.add_event("In Development", "2024-01-15", status_type="primary")
.show_timestamps(True))
Custom event types:
timeline = TimelineWidget()
timeline.add_event("System Launch", "2024-03-01", "Production environment deployment", "success")
timeline.add_event("Bug Found", "2024-03-05", "User feedback issue", "error")
timeline.add_event("Fix Complete", "2024-03-06", "Issue resolved", "success")
初始化时间线组件。
Attributes¶
events
property
¶
获取所有时间线事件。
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
List[Dict[str, Any]]: 事件列表 |
title
property
¶
获取时间线标题。
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
时间线标题 |
event_count
property
¶
获取事件总数。
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
事件总数 |
Functions¶
add_event(title, time=None, description='', status_type=None)
¶
添加时间线事件。
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
事件标题 |
required |
time
|
Union[str, datetime, None]
|
事件时间,可选 |
None
|
description
|
str
|
事件描述 |
''
|
status_type
|
Union[str, StatusType, None]
|
状态类型 |
None
|
Returns:
Name | Type | Description |
---|---|---|
TimelineWidget |
TimelineWidget
|
返回self以支持链式调用 |
Examples:
set_title(title)
¶
设置时间线标题。
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
时间线标题 |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineWidget |
TimelineWidget
|
返回self以支持链式调用 |
show_timestamps(show=True)
¶
设置是否显示时间戳。
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show
|
bool
|
是否显示时间信息 |
True
|
Returns:
Name | Type | Description |
---|---|---|
TimelineWidget |
TimelineWidget
|
返回self以支持链式调用 |
set_reverse_order(reverse=True)
¶
设置是否按时间倒序排列。
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reverse
|
bool
|
是否倒序排列(最新的在前) |
True
|
Returns:
Name | Type | Description |
---|---|---|
TimelineWidget |
TimelineWidget
|
返回self以支持链式调用 |
clear_events()
¶
remove_event(index)
¶
根据索引移除事件。
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
int
|
要移除的事件索引 |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineWidget |
TimelineWidget
|
返回self以支持链式调用 |
Raises:
Type | Description |
---|---|
IndexError
|
当索引超出范围时 |