1.1.94 • Published 1 year ago

react-ganttastic v1.1.94

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

React-Ganttastic

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

基于dayjs.js开发,更轻便

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

image.jpg image.gif

安装

推荐使用 npm/yarn 安装

npm install react-ganttastic

用法

  const data: IChartRows<{name:string}> = {
    "2023-08-13": [],
    "2023-08-14": [
      {
        role: { name: "第一" },
        id:1, //唯一值
        children: [
          {
            start: "2023-8-14 04:00",
            end: "2023-8-15 07:00",
            // rowHeight:0 // 可重置row的感度
            // immobile: true, //是否固定,固定后不能拖动
          },
        ],
      },
    ],
    "2023-08-15": [
      {
        role: { name: "第一" },
        id:1,
        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: "第二" },
        id:2,
        type: "line",
        children: [
          {
            start: "2023-8-15 15:00",
            end: "2023-8-15 17:00",
          },
        ],
      },
    ],
    "2023-08-16": [
      {
        role: { name: "第一" },
        id:1,
        children: [],
      },
      {
        role: { name: "第二" },
        id:2,
        children: [],
      },
    ],
    "2023-08-17": [
      {
        role: { name: "第一" },
        id:1,
        children: [],
      },
      {
        role: { name: "第二" },
        id:2,
        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 |autoauto
depthConfig用力拖拽的配置项 depthConfig 配置 {width:20,duration:3600}
barStart指定开始时间stringstart
barEnd指定结束时间stringend
immobile是否可以拖动booleantrue
dateFormat日期格式化方式stringYYYY-MM-DD HH:mm:ss
timeaxisConfig顶部时间配置 timeaxisConfig 配置
dateConfig日期配置{className?: string; width?: number; format?: (time: string) => React.ReactNode;}{width:120}
dragConfig拖动手柄配置{left: dragConfig配置 }; right?: dragConfig配置 }

timeaxisConfig 配置

参数说明类型默认值
classNameclass类名string-
style样式React.CSSProperties-
format格式化时间(time: string) => React.ReactNode-
extraContent额外的元素React.ReactNode-

depthConfig配置

参数说明类型默认值
width拖拽的距离达到多少时触发number20
duration拖拽后新增的大小,单位秒number | { start?: number; end?: number }3600

dragConfig配置

参数说明类型默认值
classNameclass类名string-
style样式React.CSSProperties-

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;-

ref 方法

参数说明
onFormatJson格式化数据
onResize重置大小
1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.92

1 year ago

1.1.91

1 year ago

1.1.94

1 year ago

1.1.93

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago