Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@losting/timeline

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@losting/timeline

Canvas timeline supports zooming, dragging, infinite scrolling, and custom control levels.

  • 5.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
42
decreased by-43.24%
Maintainers
0
Weekly downloads
 
Created
Source

简体中文 | 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@4.0.0/dist/timeline.iife.js"></script>
</head>
<body>
  <canvas id="Timeline"></canvas>
  <script>
    const timeline = new window['$timeline']('#Timeline');
    // ....
  </script>
</body>
</html>

配置文档

Config

属性类型是否必填默认值说明
fillbooleantrue是否适应父容器宽高,若为false则需要手动设定canvas宽高
widthnumber1000canvas宽度
heightnumber60canvas高度
bgColorstringrgba(0,0,0,0.5)canvas背景色
textColorstring#ffffff文字颜色
fontFamilystringArial字体
scaleColorstring#ffffff刻度颜色
scaleSpacingnumber7刻度间距
areaBgColorstring#ffffff55阴影区域背景颜色
pointerColorstring#00aeec当前时间指针颜色
pointerWidthnumber3当前时间指针宽度
pointerDisplayWidthnumber100当前时间显示区域宽度
pointerDisplayHeightnumber14当前时间显示区域高度
fpsnumber60帧数
zoominteger3初始缩放值,0 ~ timeSpacingList.length - 1 之间(包含)的正整数。 对应 timeSpacingList 的索引值
timeSpacingListnumber[][10, 100, 1000, 10000, 60000, 600000, 3600000, 86400000, 604800000]自定义每刻度所占时间(毫秒)
scaleHeightobject{ long: this.$canvas.height / 3, short: this.$canvas.height / 10 }刻度高度,如果设置此项,则long、short必填
bgTextColorstringrgba(textColor, .18)背景文字的颜色
thresholdsConfigObject见默认配置文件对应缩放阈值的配置, 当 timeSpacingList 配置时,该选项必填

Events

事件名说明参数示例
drawtimeline 的自定义绘制方法draw(DrawConfig)
on监听 timeline 内部事件,目前只支持事件名 dragged, 拖动结束的回调事件。on(name, (listener) => void)
off取消监听 timeline 内部事件off(name, listener)、 取消全部 off('*')
getCurrentTime获取当前时间-
DrawConfig
参数类型是否必填默认值说明
currentTimenumberDate.now()中心点指向时间戳(毫秒)
areasObject[][]阴影区配置,见 AreaConfig
AreaConfig
参数类型是否必填默认值说明
startTimenumber-阴影区域开始时间戳(毫秒)
endTimenumber-阴影区域结束时间戳(毫秒)
bgColorstringConfig.bgColor当前阴影区背景颜色

License

MIT

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

Keywords

FAQs

Package last updated on 19 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc