1 Star 11 Fork 2

losting / timeline

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

简体中文 | English

Timeline

Canvas 时间轴,支持缩放、拖拽、无限滚动、自定义控制级别 预览图 演示地址

如何使用

ES Module

npm install @losting/timeline
<canvas id="Timeline"></canvas>
import Timeline from '@losting/timeline';

const timeline = new Timeline('#Timeline', {
  fill: false,
  width: 1000,
  height: 60,
});

// 自定义绘制
timeline.draw({
  currentTime: 1651827817000,
  areas: [{
    startTime: 1651827433000,
    endTime: 1651829413000,
    bgColor: '#f897aa'
  },{
    startTime: 1651829533000,
    endTime: 1651832533000,
  }],
});

timeline.on('dragged', (timestamp) => {
  console.log(new Date(timestamp));
  // ...
})

CDN

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/@losting/timeline@3.0.0/dist/timeline.iife.js"></script>
</head>
<body>
  <canvas id="Timeline"></canvas>
  <script>
    const timeline = new window['$timeline']('#Timeline');
    // ....
  </script>
</body>
</html>

配置文档

Config

属性 类型 是否必填 默认值 说明
fill boolean true 是否适应父容器宽高,若为false则需要手动设定canvas宽高
width number 1000 canvas宽度
height number 60 canvas高度
bgColor string rgba(0,0,0,0.5) canvas背景色
textColor string #ffffff 文字颜色
fontFamily string Arial 字体
scaleColor string #ffffff 刻度颜色
scaleSpacing number 7 刻度间距
areaBgColor string #ffffff55 阴影区域背景颜色
pointerColor string #00aeec 当前时间指针颜色
pointerWidth number 3 当前时间指针宽度
pointerDisplayWidth number 100 当前时间显示区域宽度
pointerDisplayHeight number 14 当前时间显示区域高度
fps number 60 帧数
zoom integer 3 初始缩放值,0 ~ timeSpacingList.length - 1 之间(包含)的正整数。 对应 timeSpacingList 的索引值
timeSpacingList number[] [10, 100, 1000, 10000, 60000, 600000, 3600000, 86400000, 604800000] 自定义每刻度所占时间(毫秒)
scaleHeight object { long: this.$canvas.height / 3, short: this.$canvas.height / 10 } 刻度高度,如果设置此项,则long、short必填
bgTextColor string rgba(textColor, .18) 背景文字的颜色
thresholdsConfig Object 见默认配置文件 对应缩放阈值的配置, 当 timeSpacingList 配置时,该选项必填

Events

事件名 说明 参数示例
draw timeline 的自定义绘制方法 draw(DrawConfig)
on 监听 timeline 内部事件,目前只支持事件名 dragged, 拖动结束的回调事件。 on(name, (listener) => void)
off 取消监听 timeline 内部事件 off(name, listener)、 取消全部 off('*')
getCurrentTime 获取当前时间 -

DrawConfig

参数 类型 是否必填 默认值 说明
currentTime number Date.now() 中心点指向时间戳(毫秒)
areas Object[] [] 阴影区配置,见 AreaConfig
AreaConfig
参数 类型 是否必填 默认值 说明
startTime number - 阴影区域开始时间戳(毫秒)
endTime number - 阴影区域结束时间戳(毫秒)
bgColor string Config.bgColor 当前阴影区背景颜色

License

MIT

Copyright (c) 2022-present lostinghttps://www.github.com/thelostword

MIT License Copyright (c) 2022-present losting<https://www.github.com/thelostword> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

canvas时间轴组件,支持缩放、拖拽、无限滚动。 本仓库是 GitHub 的镜像,Issues及PR请前往https://github.com/thelostword/timeline 展开 收起
TypeScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/thelostword/timeline.git
git@gitee.com:thelostword/timeline.git
thelostword
timeline
timeline
main

搜索帮助