gantt-task-react-powern 0.4.50 → 0.4.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -106,27 +106,27 @@ var startOfDate = function startOfDate(date, scale) {
106
106
  return newDate;
107
107
  };
108
108
  var ganttDateRange = function ganttDateRange(tasks, viewMode, preStepsCount) {
109
- var _tasks$, _tasks$2;
109
+ var _tasks$, _tasks$2, _tasks$3, _tasks$4;
110
110
 
111
- var newStartDate = ((_tasks$ = tasks[0]) === null || _tasks$ === void 0 ? void 0 : _tasks$.start) || new Date();
112
- var newEndDate = ((_tasks$2 = tasks[0]) === null || _tasks$2 === void 0 ? void 0 : _tasks$2.start) || new Date();
111
+ var newStartDate = ((_tasks$ = tasks[0]) === null || _tasks$ === void 0 ? void 0 : _tasks$.start.getTime()) !== 0 ? ((_tasks$2 = tasks[0]) === null || _tasks$2 === void 0 ? void 0 : _tasks$2.start) || new Date() : new Date();
112
+ var newEndDate = ((_tasks$3 = tasks[0]) === null || _tasks$3 === void 0 ? void 0 : _tasks$3.end.getTime()) !== 0 ? ((_tasks$4 = tasks[0]) === null || _tasks$4 === void 0 ? void 0 : _tasks$4.end) || new Date() : new Date();
113
113
 
114
114
  for (var _iterator = _createForOfIteratorHelperLoose(tasks), _step; !(_step = _iterator()).done;) {
115
115
  var task = _step.value;
116
116
 
117
- if (task.start < newStartDate) {
117
+ if (task.start && task.start.getTime() !== 0 && task.start < newStartDate) {
118
118
  newStartDate = task.start;
119
119
  }
120
120
 
121
- if (task.end > newEndDate) {
121
+ if (task.end && task.end.getTime() !== 0 && task.end > newEndDate) {
122
122
  newEndDate = task.end;
123
123
  }
124
124
 
125
- if (task.actualStart < newStartDate) {
125
+ if (task.actualStart && task.actualStart.getTime() !== 0 && task.actualStart < newStartDate) {
126
126
  newStartDate = task.actualStart;
127
127
  }
128
128
 
129
- if (task.actualEnd > newEndDate) {
129
+ if (task.actualEnd && task.actualEnd.getTime() !== 0 && task.actualEnd > newEndDate) {
130
130
  newEndDate = task.actualEnd;
131
131
  }
132
132
  }
@@ -348,6 +348,7 @@ var localeDateStringCache = {};
348
348
 
349
349
  var toLocaleDateStringFactory = function toLocaleDateStringFactory(locale) {
350
350
  return function (date, dateTimeOptions) {
351
+ if (!date || date.getTime() === 0) return "";
351
352
  var key = date.toString();
352
353
  var lds = localeDateStringCache[key];
353
354
 
@@ -1212,8 +1213,16 @@ var Arrow = function Arrow(_ref) {
1212
1213
  };
1213
1214
 
1214
1215
  var drownPathAndTriangle = function drownPathAndTriangle(taskFrom, taskTo, rowHeight, taskHeight, arrowIndent) {
1215
- var taskToStart = Math.min(taskTo.x1, taskTo.actualx1);
1216
- var taskFromEnd = Math.max(taskFrom.x2, taskFrom.actualx2);
1216
+ var taskToStart, taskFromEnd;
1217
+
1218
+ if (taskTo.x1 >= 0 && taskTo.actualx1 >= 0) {
1219
+ taskToStart = Math.min(taskTo.x1, taskTo.actualx1);
1220
+ } else if (taskTo.x1 >= 0) taskToStart = taskTo.x1;else if (taskTo.actualx1 >= 0) taskToStart = taskTo.actualx1;else taskToStart = 0;
1221
+
1222
+ if (taskFrom.x2 >= 0 && taskFrom.actualx2 >= 0) {
1223
+ taskFromEnd = Math.min(taskFrom.x2, taskFrom.actualx2);
1224
+ } else if (taskFrom.x2 >= 0) taskFromEnd = taskFrom.x2;else if (taskFrom.actualx2 >= 0) taskFromEnd = taskFrom.actualx2;else taskFromEnd = 0;
1225
+
1217
1226
  var indexCompare = taskFrom.index > taskTo.index ? -1 : 1;
1218
1227
  var taskToEndPosition = taskTo.y + taskHeight / 2;
1219
1228
  var taskFromEndPosition = taskFromEnd + arrowIndent * 2;
@@ -1287,26 +1296,21 @@ var convertToBar = function convertToBar(task, index, dates, columnWidth, rowHei
1287
1296
  var progressEndWidth;
1288
1297
 
1289
1298
  if (rtl) {
1290
- x2 = taskXCoordinateRTL(task.start, dates, columnWidth);
1291
- x1 = taskXCoordinateRTL(task.end, dates, columnWidth);
1292
- actualx1 = taskXCoordinateRTL(task.actualStart, dates, columnWidth);
1293
- actualx2 = taskXCoordinateRTL(task.actualEnd, dates, columnWidth);
1299
+ x2 = task.start ? taskXCoordinateRTL(task.start, dates, columnWidth) : -1;
1300
+ x1 = task.end ? taskXCoordinateRTL(task.end, dates, columnWidth) : -1;
1301
+ actualx1 = task.actualStart ? taskXCoordinateRTL(task.actualStart, dates, columnWidth) : -1;
1302
+ actualx2 = task.actualEnd ? taskXCoordinateRTL(task.actualEnd, dates, columnWidth) : -1;
1294
1303
  } else {
1295
- x1 = taskXCoordinate(task.start, dates, columnWidth);
1296
- x2 = taskXCoordinate(task.end, dates, columnWidth);
1297
- actualx1 = taskXCoordinate(task.actualStart, dates, columnWidth);
1298
- actualx2 = taskXCoordinate(task.actualEnd, dates, columnWidth);
1304
+ x1 = task.start ? taskXCoordinate(task.start, dates, columnWidth) : -1;
1305
+ x2 = task.end ? taskXCoordinate(task.end, dates, columnWidth) : -1;
1306
+ actualx1 = task.actualStart ? taskXCoordinate(task.actualStart, dates, columnWidth) : -1;
1307
+ actualx2 = task.actualEnd ? taskXCoordinate(task.actualEnd, dates, columnWidth) : -1;
1299
1308
  }
1300
1309
 
1301
- progressStartWidth = Math.abs(actualx1 - x1);
1302
- progressEndWidth = Math.abs(actualx2 - x2);
1310
+ progressStartWidth = actualx1 && x1 ? Math.abs(actualx1 - x1) : -1;
1311
+ progressEndWidth = actualx2 && x2 ? Math.abs(actualx2 - x2) : -1;
1303
1312
  var typeInternal = task.type;
1304
1313
 
1305
- if (typeInternal === "task" && x2 - x1 < handleWidth * 2) {
1306
- typeInternal = "smalltask";
1307
- x2 = x1 + handleWidth * 2;
1308
- }
1309
-
1310
1314
  var _progressWithByParams = progressWithByParams(actualx1, actualx2, task.progress, rtl),
1311
1315
  progressWidth = _progressWithByParams[0],
1312
1316
  progressX = _progressWithByParams[1];
@@ -1343,10 +1347,10 @@ var convertToBar = function convertToBar(task, index, dates, columnWidth, rowHei
1343
1347
  };
1344
1348
 
1345
1349
  var convertToMilestone = function convertToMilestone(task, index, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, milestoneBackgroundColor, milestoneBackgroundSelectedColor) {
1346
- var x = taskXCoordinate(task.start, dates, columnWidth);
1350
+ var x = task.start && task.end ? taskXCoordinate(task.start, dates, columnWidth) : 0;
1347
1351
  var y = taskYCoordinate(index, rowHeight, taskHeight);
1348
- var x1 = x - taskHeight * 0.5;
1349
- var x2 = x + taskHeight * 0.5;
1352
+ var x1 = task.start && task.end ? x - taskHeight * 0.5 : 0;
1353
+ var x2 = task.start && task.end ? x + taskHeight * 0.5 : 0;
1350
1354
  var rotatedHeight = taskHeight / 1.414;
1351
1355
 
1352
1356
  var styles = _extends({
@@ -1383,6 +1387,11 @@ var taskXCoordinate = function taskXCoordinate(xDate, dates, columnWidth) {
1383
1387
  var index = dates.findIndex(function (d) {
1384
1388
  return d.getTime() >= xDate.getTime();
1385
1389
  }) - 1;
1390
+
1391
+ if (index < 0) {
1392
+ return 0;
1393
+ }
1394
+
1386
1395
  var remainderMillis = xDate.getTime() - dates[index].getTime();
1387
1396
  var percentOfInterval = remainderMillis / (dates[index + 1].getTime() - dates[index].getTime());
1388
1397
  var x = index * columnWidth + percentOfInterval * columnWidth;
@@ -1401,13 +1410,13 @@ var taskYCoordinate = function taskYCoordinate(index, rowHeight, taskHeight) {
1401
1410
  };
1402
1411
 
1403
1412
  var progressWithByParams = function progressWithByParams(taskX1, taskX2, progress, rtl) {
1404
- var progressWidth = (taskX2 - taskX1) * progress * 0.01;
1413
+ var progressWidth = taskX2 > 0 && taskX1 > 0 ? (taskX2 - taskX1) * progress * 0.01 : 0;
1405
1414
  var progressX;
1406
1415
 
1407
1416
  if (rtl) {
1408
- progressX = taskX2 - progressWidth;
1417
+ progressX = taskX2 > 0 ? taskX2 - progressWidth : 0;
1409
1418
  } else {
1410
- progressX = taskX1;
1419
+ progressX = taskX1 > 0 ? taskX1 : 0;
1411
1420
  }
1412
1421
 
1413
1422
  return [progressWidth, progressX];
@@ -1781,95 +1790,108 @@ var Bar = function Bar(_ref) {
1781
1790
  isSelected = _ref.isSelected;
1782
1791
  var progressPoint = getProgressPoint(+!rtl * task.progressWidth + task.progressX, task.y, task.height);
1783
1792
  var handleHeight = task.height / 2 - 1;
1784
- if (type == "planned") return React__default.createElement("g", {
1785
- className: styles$6.barWrapper,
1786
- tabIndex: 0
1787
- }, React__default.createElement(BarDisplay, {
1788
- x: task.x1,
1789
- y: task.y,
1790
- type: type,
1791
- startProgressWidth: task.progressStartWidth,
1792
- endProgressWidth: task.progressEndWidth,
1793
- width: task.x2 - task.x1,
1794
- height: task.height / 2,
1795
- progressX: task.progressX,
1796
- progressWidth: task.progressWidth,
1797
- barCornerRadius: task.barCornerRadius,
1798
- styles: task.styles,
1799
- isSelected: isSelected,
1800
- onMouseDown: function onMouseDown(e) {
1801
- isDateChangeable && onEventStart("move", task, e, "planned");
1802
- }
1803
- }), React__default.createElement("g", {
1804
- className: "handleGroup"
1805
- }, isDateChangeable && React__default.createElement("g", null, React__default.createElement(BarDateHandle, {
1806
- x: task.x1 + 1,
1807
- y: task.y + 1,
1808
- width: task.handleWidth,
1809
- height: handleHeight,
1810
- barCornerRadius: task.barCornerRadius,
1811
- onMouseDown: function onMouseDown(e) {
1812
- onEventStart("start", task, e, "planned");
1813
- }
1814
- }), React__default.createElement(BarDateHandle, {
1815
- x: task.x2 - task.handleWidth - 1,
1816
- y: task.y + 1,
1817
- width: task.handleWidth,
1818
- height: handleHeight,
1819
- barCornerRadius: task.barCornerRadius,
1820
- onMouseDown: function onMouseDown(e) {
1821
- onEventStart("end", task, e, "planned");
1822
- }
1823
- })), isProgressChangeable && React__default.createElement(BarProgressHandle, {
1824
- progressPoint: progressPoint,
1825
- onMouseDown: function onMouseDown(e) {
1826
- onEventStart("progress", task, e, "planned");
1827
- }
1828
- })));else return React__default.createElement("g", {
1829
- className: styles$6.barWrapper,
1830
- tabIndex: 0
1831
- }, React__default.createElement(BarDisplay, {
1832
- x: task.actualx1,
1833
- y: task.y + task.height / 2,
1834
- type: type,
1835
- startProgressWidth: task.progressStartWidth,
1836
- endProgressWidth: task.progressEndWidth,
1837
- width: task.actualx2 - task.actualx1,
1838
- height: task.height / 2,
1839
- progressX: task.progressX,
1840
- progressWidth: task.progressWidth,
1841
- barCornerRadius: task.barCornerRadius,
1842
- styles: task.styles,
1843
- isSelected: isSelected,
1844
- onMouseDown: function onMouseDown(e) {
1845
- isDateChangeable && onEventStart("move", task, e, "actual");
1846
- }
1847
- }), React__default.createElement("g", {
1848
- className: "handleGroup"
1849
- }, isDateChangeable && React__default.createElement("g", null, React__default.createElement(BarDateHandle, {
1850
- x: task.actualx1 + 1,
1851
- y: task.y + task.height / 2 + 1,
1852
- width: task.handleWidth,
1853
- height: handleHeight,
1854
- barCornerRadius: task.barCornerRadius,
1855
- onMouseDown: function onMouseDown(e) {
1856
- onEventStart("start", task, e, "actual");
1857
- }
1858
- }), React__default.createElement(BarDateHandle, {
1859
- x: task.actualx2 - task.handleWidth - 1,
1860
- y: task.y + task.height / 2 + 1,
1861
- width: task.handleWidth,
1862
- height: handleHeight,
1863
- barCornerRadius: task.barCornerRadius,
1864
- onMouseDown: function onMouseDown(e) {
1865
- onEventStart("end", task, e, "actual");
1866
- }
1867
- })), isProgressChangeable && React__default.createElement(BarProgressHandle, {
1868
- progressPoint: progressPoint,
1869
- onMouseDown: function onMouseDown(e) {
1870
- onEventStart("progress", task, e, "actual");
1871
- }
1872
- })));
1793
+
1794
+ if (type == "planned") {
1795
+ if (task.x1 && task.x2) return React__default.createElement("g", {
1796
+ className: styles$6.barWrapper,
1797
+ tabIndex: 0
1798
+ }, React__default.createElement(BarDisplay, {
1799
+ x: task.x1,
1800
+ y: task.y,
1801
+ type: type,
1802
+ startProgressWidth: task.progressStartWidth,
1803
+ endProgressWidth: task.progressEndWidth,
1804
+ width: task.x2 - task.x1,
1805
+ height: task.height / 2,
1806
+ progressX: task.progressX,
1807
+ progressWidth: task.progressWidth,
1808
+ barCornerRadius: task.barCornerRadius,
1809
+ styles: task.styles,
1810
+ isSelected: isSelected,
1811
+ onMouseDown: function onMouseDown(e) {
1812
+ isDateChangeable && onEventStart("move", task, e, "planned");
1813
+ }
1814
+ }), React__default.createElement("g", {
1815
+ className: "handleGroup"
1816
+ }, isDateChangeable && React__default.createElement("g", null, React__default.createElement(BarDateHandle, {
1817
+ x: task.x1 + 1,
1818
+ y: task.y + 1,
1819
+ width: task.handleWidth,
1820
+ height: handleHeight,
1821
+ barCornerRadius: task.barCornerRadius,
1822
+ onMouseDown: function onMouseDown(e) {
1823
+ onEventStart("start", task, e, "planned");
1824
+ }
1825
+ }), React__default.createElement(BarDateHandle, {
1826
+ x: task.x2 - task.handleWidth - 1,
1827
+ y: task.y + 1,
1828
+ width: task.handleWidth,
1829
+ height: handleHeight,
1830
+ barCornerRadius: task.barCornerRadius,
1831
+ onMouseDown: function onMouseDown(e) {
1832
+ onEventStart("end", task, e, "planned");
1833
+ }
1834
+ })), isProgressChangeable && React__default.createElement(BarProgressHandle, {
1835
+ progressPoint: progressPoint,
1836
+ onMouseDown: function onMouseDown(e) {
1837
+ onEventStart("progress", task, e, "planned");
1838
+ }
1839
+ })));else return React__default.createElement("g", {
1840
+ className: styles$6.barWrapper,
1841
+ tabIndex: 0
1842
+ });
1843
+ } else if (task.actualx1 && task.actualx2) {
1844
+ return React__default.createElement("g", {
1845
+ className: styles$6.barWrapper,
1846
+ tabIndex: 0
1847
+ }, React__default.createElement(BarDisplay, {
1848
+ x: task.actualx1,
1849
+ y: task.y + task.height / 2,
1850
+ type: type,
1851
+ startProgressWidth: task.progressStartWidth,
1852
+ endProgressWidth: task.progressEndWidth,
1853
+ width: task.actualx2 - task.actualx1,
1854
+ height: task.height / 2,
1855
+ progressX: task.progressX,
1856
+ progressWidth: task.progressWidth,
1857
+ barCornerRadius: task.barCornerRadius,
1858
+ styles: task.styles,
1859
+ isSelected: isSelected,
1860
+ onMouseDown: function onMouseDown(e) {
1861
+ isDateChangeable && onEventStart("move", task, e, "actual");
1862
+ }
1863
+ }), React__default.createElement("g", {
1864
+ className: "handleGroup"
1865
+ }, isDateChangeable && React__default.createElement("g", null, React__default.createElement(BarDateHandle, {
1866
+ x: task.actualx1 + 1,
1867
+ y: task.y + task.height / 2 + 1,
1868
+ width: task.handleWidth,
1869
+ height: handleHeight,
1870
+ barCornerRadius: task.barCornerRadius,
1871
+ onMouseDown: function onMouseDown(e) {
1872
+ onEventStart("start", task, e, "actual");
1873
+ }
1874
+ }), React__default.createElement(BarDateHandle, {
1875
+ x: task.actualx2 - task.handleWidth - 1,
1876
+ y: task.y + task.height / 2 + 1,
1877
+ width: task.handleWidth,
1878
+ height: handleHeight,
1879
+ barCornerRadius: task.barCornerRadius,
1880
+ onMouseDown: function onMouseDown(e) {
1881
+ onEventStart("end", task, e, "actual");
1882
+ }
1883
+ })), isProgressChangeable && React__default.createElement(BarProgressHandle, {
1884
+ progressPoint: progressPoint,
1885
+ onMouseDown: function onMouseDown(e) {
1886
+ onEventStart("progress", task, e, "actual");
1887
+ }
1888
+ })));
1889
+ } else {
1890
+ return React__default.createElement("g", {
1891
+ className: styles$6.barWrapper,
1892
+ tabIndex: 0
1893
+ });
1894
+ }
1873
1895
  };
1874
1896
 
1875
1897
  var BarSmall = function BarSmall(_ref) {
@@ -2017,11 +2039,23 @@ var TaskItem = function TaskItem(props) {
2017
2039
  break;
2018
2040
 
2019
2041
  default:
2020
- setTaskItem([React__default.createElement(Bar, Object.assign({}, props, {
2021
- type: "planned"
2022
- })), React__default.createElement(Bar, Object.assign({}, props, {
2023
- type: "actual"
2024
- }))]);
2042
+ {
2043
+ var _taskItem = [];
2044
+
2045
+ if (task.x1 && task.x2) {
2046
+ _taskItem.push(React__default.createElement(Bar, Object.assign({}, props, {
2047
+ type: "planned"
2048
+ })));
2049
+ }
2050
+
2051
+ if (task.actualx1 && task.actualx2) {
2052
+ _taskItem.push(React__default.createElement(Bar, Object.assign({}, props, {
2053
+ type: "actual"
2054
+ })));
2055
+ }
2056
+
2057
+ setTaskItem(_taskItem);
2058
+ }
2025
2059
  break;
2026
2060
  }
2027
2061
  }, [task, isSelected]);
@@ -2310,7 +2344,18 @@ var TaskGanttContent = function TaskGanttContent(_ref) {
2310
2344
  className: "content"
2311
2345
  }, React__default.createElement("g", {
2312
2346
  className: "arrows"
2313
- }, tasks.map(function (task) {
2347
+ }, tasks.map(function (_task) {
2348
+ var task = _task.start.getTime() > 0 && _task.end.getTime() > 0 ? _task : undefined;
2349
+
2350
+ if (!task) {
2351
+ return React__default.createElement("g", {
2352
+ key: _task.id,
2353
+ style: {
2354
+ height: taskHeight
2355
+ }
2356
+ });
2357
+ }
2358
+
2314
2359
  return task.barChildren.map(function (child) {
2315
2360
  var _task$criticalPathArr, _task$criticalPathArr2;
2316
2361
 
@@ -2331,7 +2376,18 @@ var TaskGanttContent = function TaskGanttContent(_ref) {
2331
2376
  className: "bar",
2332
2377
  fontFamily: fontFamily,
2333
2378
  fontSize: fontSize
2334
- }, tasks.map(function (task) {
2379
+ }, tasks.map(function (_task) {
2380
+ var task = _task.start.getTime() > 0 && _task.end.getTime() > 0 ? _task : undefined;
2381
+
2382
+ if (!task) {
2383
+ return React__default.createElement("g", {
2384
+ key: _task.id,
2385
+ style: {
2386
+ height: taskHeight
2387
+ }
2388
+ });
2389
+ }
2390
+
2335
2391
  return React__default.createElement(TaskItem, {
2336
2392
  task: task,
2337
2393
  arrowIndent: arrowIndent,
@@ -2646,7 +2702,7 @@ var Gantt = function Gantt(_ref) {
2646
2702
  return t.id === changedTask.id;
2647
2703
  });
2648
2704
 
2649
- if (prevStateTask && (prevStateTask.start.getTime() !== changedTask.start.getTime() || prevStateTask.end.getTime() !== changedTask.end.getTime() || prevStateTask.actualStart.getTime() !== changedTask.actualStart.getTime() || prevStateTask.actualEnd.getTime() !== changedTask.actualEnd.getTime() || prevStateTask.progress !== changedTask.progress)) {
2705
+ if (prevStateTask && (prevStateTask.start.getTime() >= 0 && prevStateTask.start.getTime() !== changedTask.start.getTime() || prevStateTask.end.getTime() >= 0 && prevStateTask.end.getTime() !== changedTask.end.getTime() || (prevStateTask.actualStart.getTime() >= 0 && prevStateTask.actualStart.getTime()) !== changedTask.actualStart.getTime() || prevStateTask.actualEnd.getTime() >= 0 && prevStateTask.actualEnd.getTime() !== changedTask.actualEnd.getTime() || prevStateTask.progress !== changedTask.progress)) {
2650
2706
  var newTaskList = barTasks.map(function (t) {
2651
2707
  return t.id === changedTask.id ? changedTask : t;
2652
2708
  });