d3.js - 使用 D3.js 构建平面日历
问题描述
无法理解这些数字在代码片段中的含义。源代码在链接中可用
if ((maxExtent - minExtent) > **1468800000**) {
x1DateAxis.ticks(d3.time.mondays, 1).tickFormat(d3.time.format('%a %d'))
x1MonthAxis.ticks(d3.time.mondays, 1).tickFormat(d3.time.format('%b - Week %W'))
}
else if ((maxExtent - minExtent) > **172800000**) {
x1DateAxis.ticks(d3.time.days, 1).tickFormat(d3.time.format('%a %d'))
x1MonthAxis.ticks(d3.time.mondays, 1).tickFormat(d3.time.format('%b - Week %W'))
}
else {
x1DateAxis.ticks(d3.time.hours, 4).tickFormat(d3.time.format('%I %p'))
x1MonthAxis.ticks(d3.time.days, 1).tickFormat(d3.time.format('%b %e'))
}
解决方案
此代码指定在日期线/轴上放置刻度(单位)标记的间隔,以及每个刻度标记的标签格式。线所代表的周期越长,该线上刻度的粒度就越粗。
1468800000 是 17 天的毫秒数, 172800000 是 2 天的毫秒数。因此,跨度小于 2 天的日期线、跨度在 2 到 17 天之间的日期线以及跨度超过 17 天的日期线将获得不同的刻度间隔和标签。(好吧,在这种特定情况下,2-17 天和 >17 天的标签将采用相同的格式,但刻度的间隔将不同。)
推荐阅读
- c# - Swagger json 验证未使用的模型警告
- android - 添加动态删除网格项导致 columnCount 必须大于或等于所有网格索引的最大值
- reactjs - 如何使用反应测试库模拟反应组件?
- javascript - React Javascript 数组内在函数
- python - 仅当另一个文件夹中不存在子文件夹和文件时才从一个文件夹复制子文件夹和文件
- python - python如何从df字符串中选择特殊元素
- asp.net-mvc - Entity Framework Core 中的冗余引用列
- delphi - 关闭应用程序时,FastMM 在发布版本中显示错误
- pine-script - Pine 脚本:在历史数据中只运行一次代码块
- typescript - 在 .vue 文件末尾插入新行