1.1.4 • Published 1 day ago

react-ganttastic v1.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 day ago

React-Ganttastic

一款简洁的甘特图插件,并且支持跨天拖动

基于dayjs.js开发

如有问题联系 邮箱:hyj-228@qq.com

image.png

安装

推荐使用 npm/yarn 安装

npm install react-ganttastic

用法

  const data: IChartRows<{name:string}> = {
    "2023-08-13": [],
    "2023-08-14": [
      {
        role: { name: "第一" },
        children: [
          {
            start: "2023-8-14 04:00",
            end: "2023-8-15 07:00",
            // rowHeight:0 // 可重置row的感度
            // immobile: true, //是否固定,固定后不能拖动
          },
        ],
      },
    ],
    "2023-08-15": [
      {
        role: { name: "第一" },
        children: [
          {
            start: "2023-8-15 01:00",
            end: "2023-8-15 07:00",
          },
          {
            start: "2023-8-15 09:00",
            end: "2023-8-15 16:00",
          },
        ],
      },
      {
        role: { name: "第二" },
        type: "line",
        children: [
          {
            start: "2023-8-15 15:00",
            end: "2023-8-15 17:00",
          },
        ],
      },
    ],
    "2023-08-16": [
      {
        role: { name: "第一" },
        children: [],
      },
      {
        role: { name: "第二" },
        children: [],
      },
    ],
    "2023-08-17": [
      {
        role: { name: "第一" },
        children: [],
      },
      {
        role: { name: "第二" },
        children: [],
      },
    ],
  }
      <GanttChart
        barStart="start" //开始时间的标识 默认:start
        barEnd="end"//结束时间的标识 默认是:end
        value={chartData}
        rowHeight={50} //bar感度 默认70
        ref={chartRef}
        multipleRow //是否多行 默认false
        /* 包含两个方法 */
        /* 格式化返回值 */
        /* onFormatJson: (value: IChartRows<RecordType>) => IChartRows<RecordType>; */
        /* 重置宽度 */
        /* onResize: (width?: number) => void; */
        /* 值变化的事件 */
        onChange={(value) => setChartData(value)}
      >
      // children 必填
        {(el) => (
          <React.Fragment>
            <div className="flex_title">{el.name}</div>
            {(el.children || []).map((el) => (
              <GanttBar
                bar={el}
                key={el.id}
                style={{ background: "#4F7EFF",
                border: '1px solid #FFFFFF', borderRadius: 20, height: 30 }}
              >
              /* 可自定义结构 */
              </GanttBar>
            ))}
          </React.Fragment>
        )}
      </GanttChart>

文档

GanttChart 配置

参数说明类型默认值
value数据IChartRows< RecordType >[]
rowHeight行高度number70
step每次拖动的步长,为数字时必须大于 0 且必须为整数,为 auto 时不限制步长number |'auto'auto
depthConfig用力拖拽的配置项{width?: number; duration?: number | { start?: number; end?: number };}{width:20,duration:1 60 60}
barStart指定开始时间stringstart
barEnd指定结束时间stringend
immobile是否可以拖动booleantrue
dateFormat日期格式化方式stringYYYY-MM-DD HH:mm:ss
timeaxisConfig顶部时间配置{className?: string;style?: React.CSSProperties;format?: (time: string) => React.ReactNode;}
dateConfig日期配置{className?: string; width?: number; format?: (time: string) => React.ReactNode;}{width:120}
dragConfig拖动手柄配置{left: { className?: string; format?: (time: string) => React.ReactNode; }; right?: { className?: string; format?: (time: string) => React.ReactNode; };}

GanttBar 配置

参数说明类型默认值
immobile是否可以拖动booleantrue
rowHeight行高度number70

GanttChart 方法

方法

|onChange?:(value:IChartRows< RecordType >)=>void |onClick?: (value: { bar: IGanttBarObject; e: MouseEvent; datetime?: string | Date; }) => void; |onMouseDown?: (value: { bar: IGanttBarObject; e: MouseEvent; datetime?: string | Date; }) => void; |onMouseUp?: (value: {bar: IGanttBarObject;e: MouseEvent;datetime?: string | Date;}) => void; |onDblClick?: (value: {bar: IGanttBarObject;e: MouseEvent;datetime?: string | Dat}) => void; |onMouseEnter?: (value: { bar: IGanttBarObject; e: MouseEvent }) => void; |onMouseLeave?: (value: { bar: IGanttBarObject; e: MouseEvent }) => void; |onDragStart?: (value: { bar: IGanttBarObject; e: MouseEvent }) => void; |onDrag?: (value: { bar: IGanttBarObject; e: MouseEvent }) => void; |onDragEnd?: (value: {bar: IGanttBarObject;e: MouseEvent;movedBars?: Map<IGanttBarObject, { oldStart: string; oldEnd: string }}) => void; |onContextMenu?: (value: {bar: IGanttBarObject;e: MouseEvent;datetime?: string | Date}) => void;

ref 方法

方法说明
onFormatJson格式化数据
onResize重置大小
1.1.4

1 day ago

1.1.3

2 months ago

1.1.2

2 months ago

1.1.1

2 months ago

1.1.0

2 months ago

1.0.33

8 months ago

1.0.32

8 months ago

1.0.31

8 months ago

1.0.30

8 months ago

1.0.29

8 months ago

1.0.28

8 months ago

1.0.27

9 months ago

1.0.26

9 months ago

1.0.25

9 months ago

1.0.24

9 months ago

1.0.23

9 months ago

1.0.22

9 months ago

1.0.21

9 months ago

1.0.20

9 months ago

1.0.19

9 months ago

1.0.18

9 months ago

1.0.17

9 months ago

1.0.16

9 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago