5.1 时间属性
时间有 5 个核心属性:有序 / 连续 / 周期 / 独立于空间 / 结构性。每个属性都影响可视化设计。
Time has 5 core properties: ordered / continuous / cyclic / independent of space / structural. Each property shapes visualization design.
你的原案例
Your Original Case
原 6.1 节列出 5 个时间属性,没有可视化。这章把这 5 个属性变成可交互卡片。
Original section 6.1 listed the 5 time properties without any visualization. This chapter turns those 5 properties into interactive cards.
嵌入陈为教材理论
Embedding Chen Wei's Textbook Theory
- 有序性:时间是有序的,两个事件有先后次序,与因果关系紧密相连。
- Order: Time is ordered—any two events have a before/after, tightly linked to causality.
- 连续性:时间连续,两个时间点之间总存在另一个时间点。
- Continuity: Time is continuous—between any two moments there is always another moment.
- 周期性:自然过程常有循环规律(季节、昼夜),可采用循环时间域。
- Periodicity: Natural processes often follow cyclic patterns (seasons, day/night)—a cyclic time domain can be used.
- 独立于空间:时间与空间紧相关,但科学过程大多独立处理。
- Independence from space: Time is tightly coupled with space, but scientific processes usually treat them independently.
- 结构性:时间尺度分年/月/日/时/分/秒,分割既有自然反映(昼夜)也有人为定义(60 秒)。
- Structure: Time scales split into year / month / day / hour / minute / second—some divisions reflect nature (day/night), others are human convention (60 seconds).
为什么 5 个属性都重要?
Why do all 5 properties matter?
设计时序图前先想清楚这 5 个属性,能避免常见错误:
Thinking through these 5 properties before designing a time series chart avoids common pitfalls:
- 有序性缺失 → 散点图错位成噪声
- Missing order → scatter plot misaligned into noise
- 连续性混淆 → 离散数据用错连线
- Confused continuity → discrete data wrongly connected
- 周期性忽略 → 季节趋势被"抹平"
- Ignored periodicity → seasonal trends “flattened out”
- 结构性不匹配 → 工作日/周末、闰年都出错
- Mismatched structure → weekdays/weekends, leap years all go wrong
⭐ 关键代码
⭐ Key Code
⭐ 关键点 1:5 个属性以对象数组组织
⭐ Key Point 1: the 5 properties are organized as an array of objects
// ⭐ 单一数据源:5 个属性 + 含义 + 例子 + 颜色
const TIME_ATTRIBUTES = [
{ key: 'ordered', name: '有序性', icon: '↗',
desc: '时间是有序的。两个事件发生的时间有先后次序,与因果关系紧密相连。',
example: '火车时刻表、事件日志、git commit history', color: '#3b82f6' },
{ key: 'continuous', name: '连续性', icon: '∞',
desc: '时间是连续的。两个时间点之间总存在另一个时间点。',
example: '实时传感器数据(温度、心率)、流式数据流', color: '#10b981' },
{ key: 'periodic', name: '周期性', icon: '🔁',
desc: '许多自然过程有循环规律(季节、昼夜)。可采用循环时间域表示。',
example: '24h 体温、12 个月气温、年周期销售', color: '#f59e0b' },
{ key: 'spatial_independent', name: '独立于空间', icon: '✂️',
desc: '时间与空间紧相关,但科学过程大多将它们独立处理。',
example: '折线图 x 轴只用时间、y 轴只用度量', color: '#8b5cf6' },
{ key: 'structured', name: '结构性', icon: '📐',
desc: '时间尺度分年/月/日/时/分/秒,分割既有自然反映(昼夜)也有人为定义。',
example: '日历/周排列、闰年调整、工作日 vs 周末', color: '#ec4899' }
];
⭐ 对象数组 = 一份数据 + 多处使用。卡片渲染、详细解释、筛选过滤都从同一数据源派生,避免改一处漏一处。
⭐ Array of objects = one data source, many uses. Card rendering, detailed explanations, and filtering all derive from the same source—so you never miss a spot when editing.
⭐ 关键点 2:d3.timeDay.range 生成等间距日序列
⭐ Key Point 2: d3.timeDay.range generates an equally-spaced day sequence
// 生成 2024-01-01 到 2024-12-31 之间所有日期(366 天)
const days = d3.timeDay.range(new Date(2024, 0, 1), new Date(2025, 0, 1));
// 输出:[Date(2024-01-01), Date(2024-01-02), ..., Date(2024-12-31)]
console.log(days.length); // 366(闰年)
⭐ d3.timeDay 是 d3-time 模块的核心:range(start, stop) 返回两个时刻之间所有"日"的离散数组,offset(date, n) 加减 n 天。结构性(structural)就靠这种"时间尺度"操作实现。
⭐ d3.timeDay is the core of the d3-time module: range(start, stop) returns a discrete array of every “day” between two moments; offset(date, n) adds or subtracts n days. Structure (structural) is achieved through this kind of “time-scale” operation.