gantt-task-react-powern 0.4.49 → 0.4.51

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,25 +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 newStartDate = tasks[0].start;
110
- var newEndDate = tasks[0].start;
109
+ var _tasks$, _tasks$2;
110
+
111
+ var newStartDate = tasks[0].start.getTime() !== 0 ? ((_tasks$ = tasks[0]) === null || _tasks$ === void 0 ? void 0 : _tasks$.start) || new Date() : new Date();
112
+ var newEndDate = tasks[0].end.getTime() !== 0 ? ((_tasks$2 = tasks[0]) === null || _tasks$2 === void 0 ? void 0 : _tasks$2.end) || new Date() : new Date();
111
113
 
112
114
  for (var _iterator = _createForOfIteratorHelperLoose(tasks), _step; !(_step = _iterator()).done;) {
113
115
  var task = _step.value;
114
116
 
115
- if (task.start < newStartDate) {
117
+ if (task.start && task.start.getTime() !== 0 && task.start < newStartDate) {
116
118
  newStartDate = task.start;
117
119
  }
118
120
 
119
- if (task.end > newEndDate) {
121
+ if (task.end && task.end.getTime() !== 0 && task.end > newEndDate) {
120
122
  newEndDate = task.end;
121
123
  }
122
124
 
123
- if (task.actualStart < newStartDate) {
125
+ if (task.actualStart && task.actualStart.getTime() !== 0 && task.actualStart < newStartDate) {
124
126
  newStartDate = task.actualStart;
125
127
  }
126
128
 
127
- if (task.actualEnd > newEndDate) {
129
+ if (task.actualEnd && task.actualEnd.getTime() !== 0 && task.actualEnd > newEndDate) {
128
130
  newEndDate = task.actualEnd;
129
131
  }
130
132
  }
@@ -346,6 +348,7 @@ var localeDateStringCache = {};
346
348
 
347
349
  var toLocaleDateStringFactory = function toLocaleDateStringFactory(locale) {
348
350
  return function (date, dateTimeOptions) {
351
+ if (!date || date.getTime() === 0) return "";
349
352
  var key = date.toString();
350
353
  var lds = localeDateStringCache[key];
351
354
 
@@ -1210,8 +1213,16 @@ var Arrow = function Arrow(_ref) {
1210
1213
  };
1211
1214
 
1212
1215
  var drownPathAndTriangle = function drownPathAndTriangle(taskFrom, taskTo, rowHeight, taskHeight, arrowIndent) {
1213
- var taskToStart = Math.min(taskTo.x1, taskTo.actualx1);
1214
- 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
+
1215
1226
  var indexCompare = taskFrom.index > taskTo.index ? -1 : 1;
1216
1227
  var taskToEndPosition = taskTo.y + taskHeight / 2;
1217
1228
  var taskFromEndPosition = taskFromEnd + arrowIndent * 2;
@@ -1285,26 +1296,21 @@ var convertToBar = function convertToBar(task, index, dates, columnWidth, rowHei
1285
1296
  var progressEndWidth;
1286
1297
 
1287
1298
  if (rtl) {
1288
- x2 = taskXCoordinateRTL(task.start, dates, columnWidth);
1289
- x1 = taskXCoordinateRTL(task.end, dates, columnWidth);
1290
- actualx1 = taskXCoordinateRTL(task.actualStart, dates, columnWidth);
1291
- 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;
1292
1303
  } else {
1293
- x1 = taskXCoordinate(task.start, dates, columnWidth);
1294
- x2 = taskXCoordinate(task.end, dates, columnWidth);
1295
- actualx1 = taskXCoordinate(task.actualStart, dates, columnWidth);
1296
- 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;
1297
1308
  }
1298
1309
 
1299
- progressStartWidth = Math.abs(actualx1 - x1);
1300
- progressEndWidth = Math.abs(actualx2 - x2);
1310
+ progressStartWidth = actualx1 && x1 ? Math.abs(actualx1 - x1) : -1;
1311
+ progressEndWidth = actualx2 && x2 ? Math.abs(actualx2 - x2) : -1;
1301
1312
  var typeInternal = task.type;
1302
1313
 
1303
- if (typeInternal === "task" && x2 - x1 < handleWidth * 2) {
1304
- typeInternal = "smalltask";
1305
- x2 = x1 + handleWidth * 2;
1306
- }
1307
-
1308
1314
  var _progressWithByParams = progressWithByParams(actualx1, actualx2, task.progress, rtl),
1309
1315
  progressWidth = _progressWithByParams[0],
1310
1316
  progressX = _progressWithByParams[1];
@@ -1341,10 +1347,10 @@ var convertToBar = function convertToBar(task, index, dates, columnWidth, rowHei
1341
1347
  };
1342
1348
 
1343
1349
  var convertToMilestone = function convertToMilestone(task, index, dates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, milestoneBackgroundColor, milestoneBackgroundSelectedColor) {
1344
- var x = taskXCoordinate(task.start, dates, columnWidth);
1350
+ var x = task.start && task.end ? taskXCoordinate(task.start, dates, columnWidth) : 0;
1345
1351
  var y = taskYCoordinate(index, rowHeight, taskHeight);
1346
- var x1 = x - taskHeight * 0.5;
1347
- 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;
1348
1354
  var rotatedHeight = taskHeight / 1.414;
1349
1355
 
1350
1356
  var styles = _extends({
@@ -1381,6 +1387,11 @@ var taskXCoordinate = function taskXCoordinate(xDate, dates, columnWidth) {
1381
1387
  var index = dates.findIndex(function (d) {
1382
1388
  return d.getTime() >= xDate.getTime();
1383
1389
  }) - 1;
1390
+
1391
+ if (index < 0) {
1392
+ return 0;
1393
+ }
1394
+
1384
1395
  var remainderMillis = xDate.getTime() - dates[index].getTime();
1385
1396
  var percentOfInterval = remainderMillis / (dates[index + 1].getTime() - dates[index].getTime());
1386
1397
  var x = index * columnWidth + percentOfInterval * columnWidth;
@@ -1399,13 +1410,13 @@ var taskYCoordinate = function taskYCoordinate(index, rowHeight, taskHeight) {
1399
1410
  };
1400
1411
 
1401
1412
  var progressWithByParams = function progressWithByParams(taskX1, taskX2, progress, rtl) {
1402
- var progressWidth = (taskX2 - taskX1) * progress * 0.01;
1413
+ var progressWidth = taskX2 > 0 && taskX1 > 0 ? (taskX2 - taskX1) * progress * 0.01 : 0;
1403
1414
  var progressX;
1404
1415
 
1405
1416
  if (rtl) {
1406
- progressX = taskX2 - progressWidth;
1417
+ progressX = taskX2 > 0 ? taskX2 - progressWidth : 0;
1407
1418
  } else {
1408
- progressX = taskX1;
1419
+ progressX = taskX1 > 0 ? taskX1 : 0;
1409
1420
  }
1410
1421
 
1411
1422
  return [progressWidth, progressX];
@@ -1779,95 +1790,108 @@ var Bar = function Bar(_ref) {
1779
1790
  isSelected = _ref.isSelected;
1780
1791
  var progressPoint = getProgressPoint(+!rtl * task.progressWidth + task.progressX, task.y, task.height);
1781
1792
  var handleHeight = task.height / 2 - 1;
1782
- if (type == "planned") return React__default.createElement("g", {
1783
- className: styles$6.barWrapper,
1784
- tabIndex: 0
1785
- }, React__default.createElement(BarDisplay, {
1786
- x: task.x1,
1787
- y: task.y,
1788
- type: type,
1789
- startProgressWidth: task.progressStartWidth,
1790
- endProgressWidth: task.progressEndWidth,
1791
- width: task.x2 - task.x1,
1792
- height: task.height / 2,
1793
- progressX: task.progressX,
1794
- progressWidth: task.progressWidth,
1795
- barCornerRadius: task.barCornerRadius,
1796
- styles: task.styles,
1797
- isSelected: isSelected,
1798
- onMouseDown: function onMouseDown(e) {
1799
- isDateChangeable && onEventStart("move", task, e, "planned");
1800
- }
1801
- }), React__default.createElement("g", {
1802
- className: "handleGroup"
1803
- }, isDateChangeable && React__default.createElement("g", null, React__default.createElement(BarDateHandle, {
1804
- x: task.x1 + 1,
1805
- y: task.y + 1,
1806
- width: task.handleWidth,
1807
- height: handleHeight,
1808
- barCornerRadius: task.barCornerRadius,
1809
- onMouseDown: function onMouseDown(e) {
1810
- onEventStart("start", task, e, "planned");
1811
- }
1812
- }), React__default.createElement(BarDateHandle, {
1813
- x: task.x2 - task.handleWidth - 1,
1814
- y: task.y + 1,
1815
- width: task.handleWidth,
1816
- height: handleHeight,
1817
- barCornerRadius: task.barCornerRadius,
1818
- onMouseDown: function onMouseDown(e) {
1819
- onEventStart("end", task, e, "planned");
1820
- }
1821
- })), isProgressChangeable && React__default.createElement(BarProgressHandle, {
1822
- progressPoint: progressPoint,
1823
- onMouseDown: function onMouseDown(e) {
1824
- onEventStart("progress", task, e, "planned");
1825
- }
1826
- })));else return React__default.createElement("g", {
1827
- className: styles$6.barWrapper,
1828
- tabIndex: 0
1829
- }, React__default.createElement(BarDisplay, {
1830
- x: task.actualx1,
1831
- y: task.y + task.height / 2,
1832
- type: type,
1833
- startProgressWidth: task.progressStartWidth,
1834
- endProgressWidth: task.progressEndWidth,
1835
- width: task.actualx2 - task.actualx1,
1836
- height: task.height / 2,
1837
- progressX: task.progressX,
1838
- progressWidth: task.progressWidth,
1839
- barCornerRadius: task.barCornerRadius,
1840
- styles: task.styles,
1841
- isSelected: isSelected,
1842
- onMouseDown: function onMouseDown(e) {
1843
- isDateChangeable && onEventStart("move", task, e, "actual");
1844
- }
1845
- }), React__default.createElement("g", {
1846
- className: "handleGroup"
1847
- }, isDateChangeable && React__default.createElement("g", null, React__default.createElement(BarDateHandle, {
1848
- x: task.actualx1 + 1,
1849
- y: task.y + task.height / 2 + 1,
1850
- width: task.handleWidth,
1851
- height: handleHeight,
1852
- barCornerRadius: task.barCornerRadius,
1853
- onMouseDown: function onMouseDown(e) {
1854
- onEventStart("start", task, e, "actual");
1855
- }
1856
- }), React__default.createElement(BarDateHandle, {
1857
- x: task.actualx2 - task.handleWidth - 1,
1858
- y: task.y + task.height / 2 + 1,
1859
- width: task.handleWidth,
1860
- height: handleHeight,
1861
- barCornerRadius: task.barCornerRadius,
1862
- onMouseDown: function onMouseDown(e) {
1863
- onEventStart("end", task, e, "actual");
1864
- }
1865
- })), isProgressChangeable && React__default.createElement(BarProgressHandle, {
1866
- progressPoint: progressPoint,
1867
- onMouseDown: function onMouseDown(e) {
1868
- onEventStart("progress", task, e, "actual");
1869
- }
1870
- })));
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
+ }
1871
1895
  };
1872
1896
 
1873
1897
  var BarSmall = function BarSmall(_ref) {
@@ -2015,11 +2039,23 @@ var TaskItem = function TaskItem(props) {
2015
2039
  break;
2016
2040
 
2017
2041
  default:
2018
- setTaskItem([React__default.createElement(Bar, Object.assign({}, props, {
2019
- type: "planned"
2020
- })), React__default.createElement(Bar, Object.assign({}, props, {
2021
- type: "actual"
2022
- }))]);
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
+ }
2023
2059
  break;
2024
2060
  }
2025
2061
  }, [task, isSelected]);
@@ -2308,7 +2344,18 @@ var TaskGanttContent = function TaskGanttContent(_ref) {
2308
2344
  className: "content"
2309
2345
  }, React__default.createElement("g", {
2310
2346
  className: "arrows"
2311
- }, 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
+
2312
2359
  return task.barChildren.map(function (child) {
2313
2360
  var _task$criticalPathArr, _task$criticalPathArr2;
2314
2361
 
@@ -2329,7 +2376,18 @@ var TaskGanttContent = function TaskGanttContent(_ref) {
2329
2376
  className: "bar",
2330
2377
  fontFamily: fontFamily,
2331
2378
  fontSize: fontSize
2332
- }, 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
+
2333
2391
  return React__default.createElement(TaskItem, {
2334
2392
  task: task,
2335
2393
  arrowIndent: arrowIndent,
@@ -2644,7 +2702,7 @@ var Gantt = function Gantt(_ref) {
2644
2702
  return t.id === changedTask.id;
2645
2703
  });
2646
2704
 
2647
- 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)) {
2648
2706
  var newTaskList = barTasks.map(function (t) {
2649
2707
  return t.id === changedTask.id ? changedTask : t;
2650
2708
  });