@worktile/gantt 12.0.1 → 12.1.1

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.
Files changed (232) hide show
  1. package/README.md +13 -116
  2. package/bundles/worktile-gantt.umd.js +3369 -0
  3. package/bundles/worktile-gantt.umd.js.map +1 -0
  4. package/class/date-point.d.ts +15 -0
  5. package/{packages/gantt/src/class/event.ts → class/event.d.ts} +6 -12
  6. package/class/group.d.ts +22 -0
  7. package/{packages/gantt/src/class/index.ts → class/index.d.ts} +0 -0
  8. package/class/item.d.ts +70 -0
  9. package/class/view-type.d.ts +7 -0
  10. package/components/bar/bar-drag.d.ts +37 -0
  11. package/components/bar/bar.component.d.ts +26 -0
  12. package/components/calendar/calendar.component.d.ts +28 -0
  13. package/components/drag-backdrop/drag-backdrop.component.d.ts +9 -0
  14. package/components/icon/icon.component.d.ts +13 -0
  15. package/components/icon/icons.d.ts +8 -0
  16. package/components/links/links.component.d.ts +47 -0
  17. package/components/main/gantt-main.component.d.ts +21 -0
  18. package/components/range/range.component.d.ts +13 -0
  19. package/components/table/gantt-table.component.d.ts +37 -0
  20. package/esm2015/class/date-point.js +10 -0
  21. package/esm2015/class/event.js +13 -0
  22. package/esm2015/class/group.js +17 -0
  23. package/esm2015/class/index.js +6 -0
  24. package/esm2015/class/item.js +78 -0
  25. package/esm2015/class/view-type.js +9 -0
  26. package/esm2015/components/bar/bar-drag.js +269 -0
  27. package/esm2015/components/bar/bar.component.js +98 -0
  28. package/esm2015/components/calendar/calendar.component.js +86 -0
  29. package/esm2015/components/drag-backdrop/drag-backdrop.component.js +21 -0
  30. package/esm2015/components/icon/icon.component.js +38 -0
  31. package/esm2015/components/icon/icons.js +87 -0
  32. package/esm2015/components/links/links.component.js +213 -0
  33. package/esm2015/components/main/gantt-main.component.js +53 -0
  34. package/esm2015/components/range/range.component.js +37 -0
  35. package/esm2015/components/table/gantt-table.component.js +149 -0
  36. package/esm2015/gantt-abstract.js +3 -0
  37. package/esm2015/gantt-dom.service.js +103 -0
  38. package/esm2015/gantt-drag-container.js +60 -0
  39. package/esm2015/gantt-item-upper.js +58 -0
  40. package/esm2015/gantt-print.service.js +94 -0
  41. package/esm2015/gantt-upper.js +280 -0
  42. package/esm2015/gantt.component.js +135 -0
  43. package/esm2015/gantt.config.js +13 -0
  44. package/esm2015/gantt.module.js +85 -0
  45. package/esm2015/gantt.pipe.js +43 -0
  46. package/esm2015/gantt.styles.js +15 -0
  47. package/esm2015/public-api.js +19 -0
  48. package/esm2015/root.component.js +123 -0
  49. package/esm2015/table/gantt-column.component.js +37 -0
  50. package/esm2015/table/gantt-table.component.js +20 -0
  51. package/esm2015/utils/date.js +160 -0
  52. package/esm2015/utils/helpers.js +55 -0
  53. package/esm2015/views/day.js +54 -0
  54. package/esm2015/views/factory.js +23 -0
  55. package/esm2015/views/month.js +48 -0
  56. package/esm2015/views/quarter.js +51 -0
  57. package/esm2015/views/view.js +123 -0
  58. package/esm2015/views/week.js +49 -0
  59. package/esm2015/views/year.js +50 -0
  60. package/esm2015/worktile-gantt.js +5 -0
  61. package/fesm2015/worktile-gantt.js +2697 -0
  62. package/fesm2015/worktile-gantt.js.map +1 -0
  63. package/{packages/gantt/src/gantt-abstract.ts → gantt-abstract.d.ts} +1 -3
  64. package/gantt-dom.service.d.ts +32 -0
  65. package/gantt-drag-container.d.ts +24 -0
  66. package/gantt-item-upper.d.ts +20 -0
  67. package/gantt-print.service.d.ts +13 -0
  68. package/gantt-upper.d.ts +69 -0
  69. package/gantt.component.d.ts +30 -0
  70. package/gantt.config.d.ts +23 -0
  71. package/gantt.module.d.ts +21 -0
  72. package/gantt.pipe.d.ts +18 -0
  73. package/gantt.styles.d.ts +15 -0
  74. package/main.bundle.scss +645 -0
  75. package/package.json +16 -113
  76. package/{packages/gantt/src/public-api.ts → public-api.d.ts} +1 -4
  77. package/root.component.d.ts +28 -0
  78. package/table/gantt-column.component.d.ts +15 -0
  79. package/table/gantt-table.component.d.ts +10 -0
  80. package/utils/date.d.ts +59 -0
  81. package/utils/helpers.d.ts +12 -0
  82. package/views/day.d.ts +14 -0
  83. package/views/factory.d.ts +8 -0
  84. package/views/month.d.ts +12 -0
  85. package/views/quarter.d.ts +12 -0
  86. package/views/view.d.ts +58 -0
  87. package/views/week.d.ts +12 -0
  88. package/views/year.d.ts +12 -0
  89. package/worktile-gantt.d.ts +5 -0
  90. package/.all-contributorsrc +0 -53
  91. package/.angulardoc.json +0 -4
  92. package/.circleci/config.yml +0 -17
  93. package/.coveralls.yml +0 -1
  94. package/.docgenirc.js +0 -64
  95. package/.editorconfig +0 -22
  96. package/.prettierrc +0 -24
  97. package/.travis.yml +0 -23
  98. package/CHANGELOG.md +0 -564
  99. package/Dockerfile +0 -4
  100. package/LICENSE +0 -21
  101. package/angular.json +0 -136
  102. package/docs/guides/basic/components.md +0 -54
  103. package/docs/guides/basic/event.md +0 -70
  104. package/docs/guides/basic/index.md +0 -4
  105. package/docs/guides/basic/style.md +0 -68
  106. package/docs/guides/basic/type.md +0 -70
  107. package/docs/guides/basic/usage.md +0 -189
  108. package/docs/guides/index.md +0 -5
  109. package/docs/guides/intro/getting-started.md +0 -79
  110. package/docs/guides/intro/index.md +0 -51
  111. package/docs/index.md +0 -0
  112. package/example/browserslist +0 -12
  113. package/example/src/app/app-routing.module.ts +0 -26
  114. package/example/src/app/app.component.html +0 -2
  115. package/example/src/app/app.component.ts +0 -11
  116. package/example/src/app/app.module.ts +0 -57
  117. package/example/src/app/components/components.component.html +0 -6
  118. package/example/src/app/components/components.component.ts +0 -33
  119. package/example/src/app/configuration/parameters/api/zh-cn.js +0 -350
  120. package/example/src/app/configuration/parameters/doc/zh-cn.md +0 -5
  121. package/example/src/app/gantt/gantt.component.html +0 -51
  122. package/example/src/app/gantt/gantt.component.ts +0 -119
  123. package/example/src/app/gantt-advanced/component/flat.component.html +0 -30
  124. package/example/src/app/gantt-advanced/component/flat.component.ts +0 -72
  125. package/example/src/app/gantt-advanced/component/flat.scss +0 -31
  126. package/example/src/app/gantt-advanced/gantt-advanced.component.html +0 -32
  127. package/example/src/app/gantt-advanced/gantt-advanced.component.ts +0 -34
  128. package/example/src/app/gantt-advanced/mocks.ts +0 -158
  129. package/example/src/app/gantt-groups/gantt-groups.component.html +0 -42
  130. package/example/src/app/gantt-groups/gantt-groups.component.ts +0 -62
  131. package/example/src/app/gantt-range/gantt-range.component.html +0 -66
  132. package/example/src/app/gantt-range/gantt-range.component.ts +0 -67
  133. package/example/src/app/gantt-range/mocks.ts +0 -150
  134. package/example/src/app/helper.ts +0 -38
  135. package/example/src/assets/.gitkeep +0 -0
  136. package/example/src/environments/environment.prod.ts +0 -3
  137. package/example/src/environments/environment.ts +0 -16
  138. package/example/src/favicon.ico +0 -0
  139. package/example/src/index.html +0 -13
  140. package/example/src/main.ts +0 -12
  141. package/example/src/polyfills.ts +0 -63
  142. package/example/src/styles.scss +0 -56
  143. package/example/tsconfig.app.json +0 -18
  144. package/nginx.conf +0 -17
  145. package/packages/gantt/README.md +0 -24
  146. package/packages/gantt/karma.conf.js +0 -46
  147. package/packages/gantt/ng-package.json +0 -7
  148. package/packages/gantt/ng-package.prod.json +0 -7
  149. package/packages/gantt/package.json +0 -16
  150. package/packages/gantt/src/class/date-point.ts +0 -14
  151. package/packages/gantt/src/class/group.ts +0 -36
  152. package/packages/gantt/src/class/item.ts +0 -129
  153. package/packages/gantt/src/class/test/group.spec.ts +0 -21
  154. package/packages/gantt/src/class/test/item.spec.ts +0 -102
  155. package/packages/gantt/src/class/view-type.ts +0 -7
  156. package/packages/gantt/src/components/bar/bar-drag.ts +0 -298
  157. package/packages/gantt/src/components/bar/bar.component.html +0 -17
  158. package/packages/gantt/src/components/bar/bar.component.scss +0 -169
  159. package/packages/gantt/src/components/bar/bar.component.ts +0 -109
  160. package/packages/gantt/src/components/bar/test/bar.component.spec.ts +0 -54
  161. package/packages/gantt/src/components/bar/test/bar.drag.spec.ts +0 -196
  162. package/packages/gantt/src/components/calendar/calendar.component.html +0 -52
  163. package/packages/gantt/src/components/calendar/calendar.component.scss +0 -77
  164. package/packages/gantt/src/components/calendar/calendar.component.ts +0 -100
  165. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.html +0 -6
  166. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.scss +0 -48
  167. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.ts +0 -13
  168. package/packages/gantt/src/components/icon/icon.component.scss +0 -13
  169. package/packages/gantt/src/components/icon/icon.component.ts +0 -28
  170. package/packages/gantt/src/components/icon/icons.ts +0 -86
  171. package/packages/gantt/src/components/links/links.component.html +0 -19
  172. package/packages/gantt/src/components/links/links.component.scss +0 -27
  173. package/packages/gantt/src/components/links/links.component.ts +0 -263
  174. package/packages/gantt/src/components/main/gantt-main.component.html +0 -35
  175. package/packages/gantt/src/components/main/gantt-main.component.ts +0 -35
  176. package/packages/gantt/src/components/range/range.component.html +0 -8
  177. package/packages/gantt/src/components/range/range.component.scss +0 -35
  178. package/packages/gantt/src/components/range/range.component.ts +0 -27
  179. package/packages/gantt/src/components/range/test/range.component.spec.ts +0 -80
  180. package/packages/gantt/src/components/table/gantt-table.component.html +0 -105
  181. package/packages/gantt/src/components/table/gantt-table.component.scss +0 -144
  182. package/packages/gantt/src/components/table/gantt-table.component.ts +0 -166
  183. package/packages/gantt/src/components/table/test/table.spec.ts +0 -129
  184. package/packages/gantt/src/gantt-dom.service.ts +0 -134
  185. package/packages/gantt/src/gantt-drag-container.ts +0 -73
  186. package/packages/gantt/src/gantt-item-upper.ts +0 -50
  187. package/packages/gantt/src/gantt-print.service.ts +0 -104
  188. package/packages/gantt/src/gantt-upper.ts +0 -289
  189. package/packages/gantt/src/gantt.component.html +0 -18
  190. package/packages/gantt/src/gantt.component.scss +0 -77
  191. package/packages/gantt/src/gantt.component.ts +0 -134
  192. package/packages/gantt/src/gantt.module.ts +0 -47
  193. package/packages/gantt/src/gantt.pipe.ts +0 -31
  194. package/packages/gantt/src/gantt.styles.ts +0 -28
  195. package/packages/gantt/src/root.component.html +0 -12
  196. package/packages/gantt/src/root.component.ts +0 -121
  197. package/packages/gantt/src/styles/index.scss +0 -9
  198. package/packages/gantt/src/styles/variables.scss +0 -46
  199. package/packages/gantt/src/table/gantt-column.component.ts +0 -25
  200. package/packages/gantt/src/table/gantt-table.component.ts +0 -14
  201. package/packages/gantt/src/table/test/table.spec.ts +0 -56
  202. package/packages/gantt/src/test/gantt.component.spec.ts +0 -404
  203. package/packages/gantt/src/test/mocks/data.ts +0 -303
  204. package/packages/gantt/src/test.ts +0 -21
  205. package/packages/gantt/src/utils/date.ts +0 -276
  206. package/packages/gantt/src/utils/helpers.ts +0 -66
  207. package/packages/gantt/src/utils/test/date.spec.ts +0 -105
  208. package/packages/gantt/src/utils/test/helpers.spec.ts +0 -73
  209. package/packages/gantt/src/utils/testing.ts +0 -64
  210. package/packages/gantt/src/views/day.ts +0 -74
  211. package/packages/gantt/src/views/factory.ts +0 -25
  212. package/packages/gantt/src/views/month.ts +0 -66
  213. package/packages/gantt/src/views/quarter.ts +0 -68
  214. package/packages/gantt/src/views/test/day.spec.ts +0 -45
  215. package/packages/gantt/src/views/test/factory.spec.ts +0 -41
  216. package/packages/gantt/src/views/test/mock.ts +0 -14
  217. package/packages/gantt/src/views/test/month.spec.ts +0 -45
  218. package/packages/gantt/src/views/test/quarter.spec.ts +0 -45
  219. package/packages/gantt/src/views/test/view.spec.ts +0 -144
  220. package/packages/gantt/src/views/test/week.spec.ts +0 -45
  221. package/packages/gantt/src/views/test/year.spec.ts +0 -45
  222. package/packages/gantt/src/views/view.ts +0 -186
  223. package/packages/gantt/src/views/week.ts +0 -66
  224. package/packages/gantt/src/views/year.ts +0 -62
  225. package/packages/gantt/tsconfig.lib.json +0 -20
  226. package/packages/gantt/tsconfig.lib.prod.json +0 -9
  227. package/packages/gantt/tsconfig.schematics.json +0 -25
  228. package/packages/gantt/tsconfig.spec.json +0 -17
  229. package/packages/gantt/tslint.json +0 -18
  230. package/scss-bundle.config.json +0 -7
  231. package/tsconfig.json +0 -26
  232. package/tslint.json +0 -51
@@ -1,105 +0,0 @@
1
- import { GanttDate, GanttDateUtil } from '../date';
2
-
3
- describe('tiny-date', () => {
4
- const date = new GanttDate('2020-2-2 20:20:20');
5
-
6
- it('support getTime', () => expect(date.getTime()).toBe(date.value.getTime()));
7
-
8
- it('support getDate', () => expect(date.getDate()).toBe(date.value.getDate()));
9
-
10
- it('support getMilliseconds', () => expect(date.getMilliseconds()).toBe(date.value.getMilliseconds()));
11
-
12
- it('support getDaysInMonth', () => {
13
- expect(date.getDaysInMonth()).toBe(29);
14
- });
15
-
16
- it('support getDaysInQuarter', () => {
17
- expect(date.getDaysInQuarter()).toBe(91);
18
- });
19
-
20
- it('support setDate', () => {
21
- expect(date.setDate(10).getUnixTime()).toBe(new GanttDate('2020-02-10 20:20:20').getUnixTime());
22
- });
23
-
24
- it('support startOf', () => {
25
- expect(date.startOfDay().getUnixTime()).toBe(new GanttDate('2020-02-02 00:00:00').getUnixTime());
26
- expect(date.startOfMonth().getUnixTime()).toBe(new GanttDate('2020-02-01 00:00:00').getUnixTime());
27
- });
28
-
29
- it('support endOf', () => {
30
- expect(date.endOfDay().getUnixTime()).toBe(new GanttDate('2020-02-02 23:59:59').getUnixTime());
31
- expect(date.endOfMonth().getUnixTime()).toBe(new GanttDate('2020-02-29 23:59:59').getUnixTime());
32
- });
33
-
34
- it('support is', () => {
35
- expect(date.isToday()).toBe(false);
36
- expect(date.isWeekend()).toBe(true);
37
- });
38
-
39
- it('support add', () => {
40
- let newGanttDate: GanttDate;
41
-
42
- newGanttDate = date.addYears(1);
43
- expect(newGanttDate.getYear()).toBe(date.getYear() + 1);
44
-
45
- newGanttDate = date.addQuarters(1);
46
- expect(newGanttDate.getUnixTime()).toBe(new GanttDate('2020-05-02 20:20:20').getUnixTime());
47
-
48
- newGanttDate = date.addMonths(1);
49
- expect(newGanttDate.getMonth()).toBe(date.getMonth() + 1);
50
-
51
- newGanttDate = date.addWeeks(1);
52
- expect(newGanttDate.getWeek()).toBe(date.getWeek() + 1);
53
-
54
- newGanttDate = date.addDays(1);
55
- expect(newGanttDate.getDay()).toBe(date.getDay() + 1);
56
-
57
- newGanttDate = date.addHours(1);
58
- expect(newGanttDate.getHours()).toBe(date.getHours() + 1);
59
-
60
- newGanttDate = date.addMinutes(1);
61
- expect(newGanttDate.getMinutes()).toBe(date.getMinutes() + 1);
62
-
63
- newGanttDate = date.addSeconds(1);
64
- expect(newGanttDate.getSeconds()).toBe(date.getSeconds() + 1);
65
- });
66
-
67
- it('support add by type', () => {
68
- let newGanttDate: GanttDate;
69
-
70
- newGanttDate = date.add(1, 'year');
71
- expect(newGanttDate.getYear()).toBe(date.getYear() + 1);
72
-
73
- newGanttDate = date.add(1, 'quarter');
74
- expect(newGanttDate.getUnixTime()).toBe(new GanttDate('2020-05-02 20:20:20').getUnixTime());
75
-
76
- newGanttDate = date.add(1, 'month');
77
- expect(newGanttDate.getMonth()).toBe(date.getMonth() + 1);
78
-
79
- newGanttDate = date.add(1, 'week');
80
- expect(newGanttDate.getWeek()).toBe(date.getWeek() + 1);
81
-
82
- newGanttDate = date.add(1, 'day');
83
- expect(newGanttDate.getDay()).toBe(date.getDay() + 1);
84
-
85
- newGanttDate = date.add(1, 'hour');
86
- expect(newGanttDate.getHours()).toBe(date.getHours() + 1);
87
-
88
- newGanttDate = date.add(1, 'minute');
89
- expect(newGanttDate.getMinutes()).toBe(date.getMinutes() + 1);
90
-
91
- newGanttDate = date.add(1, 'second');
92
- expect(newGanttDate.getSeconds()).toBe(date.getSeconds() + 1);
93
-
94
- newGanttDate = date.add(1);
95
- expect(newGanttDate.getSeconds()).toBe(date.getSeconds() + 1);
96
- });
97
-
98
- it('support clone', () => {
99
- expect(date.getTime()).toBe(date.clone().getTime());
100
- });
101
-
102
- it('support format', () => {
103
- expect(date.format('yyyy年QQQ')).toBe('2020年Q1');
104
- });
105
- });
@@ -1,73 +0,0 @@
1
- import { GanttItemInternal } from '../../class';
2
- import { isNumber, isString, isUndefined, hexToRgb, uniqBy, flatten, recursiveItems } from '../helpers';
3
-
4
- describe('helpers', () => {
5
- it('isNumber', () => {
6
- const result = isNumber('111');
7
- const result1 = isNumber(111);
8
-
9
- expect(result).toBe(false);
10
- expect(result1).toBe(true);
11
- });
12
-
13
- it('isString', () => {
14
- const result = isString('111');
15
- const result1 = isString(111);
16
-
17
- expect(result).toBe(true);
18
- expect(result1).toBe(false);
19
- });
20
-
21
- it('isUndefined', () => {
22
- const result = isUndefined('111');
23
- const result1 = isUndefined(undefined);
24
-
25
- expect(result).toBe(false);
26
- expect(result1).toBe(true);
27
- });
28
-
29
- it('hexToRgb', () => {
30
- const result = hexToRgb('#cccccc');
31
- const result1 = hexToRgb('rgba(255,255,255)');
32
-
33
- expect(result).toBe('rgba(204,204,204,1)');
34
- expect(result1).toBe('rgba(255,255,255)');
35
- });
36
-
37
- it('uniqBy', () => {
38
- const result = uniqBy([{ id: '3333' }, { id: '2222' }, { id: '3333' }], 'id');
39
-
40
- expect(result.length).toBe(2);
41
- });
42
-
43
- it('flatten', () => {
44
- const result = flatten([[{ id: '3333' }], [{ id: '2222' }], { id: '3333' }]);
45
- result.forEach((value) => {
46
- expect(value.length).toBe(undefined);
47
- });
48
- });
49
-
50
- it('recursiveItems', () => {
51
- const result = recursiveItems([
52
- {
53
- id: '3333',
54
- expanded: true,
55
- children: [
56
- {
57
- id: '3333-1'
58
- }
59
- ]
60
- } as GanttItemInternal,
61
- {
62
- id: '2222',
63
- expanded: false,
64
- children: [
65
- {
66
- id: '2222-1'
67
- }
68
- ]
69
- } as GanttItemInternal
70
- ]);
71
- expect(result.length).toBe(3);
72
- });
73
- });
@@ -1,64 +0,0 @@
1
- import { ModifierKeys } from '@angular/cdk/testing';
2
-
3
- function createMouseEvent(type: string, clientX = 0, clientY = 0, button = 0, modifiers: ModifierKeys = {}, relatedTarget?: Element) {
4
- const event = document.createEvent('MouseEvent');
5
- const originalPreventDefault = event.preventDefault.bind(event);
6
-
7
- // Note: We cannot determine the position of the mouse event based on the screen
8
- // because the dimensions and position of the browser window are not available
9
- // To provide reasonable `screenX` and `screenY` coordinates, we simply use the
10
- // client coordinates as if the browser is opened in fullscreen.
11
- const screenX = clientX;
12
- const screenY = clientY;
13
-
14
- event.initMouseEvent(
15
- type,
16
- /* canBubble */ true,
17
- /* cancelable */ true,
18
- /* view */ window,
19
- /* detail */ 0,
20
- /* screenX */ screenX,
21
- /* screenY */ screenY,
22
- /* clientX */ clientX,
23
- /* clientY */ clientY,
24
- /* ctrlKey */ !!modifiers.control,
25
- /* altKey */ !!modifiers.alt,
26
- /* shiftKey */ !!modifiers.shift,
27
- /* metaKey */ !!modifiers.meta,
28
- /* button */ button,
29
- /* relatedTarget */ relatedTarget
30
- );
31
-
32
- // `initMouseEvent` doesn't allow us to pass the `buttons` and
33
- // defaults it to 0 which looks like a fake event.
34
- defineReadonlyEventProperty(event, 'buttons', 1);
35
-
36
- // IE won't set `defaultPrevented` on synthetic events so we need to do it manually.
37
- event.preventDefault = function () {
38
- defineReadonlyEventProperty(event, 'defaultPrevented', true);
39
- return originalPreventDefault();
40
- };
41
-
42
- return event;
43
- }
44
-
45
- function defineReadonlyEventProperty(event: Event, propertyName: string, value: any) {
46
- Object.defineProperty(event, propertyName, { get: () => value, configurable: true });
47
- }
48
-
49
- export function dispatchEvent<T extends Event>(node: Node | Window, event: T): T {
50
- node.dispatchEvent(event);
51
- return event;
52
- }
53
-
54
- export function dispatchMouseEvent(
55
- node: Node,
56
- type: string,
57
- clientX = 0,
58
- clientY = 0,
59
- button?: number,
60
- modifiers?: ModifierKeys,
61
- relatedTarget?: Element
62
- ): MouseEvent {
63
- return dispatchEvent(node, createMouseEvent(type, clientX, clientY, button, modifiers, relatedTarget));
64
- }
@@ -1,74 +0,0 @@
1
- import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop, GanttViewDate } from './view';
2
- import { GanttDate, eachWeekOfInterval, eachDayOfInterval } from '../utils/date';
3
- import { GanttDatePoint } from '../class/date-point';
4
-
5
- const viewOptions: GanttViewOptions = {
6
- cellWidth: 35,
7
- start: new GanttDate().startOfYear().startOfWeek({ weekStartsOn: 1 }),
8
- end: new GanttDate().endOfYear().endOfWeek({ weekStartsOn: 1 }),
9
- addAmount: 1,
10
- addUnit: 'month'
11
- };
12
-
13
- export class GanttViewDay extends GanttView {
14
- showWeekBackdrop = true;
15
-
16
- showTimeline = false;
17
-
18
- constructor(start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
19
- super(start, end, Object.assign({}, viewOptions, options));
20
- }
21
-
22
- startOf(date: GanttDate) {
23
- return date.startOfWeek({ weekStartsOn: 1 });
24
- }
25
-
26
- endOf(date: GanttDate) {
27
- return date.endOfWeek({ weekStartsOn: 1 });
28
- }
29
-
30
- getPrimaryWidth() {
31
- return this.getCellWidth() * 7;
32
- }
33
-
34
- getDayOccupancyWidth(): number {
35
- return this.cellWidth;
36
- }
37
-
38
- getPrimaryDatePoints(): GanttDatePoint[] {
39
- const weeks = eachWeekOfInterval({ start: this.start.value, end: this.end.addSeconds(1).value }, { weekStartsOn: 1 });
40
- const points: GanttDatePoint[] = [];
41
- for (let i = 0; i < weeks.length; i++) {
42
- const weekStart = new GanttDate(weeks[i]);
43
- const increaseWeek = weekStart.getDaysInMonth() - weekStart.getDate() >= 3 ? 0 : 1;
44
- const point = new GanttDatePoint(
45
- weekStart,
46
- weekStart.addWeeks(increaseWeek).format('yyyy年MM月'),
47
- (this.getCellWidth() * 7) / 2 + i * (this.getCellWidth() * 7),
48
- primaryDatePointTop
49
- );
50
- points.push(point);
51
- }
52
- return points;
53
- }
54
-
55
- getSecondaryDatePoints(): GanttDatePoint[] {
56
- const days = eachDayOfInterval({ start: this.start.value, end: this.end.value });
57
- const points: GanttDatePoint[] = [];
58
- for (let i = 0; i < days.length; i++) {
59
- const start = new GanttDate(days[i]);
60
- const point = new GanttDatePoint(
61
- start,
62
- start.getDate().toString(),
63
- i * this.getCellWidth() + this.getCellWidth() / 2,
64
- secondaryDatePointTop,
65
- {
66
- isWeekend: start.isWeekend(),
67
- isToday: start.isToday()
68
- }
69
- );
70
- points.push(point);
71
- }
72
- return points;
73
- }
74
- }
@@ -1,25 +0,0 @@
1
- import { GanttViewOptions, GanttViewDate } from './view';
2
- import { GanttViewMonth } from './month';
3
- import { GanttDate } from '../utils/date';
4
- import { GanttViewType } from '../class/view-type';
5
- import { GanttViewQuarter } from './quarter';
6
- import { GanttViewDay } from './day';
7
- import { GanttViewWeek } from './week';
8
- import { GanttViewYear } from './year';
9
-
10
- export function createViewFactory(type: GanttViewType, start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
11
- switch (type) {
12
- case GanttViewType.month:
13
- return new GanttViewMonth(start, end, options);
14
- case GanttViewType.week:
15
- return new GanttViewWeek(start, end, options);
16
- case GanttViewType.quarter:
17
- return new GanttViewQuarter(start, end, options);
18
- case GanttViewType.day:
19
- return new GanttViewDay(start, end, options);
20
- case GanttViewType.year:
21
- return new GanttViewYear(start, end, options);
22
- default:
23
- throw new Error('gantt view type invalid');
24
- }
25
- }
@@ -1,66 +0,0 @@
1
- import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop, GanttViewDate } from './view';
2
- import { GanttDate, differenceInCalendarQuarters, eachMonthOfInterval } from '../utils/date';
3
- import { GanttDatePoint } from '../class/date-point';
4
-
5
- const viewOptions: GanttViewOptions = {
6
- start: new GanttDate().startOfQuarter().addQuarters(-1),
7
- end: new GanttDate().endOfQuarter().addQuarters(2),
8
- cellWidth: 280,
9
- addAmount: 1,
10
- addUnit: 'quarter'
11
- };
12
-
13
- export class GanttViewMonth extends GanttView {
14
- constructor(start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
15
- super(start, end, Object.assign({}, viewOptions, options));
16
- }
17
-
18
- startOf(date: GanttDate) {
19
- return date.startOfQuarter();
20
- }
21
-
22
- endOf(date: GanttDate) {
23
- return date.endOfQuarter();
24
- }
25
-
26
- getPrimaryWidth() {
27
- return this.getCellWidth() * 3;
28
- }
29
-
30
- getDayOccupancyWidth(date: GanttDate): number {
31
- return this.cellWidth / date.getDaysInMonth();
32
- }
33
-
34
- getPrimaryDatePoints(): GanttDatePoint[] {
35
- const quarters = differenceInCalendarQuarters(this.end.addSeconds(1).value, this.start.value);
36
- const points: GanttDatePoint[] = [];
37
- for (let i = 0; i < quarters; i++) {
38
- const start = this.start.addQuarters(i);
39
- const point = new GanttDatePoint(
40
- start,
41
- start.format('yyyy年QQQ'),
42
- (this.getCellWidth() * 3) / 2 + i * (this.getCellWidth() * 3),
43
- primaryDatePointTop
44
- );
45
- points.push(point);
46
- }
47
-
48
- return points;
49
- }
50
-
51
- getSecondaryDatePoints(): GanttDatePoint[] {
52
- const months = eachMonthOfInterval({ start: this.start.value, end: this.end.value });
53
- const points: GanttDatePoint[] = [];
54
- for (let i = 0; i < months.length; i++) {
55
- const start = new GanttDate(months[i]);
56
- const point = new GanttDatePoint(
57
- start,
58
- `${start.getMonth() + 1}月`,
59
- i * this.getCellWidth() + this.getCellWidth() / 2,
60
- secondaryDatePointTop
61
- );
62
- points.push(point);
63
- }
64
- return points;
65
- }
66
- }
@@ -1,68 +0,0 @@
1
- import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop, GanttViewDate } from './view';
2
- import { GanttDate } from '../utils/date';
3
- import { GanttDatePoint } from '../class/date-point';
4
- import { eachYearOfInterval, differenceInCalendarQuarters } from 'date-fns';
5
-
6
- const viewOptions: GanttViewOptions = {
7
- start: new GanttDate().addYears(-1).startOfYear(),
8
- end: new GanttDate().addYears(1).endOfYear(),
9
- min: new GanttDate().addYears(-2).startOfYear(),
10
- max: new GanttDate().addYears(2).endOfYear(),
11
- cellWidth: 500,
12
- addAmount: 1,
13
- addUnit: 'year'
14
- };
15
-
16
- export class GanttViewQuarter extends GanttView {
17
- constructor(start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
18
- super(start, end, Object.assign({}, viewOptions, options));
19
- }
20
-
21
- startOf(date: GanttDate) {
22
- return date.startOfYear();
23
- }
24
-
25
- endOf(date: GanttDate) {
26
- return date.endOfYear();
27
- }
28
-
29
- getPrimaryWidth() {
30
- return this.getCellWidth() * 4;
31
- }
32
-
33
- getDayOccupancyWidth(date: GanttDate): number {
34
- return this.cellWidth / date.getDaysInQuarter();
35
- }
36
-
37
- getPrimaryDatePoints(): GanttDatePoint[] {
38
- const years = eachYearOfInterval({ start: this.start.value, end: this.end.value });
39
- const points: GanttDatePoint[] = [];
40
- for (let i = 0; i < years.length; i++) {
41
- const start = new GanttDate(years[i]);
42
- const point = new GanttDatePoint(
43
- start,
44
- `${start.format('yyyy')}年`,
45
- (this.getCellWidth() * 4) / 2 + i * (this.getCellWidth() * 4),
46
- primaryDatePointTop
47
- );
48
- points.push(point);
49
- }
50
- return points;
51
- }
52
-
53
- getSecondaryDatePoints(): GanttDatePoint[] {
54
- const quarters = differenceInCalendarQuarters(this.end.value, this.start.value);
55
- const points: GanttDatePoint[] = [];
56
- for (let i = 0; i <= quarters; i++) {
57
- const start = this.start.addQuarters(i);
58
- const point = new GanttDatePoint(
59
- start,
60
- start.format('QQQ'),
61
- i * this.getCellWidth() + this.getCellWidth() / 2,
62
- secondaryDatePointTop
63
- );
64
- points.push(point);
65
- }
66
- return points;
67
- }
68
- }
@@ -1,45 +0,0 @@
1
- import { GanttViewDay } from '../day';
2
- import { GanttDate } from '../../utils/date';
3
- import { date, today } from './mock';
4
-
5
- describe('GanttViewDay', () => {
6
- let ganttViewDay: GanttViewDay;
7
-
8
- beforeEach(() => {
9
- ganttViewDay = new GanttViewDay(date.start, date.end, {
10
- cellWidth: 20,
11
- start: today.startOfYear().startOfWeek({ weekStartsOn: 1 }),
12
- end: today.endOfYear().endOfWeek({ weekStartsOn: 1 })
13
- });
14
- });
15
-
16
- it(`should has correct view start`, () => {
17
- const startOfDay = ganttViewDay.startOf(date.start.date).getUnixTime();
18
- expect(startOfDay).toEqual(new GanttDate('2019-12-30 00:00:00').getUnixTime());
19
- });
20
-
21
- it(`should has correct view end`, () => {
22
- const endOfDay = ganttViewDay.endOf(date.end.date).getUnixTime();
23
- expect(endOfDay).toEqual(new GanttDate('2021-01-03 23:59:59').getUnixTime());
24
- });
25
-
26
- it(`should has correct cell width`, () => {
27
- const dayCellWidth = ganttViewDay.getDayOccupancyWidth();
28
- expect(dayCellWidth).toEqual(20);
29
- });
30
-
31
- it(`should has correct primary width`, () => {
32
- const dayPrimaryWidth = ganttViewDay.getPrimaryWidth();
33
- expect(dayPrimaryWidth).toEqual(140);
34
- });
35
-
36
- it(`should has correct primary date points`, () => {
37
- const dayPoints = ganttViewDay.getPrimaryDatePoints();
38
- expect(dayPoints.length).toBe(54);
39
- });
40
-
41
- it(`should has correct secondary date points`, () => {
42
- const dayPoints = ganttViewDay.getSecondaryDatePoints();
43
- expect(dayPoints.length).toBe(371);
44
- });
45
- });
@@ -1,41 +0,0 @@
1
- import { GanttViewMonth } from '../month';
2
- import { GanttViewDay } from '../day';
3
- import { GanttViewQuarter } from '../quarter';
4
- import { createViewFactory } from '../factory';
5
- import { GanttViewType } from '../../class';
6
- import { date } from './mock';
7
- import { GanttViewYear } from '../year';
8
- import { GanttViewWeek } from '../week';
9
-
10
- describe('CreateViewFactory', () => {
11
- it(`should be day view`, () => {
12
- const dayView = createViewFactory(GanttViewType.day, date.start, date.end);
13
- expect(dayView).toEqual(jasmine.any(GanttViewDay));
14
- });
15
-
16
- it(`should be week view`, () => {
17
- const weekView = createViewFactory(GanttViewType.week, date.start, date.end);
18
- expect(weekView).toEqual(jasmine.any(GanttViewWeek));
19
- });
20
-
21
- it(`should be month view`, () => {
22
- const monthView = createViewFactory(GanttViewType.month, date.start, date.end);
23
- expect(monthView).toEqual(jasmine.any(GanttViewMonth));
24
- });
25
-
26
- it(`should be quarter view`, () => {
27
- const quarterView = createViewFactory(GanttViewType.quarter, date.start, date.end);
28
- expect(quarterView).toEqual(jasmine.any(GanttViewQuarter));
29
- });
30
-
31
- it('should be year view', () => {
32
- const yearView = createViewFactory(GanttViewType.year, date.start, date.end);
33
- expect(yearView).toEqual(jasmine.any(GanttViewYear));
34
- });
35
-
36
- // it(`should throw error`, () => {
37
- // expect(() => {
38
- // createViewFactory(GanttViewType.year, date.start, date.end);
39
- // }).toThrow(new Error('gantt view type invalid'));
40
- // });
41
- });
@@ -1,14 +0,0 @@
1
- import { GanttDate } from '../../utils/date';
2
-
3
- export const today = new GanttDate('2020-02-01 00:00:00');
4
-
5
- export const date = {
6
- start: {
7
- date: new GanttDate('2020-01-01 00:00:00'),
8
- isCustom: true
9
- },
10
- end: {
11
- date: new GanttDate('2020-12-31 00:00:00'),
12
- isCustom: true
13
- }
14
- };
@@ -1,45 +0,0 @@
1
- import { GanttViewMonth } from '../month';
2
- import { GanttDate } from '../../utils/date';
3
- import { date, today } from './mock';
4
-
5
- describe('GanttViewMonth', () => {
6
- let ganttViewMonth: GanttViewMonth;
7
-
8
- beforeEach(() => {
9
- ganttViewMonth = new GanttViewMonth(date.start, date.end, {
10
- cellWidth: 310,
11
- start: today.startOfQuarter().addQuarters(-1),
12
- end: today.endOfQuarter().addQuarters(2)
13
- });
14
- });
15
-
16
- it(`should has correct view start`, () => {
17
- const startOfMonth = ganttViewMonth.startOf(date.start.date).getUnixTime();
18
- expect(startOfMonth).toEqual(new GanttDate('2020-01-01 00:00:00').getUnixTime());
19
- });
20
-
21
- it(`should has correct view end`, () => {
22
- const endOfMonth = ganttViewMonth.endOf(date.end.date).getUnixTime();
23
- expect(endOfMonth).toEqual(new GanttDate('2020-12-31 23:59:59').getUnixTime());
24
- });
25
-
26
- it(`should has correct cell width`, () => {
27
- const monthCellWidth = ganttViewMonth.getDayOccupancyWidth(date.start.date);
28
- expect(monthCellWidth).toEqual(10);
29
- });
30
-
31
- it(`should has correct primary width`, () => {
32
- const monthPrimaryWidth = ganttViewMonth.getPrimaryWidth();
33
- expect(monthPrimaryWidth).toEqual(930);
34
- });
35
-
36
- it(`should has correct primary date points`, () => {
37
- const monthPoints = ganttViewMonth.getPrimaryDatePoints();
38
- expect(monthPoints.length).toBe(4);
39
- });
40
-
41
- it(`should has correct secondary date points`, () => {
42
- const monthPoints = ganttViewMonth.getSecondaryDatePoints();
43
- expect(monthPoints.length).toBe(12);
44
- });
45
- });
@@ -1,45 +0,0 @@
1
- import { GanttDate } from '../../utils/date';
2
- import { GanttViewQuarter } from '../quarter';
3
- import { date, today } from './mock';
4
-
5
- describe('GanttViewQuarter', () => {
6
- let ganttViewQuarter: GanttViewQuarter;
7
-
8
- beforeEach(() => {
9
- ganttViewQuarter = new GanttViewQuarter(date.start, date.end, {
10
- cellWidth: 910,
11
- start: today.addYears(-1).startOfYear(),
12
- end: today.addYears(1).endOfYear()
13
- });
14
- });
15
-
16
- it(`should has correct view start`, () => {
17
- const startOfQuarter = ganttViewQuarter.startOf(date.start.date).getUnixTime();
18
- expect(startOfQuarter).toEqual(new GanttDate('2020-01-01 00:00:00').getUnixTime());
19
- });
20
-
21
- it(`should has correct view end`, () => {
22
- const endOfQuarter = ganttViewQuarter.endOf(date.end.date).getUnixTime();
23
- expect(endOfQuarter).toEqual(new GanttDate('2020-12-31 23:59:59').getUnixTime());
24
- });
25
-
26
- it(`should has correct cell width`, () => {
27
- const quarterCellWidth = ganttViewQuarter.getDayOccupancyWidth(date.start.date);
28
- expect(quarterCellWidth).toEqual(10);
29
- });
30
-
31
- it(`should has correct primary width`, () => {
32
- const quarterPrimaryWidth = ganttViewQuarter.getPrimaryWidth();
33
- expect(quarterPrimaryWidth).toEqual(3640);
34
- });
35
-
36
- it(`should has correct primary date points`, () => {
37
- const quarterPoints = ganttViewQuarter.getPrimaryDatePoints();
38
- expect(quarterPoints.length).toBe(1);
39
- });
40
-
41
- it(`should has correct secondary date points`, () => {
42
- const quarterPoints = ganttViewQuarter.getSecondaryDatePoints();
43
- expect(quarterPoints.length).toBe(4);
44
- });
45
- });