0.1.2 • Published 4 years ago

lp-time-line v0.1.2

Weekly downloads
13
License
-
Repository
-
Last release
4 years ago

lp-time-line 时间里程碑

npm (scoped with tag) NPM downloads

以时间维度,定位的时间线组件。包含

  • 里程碑时间线 TimeLine
  • 时间范围线 TimeRangeLine

npm.io

Install

npm.io

npm install lp-time-line

Usage

import { TimeLine, TimeRangeLine } from "lp-time-line"

只能在React环境使用。

API

TimeLine 组件

属性名类型必填默认值备注
startTimeDateTime Stringtrue时间轴的开始时间。以“-”分隔的时间字符串,如“2020-1-1”。
endTimeDateTime Stringtrue时间轴的结束时间。同上。
currentTimeDateTime Stringfalse当前时间。同上。
dataArrayfalse[]时间轴上的节点数据。
legendDataArrayfalse[]时间轴下方的图例信息。

TimeLineData 类型

属性名类型必填默认值备注
colorColor String时间轴上点的颜色值。如“#abcdef”。
timeDateTime String点对应的时间。
renderTooltipFunction(item)Tootip的渲染函数,item包含了原始信息,item._isAfterCurrentTime为当前点是否在当前时间后。
renderSubContentFunction(item)点下方文本的渲染函数,item包含了原始信息,item._isAfterCurrentTime为当前点是否在当前时间后。

LegendData 类型

属性名类型必填默认值备注
colorColor String时间轴下方的图例信息点的颜色。
textString时间轴下方的图例信息点的文本。

TimeRangeLine 组件

属性名类型必填默认值备注
startTimeDateTime Stringtrue时间轴的开始时间。以“-”分隔的时间字符串,如“2020-1-1”。
endTimeDateTime Stringtrue时间轴的结束时间。同上。
startRangeTimeDateTime String范围区域的开始时间点。同上。
endRangeTimeDateTime String范围区域的结束时间点。同上。
showRangeTextBooleantrue是否显示范围两个点的时间文本。

Demo

import React from "react";
import ReactDOM from "react-dom";
import { TimeLine, TimeRangeLine } from "lp-time-line";

const renderSubContent = item => (
  <div
    style={{
      color: item._isAfterCurrentTime
        ? "rgb(215, 216, 217)"
        : "rgba(0, 0, 0, 0.65)"
    }}
  >
    <div>{item.name}</div>
    <div>{item.time}</div>
  </div>
);

const renderTooltip = item => {
  if (item.time > "2020-0-0") {
    return;
  }
  return (
    <div>
      <div>逾期完成:逾期15天</div>
      <div>计划时间:2019.04.22</div>
    </div>
  );
};

ReactDOM.render(
  <React.StrictMode>
    <h1>DEMO</h1>
    <h3>里程碑式</h3>
    <TimeLine
      startTime="2019-4-1"
      endTime="2020-4-1"
      currentTime="2020-2-1"
      data={[
        {
          name: "战役一",
          color: "#6A9BFF",
          time: "2019-5-1",
          renderTooltip,
          renderSubContent
        },
        {
          name: "战役二",
          color: "#35B34A",
          time: "2019-7-1",
          renderTooltip,
          renderSubContent
        },
        {
          name: "战役三",
          color: "#F5A623",
          time: "2020-1-1",
          renderTooltip,
          renderSubContent
        },
        {
          name: "战役四",
          color: "#FF5029",
          time: "2019-11-1",
          renderTooltip,
          renderSubContent
        },
        {
          name: "战役五",
          color: "#D7D8D9",
          time: "2020-3-1",
          renderTooltip,
          renderSubContent
        }
      ]}
      legendData={[
        { color: "#6A9BFF", text: "按计划完成" },
        { color: "#F5A623", text: "逾期完成" },
        { color: "#FF5029", text: "逾期未完成" },
        { color: "#D7D8D9", text: "未来计划" }
      ]}
    />
    <h3>时间范围式</h3>
    <TimeRangeLine
      startTime="2019-4-1"
      endTime="2020-4-1"
      startRangeTime="2019-6-1"
      endRangeTime="2020-1-1"
      showRangeText
    />
  </React.StrictMode>,
  document.getElementById("root")
);