@worktile/gantt 12.0.0 → 12.0.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 (230) hide show
  1. package/.all-contributorsrc +53 -0
  2. package/.angulardoc.json +4 -0
  3. package/.circleci/config.yml +17 -0
  4. package/.coveralls.yml +1 -0
  5. package/.docgenirc.js +64 -0
  6. package/.editorconfig +22 -0
  7. package/.prettierrc +24 -0
  8. package/.travis.yml +23 -0
  9. package/CHANGELOG.md +564 -0
  10. package/Dockerfile +4 -0
  11. package/LICENSE +21 -0
  12. package/README.md +116 -13
  13. package/angular.json +136 -0
  14. package/docs/guides/basic/components.md +54 -0
  15. package/docs/guides/basic/event.md +70 -0
  16. package/docs/guides/basic/index.md +4 -0
  17. package/docs/guides/basic/style.md +68 -0
  18. package/docs/guides/basic/type.md +70 -0
  19. package/docs/guides/basic/usage.md +189 -0
  20. package/docs/guides/index.md +5 -0
  21. package/docs/guides/intro/getting-started.md +79 -0
  22. package/docs/guides/intro/index.md +51 -0
  23. package/docs/index.md +0 -0
  24. package/example/browserslist +12 -0
  25. package/example/src/app/app-routing.module.ts +26 -0
  26. package/example/src/app/app.component.html +2 -0
  27. package/example/src/app/app.component.ts +11 -0
  28. package/example/src/app/app.module.ts +57 -0
  29. package/example/src/app/components/components.component.html +6 -0
  30. package/example/src/app/components/components.component.ts +33 -0
  31. package/example/src/app/configuration/parameters/api/zh-cn.js +350 -0
  32. package/example/src/app/configuration/parameters/doc/zh-cn.md +5 -0
  33. package/example/src/app/gantt/gantt.component.html +51 -0
  34. package/example/src/app/gantt/gantt.component.ts +119 -0
  35. package/example/src/app/gantt-advanced/component/flat.component.html +30 -0
  36. package/example/src/app/gantt-advanced/component/flat.component.ts +72 -0
  37. package/example/src/app/gantt-advanced/component/flat.scss +31 -0
  38. package/example/src/app/gantt-advanced/gantt-advanced.component.html +32 -0
  39. package/example/src/app/gantt-advanced/gantt-advanced.component.ts +34 -0
  40. package/example/src/app/gantt-advanced/mocks.ts +158 -0
  41. package/example/src/app/gantt-groups/gantt-groups.component.html +42 -0
  42. package/example/src/app/gantt-groups/gantt-groups.component.ts +62 -0
  43. package/example/src/app/gantt-range/gantt-range.component.html +66 -0
  44. package/example/src/app/gantt-range/gantt-range.component.ts +67 -0
  45. package/example/src/app/gantt-range/mocks.ts +150 -0
  46. package/example/src/app/helper.ts +38 -0
  47. package/example/src/assets/.gitkeep +0 -0
  48. package/example/src/environments/environment.prod.ts +3 -0
  49. package/example/src/environments/environment.ts +16 -0
  50. package/example/src/favicon.ico +0 -0
  51. package/example/src/index.html +13 -0
  52. package/example/src/main.ts +12 -0
  53. package/example/src/polyfills.ts +63 -0
  54. package/example/src/styles.scss +56 -0
  55. package/example/tsconfig.app.json +18 -0
  56. package/nginx.conf +17 -0
  57. package/package.json +113 -17
  58. package/packages/gantt/README.md +24 -0
  59. package/packages/gantt/karma.conf.js +46 -0
  60. package/packages/gantt/ng-package.json +7 -0
  61. package/packages/gantt/ng-package.prod.json +7 -0
  62. package/packages/gantt/package.json +16 -0
  63. package/packages/gantt/src/class/date-point.ts +14 -0
  64. package/{class/event.d.ts → packages/gantt/src/class/event.ts} +12 -6
  65. package/packages/gantt/src/class/group.ts +36 -0
  66. package/{class/index.d.ts → packages/gantt/src/class/index.ts} +0 -0
  67. package/packages/gantt/src/class/item.ts +129 -0
  68. package/packages/gantt/src/class/test/group.spec.ts +21 -0
  69. package/packages/gantt/src/class/test/item.spec.ts +102 -0
  70. package/packages/gantt/src/class/view-type.ts +7 -0
  71. package/packages/gantt/src/components/bar/bar-drag.ts +298 -0
  72. package/packages/gantt/src/components/bar/bar.component.html +17 -0
  73. package/packages/gantt/src/components/bar/bar.component.scss +169 -0
  74. package/packages/gantt/src/components/bar/bar.component.ts +109 -0
  75. package/packages/gantt/src/components/bar/test/bar.component.spec.ts +54 -0
  76. package/packages/gantt/src/components/bar/test/bar.drag.spec.ts +196 -0
  77. package/packages/gantt/src/components/calendar/calendar.component.html +52 -0
  78. package/packages/gantt/src/components/calendar/calendar.component.scss +77 -0
  79. package/packages/gantt/src/components/calendar/calendar.component.ts +100 -0
  80. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.html +6 -0
  81. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.scss +48 -0
  82. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.ts +13 -0
  83. package/packages/gantt/src/components/icon/icon.component.scss +13 -0
  84. package/packages/gantt/src/components/icon/icon.component.ts +28 -0
  85. package/packages/gantt/src/components/icon/icons.ts +86 -0
  86. package/packages/gantt/src/components/links/links.component.html +19 -0
  87. package/packages/gantt/src/components/links/links.component.scss +27 -0
  88. package/packages/gantt/src/components/links/links.component.ts +263 -0
  89. package/packages/gantt/src/components/main/gantt-main.component.html +35 -0
  90. package/packages/gantt/src/components/main/gantt-main.component.ts +35 -0
  91. package/packages/gantt/src/components/range/range.component.html +8 -0
  92. package/packages/gantt/src/components/range/range.component.scss +35 -0
  93. package/packages/gantt/src/components/range/range.component.ts +27 -0
  94. package/packages/gantt/src/components/range/test/range.component.spec.ts +80 -0
  95. package/packages/gantt/src/components/table/gantt-table.component.html +105 -0
  96. package/packages/gantt/src/components/table/gantt-table.component.scss +144 -0
  97. package/packages/gantt/src/components/table/gantt-table.component.ts +166 -0
  98. package/packages/gantt/src/components/table/test/table.spec.ts +129 -0
  99. package/packages/gantt/src/gantt-abstract.ts +14 -0
  100. package/packages/gantt/src/gantt-dom.service.ts +134 -0
  101. package/packages/gantt/src/gantt-drag-container.ts +73 -0
  102. package/packages/gantt/src/gantt-item-upper.ts +50 -0
  103. package/packages/gantt/src/gantt-print.service.ts +104 -0
  104. package/packages/gantt/src/gantt-upper.ts +289 -0
  105. package/packages/gantt/src/gantt.component.html +18 -0
  106. package/packages/gantt/src/gantt.component.scss +77 -0
  107. package/packages/gantt/src/gantt.component.ts +134 -0
  108. package/packages/gantt/src/gantt.module.ts +47 -0
  109. package/packages/gantt/src/gantt.pipe.ts +31 -0
  110. package/packages/gantt/src/gantt.styles.ts +28 -0
  111. package/{public-api.d.ts → packages/gantt/src/public-api.ts} +6 -0
  112. package/packages/gantt/src/root.component.html +12 -0
  113. package/packages/gantt/src/root.component.ts +121 -0
  114. package/packages/gantt/src/styles/index.scss +9 -0
  115. package/packages/gantt/src/styles/variables.scss +46 -0
  116. package/packages/gantt/src/table/gantt-column.component.ts +25 -0
  117. package/packages/gantt/src/table/gantt-table.component.ts +14 -0
  118. package/packages/gantt/src/table/test/table.spec.ts +56 -0
  119. package/packages/gantt/src/test/gantt.component.spec.ts +404 -0
  120. package/packages/gantt/src/test/mocks/data.ts +303 -0
  121. package/packages/gantt/src/test.ts +21 -0
  122. package/packages/gantt/src/utils/date.ts +276 -0
  123. package/packages/gantt/src/utils/helpers.ts +66 -0
  124. package/packages/gantt/src/utils/test/date.spec.ts +105 -0
  125. package/packages/gantt/src/utils/test/helpers.spec.ts +73 -0
  126. package/packages/gantt/src/utils/testing.ts +64 -0
  127. package/packages/gantt/src/views/day.ts +74 -0
  128. package/packages/gantt/src/views/factory.ts +25 -0
  129. package/packages/gantt/src/views/month.ts +66 -0
  130. package/packages/gantt/src/views/quarter.ts +68 -0
  131. package/packages/gantt/src/views/test/day.spec.ts +45 -0
  132. package/packages/gantt/src/views/test/factory.spec.ts +41 -0
  133. package/packages/gantt/src/views/test/mock.ts +14 -0
  134. package/packages/gantt/src/views/test/month.spec.ts +45 -0
  135. package/packages/gantt/src/views/test/quarter.spec.ts +45 -0
  136. package/packages/gantt/src/views/test/view.spec.ts +144 -0
  137. package/packages/gantt/src/views/test/week.spec.ts +45 -0
  138. package/packages/gantt/src/views/test/year.spec.ts +45 -0
  139. package/packages/gantt/src/views/view.ts +186 -0
  140. package/packages/gantt/src/views/week.ts +66 -0
  141. package/packages/gantt/src/views/year.ts +62 -0
  142. package/packages/gantt/tsconfig.lib.json +20 -0
  143. package/packages/gantt/tsconfig.lib.prod.json +9 -0
  144. package/packages/gantt/tsconfig.schematics.json +25 -0
  145. package/packages/gantt/tsconfig.spec.json +17 -0
  146. package/packages/gantt/tslint.json +18 -0
  147. package/scss-bundle.config.json +7 -0
  148. package/tsconfig.json +26 -0
  149. package/tslint.json +51 -0
  150. package/bundles/worktile-gantt.umd.js +0 -3128
  151. package/bundles/worktile-gantt.umd.js.map +0 -1
  152. package/class/date-point.d.ts +0 -15
  153. package/class/group.d.ts +0 -22
  154. package/class/item.d.ts +0 -70
  155. package/class/view-type.d.ts +0 -7
  156. package/components/bar/bar-drag.d.ts +0 -34
  157. package/components/bar/bar.component.d.ts +0 -23
  158. package/components/calendar/calendar.component.d.ts +0 -25
  159. package/components/drag-backdrop/drag-backdrop.component.d.ts +0 -6
  160. package/components/icon/icon.component.d.ts +0 -10
  161. package/components/icon/icons.d.ts +0 -8
  162. package/components/links/links.component.d.ts +0 -44
  163. package/components/main/gantt-main.component.d.ts +0 -18
  164. package/components/range/range.component.d.ts +0 -10
  165. package/components/table/gantt-table.component.d.ts +0 -31
  166. package/esm2015/class/date-point.js +0 -10
  167. package/esm2015/class/event.js +0 -13
  168. package/esm2015/class/group.js +0 -17
  169. package/esm2015/class/index.js +0 -6
  170. package/esm2015/class/item.js +0 -78
  171. package/esm2015/class/view-type.js +0 -9
  172. package/esm2015/components/bar/bar-drag.js +0 -266
  173. package/esm2015/components/bar/bar.component.js +0 -91
  174. package/esm2015/components/calendar/calendar.component.js +0 -82
  175. package/esm2015/components/drag-backdrop/drag-backdrop.component.js +0 -18
  176. package/esm2015/components/icon/icon.component.js +0 -36
  177. package/esm2015/components/icon/icons.js +0 -87
  178. package/esm2015/components/links/links.component.js +0 -207
  179. package/esm2015/components/main/gantt-main.component.js +0 -35
  180. package/esm2015/components/range/range.component.js +0 -32
  181. package/esm2015/components/table/gantt-table.component.js +0 -125
  182. package/esm2015/gantt-dom.service.js +0 -101
  183. package/esm2015/gantt-drag-container.js +0 -57
  184. package/esm2015/gantt-item-upper.js +0 -55
  185. package/esm2015/gantt-print.service.js +0 -92
  186. package/esm2015/gantt-upper.js +0 -231
  187. package/esm2015/gantt.component.js +0 -105
  188. package/esm2015/gantt.module.js +0 -43
  189. package/esm2015/gantt.pipe.js +0 -33
  190. package/esm2015/gantt.styles.js +0 -15
  191. package/esm2015/public-api.js +0 -16
  192. package/esm2015/root.component.js +0 -111
  193. package/esm2015/table/gantt-column.component.js +0 -28
  194. package/esm2015/table/gantt-table.component.js +0 -18
  195. package/esm2015/utils/date.js +0 -160
  196. package/esm2015/utils/helpers.js +0 -45
  197. package/esm2015/views/day.js +0 -54
  198. package/esm2015/views/factory.js +0 -23
  199. package/esm2015/views/month.js +0 -48
  200. package/esm2015/views/quarter.js +0 -51
  201. package/esm2015/views/view.js +0 -121
  202. package/esm2015/views/week.js +0 -49
  203. package/esm2015/views/year.js +0 -50
  204. package/esm2015/worktile-gantt.js +0 -16
  205. package/fesm2015/worktile-gantt.js +0 -2488
  206. package/fesm2015/worktile-gantt.js.map +0 -1
  207. package/gantt-dom.service.d.ts +0 -29
  208. package/gantt-drag-container.d.ts +0 -20
  209. package/gantt-item-upper.d.ts +0 -17
  210. package/gantt-print.service.d.ts +0 -10
  211. package/gantt-upper.d.ts +0 -62
  212. package/gantt.component.d.ts +0 -28
  213. package/gantt.module.d.ts +0 -2
  214. package/gantt.pipe.d.ts +0 -11
  215. package/gantt.styles.d.ts +0 -15
  216. package/main.bundle.scss +0 -645
  217. package/root.component.d.ts +0 -25
  218. package/table/gantt-column.component.d.ts +0 -12
  219. package/table/gantt-table.component.d.ts +0 -7
  220. package/utils/date.d.ts +0 -59
  221. package/utils/helpers.d.ts +0 -11
  222. package/views/day.d.ts +0 -14
  223. package/views/factory.d.ts +0 -8
  224. package/views/month.d.ts +0 -12
  225. package/views/quarter.d.ts +0 -12
  226. package/views/view.d.ts +0 -56
  227. package/views/week.d.ts +0 -12
  228. package/views/year.d.ts +0 -12
  229. package/worktile-gantt.d.ts +0 -15
  230. package/worktile-gantt.metadata.json +0 -1
@@ -0,0 +1,144 @@
1
+ import { GanttDatePoint } from '../../class';
2
+ import { GanttDate } from '../../utils/date';
3
+
4
+ import { GanttView, GanttViewDate, GanttViewOptions } from '../view';
5
+ import { date, today } from './mock';
6
+
7
+ class GanttViewMock extends GanttView {
8
+ constructor(start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
9
+ super(start, end, options);
10
+ }
11
+
12
+ startOf(): GanttDate {
13
+ return new GanttDate('2020-01-01 00:00:00');
14
+ }
15
+
16
+ endOf(): GanttDate {
17
+ return new GanttDate('2020-12-31 23:59:59');
18
+ }
19
+
20
+ getPrimaryWidth(): number {
21
+ return 3640;
22
+ }
23
+
24
+ getDayOccupancyWidth(): number {
25
+ return 10;
26
+ }
27
+
28
+ getPrimaryDatePoints(): GanttDatePoint[] {
29
+ return [
30
+ {
31
+ text: '2020年',
32
+ x: 1820,
33
+ y: 18,
34
+ start: new GanttDate('2020-01-01 00:00:00')
35
+ }
36
+ ];
37
+ }
38
+
39
+ getSecondaryDatePoints(): GanttDatePoint[] {
40
+ return [
41
+ {
42
+ text: 'Q1',
43
+ x: 455,
44
+ y: 36,
45
+ start: new GanttDate('2020-01-01 00:00:00')
46
+ },
47
+ {
48
+ text: 'Q2',
49
+ x: 1365,
50
+ y: 36,
51
+ start: new GanttDate('2020-04-01 00:00:00')
52
+ },
53
+ { text: 'Q3', x: 2275, y: 36, start: new GanttDate('2020-07-01 00:00:00') },
54
+ { text: 'Q4', x: 3185, y: 36, start: new GanttDate('2020-10-01 00:00:00') }
55
+ ];
56
+ }
57
+ }
58
+
59
+ describe('GanttView', () => {
60
+ let ganttView: GanttView;
61
+
62
+ beforeEach(() => {
63
+ ganttView = new GanttViewMock(date.start, date.end, {
64
+ cellWidth: 20,
65
+ start: today.startOfYear().startOfWeek({ weekStartsOn: 1 }),
66
+ end: today.endOfYear().endOfWeek({ weekStartsOn: 1 })
67
+ });
68
+ });
69
+
70
+ it(`should has correct view options`, () => {
71
+ const options = ganttView.options;
72
+ const cellWidth = options.cellWidth;
73
+ const start = options.start.getUnixTime();
74
+ const end = options.end.getUnixTime();
75
+ const max = options.max.getUnixTime();
76
+ const min = options.min.getUnixTime();
77
+
78
+ expect(cellWidth).toEqual(20);
79
+ expect(start).toEqual(new GanttDate('2019-12-30 00:00:00').getUnixTime());
80
+ expect(end).toEqual(new GanttDate('2021-01-03 23:59:59').getUnixTime());
81
+ expect(max).toEqual(new GanttDate().addYears(1).endOfYear().getUnixTime());
82
+ expect(min).toEqual(new GanttDate().addYears(-1).startOfYear().getUnixTime());
83
+ });
84
+
85
+ it(`should has correct start and end`, () => {
86
+ const start = ganttView.start.getUnixTime();
87
+ const end = ganttView.end.getUnixTime();
88
+ expect(start).toEqual(new GanttDate('2020-01-01 00:00:00').getUnixTime());
89
+ expect(end).toEqual(new GanttDate('2020-12-31 23:59:59').getUnixTime());
90
+ });
91
+
92
+ it(`should add start date`, () => {
93
+ const newDate = ganttView.addStartDate();
94
+ if (ganttView.options.min.value > new GanttDate('2020-01-01 00:00:00').value) {
95
+ expect(newDate).toBe(null);
96
+ } else {
97
+ expect(newDate.start.getUnixTime()).toEqual(new GanttDate('2020-01-01 00:00:00').getUnixTime());
98
+ expect(newDate.end.getUnixTime()).toEqual(new GanttDate('2020-01-01 00:00:00').getUnixTime());
99
+ }
100
+ });
101
+
102
+ it(`should add end date`, () => {
103
+ const newDate = ganttView.addEndDate();
104
+ expect(newDate.start.getUnixTime()).toEqual(new GanttDate('2020-12-31 23:59:59').getUnixTime());
105
+ expect(newDate.end.getUnixTime()).toEqual(new GanttDate('2020-12-31 23:59:59').getUnixTime());
106
+ });
107
+
108
+ it(`should update date`, () => {
109
+ ganttView.updateDate(new GanttDate('2020-10-01 00:00:00'), new GanttDate('2023-02-01 00:00:00'));
110
+ expect(ganttView.start.getUnixTime()).toEqual(new GanttDate('2020-01-01 00:00:00').getUnixTime());
111
+ expect(ganttView.end.getUnixTime()).toEqual(new GanttDate('2020-12-31 23:59:59').getUnixTime());
112
+ });
113
+
114
+ it(`should get width`, () => {
115
+ const width = ganttView.getWidth();
116
+ expect(width).toEqual(80);
117
+ });
118
+
119
+ it(`should get cell width`, () => {
120
+ const cellWidth = ganttView.getCellWidth();
121
+ expect(cellWidth).toEqual(20);
122
+ });
123
+
124
+ it(`should get today x point`, () => {
125
+ const xPoint = ganttView.getTodayXPoint();
126
+ expect(xPoint).toEqual(null);
127
+ });
128
+
129
+ it(`should get x point by date`, () => {
130
+ const xPoint = ganttView.getXPointByDate(new GanttDate('2020-02-01 00:00:00'));
131
+ expect(xPoint).toEqual(310);
132
+ });
133
+
134
+ it(`should get date by x point`, () => {
135
+ ganttView.getSecondaryDatePoints();
136
+ const pointDate = ganttView.getDateByXPoint(60);
137
+ expect(pointDate.getUnixTime()).toEqual(new GanttDate('2020-10-01 00:00:00').getUnixTime());
138
+ });
139
+
140
+ it(`should get date range width`, () => {
141
+ const width = ganttView.getDateRangeWidth(new GanttDate('2020-03-01 00:00:00'), new GanttDate('2020-05-01 00:00:00'));
142
+ expect(width).toEqual(610);
143
+ });
144
+ });
@@ -0,0 +1,45 @@
1
+ import { GanttDate } from '../../utils/date';
2
+ import { GanttViewWeek } from '../week';
3
+ import { date, today } from './mock';
4
+
5
+ describe('GanttViewWeek', () => {
6
+ let ganttViewWeek: GanttViewWeek;
7
+
8
+ beforeEach(() => {
9
+ ganttViewWeek = new GanttViewWeek(date.start, date.end, {
10
+ cellWidth: 140,
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 startOfWeek = ganttViewWeek.startOf(date.start.date).getUnixTime();
18
+ expect(startOfWeek).toEqual(new GanttDate('2019-12-30 00:00:00').getUnixTime());
19
+ });
20
+
21
+ it(`should has correct view end`, () => {
22
+ const endOfWeek = ganttViewWeek.endOf(date.end.date).getUnixTime();
23
+ expect(endOfWeek).toEqual(new GanttDate('2021-01-03 23:59:59').getUnixTime());
24
+ });
25
+
26
+ it(`should has correct cell width`, () => {
27
+ const weekCellWidth = ganttViewWeek.getDayOccupancyWidth();
28
+ expect(weekCellWidth).toEqual(20);
29
+ });
30
+
31
+ it(`should has correct primary width`, () => {
32
+ const weekPrimaryWidth = ganttViewWeek.getPrimaryWidth();
33
+ expect(weekPrimaryWidth).toEqual(140);
34
+ });
35
+
36
+ it(`should has correct primary date points`, () => {
37
+ const weekPoints = ganttViewWeek.getPrimaryDatePoints();
38
+ expect(weekPoints.length).toBe(54);
39
+ });
40
+
41
+ it(`should has correct secondary date points`, () => {
42
+ const weekPoints = ganttViewWeek.getSecondaryDatePoints();
43
+ expect(weekPoints.length).toBe(54);
44
+ });
45
+ });
@@ -0,0 +1,45 @@
1
+ import { GanttViewYear } from '../year';
2
+ import { GanttDate } from '../../utils/date';
3
+ import { date, today } from './mock';
4
+
5
+ describe('GanttViewYear', () => {
6
+ let ganttViewYear: GanttViewYear;
7
+
8
+ beforeEach(() => {
9
+ ganttViewYear = new GanttViewYear(date.start, date.end, {
10
+ cellWidth: 732,
11
+ start: today.addYears(-1).startOfYear(),
12
+ end: today.addYears(1).endOfYear()
13
+ });
14
+ });
15
+
16
+ it(`should has correct view start`, () => {
17
+ const startOfDay = ganttViewYear.startOf(date.start.date).getUnixTime();
18
+ expect(startOfDay).toEqual(new GanttDate('2020-01-01 00:00:00').getUnixTime());
19
+ });
20
+
21
+ it(`should has correct view end`, () => {
22
+ const endOfDay = ganttViewYear.endOf(date.end.date).getUnixTime();
23
+ expect(endOfDay).toEqual(new GanttDate('2020-12-31 23:59:59').getUnixTime());
24
+ });
25
+
26
+ it(`should has correct cell width`, () => {
27
+ const yearCellWidth = ganttViewYear.getDayOccupancyWidth(date.start.date);
28
+ expect(yearCellWidth).toEqual(2);
29
+ });
30
+
31
+ it(`should has correct primary width`, () => {
32
+ const yearPrimaryWidth = ganttViewYear.getPrimaryWidth();
33
+ expect(yearPrimaryWidth).toEqual(732);
34
+ });
35
+
36
+ it(`should has correct primary date points`, () => {
37
+ const yearPoints = ganttViewYear.getPrimaryDatePoints();
38
+ expect(yearPoints.length).toBe(1);
39
+ });
40
+
41
+ it(`should has correct secondary date points`, () => {
42
+ const yearPoints = ganttViewYear.getSecondaryDatePoints();
43
+ expect(yearPoints.length).toBe(1);
44
+ });
45
+ });
@@ -0,0 +1,186 @@
1
+ import { GanttDate, differenceInDays, GanttDateUtil } from '../utils/date';
2
+ import { GanttDatePoint } from '../class/date-point';
3
+ import { BehaviorSubject } from 'rxjs';
4
+
5
+ export const primaryDatePointTop = 18;
6
+
7
+ export const secondaryDatePointTop = 36;
8
+
9
+ export interface GanttViewDate {
10
+ date: GanttDate;
11
+ isCustom?: boolean;
12
+ }
13
+
14
+ export interface GanttViewOptions {
15
+ start?: GanttDate;
16
+ end?: GanttDate;
17
+ min?: GanttDate;
18
+ max?: GanttDate;
19
+ cellWidth?: number;
20
+ addAmount?: number;
21
+ addUnit?: GanttDateUtil;
22
+ }
23
+
24
+ const viewOptions: GanttViewOptions = {
25
+ min: new GanttDate().addYears(-1).startOfYear(),
26
+ max: new GanttDate().addYears(1).endOfYear()
27
+ };
28
+
29
+ export abstract class GanttView {
30
+ start$: BehaviorSubject<GanttDate>;
31
+
32
+ end$: BehaviorSubject<GanttDate>;
33
+
34
+ get start() {
35
+ return this.start$.getValue();
36
+ }
37
+
38
+ get end() {
39
+ return this.end$.getValue();
40
+ }
41
+
42
+ primaryDatePoints: GanttDatePoint[];
43
+
44
+ secondaryDatePoints: GanttDatePoint[];
45
+
46
+ width: number;
47
+
48
+ cellWidth: number;
49
+
50
+ primaryWidth: number;
51
+
52
+ showTimeline = true;
53
+
54
+ showWeekBackdrop: boolean;
55
+
56
+ options: GanttViewOptions;
57
+
58
+ constructor(start: GanttViewDate, end: GanttViewDate, options: GanttViewOptions) {
59
+ this.options = Object.assign({}, viewOptions, options);
60
+ const startDate = start.isCustom
61
+ ? this.startOf(start.date)
62
+ : this.startOf(start.date.value < this.options.start.value ? start.date : this.options.start);
63
+ const endDate = end.isCustom
64
+ ? this.endOf(end.date)
65
+ : this.endOf(end.date.value > this.options.end.value ? end.date : this.options.end);
66
+ this.start$ = new BehaviorSubject<GanttDate>(startDate);
67
+ this.end$ = new BehaviorSubject<GanttDate>(endDate);
68
+ this.initialize();
69
+ }
70
+
71
+ abstract startOf(date: GanttDate): GanttDate;
72
+
73
+ abstract endOf(date: GanttDate): GanttDate;
74
+
75
+ // 获取一级时间网格合并后的宽度
76
+ abstract getPrimaryWidth(): number;
77
+
78
+ // 获取当前视图下每一天占用的宽度
79
+ abstract getDayOccupancyWidth(date: GanttDate): number;
80
+
81
+ // 获取一级时间点(坐标,显示名称)
82
+ abstract getPrimaryDatePoints(): GanttDatePoint[];
83
+
84
+ // 获取二级时间点(坐标,显示名称)
85
+ abstract getSecondaryDatePoints(): GanttDatePoint[];
86
+
87
+ protected getDateIntervalWidth(start: GanttDate, end: GanttDate) {
88
+ let result = 0;
89
+ const days = differenceInDays(end.value, start.value);
90
+ for (let i = 0; i < Math.abs(days); i++) {
91
+ result += this.getDayOccupancyWidth(start.addDays(i));
92
+ }
93
+ result = days >= 0 ? result : -result;
94
+ return Number(result.toFixed(3));
95
+ }
96
+
97
+ protected initialize() {
98
+ this.primaryDatePoints = this.getPrimaryDatePoints();
99
+ this.secondaryDatePoints = this.getSecondaryDatePoints();
100
+ this.width = this.getWidth();
101
+ this.cellWidth = this.getCellWidth();
102
+ this.primaryWidth = this.getPrimaryWidth();
103
+ }
104
+
105
+ addStartDate() {
106
+ const start = this.startOf(this.start.add(this.options.addAmount * -1, this.options.addUnit));
107
+ if (start.value >= this.options.min.value) {
108
+ const origin = this.start;
109
+ this.start$.next(start);
110
+ this.initialize();
111
+ return { start: this.start, end: origin };
112
+ }
113
+ return null;
114
+ }
115
+
116
+ addEndDate() {
117
+ const end = this.endOf(this.end.add(this.options.addAmount, this.options.addUnit));
118
+ if (end.value <= this.options.max.value) {
119
+ const origin = this.end;
120
+ this.end$.next(end);
121
+ this.initialize();
122
+ return { start: origin, end: this.end };
123
+ }
124
+ return null;
125
+ }
126
+
127
+ updateDate(start: GanttDate, end: GanttDate) {
128
+ start = this.startOf(start);
129
+ end = this.endOf(end);
130
+ if (start.value < this.start.value) {
131
+ this.start$.next(start);
132
+ }
133
+ if (end.value > this.end.value) {
134
+ this.end$.next(end);
135
+ }
136
+ this.initialize();
137
+ }
138
+
139
+ // 获取View的宽度
140
+ getWidth() {
141
+ return this.getCellWidth() * this.secondaryDatePoints.length;
142
+ }
143
+
144
+ // 获取单个网格的宽度
145
+ getCellWidth() {
146
+ return this.options.cellWidth;
147
+ }
148
+
149
+ // 获取当前时间的X坐标
150
+ getTodayXPoint(): number {
151
+ const toady = new GanttDate().startOfDay();
152
+ if (toady.value > this.start.value && toady.value < this.end.value) {
153
+ const x = this.getXPointByDate(toady) + this.getDayOccupancyWidth(toady) / 2;
154
+ return x;
155
+ } else {
156
+ return null;
157
+ }
158
+ }
159
+
160
+ // 获取指定时间的X坐标
161
+ getXPointByDate(date: GanttDate) {
162
+ return this.getDateIntervalWidth(this.start, date);
163
+ }
164
+
165
+ // 根据X坐标获取对应时间
166
+ getDateByXPoint(x: number) {
167
+ const indexOfSecondaryDate = Math.floor(x / this.getCellWidth());
168
+ const matchDate = this.secondaryDatePoints[indexOfSecondaryDate];
169
+ const dayWidth = this.getDayOccupancyWidth(matchDate?.start);
170
+ if (dayWidth === this.getCellWidth()) {
171
+ return matchDate?.start;
172
+ } else {
173
+ const day = Math.floor((x % this.getCellWidth()) / dayWidth) + 1;
174
+ if (this.getCellWidth() / dayWidth === 7) {
175
+ return matchDate?.start.addDays(day);
176
+ }
177
+ return matchDate?.start.setDate(day);
178
+ }
179
+ }
180
+
181
+ // 获取指定时间范围的宽度
182
+ getDateRangeWidth(start: GanttDate, end: GanttDate) {
183
+ // addSeconds(1) 是因为计算相差天会以一个整天来计算 end时间一般是59分59秒不是一个整天,所以需要加1
184
+ return this.getDateIntervalWidth(start, end.addSeconds(1));
185
+ }
186
+ }
@@ -0,0 +1,66 @@
1
+ import { GanttDatePoint } from '../class/date-point';
2
+ import { eachWeekOfInterval, GanttDate } from '../utils/date';
3
+ import { GanttView, GanttViewDate, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop } from './view';
4
+
5
+ const viewOptions: GanttViewOptions = {
6
+ cellWidth: 280,
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 GanttViewWeek 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.startOfWeek({ weekStartsOn: 1 });
20
+ }
21
+
22
+ endOf(date: GanttDate) {
23
+ return date.endOfWeek({ weekStartsOn: 1 });
24
+ }
25
+
26
+ getPrimaryWidth() {
27
+ return this.getCellWidth();
28
+ }
29
+
30
+ getDayOccupancyWidth(): number {
31
+ return this.cellWidth / 7;
32
+ }
33
+
34
+ getPrimaryDatePoints(): GanttDatePoint[] {
35
+ const weeks = eachWeekOfInterval({ start: this.start.value, end: this.end.addSeconds(1).value }, { weekStartsOn: 1 });
36
+ const points: GanttDatePoint[] = [];
37
+ for (let i = 0; i < weeks.length; i++) {
38
+ const weekStart = new GanttDate(weeks[i]);
39
+ const increaseWeek = weekStart.getDaysInMonth() - weekStart.getDate() >= 3 ? 0 : 1;
40
+ const point = new GanttDatePoint(
41
+ weekStart,
42
+ weekStart.addWeeks(increaseWeek).format('yyyy年'),
43
+ this.getCellWidth() / 2 + i * this.getCellWidth(),
44
+ primaryDatePointTop
45
+ );
46
+ points.push(point);
47
+ }
48
+ return points;
49
+ }
50
+
51
+ getSecondaryDatePoints(): GanttDatePoint[] {
52
+ const weeks = eachWeekOfInterval({ start: this.start.value, end: this.end.value });
53
+ const points: GanttDatePoint[] = [];
54
+ for (let i = 0; i < weeks.length; i++) {
55
+ const start = new GanttDate(weeks[i]);
56
+ const point = new GanttDatePoint(
57
+ start,
58
+ `第${start.format('w')}周`,
59
+ i * this.getCellWidth() + this.getCellWidth() / 2,
60
+ secondaryDatePointTop
61
+ );
62
+ points.push(point);
63
+ }
64
+ return points;
65
+ }
66
+ }
@@ -0,0 +1,62 @@
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, differenceInCalendarYears } from 'date-fns';
5
+
6
+ const viewOptions: GanttViewOptions = {
7
+ cellWidth: 480,
8
+ start: new GanttDate().addYears(-2).startOfYear(),
9
+ end: new GanttDate().addYears(2).endOfYear(),
10
+ addAmount: 1,
11
+ addUnit: 'year'
12
+ };
13
+
14
+ export class GanttViewYear extends GanttView {
15
+ constructor(start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
16
+ super(start, end, Object.assign({}, viewOptions, options));
17
+ }
18
+
19
+ startOf(date: GanttDate) {
20
+ return date.startOfYear();
21
+ }
22
+
23
+ endOf(date: GanttDate) {
24
+ return date.endOfYear();
25
+ }
26
+
27
+ getPrimaryWidth() {
28
+ return this.getCellWidth();
29
+ }
30
+
31
+ getDayOccupancyWidth(date: GanttDate): number {
32
+ return this.cellWidth / date.getDaysInYear();
33
+ }
34
+
35
+ getPrimaryDatePoints(): GanttDatePoint[] {
36
+ const years = eachYearOfInterval({ start: this.start.value, end: this.end.value });
37
+ const points: GanttDatePoint[] = [];
38
+ for (let i = 0; i < years.length; i++) {
39
+ const start = new GanttDate(years[i]);
40
+ const point = new GanttDatePoint(start, ``, this.getCellWidth() / 2 + i * this.getCellWidth(), primaryDatePointTop);
41
+ points.push(point);
42
+ }
43
+ return points;
44
+ }
45
+
46
+ getSecondaryDatePoints(): GanttDatePoint[] {
47
+ const years = differenceInCalendarYears(this.end.value, this.start.value);
48
+ const points: GanttDatePoint[] = [];
49
+ const pointTop = 27;
50
+ for (let i = 0; i <= years; i++) {
51
+ const start = this.start.addYears(i);
52
+ const point = new GanttDatePoint(
53
+ start,
54
+ `${start.format('yyyy')}年`,
55
+ i * this.getCellWidth() + this.getCellWidth() / 2,
56
+ pointTop
57
+ );
58
+ points.push(point);
59
+ }
60
+ return points;
61
+ }
62
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../out-tsc/lib",
5
+ "declarationMap": true,
6
+ "target": "es2015",
7
+ "declaration": true,
8
+ "inlineSources": true,
9
+ "types": [],
10
+ "lib": ["dom", "es2018"]
11
+ },
12
+ "angularCompilerOptions": {
13
+ "skipTemplateCodegen": true,
14
+ "strictMetadataEmit": true,
15
+ "fullTemplateTypeCheck": true,
16
+ "strictInjectionParameters": true,
17
+ "enableResourceInlining": true,
18
+ },
19
+ "exclude": ["src/test.ts", "**/*.spec.ts"]
20
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.lib.json",
3
+ "compilerOptions": {
4
+ "declarationMap": false
5
+ },
6
+ "angularCompilerOptions": {
7
+ "compilationMode": "partial"
8
+ }
9
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "lib": ["es2018", "dom"],
5
+ "declaration": true,
6
+ "module": "commonjs",
7
+ "moduleResolution": "node",
8
+ "noEmitOnError": true,
9
+ "noFallthroughCasesInSwitch": true,
10
+ "noImplicitAny": true,
11
+ "noImplicitThis": true,
12
+ "noUnusedParameters": true,
13
+ "noUnusedLocals": true,
14
+ "rootDir": "schematics",
15
+ "outDir": "../../dist/gantt/schematics",
16
+ "skipDefaultLibCheck": true,
17
+ "skipLibCheck": true,
18
+ "sourceMap": true,
19
+ "strictNullChecks": true,
20
+ "target": "es6",
21
+ "types": ["jasmine", "node"]
22
+ },
23
+ "include": ["schematics/**/*"],
24
+ "exclude": ["schematics/*/files/**/*"]
25
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../out-tsc/spec",
5
+ "types": [
6
+ "jasmine",
7
+ "node"
8
+ ]
9
+ },
10
+ "files": [
11
+ "src/test.ts"
12
+ ],
13
+ "include": [
14
+ "**/*.spec.ts",
15
+ "**/*.d.ts"
16
+ ]
17
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../tslint.json",
3
+ "rules": {
4
+ "directive-selector": [
5
+ true,
6
+ "attribute",
7
+ "ngx",
8
+ "camelCase"
9
+ ],
10
+ "component-selector": [
11
+ true,
12
+ "element",
13
+ "ngx",
14
+ "gantt",
15
+ "kebab-case"
16
+ ]
17
+ }
18
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "bundlerOptions": {
3
+ "entryFile": "./packages/gantt/src/styles/index.scss",
4
+ "rootDir": "./",
5
+ "outFile": "dist/gantt/main.bundle.scss"
6
+ }
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compileOnSave": false,
3
+ "compilerOptions": {
4
+ "baseUrl": "./",
5
+ "outDir": "./dist/out-tsc",
6
+ "sourceMap": true,
7
+ "declaration": false,
8
+ "downlevelIteration": true,
9
+ "experimentalDecorators": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "node",
12
+ "importHelpers": true,
13
+ "target": "es2015",
14
+ "typeRoots": ["node_modules/@types"],
15
+ "lib": ["es2018", "dom"],
16
+ "paths": {
17
+ "ngx-gantt": ["packages/gantt/src/public-api.ts"],
18
+ "ngx-gantt/*": ["packages/gantt/src/*"]
19
+ }
20
+ },
21
+ "angularCompilerOptions": {
22
+ "fullTemplateTypeCheck": true,
23
+ "strictInjectionParameters": true,
24
+ "skipLibCheck": true
25
+ }
26
+ }