@worktile/gantt 11.0.2 → 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 (232) 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 -3129
  151. package/bundles/worktile-gantt.umd.js.map +0 -1
  152. package/bundles/worktile-gantt.umd.min.js +0 -16
  153. package/bundles/worktile-gantt.umd.min.js.map +0 -1
  154. package/class/date-point.d.ts +0 -15
  155. package/class/group.d.ts +0 -22
  156. package/class/item.d.ts +0 -70
  157. package/class/view-type.d.ts +0 -7
  158. package/components/bar/bar-drag.d.ts +0 -34
  159. package/components/bar/bar.component.d.ts +0 -23
  160. package/components/calendar/calendar.component.d.ts +0 -25
  161. package/components/drag-backdrop/drag-backdrop.component.d.ts +0 -6
  162. package/components/icon/icon.component.d.ts +0 -10
  163. package/components/icon/icons.d.ts +0 -8
  164. package/components/links/links.component.d.ts +0 -44
  165. package/components/main/gantt-main.component.d.ts +0 -18
  166. package/components/range/range.component.d.ts +0 -10
  167. package/components/table/gantt-table.component.d.ts +0 -31
  168. package/esm2015/class/date-point.js +0 -10
  169. package/esm2015/class/event.js +0 -13
  170. package/esm2015/class/group.js +0 -17
  171. package/esm2015/class/index.js +0 -6
  172. package/esm2015/class/item.js +0 -78
  173. package/esm2015/class/view-type.js +0 -9
  174. package/esm2015/components/bar/bar-drag.js +0 -266
  175. package/esm2015/components/bar/bar.component.js +0 -91
  176. package/esm2015/components/calendar/calendar.component.js +0 -82
  177. package/esm2015/components/drag-backdrop/drag-backdrop.component.js +0 -18
  178. package/esm2015/components/icon/icon.component.js +0 -36
  179. package/esm2015/components/icon/icons.js +0 -87
  180. package/esm2015/components/links/links.component.js +0 -207
  181. package/esm2015/components/main/gantt-main.component.js +0 -35
  182. package/esm2015/components/range/range.component.js +0 -32
  183. package/esm2015/components/table/gantt-table.component.js +0 -128
  184. package/esm2015/gantt-dom.service.js +0 -101
  185. package/esm2015/gantt-drag-container.js +0 -57
  186. package/esm2015/gantt-item-upper.js +0 -55
  187. package/esm2015/gantt-print.service.js +0 -92
  188. package/esm2015/gantt-upper.js +0 -231
  189. package/esm2015/gantt.component.js +0 -105
  190. package/esm2015/gantt.module.js +0 -43
  191. package/esm2015/gantt.pipe.js +0 -33
  192. package/esm2015/gantt.styles.js +0 -15
  193. package/esm2015/public-api.js +0 -16
  194. package/esm2015/root.component.js +0 -111
  195. package/esm2015/table/gantt-column.component.js +0 -28
  196. package/esm2015/table/gantt-table.component.js +0 -18
  197. package/esm2015/utils/date.js +0 -160
  198. package/esm2015/utils/helpers.js +0 -45
  199. package/esm2015/views/day.js +0 -54
  200. package/esm2015/views/factory.js +0 -23
  201. package/esm2015/views/month.js +0 -48
  202. package/esm2015/views/quarter.js +0 -51
  203. package/esm2015/views/view.js +0 -121
  204. package/esm2015/views/week.js +0 -49
  205. package/esm2015/views/year.js +0 -50
  206. package/esm2015/worktile-gantt.js +0 -16
  207. package/fesm2015/worktile-gantt.js +0 -2491
  208. package/fesm2015/worktile-gantt.js.map +0 -1
  209. package/gantt-dom.service.d.ts +0 -29
  210. package/gantt-drag-container.d.ts +0 -20
  211. package/gantt-item-upper.d.ts +0 -17
  212. package/gantt-print.service.d.ts +0 -10
  213. package/gantt-upper.d.ts +0 -62
  214. package/gantt.component.d.ts +0 -28
  215. package/gantt.module.d.ts +0 -2
  216. package/gantt.pipe.d.ts +0 -11
  217. package/gantt.styles.d.ts +0 -15
  218. package/root.component.d.ts +0 -25
  219. package/style.scss +0 -645
  220. package/table/gantt-column.component.d.ts +0 -12
  221. package/table/gantt-table.component.d.ts +0 -7
  222. package/utils/date.d.ts +0 -59
  223. package/utils/helpers.d.ts +0 -11
  224. package/views/day.d.ts +0 -14
  225. package/views/factory.d.ts +0 -8
  226. package/views/month.d.ts +0 -12
  227. package/views/quarter.d.ts +0 -12
  228. package/views/view.d.ts +0 -56
  229. package/views/week.d.ts +0 -12
  230. package/views/year.d.ts +0 -12
  231. package/worktile-gantt.d.ts +0 -15
  232. package/worktile-gantt.metadata.json +0 -1
@@ -1,2491 +0,0 @@
1
- import { EventEmitter, Directive, ElementRef, ChangeDetectorRef, NgZone, Input, Output, ContentChild, HostBinding, InjectionToken, Component, Inject, ChangeDetectionStrategy, ContentChildren, ViewChild, Injectable, Optional, Pipe, NgModule } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { take, skip, takeUntil, startWith, finalize, map, pairwise, auditTime } from 'rxjs/operators';
4
- import { BehaviorSubject, Subject, merge, fromEvent } from 'rxjs';
5
- import { fromUnixTime, getWeek, getDaysInMonth, differenceInCalendarDays, setDate, addSeconds, addMinutes, addHours, addDays, addWeeks, addMonths, addQuarters, addYears, startOfDay, startOfWeek, startOfMonth, startOfQuarter, startOfYear, endOfDay, endOfWeek, endOfMonth, endOfQuarter, endOfYear, getUnixTime, format, isWeekend, isToday, differenceInDays, differenceInCalendarQuarters, eachMonthOfInterval, eachYearOfInterval, eachWeekOfInterval, eachDayOfInterval, differenceInCalendarYears } from 'date-fns';
6
- export { addDays, addHours, addMinutes, addMonths, addQuarters, addSeconds, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarQuarters, differenceInDays, eachDayOfInterval, eachMonthOfInterval, eachWeekOfInterval, endOfDay, endOfMonth, endOfQuarter, endOfWeek, endOfYear, format, fromUnixTime, getDaysInMonth, getUnixTime, getWeek, isToday, isWeekend, setDate, startOfDay, startOfMonth, startOfQuarter, startOfWeek, startOfYear } from 'date-fns';
7
- import { coerceCssPixelValue } from '@angular/cdk/coercion';
8
- import { DragDrop, DragDropModule } from '@angular/cdk/drag-drop';
9
- import html2canvas from 'html2canvas';
10
-
11
- class GanttDatePoint {
12
- constructor(start, text, x, y, additions) {
13
- this.start = start;
14
- this.text = text;
15
- this.x = x;
16
- this.y = y;
17
- this.additions = additions;
18
- }
19
- }
20
-
21
- class GanttDragEvent {
22
- }
23
- class GanttTableEvent {
24
- }
25
- class GanttLinkDragEvent {
26
- }
27
- class GanttLoadOnScrollEvent {
28
- }
29
- class GanttLineClickEvent {
30
- }
31
- class GanttBarClickEvent {
32
- }
33
-
34
- class GanttDate {
35
- constructor(date) {
36
- if (date) {
37
- if (date instanceof Date) {
38
- this.value = date;
39
- }
40
- else if (typeof date === 'string' || typeof date === 'number') {
41
- if (date.toString().length < 13) {
42
- this.value = fromUnixTime(+date);
43
- }
44
- else {
45
- this.value = new Date(date);
46
- }
47
- }
48
- else {
49
- throw new Error(`The input date type is not supported expect Date | string
50
- | number | { date: number; with_time: 0 | 1}, actual ${JSON.stringify(date)}`);
51
- }
52
- }
53
- else {
54
- this.value = new Date();
55
- }
56
- }
57
- getYear() {
58
- return this.value.getFullYear();
59
- }
60
- getMonth() {
61
- return this.value.getMonth();
62
- }
63
- getDay() {
64
- return this.value.getDay();
65
- }
66
- getTime() {
67
- return this.value.getTime();
68
- }
69
- getDate() {
70
- return this.value.getDate();
71
- }
72
- getHours() {
73
- return this.value.getHours();
74
- }
75
- getMinutes() {
76
- return this.value.getMinutes();
77
- }
78
- getSeconds() {
79
- return this.value.getSeconds();
80
- }
81
- getMilliseconds() {
82
- return this.value.getMilliseconds();
83
- }
84
- getWeek(options = { weekStartsOn: 1 }) {
85
- return getWeek(this.value, options);
86
- }
87
- getDaysInMonth() {
88
- return getDaysInMonth(this.value);
89
- }
90
- getDaysInQuarter() {
91
- return differenceInCalendarDays(this.endOfQuarter().addSeconds(1).value, this.startOfQuarter().value);
92
- }
93
- getDaysInYear() {
94
- return differenceInCalendarDays(this.endOfYear().addSeconds(1).value, this.startOfYear().value);
95
- }
96
- setDate(dayOfMonth) {
97
- return new GanttDate(setDate(this.value, dayOfMonth));
98
- }
99
- clone() {
100
- return new GanttDate(new Date(this.value));
101
- }
102
- add(amount, unit) {
103
- switch (unit) {
104
- case 'second':
105
- return new GanttDate(this.value).addSeconds(amount);
106
- case 'minute':
107
- return new GanttDate(this.value).addMinutes(amount);
108
- case 'hour':
109
- return new GanttDate(this.value).addHours(amount);
110
- case 'day':
111
- return new GanttDate(this.value).addDays(amount);
112
- case 'week':
113
- return new GanttDate(this.value).addWeeks(amount);
114
- case 'month':
115
- return new GanttDate(this.value).addMonths(amount);
116
- case 'quarter':
117
- return new GanttDate(this.value).addQuarters(amount);
118
- case 'year':
119
- return new GanttDate(this.value).addYears(amount);
120
- default:
121
- return new GanttDate(this.value).addSeconds(amount);
122
- }
123
- }
124
- addSeconds(amount) {
125
- return new GanttDate(addSeconds(this.value, amount));
126
- }
127
- addMinutes(amount) {
128
- return new GanttDate(addMinutes(this.value, amount));
129
- }
130
- addHours(amount) {
131
- return new GanttDate(addHours(this.value, amount));
132
- }
133
- addDays(amount) {
134
- return new GanttDate(addDays(this.value, amount));
135
- }
136
- addWeeks(amount) {
137
- return new GanttDate(addWeeks(this.value, amount));
138
- }
139
- addMonths(amount) {
140
- return new GanttDate(addMonths(this.value, amount));
141
- }
142
- addQuarters(amount) {
143
- return new GanttDate(addQuarters(this.value, amount));
144
- }
145
- addYears(amount) {
146
- return new GanttDate(addYears(this.value, amount));
147
- }
148
- startOfDay() {
149
- return new GanttDate(startOfDay(this.value));
150
- }
151
- startOfWeek(options) {
152
- return new GanttDate(startOfWeek(this.value, options));
153
- }
154
- startOfMonth() {
155
- return new GanttDate(startOfMonth(this.value));
156
- }
157
- startOfQuarter() {
158
- return new GanttDate(startOfQuarter(this.value));
159
- }
160
- startOfYear() {
161
- return new GanttDate(startOfYear(this.value));
162
- }
163
- endOfDay() {
164
- return new GanttDate(endOfDay(this.value));
165
- }
166
- endOfWeek(options) {
167
- return new GanttDate(endOfWeek(this.value, options));
168
- }
169
- endOfMonth() {
170
- return new GanttDate(endOfMonth(this.value));
171
- }
172
- endOfQuarter() {
173
- return new GanttDate(endOfQuarter(this.value));
174
- }
175
- endOfYear() {
176
- return new GanttDate(endOfYear(this.value));
177
- }
178
- getUnixTime() {
179
- return getUnixTime(this.value);
180
- }
181
- format(mat, options) {
182
- return format(this.value, mat, options);
183
- }
184
- isWeekend() {
185
- return isWeekend(this.value);
186
- }
187
- isToday() {
188
- return isToday(this.value);
189
- }
190
- }
191
-
192
- var GanttViewType;
193
- (function (GanttViewType) {
194
- GanttViewType["day"] = "day";
195
- GanttViewType["quarter"] = "quarter";
196
- GanttViewType["month"] = "month";
197
- GanttViewType["year"] = "year";
198
- GanttViewType["week"] = "week";
199
- })(GanttViewType || (GanttViewType = {}));
200
-
201
- var GanttItemType;
202
- (function (GanttItemType) {
203
- GanttItemType["bar"] = "bar";
204
- GanttItemType["range"] = "range";
205
- GanttItemType["custom"] = "custom";
206
- })(GanttItemType || (GanttItemType = {}));
207
- class GanttItemInternal {
208
- constructor(item, options) {
209
- this.refs$ = new BehaviorSubject(null);
210
- this.origin = item;
211
- this.id = this.origin.id;
212
- this.links = this.origin.links || [];
213
- this.color = this.origin.color;
214
- this.barStyle = this.origin.barStyle;
215
- this.linkable = this.origin.linkable === undefined ? true : this.origin.linkable;
216
- this.draggable = this.origin.draggable === undefined ? true : this.origin.draggable;
217
- this.expandable = this.origin.expandable || (this.origin.children || []).length > 0;
218
- this.expanded = this.origin.expanded === undefined ? false : this.origin.expanded;
219
- this.start = item.start ? new GanttDate(item.start) : null;
220
- this.end = item.end ? new GanttDate(item.end) : null;
221
- this.viewType = options && options.viewType ? options.viewType : GanttViewType.month;
222
- this.children = (item.children || []).map((subItem) => {
223
- return new GanttItemInternal(subItem, { viewType: this.viewType });
224
- });
225
- this.type = this.origin.type || GanttItemType.bar;
226
- this.progress = this.origin.progress;
227
- // fill one month when start or end is null
228
- this.fillItemStartOrEnd(item);
229
- }
230
- get refs() {
231
- return this.refs$.getValue();
232
- }
233
- fillItemStartOrEnd(item) {
234
- let addInterval;
235
- switch (this.viewType) {
236
- case GanttViewType.day:
237
- case GanttViewType.week:
238
- addInterval = 0;
239
- break;
240
- default:
241
- addInterval = 30;
242
- break;
243
- }
244
- if (item.start && !item.end) {
245
- this.end = new GanttDate(item.start).addDays(addInterval).endOfDay();
246
- }
247
- if (!item.start && item.end) {
248
- this.start = new GanttDate(item.end).addDays(-addInterval).startOfDay();
249
- }
250
- }
251
- updateRefs(refs) {
252
- this.refs$.next(refs);
253
- }
254
- updateDate(start, end) {
255
- this.start = start.startOfDay();
256
- this.end = end.endOfDay();
257
- this.origin.start = this.start.getUnixTime();
258
- this.origin.end = this.end.getUnixTime();
259
- }
260
- addChildren(items) {
261
- this.origin.children = items;
262
- this.children = (items || []).map((subItem) => {
263
- return new GanttItemInternal(subItem, { viewType: this.viewType });
264
- });
265
- }
266
- setExpand(expanded) {
267
- this.expanded = expanded;
268
- this.origin.expanded = expanded;
269
- }
270
- addLink(linkId) {
271
- this.links = [...this.links, linkId];
272
- this.origin.links = this.links;
273
- }
274
- }
275
-
276
- class GanttGroupInternal {
277
- constructor(group) {
278
- this.refs = {};
279
- this.id = group.id;
280
- this.origin = group;
281
- this.title = group.title;
282
- this.expanded = group.expanded === undefined ? true : group.expanded;
283
- this.items = [];
284
- this.mergedItems = [[]];
285
- this.class = group.class || '';
286
- }
287
- setExpand(expanded) {
288
- this.expanded = expanded;
289
- this.origin.expanded = expanded;
290
- }
291
- }
292
-
293
- const primaryDatePointTop = 18;
294
- const secondaryDatePointTop = 36;
295
- const viewOptions = {
296
- min: new GanttDate().addYears(-1).startOfYear(),
297
- max: new GanttDate().addYears(1).endOfYear()
298
- };
299
- class GanttView {
300
- constructor(start, end, options) {
301
- this.showTimeline = true;
302
- this.options = Object.assign({}, viewOptions, options);
303
- const startDate = start.isCustom
304
- ? this.startOf(start.date)
305
- : this.startOf(start.date.value < this.options.start.value ? start.date : this.options.start);
306
- const endDate = end.isCustom
307
- ? this.endOf(end.date)
308
- : this.endOf(end.date.value > this.options.end.value ? end.date : this.options.end);
309
- this.start$ = new BehaviorSubject(startDate);
310
- this.end$ = new BehaviorSubject(endDate);
311
- this.initialize();
312
- }
313
- get start() {
314
- return this.start$.getValue();
315
- }
316
- get end() {
317
- return this.end$.getValue();
318
- }
319
- getDateIntervalWidth(start, end) {
320
- let result = 0;
321
- const days = differenceInDays(end.value, start.value);
322
- for (let i = 0; i < Math.abs(days); i++) {
323
- result += this.getDayOccupancyWidth(start.addDays(i));
324
- }
325
- result = days >= 0 ? result : -result;
326
- return Number(result.toFixed(3));
327
- }
328
- initialize() {
329
- this.primaryDatePoints = this.getPrimaryDatePoints();
330
- this.secondaryDatePoints = this.getSecondaryDatePoints();
331
- this.width = this.getWidth();
332
- this.cellWidth = this.getCellWidth();
333
- this.primaryWidth = this.getPrimaryWidth();
334
- }
335
- addStartDate() {
336
- const start = this.startOf(this.start.add(this.options.addAmount * -1, this.options.addUnit));
337
- if (start.value >= this.options.min.value) {
338
- const origin = this.start;
339
- this.start$.next(start);
340
- this.initialize();
341
- return { start: this.start, end: origin };
342
- }
343
- return null;
344
- }
345
- addEndDate() {
346
- const end = this.endOf(this.end.add(this.options.addAmount, this.options.addUnit));
347
- if (end.value <= this.options.max.value) {
348
- const origin = this.end;
349
- this.end$.next(end);
350
- this.initialize();
351
- return { start: origin, end: this.end };
352
- }
353
- return null;
354
- }
355
- updateDate(start, end) {
356
- start = this.startOf(start);
357
- end = this.endOf(end);
358
- if (start.value < this.start.value) {
359
- this.start$.next(start);
360
- }
361
- if (end.value > this.end.value) {
362
- this.end$.next(end);
363
- }
364
- this.initialize();
365
- }
366
- // 获取View的宽度
367
- getWidth() {
368
- return this.getCellWidth() * this.secondaryDatePoints.length;
369
- }
370
- // 获取单个网格的宽度
371
- getCellWidth() {
372
- return this.options.cellWidth;
373
- }
374
- // 获取当前时间的X坐标
375
- getTodayXPoint() {
376
- const toady = new GanttDate().startOfDay();
377
- if (toady.value > this.start.value && toady.value < this.end.value) {
378
- const x = this.getXPointByDate(toady) + this.getDayOccupancyWidth(toady) / 2;
379
- return x;
380
- }
381
- else {
382
- return null;
383
- }
384
- }
385
- // 获取指定时间的X坐标
386
- getXPointByDate(date) {
387
- return this.getDateIntervalWidth(this.start, date);
388
- }
389
- // 根据X坐标获取对应时间
390
- getDateByXPoint(x) {
391
- const indexOfSecondaryDate = Math.floor(x / this.getCellWidth());
392
- const matchDate = this.secondaryDatePoints[indexOfSecondaryDate];
393
- const dayWidth = this.getDayOccupancyWidth(matchDate === null || matchDate === void 0 ? void 0 : matchDate.start);
394
- if (dayWidth === this.getCellWidth()) {
395
- return matchDate === null || matchDate === void 0 ? void 0 : matchDate.start;
396
- }
397
- else {
398
- const day = Math.floor((x % this.getCellWidth()) / dayWidth) + 1;
399
- if (this.getCellWidth() / dayWidth === 7) {
400
- return matchDate === null || matchDate === void 0 ? void 0 : matchDate.start.addDays(day);
401
- }
402
- return matchDate === null || matchDate === void 0 ? void 0 : matchDate.start.setDate(day);
403
- }
404
- }
405
- // 获取指定时间范围的宽度
406
- getDateRangeWidth(start, end) {
407
- // addSeconds(1) 是因为计算相差天会以一个整天来计算 end时间一般是59分59秒不是一个整天,所以需要加1
408
- return this.getDateIntervalWidth(start, end.addSeconds(1));
409
- }
410
- }
411
-
412
- const viewOptions$1 = {
413
- start: new GanttDate().startOfQuarter().addQuarters(-1),
414
- end: new GanttDate().endOfQuarter().addQuarters(2),
415
- cellWidth: 280,
416
- addAmount: 1,
417
- addUnit: 'quarter'
418
- };
419
- class GanttViewMonth extends GanttView {
420
- constructor(start, end, options) {
421
- super(start, end, Object.assign({}, viewOptions$1, options));
422
- }
423
- startOf(date) {
424
- return date.startOfQuarter();
425
- }
426
- endOf(date) {
427
- return date.endOfQuarter();
428
- }
429
- getPrimaryWidth() {
430
- return this.getCellWidth() * 3;
431
- }
432
- getDayOccupancyWidth(date) {
433
- return this.cellWidth / date.getDaysInMonth();
434
- }
435
- getPrimaryDatePoints() {
436
- const quarters = differenceInCalendarQuarters(this.end.addSeconds(1).value, this.start.value);
437
- const points = [];
438
- for (let i = 0; i < quarters; i++) {
439
- const start = this.start.addQuarters(i);
440
- const point = new GanttDatePoint(start, start.format('yyyy年QQQ'), (this.getCellWidth() * 3) / 2 + i * (this.getCellWidth() * 3), primaryDatePointTop);
441
- points.push(point);
442
- }
443
- return points;
444
- }
445
- getSecondaryDatePoints() {
446
- const months = eachMonthOfInterval({ start: this.start.value, end: this.end.value });
447
- const points = [];
448
- for (let i = 0; i < months.length; i++) {
449
- const start = new GanttDate(months[i]);
450
- const point = new GanttDatePoint(start, `${start.getMonth() + 1}月`, i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop);
451
- points.push(point);
452
- }
453
- return points;
454
- }
455
- }
456
-
457
- const viewOptions$2 = {
458
- start: new GanttDate().addYears(-1).startOfYear(),
459
- end: new GanttDate().addYears(1).endOfYear(),
460
- min: new GanttDate().addYears(-2).startOfYear(),
461
- max: new GanttDate().addYears(2).endOfYear(),
462
- cellWidth: 500,
463
- addAmount: 1,
464
- addUnit: 'year'
465
- };
466
- class GanttViewQuarter extends GanttView {
467
- constructor(start, end, options) {
468
- super(start, end, Object.assign({}, viewOptions$2, options));
469
- }
470
- startOf(date) {
471
- return date.startOfYear();
472
- }
473
- endOf(date) {
474
- return date.endOfYear();
475
- }
476
- getPrimaryWidth() {
477
- return this.getCellWidth() * 4;
478
- }
479
- getDayOccupancyWidth(date) {
480
- return this.cellWidth / date.getDaysInQuarter();
481
- }
482
- getPrimaryDatePoints() {
483
- const years = eachYearOfInterval({ start: this.start.value, end: this.end.value });
484
- const points = [];
485
- for (let i = 0; i < years.length; i++) {
486
- const start = new GanttDate(years[i]);
487
- const point = new GanttDatePoint(start, `${start.format('yyyy')}年`, (this.getCellWidth() * 4) / 2 + i * (this.getCellWidth() * 4), primaryDatePointTop);
488
- points.push(point);
489
- }
490
- return points;
491
- }
492
- getSecondaryDatePoints() {
493
- const quarters = differenceInCalendarQuarters(this.end.value, this.start.value);
494
- const points = [];
495
- for (let i = 0; i <= quarters; i++) {
496
- const start = this.start.addQuarters(i);
497
- const point = new GanttDatePoint(start, start.format('QQQ'), i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop);
498
- points.push(point);
499
- }
500
- return points;
501
- }
502
- }
503
-
504
- const viewOptions$3 = {
505
- cellWidth: 35,
506
- start: new GanttDate().startOfYear().startOfWeek({ weekStartsOn: 1 }),
507
- end: new GanttDate().endOfYear().endOfWeek({ weekStartsOn: 1 }),
508
- addAmount: 1,
509
- addUnit: 'month'
510
- };
511
- class GanttViewDay extends GanttView {
512
- constructor(start, end, options) {
513
- super(start, end, Object.assign({}, viewOptions$3, options));
514
- this.showWeekBackdrop = true;
515
- this.showTimeline = false;
516
- }
517
- startOf(date) {
518
- return date.startOfWeek({ weekStartsOn: 1 });
519
- }
520
- endOf(date) {
521
- return date.endOfWeek({ weekStartsOn: 1 });
522
- }
523
- getPrimaryWidth() {
524
- return this.getCellWidth() * 7;
525
- }
526
- getDayOccupancyWidth() {
527
- return this.cellWidth;
528
- }
529
- getPrimaryDatePoints() {
530
- const weeks = eachWeekOfInterval({ start: this.start.value, end: this.end.addSeconds(1).value }, { weekStartsOn: 1 });
531
- const points = [];
532
- for (let i = 0; i < weeks.length; i++) {
533
- const weekStart = new GanttDate(weeks[i]);
534
- const increaseWeek = weekStart.getDaysInMonth() - weekStart.getDate() >= 3 ? 0 : 1;
535
- const point = new GanttDatePoint(weekStart, weekStart.addWeeks(increaseWeek).format('yyyy年MM月'), (this.getCellWidth() * 7) / 2 + i * (this.getCellWidth() * 7), primaryDatePointTop);
536
- points.push(point);
537
- }
538
- return points;
539
- }
540
- getSecondaryDatePoints() {
541
- const days = eachDayOfInterval({ start: this.start.value, end: this.end.value });
542
- const points = [];
543
- for (let i = 0; i < days.length; i++) {
544
- const start = new GanttDate(days[i]);
545
- const point = new GanttDatePoint(start, start.getDate().toString(), i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop, {
546
- isWeekend: start.isWeekend(),
547
- isToday: start.isToday()
548
- });
549
- points.push(point);
550
- }
551
- return points;
552
- }
553
- }
554
-
555
- const viewOptions$4 = {
556
- cellWidth: 280,
557
- start: new GanttDate().startOfYear().startOfWeek({ weekStartsOn: 1 }),
558
- end: new GanttDate().endOfYear().endOfWeek({ weekStartsOn: 1 }),
559
- addAmount: 1,
560
- addUnit: 'month'
561
- };
562
- class GanttViewWeek extends GanttView {
563
- constructor(start, end, options) {
564
- super(start, end, Object.assign({}, viewOptions$4, options));
565
- }
566
- startOf(date) {
567
- return date.startOfWeek({ weekStartsOn: 1 });
568
- }
569
- endOf(date) {
570
- return date.endOfWeek({ weekStartsOn: 1 });
571
- }
572
- getPrimaryWidth() {
573
- return this.getCellWidth();
574
- }
575
- getDayOccupancyWidth() {
576
- return this.cellWidth / 7;
577
- }
578
- getPrimaryDatePoints() {
579
- const weeks = eachWeekOfInterval({ start: this.start.value, end: this.end.addSeconds(1).value }, { weekStartsOn: 1 });
580
- const points = [];
581
- for (let i = 0; i < weeks.length; i++) {
582
- const weekStart = new GanttDate(weeks[i]);
583
- const increaseWeek = weekStart.getDaysInMonth() - weekStart.getDate() >= 3 ? 0 : 1;
584
- const point = new GanttDatePoint(weekStart, weekStart.addWeeks(increaseWeek).format('yyyy年'), this.getCellWidth() / 2 + i * this.getCellWidth(), primaryDatePointTop);
585
- points.push(point);
586
- }
587
- return points;
588
- }
589
- getSecondaryDatePoints() {
590
- const weeks = eachWeekOfInterval({ start: this.start.value, end: this.end.value });
591
- const points = [];
592
- for (let i = 0; i < weeks.length; i++) {
593
- const start = new GanttDate(weeks[i]);
594
- const point = new GanttDatePoint(start, `第${start.format('w')}周`, i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop);
595
- points.push(point);
596
- }
597
- return points;
598
- }
599
- }
600
-
601
- const viewOptions$5 = {
602
- cellWidth: 480,
603
- start: new GanttDate().addYears(-1).startOfYear(),
604
- end: new GanttDate().addYears(1).endOfYear(),
605
- addAmount: 1,
606
- addUnit: 'year'
607
- };
608
- class GanttViewYear extends GanttView {
609
- constructor(start, end, options) {
610
- super(start, end, Object.assign({}, viewOptions$5, options));
611
- }
612
- startOf(date) {
613
- return date.startOfYear();
614
- }
615
- endOf(date) {
616
- return date.endOfYear();
617
- }
618
- getPrimaryWidth() {
619
- return this.getCellWidth();
620
- }
621
- getDayOccupancyWidth(date) {
622
- return this.cellWidth / date.getDaysInYear();
623
- }
624
- getPrimaryDatePoints() {
625
- const years = eachYearOfInterval({ start: this.start.value, end: this.end.value });
626
- const points = [];
627
- for (let i = 0; i < years.length; i++) {
628
- const start = new GanttDate(years[i]);
629
- const point = new GanttDatePoint(start, ``, this.getCellWidth() / 2 + i * this.getCellWidth(), primaryDatePointTop);
630
- points.push(point);
631
- }
632
- return points;
633
- }
634
- getSecondaryDatePoints() {
635
- const years = differenceInCalendarYears(this.end.value, this.start.value);
636
- const points = [];
637
- const pointTop = 27;
638
- for (let i = 0; i <= years; i++) {
639
- const start = this.start.addYears(i);
640
- const point = new GanttDatePoint(start, `${start.format('yyyy')}年`, i * this.getCellWidth() + this.getCellWidth() / 2, pointTop);
641
- points.push(point);
642
- }
643
- return points;
644
- }
645
- }
646
-
647
- function createViewFactory(type, start, end, options) {
648
- switch (type) {
649
- case GanttViewType.month:
650
- return new GanttViewMonth(start, end, options);
651
- case GanttViewType.week:
652
- return new GanttViewWeek(start, end, options);
653
- case GanttViewType.quarter:
654
- return new GanttViewQuarter(start, end, options);
655
- case GanttViewType.day:
656
- return new GanttViewDay(start, end, options);
657
- case GanttViewType.year:
658
- return new GanttViewYear(start, end, options);
659
- default:
660
- throw new Error('gantt view type invalid');
661
- }
662
- }
663
-
664
- const defaultStyles = {
665
- lineHeight: 44,
666
- barHeight: 22
667
- };
668
- const headerHeight = 44;
669
- const sideWidth = 400;
670
- const sideMiddleWidth = 500;
671
- const sideMaxWidth = 600;
672
- const sideMinWidth = 400;
673
- const barBackground = '#348fe4';
674
- const rangeHeight = 17;
675
- const todayHeight = 24;
676
- const todayWidth = 35;
677
- const todayBorderRadius = 4;
678
-
679
- function isNumber(value) {
680
- return typeof value === 'number';
681
- }
682
- function isString(value) {
683
- return typeof value === 'string';
684
- }
685
- function isUndefined(value) {
686
- return value === undefined;
687
- }
688
- function hexToRgb(color, opacity = 1) {
689
- if (/^#/g.test(color)) {
690
- return `rgba(${parseInt(color.slice(1, 3), 16)},${parseInt(color.slice(3, 5), 16)},${parseInt(color.slice(5, 7), 16)},${opacity})`;
691
- }
692
- else {
693
- return color;
694
- }
695
- }
696
- function uniqBy(array, key) {
697
- const valuesMap = {};
698
- const result = [];
699
- (array || []).forEach((value) => {
700
- const _key = value[key];
701
- if (!valuesMap[_key]) {
702
- valuesMap[_key] = value;
703
- result.push(value);
704
- }
705
- });
706
- return result;
707
- }
708
- function flatten(array) {
709
- return array.reduce((pre, cur) => {
710
- return pre.concat(Array.isArray(cur) ? flatten(cur) : cur);
711
- }, []);
712
- }
713
- function recursiveItems(items) {
714
- const result = [];
715
- (items || []).forEach((item) => {
716
- result.push(item);
717
- if (item.expanded && item.children) {
718
- result.push(...recursiveItems(item.children));
719
- }
720
- });
721
- return result;
722
- }
723
-
724
- class GanttUpper {
725
- constructor(elementRef, cdr, ngZone) {
726
- this.elementRef = elementRef;
727
- this.cdr = cdr;
728
- this.ngZone = ngZone;
729
- this.originItems = [];
730
- this.originGroups = [];
731
- this.viewType = GanttViewType.month;
732
- this.showTodayLine = true;
733
- this.loadOnScroll = new EventEmitter();
734
- this.dragStarted = new EventEmitter();
735
- this.dragEnded = new EventEmitter();
736
- this.barClick = new EventEmitter();
737
- this.linkDragEnded = new EventEmitter();
738
- this.items = [];
739
- this.groups = [];
740
- this.viewChange = new EventEmitter();
741
- this.expandChange = new EventEmitter();
742
- this.firstChange = true;
743
- this.unsubscribe$ = new Subject();
744
- this.expandedItemIds = [];
745
- this.ganttClass = true;
746
- }
747
- get element() {
748
- return this.elementRef.nativeElement;
749
- }
750
- createView() {
751
- const viewDate = this.getViewDate();
752
- this.view = createViewFactory(this.viewType, viewDate.start, viewDate.end, this.viewOptions);
753
- }
754
- setupGroups() {
755
- const collapsedIds = this.groups.filter((group) => group.expanded === false).map((group) => group.id);
756
- this.groupsMap = {};
757
- this.groups = [];
758
- this.originGroups.forEach((origin) => {
759
- const group = new GanttGroupInternal(origin);
760
- group.expanded = !collapsedIds.includes(group.id);
761
- this.groupsMap[group.id] = group;
762
- this.groups.push(group);
763
- });
764
- }
765
- setupItems() {
766
- this.items = [];
767
- this.originItems = uniqBy(this.originItems, 'id');
768
- // 根据上一次数据展开状态同步新的数据展开状态
769
- this.originItems.forEach((item) => {
770
- if (!this.firstChange) {
771
- item.expanded = item.expanded || this.expandedItemIds.includes(item.id);
772
- }
773
- });
774
- if (this.groups.length > 0) {
775
- this.originItems.forEach((origin) => {
776
- const group = this.groupsMap[origin.group_id];
777
- if (group) {
778
- const item = new GanttItemInternal(origin, { viewType: this.viewType });
779
- group.items.push(item);
780
- }
781
- });
782
- }
783
- else {
784
- this.originItems.forEach((origin) => {
785
- const item = new GanttItemInternal(origin, { viewType: this.viewType });
786
- this.items.push(item);
787
- });
788
- }
789
- }
790
- setupExpandedState() {
791
- let items = [];
792
- if (this.items.length > 0) {
793
- items = recursiveItems(this.items);
794
- }
795
- else {
796
- items = flatten(this.groups.map((group) => recursiveItems(group.items)));
797
- }
798
- this.expandedItemIds = [];
799
- items.forEach((item) => {
800
- if (item.origin.expanded) {
801
- this.expandedItemIds.push(item.id);
802
- }
803
- });
804
- }
805
- getViewDate() {
806
- let start = this.start;
807
- let end = this.end;
808
- if (!this.start || !this.end) {
809
- this.originItems.forEach((item) => {
810
- if (item.start && !this.start) {
811
- start = start ? Math.min(start, item.start) : item.start;
812
- }
813
- if (item.end && !this.end) {
814
- end = end ? Math.max(end, item.end) : item.end;
815
- }
816
- });
817
- }
818
- return {
819
- start: {
820
- date: new GanttDate(start),
821
- isCustom: this.start ? true : false
822
- },
823
- end: {
824
- date: new GanttDate(end),
825
- isCustom: this.end ? true : false
826
- }
827
- };
828
- }
829
- computeRefs() {
830
- this.groups.forEach((group) => {
831
- const groupItems = recursiveItems(group.items);
832
- this.computeItemsRefs(...groupItems);
833
- });
834
- const items = recursiveItems(this.items);
835
- this.computeItemsRefs(...items);
836
- }
837
- expandGroups(expanded) {
838
- this.groups.forEach((group) => {
839
- group.setExpand(expanded);
840
- });
841
- this.expandChange.next();
842
- this.cdr.detectChanges();
843
- }
844
- onInit() {
845
- this.styles = Object.assign({}, defaultStyles, this.styles);
846
- this.createView();
847
- this.setupGroups();
848
- this.setupItems();
849
- this.computeRefs();
850
- this.firstChange = false;
851
- this.ngZone.onStable.pipe(take(1)).subscribe(() => {
852
- this.element.style.opacity = '1';
853
- this.dragContainer.dragStarted.subscribe((event) => {
854
- this.dragStarted.emit(event);
855
- });
856
- this.dragContainer.dragEnded.subscribe((event) => {
857
- this.dragEnded.emit(event);
858
- this.computeRefs();
859
- this.detectChanges();
860
- });
861
- });
862
- this.view.start$.pipe(skip(1), takeUntil(this.unsubscribe$)).subscribe(() => {
863
- this.computeRefs();
864
- });
865
- }
866
- onChanges(changes) {
867
- if (!this.firstChange) {
868
- if (changes.viewType && changes.viewType.currentValue) {
869
- this.createView();
870
- this.setupGroups();
871
- this.setupItems();
872
- this.computeRefs();
873
- this.viewChange.emit(this.view);
874
- }
875
- if (changes.originItems || changes.originGroups) {
876
- this.setupExpandedState();
877
- this.setupGroups();
878
- this.setupItems();
879
- this.computeRefs();
880
- }
881
- }
882
- }
883
- onDestroy() {
884
- this.unsubscribe$.next();
885
- this.unsubscribe$.complete();
886
- }
887
- computeItemsRefs(...items) {
888
- items.forEach((item) => {
889
- item.updateRefs({
890
- width: item.start && item.end ? this.view.getDateRangeWidth(item.start.startOfDay(), item.end.endOfDay()) : 0,
891
- x: item.start ? this.view.getXPointByDate(item.start) : 0,
892
- y: (this.styles.lineHeight - this.styles.barHeight) / 2 - 1
893
- });
894
- });
895
- }
896
- trackBy(item, index) {
897
- return item.id || index;
898
- }
899
- detectChanges() {
900
- this.cdr.detectChanges();
901
- }
902
- expandGroup(group) {
903
- group.setExpand(!group.expanded);
904
- this.expandChange.emit();
905
- this.cdr.detectChanges();
906
- }
907
- // public functions
908
- expandAll() {
909
- this.expandGroups(true);
910
- }
911
- collapseAll() {
912
- this.expandGroups(false);
913
- }
914
- }
915
- GanttUpper.decorators = [
916
- { type: Directive }
917
- ];
918
- GanttUpper.ctorParameters = () => [
919
- { type: ElementRef },
920
- { type: ChangeDetectorRef },
921
- { type: NgZone }
922
- ];
923
- GanttUpper.propDecorators = {
924
- originItems: [{ type: Input, args: ['items',] }],
925
- originGroups: [{ type: Input, args: ['groups',] }],
926
- viewType: [{ type: Input }],
927
- start: [{ type: Input }],
928
- end: [{ type: Input }],
929
- showTodayLine: [{ type: Input }],
930
- draggable: [{ type: Input }],
931
- styles: [{ type: Input }],
932
- viewOptions: [{ type: Input }],
933
- disabledLoadOnScroll: [{ type: Input }],
934
- loadOnScroll: [{ type: Output }],
935
- dragStarted: [{ type: Output }],
936
- dragEnded: [{ type: Output }],
937
- barClick: [{ type: Output }],
938
- barTemplate: [{ type: ContentChild, args: ['bar', { static: true },] }],
939
- rangeTemplate: [{ type: ContentChild, args: ['range', { static: true },] }],
940
- itemTemplate: [{ type: ContentChild, args: ['item', { static: true },] }],
941
- groupTemplate: [{ type: ContentChild, args: ['group', { static: true },] }],
942
- groupHeaderTemplate: [{ type: ContentChild, args: ['groupHeader', { static: true },] }],
943
- ganttClass: [{ type: HostBinding, args: ['class.gantt',] }]
944
- };
945
- const GANTT_UPPER_TOKEN = new InjectionToken('GANTT_UPPER_TOKEN');
946
-
947
- class NgxGanttTableColumnComponent {
948
- constructor(ganttUpper) {
949
- this.ganttUpper = ganttUpper;
950
- }
951
- set width(width) {
952
- this.columnWidth = coerceCssPixelValue(width);
953
- }
954
- ngOnInit() { }
955
- }
956
- NgxGanttTableColumnComponent.decorators = [
957
- { type: Component, args: [{
958
- selector: 'ngx-gantt-column',
959
- template: ''
960
- },] }
961
- ];
962
- NgxGanttTableColumnComponent.ctorParameters = () => [
963
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
964
- ];
965
- NgxGanttTableColumnComponent.propDecorators = {
966
- width: [{ type: Input }],
967
- name: [{ type: Input }],
968
- templateRef: [{ type: ContentChild, args: ['cell', { static: true },] }],
969
- headerTemplateRef: [{ type: ContentChild, args: ['header', { static: true },] }]
970
- };
971
-
972
- class NgxGanttTableComponent {
973
- constructor() {
974
- this.columnChanges = new EventEmitter();
975
- }
976
- ngOnInit() { }
977
- }
978
- NgxGanttTableComponent.decorators = [
979
- { type: Component, args: [{
980
- selector: 'ngx-gantt-table',
981
- template: ''
982
- },] }
983
- ];
984
- NgxGanttTableComponent.ctorParameters = () => [];
985
- NgxGanttTableComponent.propDecorators = {
986
- columnChanges: [{ type: Output }]
987
- };
988
-
989
- const defaultColumnWidth = 100;
990
- const minColumnWidth = 80;
991
- class NgxGanttComponent extends GanttUpper {
992
- constructor(elementRef, cdr, ngZone) {
993
- super(elementRef, cdr, ngZone);
994
- this.maxLevel = 2;
995
- this.linkDragStarted = new EventEmitter();
996
- this.linkDragEnded = new EventEmitter();
997
- this.lineClick = new EventEmitter();
998
- this.ngUnsubscribe$ = new Subject();
999
- this.sideTableWidth = sideWidth;
1000
- }
1001
- ngOnInit() {
1002
- super.onInit();
1003
- this.ngZone.onStable.pipe(take(1)).subscribe(() => {
1004
- this.dragContainer.linkDragStarted.pipe(takeUntil(this.ngUnsubscribe$)).subscribe((event) => {
1005
- this.linkDragStarted.emit(event);
1006
- });
1007
- this.dragContainer.linkDragEnded.pipe(takeUntil(this.ngUnsubscribe$)).subscribe((event) => {
1008
- this.linkDragEnded.emit(event);
1009
- });
1010
- });
1011
- }
1012
- ngAfterViewInit() {
1013
- this.columns.changes.pipe(startWith(true), takeUntil(this.ngUnsubscribe$)).subscribe(() => {
1014
- this.columns.forEach((column) => {
1015
- if (!column.columnWidth) {
1016
- column.columnWidth = coerceCssPixelValue(defaultColumnWidth);
1017
- }
1018
- });
1019
- this.cdr.detectChanges();
1020
- });
1021
- }
1022
- ngOnChanges(changes) {
1023
- super.onChanges(changes);
1024
- }
1025
- expandChildren(item) {
1026
- if (!item.expanded) {
1027
- item.setExpand(true);
1028
- if (this.async && this.childrenResolve && item.children.length === 0) {
1029
- item.loading = true;
1030
- this.childrenResolve(item.origin)
1031
- .pipe(take(1), finalize(() => {
1032
- item.loading = false;
1033
- this.expandChange.emit();
1034
- this.cdr.detectChanges();
1035
- }))
1036
- .subscribe((items) => {
1037
- item.addChildren(items);
1038
- this.computeItemsRefs(...item.children);
1039
- });
1040
- }
1041
- else {
1042
- this.computeItemsRefs(...item.children);
1043
- this.expandChange.emit();
1044
- }
1045
- }
1046
- else {
1047
- item.setExpand(false);
1048
- this.expandChange.emit();
1049
- }
1050
- }
1051
- ngOnDestroy() {
1052
- super.onDestroy();
1053
- }
1054
- }
1055
- NgxGanttComponent.decorators = [
1056
- { type: Component, args: [{
1057
- selector: 'ngx-gantt',
1058
- template: "<ngx-gantt-root>\n <ng-template #sideTemplate>\n <gantt-table [groups]=\"groups\" [items]=\"items\" [columns]=\"columns\" [groupTemplate]=\"groupTemplate\" [emptyTemplate]=\"tableEmptyTemplate\"></gantt-table>\n </ng-template>\n <ng-template #mainTemplate>\n <gantt-main\n [groups]=\"groups\"\n [items]=\"items\"\n [groupHeaderTemplate]=\"groupHeaderTemplate\"\n [itemTemplate]=\"itemTemplate\"\n [barTemplate]=\"barTemplate\"\n [rangeTemplate]=\"rangeTemplate\"\n (barClick)=\"barClick.emit($event)\"\n (lineClick)=\"lineClick.emit($event)\"\n >\n </gantt-main>\n </ng-template>\n</ngx-gantt-root>\n",
1059
- changeDetection: ChangeDetectionStrategy.OnPush,
1060
- providers: [
1061
- {
1062
- provide: GANTT_UPPER_TOKEN,
1063
- useExisting: NgxGanttComponent
1064
- }
1065
- ]
1066
- },] }
1067
- ];
1068
- NgxGanttComponent.ctorParameters = () => [
1069
- { type: ElementRef },
1070
- { type: ChangeDetectorRef },
1071
- { type: NgZone }
1072
- ];
1073
- NgxGanttComponent.propDecorators = {
1074
- maxLevel: [{ type: Input }],
1075
- async: [{ type: Input }],
1076
- childrenResolve: [{ type: Input }],
1077
- linkable: [{ type: Input }],
1078
- linkDragStarted: [{ type: Output }],
1079
- linkDragEnded: [{ type: Output }],
1080
- lineClick: [{ type: Output }],
1081
- table: [{ type: ContentChild, args: [NgxGanttTableComponent,] }],
1082
- columns: [{ type: ContentChildren, args: [NgxGanttTableColumnComponent, { descendants: true },] }],
1083
- tableEmptyTemplate: [{ type: ContentChild, args: ['tableEmpty', { static: true },] }]
1084
- };
1085
-
1086
- const mainHeight = 5000;
1087
- class GanttCalendarComponent {
1088
- constructor(ganttUpper, ngZone, elementRef) {
1089
- this.ganttUpper = ganttUpper;
1090
- this.ngZone = ngZone;
1091
- this.elementRef = elementRef;
1092
- this.unsubscribe$ = new Subject();
1093
- this.headerHeight = headerHeight;
1094
- this.mainHeight = mainHeight;
1095
- this.todayHeight = todayHeight;
1096
- this.todayWidth = todayWidth;
1097
- this.todayBorderRadius = todayBorderRadius;
1098
- this.viewTypes = GanttViewType;
1099
- this.className = true;
1100
- }
1101
- get view() {
1102
- return this.ganttUpper.view;
1103
- }
1104
- setTodayPoint() {
1105
- const x = this.view.getTodayXPoint();
1106
- const today = new GanttDate().getDate();
1107
- const todayEle = this.elementRef.nativeElement.getElementsByClassName('gantt-calendar-today-overlay')[0];
1108
- const rect = this.elementRef.nativeElement.getElementsByClassName('today-rect')[0];
1109
- const line = this.elementRef.nativeElement.getElementsByClassName('today-line')[0];
1110
- if (isNumber(x)) {
1111
- if (rect) {
1112
- rect.style.left = `${x - todayWidth / 2}px`;
1113
- rect.style.top = `${headerHeight - todayHeight}px`;
1114
- rect.innerHTML = today.toString();
1115
- }
1116
- if (line) {
1117
- line.style.left = `${x}px`;
1118
- line.style.top = `${headerHeight}px`;
1119
- line.style.bottom = `${-mainHeight}px`;
1120
- }
1121
- }
1122
- else {
1123
- todayEle.style.display = 'none';
1124
- }
1125
- }
1126
- ngOnInit() {
1127
- this.ngZone.onStable.pipe(take(1)).subscribe(() => {
1128
- merge(this.ganttUpper.viewChange, this.ganttUpper.view.start$)
1129
- .pipe(takeUntil(this.unsubscribe$))
1130
- .subscribe(() => {
1131
- this.setTodayPoint();
1132
- });
1133
- });
1134
- }
1135
- ngAfterViewInit() { }
1136
- ngOnChanges(changes) { }
1137
- trackBy(point, index) {
1138
- return point.text || index;
1139
- }
1140
- ngOnDestroy() {
1141
- this.unsubscribe$.next();
1142
- this.unsubscribe$.complete();
1143
- }
1144
- }
1145
- GanttCalendarComponent.decorators = [
1146
- { type: Component, args: [{
1147
- selector: 'gantt-calendar-overlay',
1148
- template: "<div class=\"gantt-calendar-today-overlay\" [style.width.px]=\"view.width\">\n <span class=\"today-rect\" [hidden]=\"ganttUpper.viewType !== viewTypes.day\"> </span>\n <span class=\"today-line\" *ngIf=\"ganttUpper.showTodayLine\"> </span>\n</div>\n\n<svg class=\"gantt-calendar-overlay-main\" [attr.width]=\"view.width\" [attr.height]=\"headerHeight\">\n <g>\n <text class=\"primary-text\" *ngFor=\"let point of view.primaryDatePoints; trackBy: trackBy\" [attr.x]=\"point.x\" [attr.y]=\"point.y\">\n {{ point.text }}\n </text>\n <ng-container *ngFor=\"let point of view.secondaryDatePoints; trackBy: trackBy\">\n <text class=\"secondary-text\" [class.secondary-text-weekend]=\"point.additions?.isWeekend\" [attr.x]=\"point.x\" [attr.y]=\"point.y\">\n {{ point.text }}\n </text>\n </ng-container>\n\n <g>\n <line\n *ngFor=\"let point of view.primaryDatePoints; let i = index; trackBy: trackBy\"\n [attr.x1]=\"(i + 1) * view.primaryWidth\"\n [attr.x2]=\"(i + 1) * view.primaryWidth\"\n [attr.y1]=\"0\"\n [attr.y2]=\"mainHeight\"\n class=\"primary-line\"\n ></line>\n </g>\n\n <g>\n <line [attr.x1]=\"0\" [attr.x2]=\"view.width\" [attr.y1]=\"headerHeight\" [attr.y2]=\"headerHeight\" class=\"header-line\"></line>\n </g>\n </g>\n <g>\n <g *ngIf=\"view.showTimeline\">\n <line\n *ngFor=\"let point of view.secondaryDatePoints; let i = index; trackBy: trackBy\"\n [attr.x1]=\"(i + 1) * view.cellWidth\"\n [attr.x2]=\"(i + 1) * view.cellWidth\"\n [attr.y1]=\"headerHeight\"\n [attr.y2]=\"mainHeight\"\n class=\"secondary-line\"\n ></line>\n <line\n *ngFor=\"let point of view.primaryDatePoints; let i = index; trackBy: trackBy\"\n [attr.x1]=\"(i + 1) * view.primaryWidth\"\n [attr.x2]=\"(i + 1) * view.primaryWidth\"\n [attr.y1]=\"0\"\n [attr.y2]=\"mainHeight\"\n class=\"primary-line\"\n ></line>\n </g>\n </g>\n</svg>\n"
1149
- },] }
1150
- ];
1151
- GanttCalendarComponent.ctorParameters = () => [
1152
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] },
1153
- { type: NgZone },
1154
- { type: ElementRef }
1155
- ];
1156
- GanttCalendarComponent.propDecorators = {
1157
- className: [{ type: HostBinding, args: ['class.gantt-calendar-overlay',] }]
1158
- };
1159
-
1160
- class GanttTableComponent {
1161
- constructor(gantt, elementRef) {
1162
- this.gantt = gantt;
1163
- this.elementRef = elementRef;
1164
- this.ganttTableClass = true;
1165
- this.ganttTableEmptyClass = false;
1166
- }
1167
- set columns(columns) {
1168
- columns.forEach((column) => {
1169
- if (!column.columnWidth) {
1170
- column.columnWidth = coerceCssPixelValue(defaultColumnWidth);
1171
- }
1172
- });
1173
- this.columnList = columns;
1174
- }
1175
- ngOnInit() { }
1176
- ngOnChanges(changes) {
1177
- var _a, _b;
1178
- if (!((_a = changes.groups.currentValue) === null || _a === void 0 ? void 0 : _a.length) && !((_b = changes.items.currentValue) === null || _b === void 0 ? void 0 : _b.length)) {
1179
- this.ganttTableEmptyClass = true;
1180
- }
1181
- else {
1182
- this.ganttTableEmptyClass = false;
1183
- }
1184
- }
1185
- dragFixed(config) {
1186
- if (config.movedWidth < config.minWidth) {
1187
- config.target.style.transform = `translate3d(${config.minWidth - config.originWidth}px, 0, 0)`;
1188
- }
1189
- }
1190
- expandGroup(group) {
1191
- this.gantt.expandGroup(group);
1192
- }
1193
- expandChildren(item) {
1194
- this.gantt.expandChildren(item);
1195
- }
1196
- dragStarted(event) {
1197
- const target = event.source.element.nativeElement;
1198
- this.dragStartLeft = target.getBoundingClientRect().left;
1199
- }
1200
- dragMoved(event, column) {
1201
- const target = event.source.element.nativeElement;
1202
- const left = target.getBoundingClientRect().left;
1203
- let originWidth;
1204
- let movedWidth;
1205
- let minWidth;
1206
- if (column) {
1207
- originWidth = parseInt(column.columnWidth, 10);
1208
- movedWidth = originWidth + (left - this.dragStartLeft);
1209
- minWidth = minColumnWidth;
1210
- }
1211
- else {
1212
- originWidth = this.elementRef.nativeElement.getBoundingClientRect().width;
1213
- movedWidth = originWidth + (left - this.dragStartLeft);
1214
- minWidth = minColumnWidth * this.columnList.length;
1215
- }
1216
- this.dragFixed({
1217
- target,
1218
- originWidth,
1219
- movedWidth,
1220
- minWidth
1221
- });
1222
- this.showAuxiliaryLine(event);
1223
- }
1224
- columnDragEnded(event, column) {
1225
- const target = event.source.element.nativeElement;
1226
- const left = target.getBoundingClientRect().left;
1227
- const width = parseInt(column.columnWidth, 10) + (left - this.dragStartLeft);
1228
- const columnWidth = Math.max(width || 0, minColumnWidth);
1229
- column.columnWidth = coerceCssPixelValue(columnWidth);
1230
- if (this.gantt.table) {
1231
- this.gantt.table.columnChanges.emit({ columns: this.columnList });
1232
- }
1233
- this.hideAuxiliaryLine();
1234
- event.source.reset();
1235
- }
1236
- tableDragEnded(event) {
1237
- const target = event.source.element.nativeElement;
1238
- const left = target.getBoundingClientRect().left;
1239
- const tableWidth = this.elementRef.nativeElement.getBoundingClientRect().width;
1240
- const dragWidth = left - this.dragStartLeft;
1241
- this.columnList.forEach((column) => {
1242
- const lastColumnWidth = parseInt(column.columnWidth, 10);
1243
- const distributeWidth = parseInt(String(dragWidth * (lastColumnWidth / tableWidth)), 10);
1244
- const columnWidth = Math.max(lastColumnWidth + distributeWidth || 0, minColumnWidth);
1245
- column.columnWidth = coerceCssPixelValue(columnWidth);
1246
- });
1247
- if (this.gantt.table) {
1248
- this.gantt.table.columnChanges.emit({ columns: this.columnList });
1249
- }
1250
- this.hideAuxiliaryLine();
1251
- event.source.reset();
1252
- }
1253
- showAuxiliaryLine(event) {
1254
- const tableRect = this.elementRef.nativeElement.getBoundingClientRect();
1255
- const targetRect = event.source.element.nativeElement.getBoundingClientRect();
1256
- const distance = { x: targetRect.left - tableRect.left, y: targetRect.top - tableRect.top };
1257
- this.draglineElementRef.nativeElement.style.left = `${distance.x}px`;
1258
- this.draglineElementRef.nativeElement.style.display = 'block';
1259
- }
1260
- hideAuxiliaryLine() {
1261
- this.draglineElementRef.nativeElement.style.display = 'none';
1262
- }
1263
- }
1264
- GanttTableComponent.decorators = [
1265
- { type: Component, args: [{
1266
- selector: 'gantt-table',
1267
- template: "<div class=\"gantt-table-header gantt-table-row\">\n <div class=\"gantt-table-column\" *ngFor=\"let column of columnList; let i = index\" [style.width]=\"column.columnWidth\">\n <ng-container *ngIf=\"column.headerTemplateRef; else default\" [ngTemplateOutlet]=\"column.headerTemplateRef\"></ng-container>\n <ng-template #default>\n {{ column.name }}\n </ng-template>\n <div\n class=\"gantt-table-drag-trigger\"\n cdkDrag\n cdkDragLockAxis=\"x\"\n cdkDragBoundary=\".gantt\"\n (cdkDragMoved)=\"dragMoved($event, column)\"\n (cdkDragStarted)=\"dragStarted($event)\"\n (cdkDragEnded)=\"columnDragEnded($event, column)\"\n ></div>\n </div>\n</div>\n<div class=\"gantt-table-body\">\n <ng-container *ngIf=\"!groups.length && !items.length\">\n <ng-container *ngIf=\"!emptyTemplate\">\n <gantt-icon class=\"empty-icon\" iconName=\"empty\"></gantt-icon>\n <div class=\"empty-text\">\u6CA1\u6709\u6570\u636E</div>\n </ng-container>\n <ng-template [ngTemplateOutlet]=\"emptyTemplate\"></ng-template>\n </ng-container>\n\n <ng-container *ngIf=\"groups && groups.length > 0; else itemsTemplate\">\n <ng-container *ngFor=\"let group of groups\">\n <div class=\"gantt-table-group\" [ngClass]=\"group.class\">\n <div class=\"gantt-table-group-title\" [class.expanded]=\"group.expanded\" (click)=\"expandGroup(group)\">\n <gantt-icon class=\"expand-icon\" [iconName]=\"group.expanded ? 'angle-down' : 'angle-right'\"></gantt-icon>\n <ng-container *ngIf=\"groupTemplate; else default\">\n <ng-template\n [ngTemplateOutlet]=\"groupTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: group.origin, group: group.origin }\"\n ></ng-template>\n </ng-container>\n <ng-template #default>\n <span class=\"group-title\">{{ group.title }}</span>\n </ng-template>\n </div>\n </div>\n\n <ng-container *ngIf=\"group.expanded\">\n <ng-template\n [ngTemplateOutlet]=\"ganttItems\"\n [ngTemplateOutletContext]=\"{ group: group, items: group.items, level: 0 }\"\n ></ng-template>\n </ng-container>\n </ng-container>\n </ng-container>\n</div>\n\n<div\n class=\"gantt-table-drag-trigger\"\n cdkDrag\n cdkDragLockAxis=\"x\"\n cdkDragBoundary=\".gantt\"\n (cdkDragMoved)=\"dragMoved($event)\"\n (cdkDragStarted)=\"dragStarted($event)\"\n (cdkDragEnded)=\"tableDragEnded($event)\"\n></div>\n\n<div #dragLine class=\"gantt-table-drag-auxiliary-line\"></div>\n\n<ng-template #itemsTemplate>\n <ng-template [ngTemplateOutlet]=\"ganttItems\" [ngTemplateOutletContext]=\"{ items: items, level: 0 }\"></ng-template>\n</ng-template>\n\n<ng-template #ganttItems let-group=\"group\" let-items=\"items\" let-level=\"level\">\n <ng-container *ngFor=\"let item of items\">\n <div\n class=\"gantt-table-item gantt-table-row\"\n [class.gantt-table-item-first-level-group]=\"level === 0 && (item.type | isGanttRangeItem)\"\n [class.gantt-table-item-with-group]=\"group\"\n [style.height.px]=\"gantt.styles.lineHeight\"\n [style.lineHeight.px]=\"gantt.styles.lineHeight\"\n >\n <div class=\"gantt-table-column\" *ngFor=\"let column of columnList; let first = first\" [style.width]=\"column.columnWidth\">\n <div *ngIf=\"first\" class=\"gantt-expand-icon\" [style.marginLeft.px]=\"level * 20\">\n <ng-container *ngIf=\"level < gantt.maxLevel - 1 && item.expandable\">\n <gantt-icon\n *ngIf=\"!item.loading\"\n class=\"expand-icon\"\n [iconName]=\"item.expanded ? 'angle-down' : 'angle-right'\"\n (click)=\"expandChildren(item)\"\n ></gantt-icon>\n <gantt-icon *ngIf=\"item.loading\" [iconName]=\"'loading'\"></gantt-icon>\n </ng-container>\n </div>\n <div class=\"gantt-table-column-content\">\n <ng-template\n [ngTemplateOutlet]=\"column.templateRef\"\n [ngTemplateOutletContext]=\"{ $implicit: item.origin, item: item.origin }\"\n ></ng-template>\n </div>\n </div>\n </div>\n <ng-template\n *ngIf=\"item.children && item.expanded\"\n [ngTemplateOutlet]=\"ganttItems\"\n [ngTemplateOutletContext]=\"{ items: item.children, level: level + 1, group: group }\"\n ></ng-template>\n </ng-container>\n</ng-template>\n"
1268
- },] }
1269
- ];
1270
- GanttTableComponent.ctorParameters = () => [
1271
- { type: NgxGanttComponent },
1272
- { type: ElementRef }
1273
- ];
1274
- GanttTableComponent.propDecorators = {
1275
- groups: [{ type: Input }],
1276
- items: [{ type: Input }],
1277
- columns: [{ type: Input }],
1278
- groupTemplate: [{ type: Input }],
1279
- emptyTemplate: [{ type: Input }],
1280
- draglineElementRef: [{ type: ViewChild, args: ['dragLine', { static: true },] }],
1281
- ganttTableClass: [{ type: HostBinding, args: ['class.gantt-table',] }],
1282
- ganttTableEmptyClass: [{ type: HostBinding, args: ['class.gantt-table-empty',] }]
1283
- };
1284
-
1285
- const scrollThreshold = 50;
1286
- var ScrollDirection;
1287
- (function (ScrollDirection) {
1288
- ScrollDirection[ScrollDirection["NONE"] = 0] = "NONE";
1289
- ScrollDirection[ScrollDirection["LEFT"] = 1] = "LEFT";
1290
- ScrollDirection[ScrollDirection["RIGHT"] = 2] = "RIGHT";
1291
- })(ScrollDirection || (ScrollDirection = {}));
1292
- class GanttDomService {
1293
- constructor() {
1294
- this.unsubscribe$ = new Subject();
1295
- }
1296
- monitorScrollChange() {
1297
- merge(fromEvent(this.mainContainer, 'scroll'), fromEvent(this.sideContainer, 'scroll'))
1298
- .pipe(takeUntil(this.unsubscribe$))
1299
- .subscribe((event) => {
1300
- this.syncScroll(event);
1301
- });
1302
- fromEvent(this.mainContainer, 'scroll')
1303
- .pipe(startWith(), takeUntil(this.unsubscribe$))
1304
- .subscribe((event) => {
1305
- // if (this.mainContainer.scrollLeft > 0) {
1306
- // this.side.classList.add('gantt-side-has-shadow');
1307
- // } else {
1308
- // this.side.classList.remove('gantt-side-has-shadow');
1309
- // }
1310
- });
1311
- }
1312
- syncScroll(event) {
1313
- const target = event.currentTarget;
1314
- this.calendarOverlay.scrollLeft = this.mainContainer.scrollLeft;
1315
- this.sideContainer.scrollTop = target.scrollTop;
1316
- this.mainContainer.scrollTop = target.scrollTop;
1317
- }
1318
- disableBrowserWheelEvent() {
1319
- const container = this.mainContainer;
1320
- fromEvent(container, 'wheel')
1321
- .pipe(takeUntil(this.unsubscribe$))
1322
- .subscribe((event) => {
1323
- const delta = event.deltaX;
1324
- if (!delta) {
1325
- return;
1326
- }
1327
- if ((container.scrollLeft + container.offsetWidth === container.scrollWidth && delta > 0) ||
1328
- (container.scrollLeft === 0 && delta < 0)) {
1329
- event.preventDefault();
1330
- }
1331
- });
1332
- }
1333
- initialize(root) {
1334
- this.root = root.nativeElement;
1335
- this.side = this.root.getElementsByClassName('gantt-side')[0];
1336
- this.container = this.root.getElementsByClassName('gantt-container')[0];
1337
- this.sideContainer = this.root.getElementsByClassName('gantt-side-container')[0];
1338
- this.mainContainer = this.root.getElementsByClassName('gantt-main-container')[0];
1339
- this.calendarOverlay = this.root.getElementsByClassName('gantt-calendar-overlay')[0];
1340
- this.monitorScrollChange();
1341
- this.disableBrowserWheelEvent();
1342
- }
1343
- getViewerScroll() {
1344
- return fromEvent(this.mainContainer, 'scroll').pipe(map(() => this.mainContainer.scrollLeft), pairwise(), map(([previous, current]) => {
1345
- const event = {
1346
- target: this.mainContainer,
1347
- direction: ScrollDirection.NONE
1348
- };
1349
- if (current - previous < 0) {
1350
- if (this.mainContainer.scrollLeft < scrollThreshold && this.mainContainer.scrollLeft > 0) {
1351
- event.direction = ScrollDirection.LEFT;
1352
- }
1353
- }
1354
- if (current - previous > 0) {
1355
- if (this.mainContainer.scrollWidth - this.mainContainer.clientWidth - this.mainContainer.scrollLeft < scrollThreshold) {
1356
- event.direction = ScrollDirection.RIGHT;
1357
- }
1358
- }
1359
- return event;
1360
- }));
1361
- }
1362
- getResize() {
1363
- return fromEvent(window, 'resize').pipe(auditTime(150));
1364
- }
1365
- scrollMainContainer(left) {
1366
- if (isNumber(left)) {
1367
- const scrollLeft = left - this.mainContainer.clientWidth / 2;
1368
- this.mainContainer.scrollLeft = scrollLeft > scrollThreshold ? scrollLeft : 0;
1369
- this.calendarOverlay.scrollLeft = this.mainContainer.scrollLeft;
1370
- }
1371
- }
1372
- ngOnDestroy() {
1373
- this.unsubscribe$.next();
1374
- this.unsubscribe$.complete();
1375
- }
1376
- }
1377
- GanttDomService.decorators = [
1378
- { type: Injectable }
1379
- ];
1380
- GanttDomService.ctorParameters = () => [];
1381
-
1382
- class GanttDragContainer {
1383
- constructor() {
1384
- this.dragStarted = new EventEmitter();
1385
- this.dragEnded = new EventEmitter();
1386
- this.linkDragStarted = new EventEmitter();
1387
- this.linkDragEntered = new EventEmitter();
1388
- this.linkDragEnded = new EventEmitter();
1389
- }
1390
- emitLinkDragStarted(from, item) {
1391
- this.linkDraggingId = item.id;
1392
- this.linkDragFrom = from;
1393
- this.linkDragSource = this.linkDragFrom === 'source' ? item : null;
1394
- this.linkDragTarget = this.linkDragFrom === 'target' ? item : null;
1395
- this.linkDragStarted.emit({
1396
- source: this.linkDragSource && this.linkDragSource.origin,
1397
- target: this.linkDragTarget && this.linkDragTarget.origin
1398
- });
1399
- }
1400
- emitLinkDragEntered(item) {
1401
- if (this.linkDragFrom === 'source') {
1402
- this.linkDragTarget = item;
1403
- }
1404
- else {
1405
- this.linkDragSource = item;
1406
- }
1407
- this.linkDragEntered.emit({
1408
- source: this.linkDragSource.origin,
1409
- target: this.linkDragTarget.origin
1410
- });
1411
- }
1412
- emitLinkDragLeaved() {
1413
- if (this.linkDragFrom === 'source') {
1414
- this.linkDragTarget = null;
1415
- }
1416
- else {
1417
- this.linkDragSource = null;
1418
- }
1419
- }
1420
- emitLinkDragEnded() {
1421
- this.linkDraggingId = null;
1422
- if (this.linkDragSource && this.linkDragTarget) {
1423
- this.linkDragSource.addLink(this.linkDragTarget.id);
1424
- this.linkDragEnded.emit({
1425
- source: this.linkDragSource.origin,
1426
- target: this.linkDragTarget.origin
1427
- });
1428
- }
1429
- this.linkDragSource = null;
1430
- this.linkDragTarget = null;
1431
- }
1432
- }
1433
- GanttDragContainer.decorators = [
1434
- { type: Injectable }
1435
- ];
1436
- GanttDragContainer.ctorParameters = () => [];
1437
-
1438
- const dragMinWidth = 10;
1439
- const activeClass = 'gantt-bar-active';
1440
- const linkDropClass = 'gantt-bar-link-drop';
1441
- function createSvgElement(qualifiedName, className) {
1442
- const element = document.createElementNS('http://www.w3.org/2000/svg', qualifiedName);
1443
- element.classList.add(className);
1444
- return element;
1445
- }
1446
- class GanttBarDrag {
1447
- constructor(dragDrop, dom, dragContainer) {
1448
- this.dragDrop = dragDrop;
1449
- this.dom = dom;
1450
- this.dragContainer = dragContainer;
1451
- this.dragRefs = [];
1452
- this.destroy$ = new Subject();
1453
- }
1454
- get dragDisabled() {
1455
- return !this.item.draggable || !this.ganttUpper.draggable;
1456
- }
1457
- get linkDragDisabled() {
1458
- return !this.item.linkable || !this.ganttUpper.linkable;
1459
- }
1460
- createMouseEvents() {
1461
- fromEvent(this.barElement, 'mouseenter')
1462
- .pipe(takeUntil(this.destroy$))
1463
- .subscribe(() => {
1464
- if (this.dragContainer.linkDraggingId && this.dragContainer.linkDraggingId !== this.item.id) {
1465
- if (this.item.linkable) {
1466
- this.barElement.classList.add(linkDropClass);
1467
- this.dragContainer.emitLinkDragEntered(this.item);
1468
- }
1469
- }
1470
- else {
1471
- this.barElement.classList.add(activeClass);
1472
- }
1473
- });
1474
- fromEvent(this.barElement, 'mouseleave')
1475
- .pipe(takeUntil(this.destroy$))
1476
- .subscribe(() => {
1477
- if (!this.dragContainer.linkDraggingId) {
1478
- this.barElement.classList.remove(activeClass);
1479
- }
1480
- else {
1481
- this.dragContainer.emitLinkDragLeaved();
1482
- }
1483
- this.barElement.classList.remove(linkDropClass);
1484
- });
1485
- }
1486
- createBarDrag() {
1487
- const dragRef = this.dragDrop.createDrag(this.barElement);
1488
- dragRef.lockAxis = 'x';
1489
- dragRef.started.subscribe(() => {
1490
- this.setDraggingStyles();
1491
- this.dragContainer.dragStarted.emit({ item: this.item.origin });
1492
- });
1493
- dragRef.moved.subscribe((event) => {
1494
- const x = this.item.refs.x + event.distance.x;
1495
- const days = differenceInCalendarDays(this.item.end.value, this.item.start.value);
1496
- const start = this.ganttUpper.view.getDateByXPoint(x);
1497
- const end = start.addDays(days);
1498
- this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), end);
1499
- });
1500
- dragRef.ended.subscribe((event) => {
1501
- const days = differenceInCalendarDays(this.item.end.value, this.item.start.value);
1502
- const start = this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x);
1503
- const end = start.addDays(days);
1504
- this.item.updateDate(start, end);
1505
- this.clearDraggingStyles();
1506
- this.closeDragBackdrop();
1507
- event.source.reset();
1508
- this.dragContainer.dragEnded.emit({ item: this.item.origin });
1509
- });
1510
- this.barDragRef = dragRef;
1511
- return dragRef;
1512
- }
1513
- createBarHandleDrags() {
1514
- const dragRefs = [];
1515
- const handles = this.barElement.querySelectorAll('.drag-handles .handle');
1516
- handles.forEach((handle, index) => {
1517
- const isBefore = index === 0;
1518
- const dragRef = this.dragDrop.createDrag(handle);
1519
- dragRef.lockAxis = 'x';
1520
- dragRef.withBoundaryElement(this.dom.root);
1521
- dragRef.started.subscribe(() => {
1522
- this.setDraggingStyles();
1523
- this.dragContainer.dragStarted.emit({ item: this.item.origin });
1524
- });
1525
- dragRef.moved.subscribe((event) => {
1526
- if (isBefore) {
1527
- const x = this.item.refs.x + event.distance.x;
1528
- const width = this.item.refs.width + event.distance.x * -1;
1529
- if (width > dragMinWidth) {
1530
- this.barElement.style.width = width + 'px';
1531
- this.barElement.style.left = x + 'px';
1532
- this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), this.ganttUpper.view.getDateByXPoint(x + width));
1533
- }
1534
- }
1535
- else {
1536
- const width = this.item.refs.width + event.distance.x;
1537
- if (width > dragMinWidth) {
1538
- this.barElement.style.width = width + 'px';
1539
- this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(this.item.refs.x), this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width));
1540
- }
1541
- }
1542
- event.source.reset();
1543
- });
1544
- dragRef.ended.subscribe((event) => {
1545
- if (isBefore) {
1546
- const width = this.item.refs.width + event.distance.x * -1;
1547
- if (width > dragMinWidth) {
1548
- this.item.updateDate(this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x), this.item.end);
1549
- }
1550
- else {
1551
- this.item.updateDate(this.item.end.startOfDay(), this.item.end);
1552
- }
1553
- }
1554
- else {
1555
- const width = this.item.refs.width + event.distance.x;
1556
- if (width > dragMinWidth) {
1557
- this.item.updateDate(this.item.start, this.ganttUpper.view.getDateByXPoint(this.item.refs.x + this.item.refs.width + event.distance.x));
1558
- }
1559
- else {
1560
- this.item.updateDate(this.item.start, this.item.start.endOfDay());
1561
- }
1562
- }
1563
- this.clearDraggingStyles();
1564
- this.closeDragBackdrop();
1565
- this.dragContainer.dragEnded.emit({ item: this.item.origin });
1566
- });
1567
- dragRefs.push(dragRef);
1568
- });
1569
- return dragRefs;
1570
- }
1571
- createLinkHandleDrags() {
1572
- const dragRefs = [];
1573
- const handles = this.barElement.querySelectorAll('.link-handles .handle');
1574
- handles.forEach((handle, index) => {
1575
- const isBefore = index === 0;
1576
- const dragRef = this.dragDrop.createDrag(handle);
1577
- dragRef.withBoundaryElement(this.dom.root);
1578
- dragRef.beforeStarted.subscribe(() => {
1579
- handle.style.pointerEvents = 'none';
1580
- if (this.barDragRef) {
1581
- this.barDragRef.disabled = true;
1582
- }
1583
- this.createLinkDraggingLine();
1584
- this.dragContainer.emitLinkDragStarted(isBefore ? 'target' : 'source', this.item);
1585
- });
1586
- dragRef.moved.subscribe(() => {
1587
- const positions = this.calcLinkLinePositions(handle, isBefore);
1588
- this.linkDraggingLine.setAttribute('x1', positions.x1.toString());
1589
- this.linkDraggingLine.setAttribute('y1', positions.y1.toString());
1590
- this.linkDraggingLine.setAttribute('x2', positions.x2.toString());
1591
- this.linkDraggingLine.setAttribute('y2', positions.y2.toString());
1592
- });
1593
- dragRef.ended.subscribe((event) => {
1594
- event.source.reset();
1595
- handle.style.pointerEvents = '';
1596
- if (this.barDragRef) {
1597
- this.barDragRef.disabled = false;
1598
- }
1599
- this.barElement.classList.remove(activeClass);
1600
- this.destroyLinkDraggingLine();
1601
- this.dragContainer.emitLinkDragEnded();
1602
- });
1603
- dragRefs.push(dragRef);
1604
- });
1605
- return dragRefs;
1606
- }
1607
- openDragBackdrop(dragElement, start, end) {
1608
- const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask');
1609
- const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop');
1610
- const rootRect = this.dom.root.getBoundingClientRect();
1611
- const dragRect = dragElement.getBoundingClientRect();
1612
- const left = dragRect.left - rootRect.left - this.dom.side.clientWidth;
1613
- const width = dragRect.right - dragRect.left;
1614
- dragMaskElement.style.left = left + 'px';
1615
- dragMaskElement.style.width = width + 'px';
1616
- dragMaskElement.querySelector('.start').innerHTML = start.format('MM-dd');
1617
- dragMaskElement.querySelector('.end').innerHTML = end.format('MM-dd');
1618
- dragMaskElement.style.display = 'block';
1619
- dragBackdropElement.style.display = 'block';
1620
- }
1621
- closeDragBackdrop() {
1622
- const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask');
1623
- const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop');
1624
- dragMaskElement.style.display = 'none';
1625
- dragBackdropElement.style.display = 'none';
1626
- }
1627
- setDraggingStyles() {
1628
- this.barElement.style.pointerEvents = 'none';
1629
- this.barElement.classList.add('gantt-bar-draggable-drag');
1630
- }
1631
- clearDraggingStyles() {
1632
- this.barElement.style.pointerEvents = '';
1633
- this.barElement.classList.remove('gantt-bar-draggable-drag');
1634
- }
1635
- calcLinkLinePositions(target, isBefore) {
1636
- const rootRect = this.dom.root.getBoundingClientRect();
1637
- const targetRect = target.getBoundingClientRect();
1638
- const layerRect = target.parentElement.parentElement.getBoundingClientRect();
1639
- return {
1640
- x1: layerRect.left + (isBefore ? 0 : layerRect.width) - rootRect.left,
1641
- y1: layerRect.top + layerRect.height / 2 - rootRect.top,
1642
- x2: targetRect.left - rootRect.left + targetRect.width / 2,
1643
- y2: targetRect.top - rootRect.top + targetRect.height / 2
1644
- };
1645
- }
1646
- createLinkDraggingLine() {
1647
- if (!this.linkDraggingLine) {
1648
- const svgElement = createSvgElement('svg', 'gantt-link-drag-container');
1649
- const linElement = createSvgElement('line', 'link-dragging-line');
1650
- svgElement.appendChild(linElement);
1651
- this.dom.root.appendChild(svgElement);
1652
- this.linkDraggingLine = linElement;
1653
- }
1654
- }
1655
- destroyLinkDraggingLine() {
1656
- if (this.linkDraggingLine) {
1657
- this.linkDraggingLine.parentElement.remove();
1658
- this.linkDraggingLine = null;
1659
- }
1660
- }
1661
- createDrags(elementRef, item, ganttUpper) {
1662
- this.item = item;
1663
- this.barElement = elementRef.nativeElement;
1664
- this.ganttUpper = ganttUpper;
1665
- if (!item.draggable || (this.dragDisabled && this.linkDragDisabled)) {
1666
- return;
1667
- }
1668
- else {
1669
- this.createMouseEvents();
1670
- if (!this.dragDisabled) {
1671
- const dragRef = this.createBarDrag();
1672
- const dragHandlesRefs = this.createBarHandleDrags();
1673
- this.dragRefs.push(dragRef, ...dragHandlesRefs);
1674
- }
1675
- if (!this.linkDragDisabled) {
1676
- const linkDragRefs = this.createLinkHandleDrags();
1677
- this.dragRefs.push(...linkDragRefs);
1678
- }
1679
- }
1680
- }
1681
- ngOnDestroy() {
1682
- this.closeDragBackdrop();
1683
- this.dragRefs.forEach((dragRef) => dragRef.dispose());
1684
- this.destroy$.next();
1685
- this.destroy$.complete();
1686
- }
1687
- }
1688
- GanttBarDrag.decorators = [
1689
- { type: Injectable }
1690
- ];
1691
- GanttBarDrag.ctorParameters = () => [
1692
- { type: DragDrop },
1693
- { type: GanttDomService },
1694
- { type: GanttDragContainer }
1695
- ];
1696
-
1697
- class GanttItemUpper {
1698
- constructor(elementRef, ganttUpper) {
1699
- this.elementRef = elementRef;
1700
- this.ganttUpper = ganttUpper;
1701
- this.firstChange = true;
1702
- this.unsubscribe$ = new Subject();
1703
- }
1704
- onInit() {
1705
- this.firstChange = false;
1706
- this.item.refs$.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
1707
- this.setPositions();
1708
- });
1709
- }
1710
- onChanges() {
1711
- if (!this.firstChange) {
1712
- this.setPositions();
1713
- }
1714
- }
1715
- setPositions() {
1716
- const itemElement = this.elementRef.nativeElement;
1717
- itemElement.style.left = this.item.refs.x + 'px';
1718
- itemElement.style.top = this.item.refs.y + 'px';
1719
- itemElement.style.width = this.item.refs.width + 'px';
1720
- if (this.item.type === GanttItemType.bar) {
1721
- itemElement.style.height = this.ganttUpper.styles.barHeight + 'px';
1722
- }
1723
- else if (this.item.type === GanttItemType.range) {
1724
- itemElement.style.height = rangeHeight + 'px';
1725
- }
1726
- else {
1727
- }
1728
- }
1729
- onDestroy() {
1730
- this.unsubscribe$.next();
1731
- this.unsubscribe$.complete();
1732
- }
1733
- }
1734
- GanttItemUpper.decorators = [
1735
- { type: Directive }
1736
- ];
1737
- GanttItemUpper.ctorParameters = () => [
1738
- { type: ElementRef },
1739
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
1740
- ];
1741
- GanttItemUpper.propDecorators = {
1742
- template: [{ type: Input }],
1743
- item: [{ type: Input }]
1744
- };
1745
-
1746
- function linearGradient(sideOrCorner, color, stop) {
1747
- return `linear-gradient(${sideOrCorner},${color} 0%,${stop} 40%)`;
1748
- }
1749
- class NgxGanttBarComponent extends GanttItemUpper {
1750
- constructor(dragContainer, drag, elementRef, ganttUpper) {
1751
- super(elementRef, ganttUpper);
1752
- this.dragContainer = dragContainer;
1753
- this.drag = drag;
1754
- this.ganttUpper = ganttUpper;
1755
- this.barClick = new EventEmitter();
1756
- this.ganttItemClass = true;
1757
- this.color = 'red';
1758
- }
1759
- ngOnInit() {
1760
- super.onInit();
1761
- this.dragContainer.dragEnded.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
1762
- this.setContentBackground();
1763
- });
1764
- }
1765
- ngAfterViewInit() {
1766
- this.drag.createDrags(this.elementRef, this.item, this.ganttUpper);
1767
- this.setContentBackground();
1768
- }
1769
- ngOnChanges() {
1770
- super.onChanges();
1771
- }
1772
- onBarClick(event) {
1773
- this.barClick.emit({ event, item: this.item.origin });
1774
- }
1775
- setContentBackground() {
1776
- const contentElement = this.contentElementRef.nativeElement;
1777
- const color = this.item.color || barBackground;
1778
- const style = this.item.barStyle || {};
1779
- if (this.item.origin.start && this.item.origin.end) {
1780
- style.background = color;
1781
- style.borderRadius = '';
1782
- }
1783
- if (this.item.origin.start && !this.item.origin.end) {
1784
- style.background = linearGradient('to left', hexToRgb(color, 0.55), hexToRgb(color, 1));
1785
- style.borderRadius = '4px 12.5px 12.5px 4px';
1786
- }
1787
- if (!this.item.origin.start && this.item.origin.end) {
1788
- style.background = linearGradient('to right', hexToRgb(color, 0.55), hexToRgb(color, 1));
1789
- style.borderRadius = '12.5px 4px 4px 12.5px';
1790
- }
1791
- if (this.item.progress >= 0) {
1792
- const contentProgressElement = contentElement.querySelector('.gantt-bar-content-progress');
1793
- style.background = hexToRgb(color, 0.3);
1794
- style.borderRadius = '';
1795
- contentProgressElement.style.background = color;
1796
- }
1797
- for (const key in style) {
1798
- if (style.hasOwnProperty(key)) {
1799
- contentElement.style[key] = style[key];
1800
- }
1801
- }
1802
- }
1803
- stopPropagation(event) {
1804
- event.stopPropagation();
1805
- }
1806
- ngOnDestroy() {
1807
- super.onDestroy();
1808
- }
1809
- }
1810
- NgxGanttBarComponent.decorators = [
1811
- { type: Component, args: [{
1812
- selector: 'ngx-gantt-bar,gantt-bar',
1813
- template: "<div class=\"gantt-bar-layer\">\n <div *ngIf=\"item.draggable && ganttUpper.draggable\" class=\"drag-handles\">\n <ng-container>\n <span class=\"handle\" (mousedown)=\"stopPropagation($event)\"></span>\n <span class=\"handle\" (mousedown)=\"stopPropagation($event)\"></span>\n </ng-container>\n </div>\n <div *ngIf=\"item.linkable && ganttUpper.linkable\" class=\"link-handles\">\n <span class=\"handle\"><span class=\"point\"></span></span>\n <span class=\"handle\"> <span class=\"point\"></span></span>\n </div>\n</div>\n<div class=\"gantt-bar-border\"></div>\n<div #content class=\"gantt-bar-content\" (click)=\"onBarClick($event)\">\n <div class=\"gantt-bar-content-progress\" *ngIf=\"item.progress >= 0\" [style.width.%]=\"item.progress * 100\"></div>\n <ng-template [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"{ item: item.origin, refs: item.refs }\"></ng-template>\n</div>\n",
1814
- providers: [GanttBarDrag]
1815
- },] }
1816
- ];
1817
- NgxGanttBarComponent.ctorParameters = () => [
1818
- { type: GanttDragContainer },
1819
- { type: GanttBarDrag },
1820
- { type: ElementRef },
1821
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
1822
- ];
1823
- NgxGanttBarComponent.propDecorators = {
1824
- barClick: [{ type: Output }],
1825
- contentElementRef: [{ type: ViewChild, args: ['content',] }],
1826
- ganttItemClass: [{ type: HostBinding, args: ['class.gantt-bar',] }]
1827
- };
1828
-
1829
- class GanttMainComponent {
1830
- constructor(ganttUpper) {
1831
- this.ganttUpper = ganttUpper;
1832
- this.barClick = new EventEmitter();
1833
- this.lineClick = new EventEmitter();
1834
- this.ganttMainClass = true;
1835
- }
1836
- ngOnInit() { }
1837
- trackBy(item, index) {
1838
- return item.id || index;
1839
- }
1840
- }
1841
- GanttMainComponent.decorators = [
1842
- { type: Component, args: [{
1843
- selector: 'gantt-main',
1844
- template: "<gantt-links-overlay [groups]=\"groups\" [items]=\"items\" (lineClick)=\"lineClick.emit($event)\"></gantt-links-overlay>\n<!-- groups -->\n<div class=\"gantt-main-groups\" *ngIf=\"groups && groups.length > 0; else itemsTemplate\" [style.width.px]=\"ganttUpper.view.width\">\n <ng-container *ngFor=\"let group of groups; trackBy: trackBy\">\n <div class=\"gantt-group\" [ngClass]=\"group.class\">\n <ng-template [ngTemplateOutlet]=\"groupHeaderTemplate\" [ngTemplateOutletContext]=\"{ group: group }\"></ng-template>\n </div>\n <div *ngIf=\"group.expanded\" class=\"gantt-items\">\n <ng-template [ngTemplateOutlet]=\"ganttItems\" [ngTemplateOutletContext]=\"{ items: group.items }\"></ng-template>\n </div>\n </ng-container>\n</div>\n<!-- items -->\n<ng-template #itemsTemplate>\n <div class=\"gantt-main-items\" [style.width.px]=\"ganttUpper.view.width\">\n <ng-template [ngTemplateOutlet]=\"ganttItems\" [ngTemplateOutletContext]=\"{ items: items }\"></ng-template>\n </div>\n</ng-template>\n\n<ng-template #ganttItems let-items=\"items\">\n <ng-container *ngFor=\"let item of items; trackBy: trackBy\">\n <div class=\"gantt-item\" [style.height.px]=\"ganttUpper.styles.lineHeight\">\n <ng-container *ngIf=\"item.type | isGanttCustomItem\">\n <ng-template [ngTemplateOutlet]=\"itemTemplate\" [ngTemplateOutletContext]=\"{ item: item.origin, refs: item.refs }\"></ng-template>\n </ng-container>\n <gantt-range *ngIf=\"item.type | isGanttRangeItem\" [template]=\"rangeTemplate\" [item]=\"item\"></gantt-range>\n <gantt-bar *ngIf=\"item.type | isGanttBarItem\" [item]=\"item\" [template]=\"barTemplate\" (barClick)=\"barClick.emit($event)\"></gantt-bar>\n </div>\n <ng-template\n *ngIf=\"item.children && item.expanded\"\n [ngTemplateOutlet]=\"ganttItems\"\n [ngTemplateOutletContext]=\"{ items: item.children }\"\n ></ng-template>\n </ng-container>\n</ng-template>\n"
1845
- },] }
1846
- ];
1847
- GanttMainComponent.ctorParameters = () => [
1848
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
1849
- ];
1850
- GanttMainComponent.propDecorators = {
1851
- groups: [{ type: Input }],
1852
- items: [{ type: Input }],
1853
- groupHeaderTemplate: [{ type: Input }],
1854
- itemTemplate: [{ type: Input }],
1855
- barTemplate: [{ type: Input }],
1856
- rangeTemplate: [{ type: Input }],
1857
- barClick: [{ type: Output }],
1858
- lineClick: [{ type: Output }],
1859
- ganttMainClass: [{ type: HostBinding, args: ['class.gantt-main-container',] }]
1860
- };
1861
-
1862
- const angleRight = `<svg xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="amnavigation/angle-right" stroke-width="1" fill-rule="evenodd"><path d="M7.978 11.498l-.005.005L2.3 5.831 3.13 5l4.848 4.848L12.826 5l.83.831-5.673 5.672-.005-.005z" transform="rotate(-90 7.978 8.252)"></path></g></svg>`;
1863
- const angleDown = `<svg xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="aknavigation/angle-down" stroke-width="1" fill-rule="evenodd"><path d="M7.978 11.997l-.005.006L2.3 6.33l.83-.831 4.848 4.848L12.826 5.5l.83.83-5.673 5.673-.005-.006z" ></path></g></svg>`;
1864
- const plusSquare = `<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="kxaction/plus-square" stroke-width="1" fill-rule="evenodd"><path d="M2 0h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm0 1.2a.8.8 0 0 0-.8.8v12a.8.8 0 0 0 .8.8h12a.8.8 0 0 0 .8-.8V2a.8.8 0 0 0-.8-.8H2zm5.45 6.2V4.75h1.2V7.4h2.65v1.2H8.65v2.65h-1.2V8.6H4.8V7.4h2.65z"></path></g></svg>`;
1865
- const minusSquare = `<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="jnaction/minus-square" stroke-width="1" fill-rule="evenodd"><path d="M2 0h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm0 1.2a.8.8 0 0 0-.8.8v12a.8.8 0 0 0 .8.8h12a.8.8 0 0 0 .8-.8V2a.8.8 0 0 0-.8-.8H2zm2.8 6.2h6.5v1.2H4.8V7.4z"></path></g></svg>`;
1866
- const loadingIcon = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50" xml:space="preserve">
1867
- <path fill="#aaa" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" transform="rotate(275.098 25 25)">
1868
- <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animateTransform>
1869
- </path>
1870
- </svg>`;
1871
- const emptyIcon = `<svg
1872
- width="148px"
1873
- height="134px"
1874
- viewBox="0 0 148 134"
1875
- version="1.1"
1876
- xmlns="http://www.w3.org/2000/svg"
1877
- xmlns:xlink="http://www.w3.org/1999/xlink"
1878
- >
1879
- <defs>
1880
- <filter x="0.0%" y="0.0%" width="100.0%" height="100.0%" filterUnits="objectBoundingBox" id="filter-1">
1881
- <feGaussianBlur stdDeviation="0" in="SourceGraphic"></feGaussianBlur>
1882
- </filter>
1883
- </defs>
1884
- <g id="148x134" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
1885
- <g id="编组-6" transform="translate(1.000000, 1.000000)">
1886
- <ellipse
1887
- id="椭圆形"
1888
- fill="#EDEEF2"
1889
- opacity="0.3"
1890
- filter="url(#filter-1)"
1891
- cx="73.0800017"
1892
- cy="115.920003"
1893
- rx="73.0800017"
1894
- ry="16.8000004"
1895
- ></ellipse>
1896
- <g id="编组-5" transform="translate(15.120000, 0.000000)">
1897
- <polygon
1898
- id="矩形"
1899
- fill="#E2E4E9"
1900
- points="19.2789848 49.5600011 99.1200023 48.7200011 117.600003 75.9297673 117.600003 92.313049 0 92.313049 0 75.0356267"
1901
- ></polygon>
1902
- <path
1903
- d="M23.5200005,0 L94.0800002,0 C97.7913538,2.06413823e-16 100.8,3.00864655 100.8,6.72000015 L100.8,99.1200023 L100.8,99.1200023 L16.8000004,99.1200023 L16.8000004,6.72000015 C16.8000004,3.00864655 19.8086469,1.56994302e-15 23.5200005,0 Z"
1904
- id="矩形"
1905
- fill="#F9FAFB"
1906
- ></path>
1907
- <path
1908
- d="M30.9200007,12.4400003 L86.6800019,12.4400003 C88.5356787,12.4400003 90.040002,13.9443236 90.040002,15.8000004 L90.040002,42.000001 C90.040002,43.8556778 88.5356787,45.360001 86.6800019,45.360001 L30.9200007,45.360001 C29.0643239,45.360001 27.5600006,43.8556778 27.5600006,42.000001 L27.5600006,15.8000004 C27.5600006,13.9443236 29.0643239,12.4400003 30.9200007,12.4400003 Z"
1909
- id="矩形"
1910
- fill="#E8EAEE"
1911
- ></path>
1912
- <text
1913
- id="&lt;/null&gt;"
1914
- font-family="PingFangSC-Medium, PingFang SC"
1915
- font-size="15.1200003"
1916
- font-weight="400"
1917
- fill="#BCBECD"
1918
- >
1919
- <tspan x="33.6000008" y="32.8000004">&lt;/null&gt;</tspan>
1920
- </text>
1921
- <rect id="矩形" fill="#E8EAEE" x="27.5600006" y="52.0800012" width="61.4800014" height="5.04000011" rx="2.52000006"></rect>
1922
- <rect
1923
- id="矩形备份"
1924
- fill="#E8EAEE"
1925
- x="27.5600006"
1926
- y="63.8400014"
1927
- width="61.4800014"
1928
- height="5.04000011"
1929
- rx="2.52000006"
1930
- ></rect>
1931
- <path
1932
- d="M0,75.6000017 L29.280235,75.6000017 C32.0637502,75.6000017 34.3202352,77.8564866 34.3202352,80.6400018 L34.3202352,86.2591426 C34.3202352,89.0426578 36.5767201,91.2991427 39.3602353,91.2991427 L78.4136737,91.2991427 C81.1971889,91.2991427 83.4536738,89.0426578 83.4536738,86.2591426 L83.4536738,80.6400018 C83.4536738,77.8564866 85.7101587,75.6000017 88.4936739,75.6000017 L117.600003,75.6000017 L117.600003,75.6000017 L117.600003,110.880003 C117.600003,115.519195 113.839194,119.280003 109.200002,119.280003 L8.40000019,119.280003 C3.76080819,119.280003 -6.53729019e-15,115.519195 0,110.880003 L0,75.6000017 L0,75.6000017 Z"
1933
- id="矩形"
1934
- fill="#EDEFF2"
1935
- ></path>
1936
- </g>
1937
- </g>
1938
- </g>
1939
- </svg>`;
1940
- const icons = {
1941
- 'angle-right': angleRight,
1942
- 'angle-down': angleDown,
1943
- 'plus-square': plusSquare,
1944
- 'minus-square': minusSquare,
1945
- loading: loadingIcon,
1946
- empty: emptyIcon
1947
- };
1948
-
1949
- class GanttIconComponent {
1950
- constructor(elementRef) {
1951
- this.elementRef = elementRef;
1952
- this.isIcon = true;
1953
- }
1954
- set iconName(name) {
1955
- this.setSvg(name);
1956
- }
1957
- ngOnInit() { }
1958
- ngAfterViewInit() { }
1959
- setSvg(name) {
1960
- const iconSvg = icons[name];
1961
- if (iconSvg) {
1962
- this.elementRef.nativeElement.innerHTML = iconSvg;
1963
- }
1964
- else {
1965
- this.elementRef.nativeElement.innerHTML = '';
1966
- }
1967
- }
1968
- }
1969
- GanttIconComponent.decorators = [
1970
- { type: Component, args: [{
1971
- selector: 'gantt-icon',
1972
- template: ''
1973
- },] }
1974
- ];
1975
- GanttIconComponent.ctorParameters = () => [
1976
- { type: ElementRef }
1977
- ];
1978
- GanttIconComponent.propDecorators = {
1979
- isIcon: [{ type: HostBinding, args: ['class.gantt-icon',] }],
1980
- iconName: [{ type: Input }]
1981
- };
1982
-
1983
- class GanttDragBackdropComponent {
1984
- constructor() {
1985
- this.backdropClass = true;
1986
- }
1987
- ngOnInit() { }
1988
- }
1989
- GanttDragBackdropComponent.decorators = [
1990
- { type: Component, args: [{
1991
- selector: 'gantt-drag-backdrop',
1992
- template: "<div class=\"gantt-drag-mask\">\n <div class=\"date-range\">\n <span class=\"start\"></span>\n <span class=\"end\"></span>\n </div>\n</div>\n"
1993
- },] }
1994
- ];
1995
- GanttDragBackdropComponent.ctorParameters = () => [];
1996
- GanttDragBackdropComponent.propDecorators = {
1997
- backdropClass: [{ type: HostBinding, args: ['class.gantt-drag-backdrop',] }]
1998
- };
1999
-
2000
- var LinkColors;
2001
- (function (LinkColors) {
2002
- LinkColors["default"] = "#cacaca";
2003
- LinkColors["blocked"] = "#FF7575";
2004
- LinkColors["active"] = "#348FE4";
2005
- })(LinkColors || (LinkColors = {}));
2006
- class GanttLinksComponent {
2007
- constructor(ganttUpper, cdr, elementRef, ganttDragContainer) {
2008
- this.ganttUpper = ganttUpper;
2009
- this.cdr = cdr;
2010
- this.elementRef = elementRef;
2011
- this.ganttDragContainer = ganttDragContainer;
2012
- this.groups = [];
2013
- this.items = [];
2014
- this.lineClick = new EventEmitter();
2015
- this.links = [];
2016
- this.linkItems = [];
2017
- this.bezierWeight = -0.5;
2018
- this.firstChange = true;
2019
- this.unsubscribe$ = new Subject();
2020
- this.ganttLinksOverlay = true;
2021
- }
2022
- ngOnInit() {
2023
- this.buildLinks();
2024
- this.firstChange = false;
2025
- this.ganttDragContainer.dragStarted.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
2026
- this.elementRef.nativeElement.style.visibility = 'hidden';
2027
- });
2028
- merge(this.ganttUpper.viewChange, this.ganttUpper.expandChange, this.ganttUpper.view.start$, this.ganttUpper.dragEnded, this.ganttUpper.linkDragEnded)
2029
- .pipe(takeUntil(this.unsubscribe$), skip(1))
2030
- .subscribe(() => {
2031
- this.elementRef.nativeElement.style.visibility = 'visible';
2032
- this.buildLinks();
2033
- this.cdr.detectChanges();
2034
- });
2035
- }
2036
- ngOnChanges() {
2037
- if (!this.firstChange) {
2038
- this.buildLinks();
2039
- }
2040
- }
2041
- computeItemPosition() {
2042
- const lineHeight = this.ganttUpper.styles.lineHeight;
2043
- const barHeight = this.ganttUpper.styles.barHeight;
2044
- this.linkItems = [];
2045
- if (this.groups.length > 0) {
2046
- let itemNum = 0;
2047
- let groupNum = 0;
2048
- this.groups.forEach((group) => {
2049
- groupNum++;
2050
- if (group.expanded) {
2051
- const items = recursiveItems(group.items);
2052
- items.forEach((item, itemIndex) => {
2053
- const y = (groupNum + itemNum + itemIndex) * lineHeight + item.refs.y + barHeight / 2;
2054
- this.linkItems.push(Object.assign(Object.assign({}, item), { before: {
2055
- x: item.refs.x,
2056
- y
2057
- }, after: {
2058
- x: item.refs.x + item.refs.width,
2059
- y
2060
- } }));
2061
- });
2062
- itemNum += items.length;
2063
- }
2064
- });
2065
- }
2066
- else {
2067
- const items = recursiveItems(this.items);
2068
- items.forEach((item, itemIndex) => {
2069
- const y = itemIndex * lineHeight + item.refs.y + barHeight / 2;
2070
- this.linkItems.push(Object.assign(Object.assign({}, item), { before: {
2071
- x: item.refs.x,
2072
- y
2073
- }, after: {
2074
- x: item.refs.x + item.refs.width,
2075
- y
2076
- } }));
2077
- });
2078
- }
2079
- }
2080
- generatePath(source, target) {
2081
- if (source.before && source.after && target.before && target.after) {
2082
- const x1 = source.after.x;
2083
- const y1 = source.after.y;
2084
- const x4 = target.before.x;
2085
- const y4 = target.before.y;
2086
- const dx = Math.abs(x4 - x1) * this.bezierWeight;
2087
- const x2 = x1 - dx;
2088
- const x3 = x4 + dx;
2089
- const centerX = (x1 + x4) / 2;
2090
- const centerY = (y1 + y4) / 2;
2091
- let controlX = this.ganttUpper.styles.lineHeight / 2;
2092
- const controlY = this.ganttUpper.styles.lineHeight / 2;
2093
- if (x1 >= x4) {
2094
- if (y4 > y1) {
2095
- if (Math.abs(y4 - y1) <= this.ganttUpper.styles.lineHeight) {
2096
- return `M ${x1} ${y1}
2097
- C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 + controlX} ${x1} ${y1 + controlY}
2098
- L ${x1} ${y1 + controlY} ${centerX} ${centerY}
2099
-
2100
- M ${x4} ${y4}
2101
- C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 - controlX} ${x4} ${y4 - controlY}
2102
- L ${x4} ${y4 - controlY} ${centerX} ${centerY}`;
2103
- }
2104
- else {
2105
- controlX = this.ganttUpper.styles.lineHeight;
2106
- return `M ${x1} ${y1}
2107
- C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 + controlX} ${centerX} ${centerY}
2108
-
2109
-
2110
- M ${x4} ${y4}
2111
- C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 - controlX} ${centerX} ${centerY}`;
2112
- }
2113
- }
2114
- else {
2115
- if (Math.abs(y4 - y1) <= this.ganttUpper.styles.lineHeight) {
2116
- return `M ${x1} ${y1}
2117
- C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 - controlX} ${x1} ${y1 - controlY}
2118
- L ${x1} ${y1 - controlY} ${centerX} ${centerY}
2119
-
2120
- M ${x4} ${y4}
2121
- C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 + controlX} ${x4} ${y4 + controlY}
2122
- L ${x4} ${y4 + controlY} ${centerX} ${centerY}
2123
- `;
2124
- }
2125
- else {
2126
- controlX = this.ganttUpper.styles.lineHeight;
2127
- return `M ${x1} ${y1}
2128
- C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 - controlX} ${centerX} ${centerY}
2129
-
2130
- M ${x4} ${y4}
2131
- C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 + controlX} ${centerX} ${centerY}`;
2132
- }
2133
- }
2134
- }
2135
- return `M ${x1} ${y1} C ${x2} ${y1} ${x3} ${y4} ${x4} ${y4}`;
2136
- }
2137
- }
2138
- buildLinks() {
2139
- this.computeItemPosition();
2140
- this.links = [];
2141
- this.linkItems.forEach((source) => {
2142
- if (source.origin.start || source.origin.end) {
2143
- source.links.forEach((linkId) => {
2144
- const target = this.linkItems.find((item) => item.id === linkId);
2145
- if (target && (target.origin.start || target.origin.end)) {
2146
- this.links.push({
2147
- path: this.generatePath(source, target),
2148
- source: source.origin,
2149
- target: target.origin,
2150
- color: source.end.getTime() > target.start.getTime() ? LinkColors.blocked : LinkColors.default
2151
- });
2152
- }
2153
- });
2154
- }
2155
- });
2156
- }
2157
- trackBy(index) {
2158
- return index;
2159
- }
2160
- onLineClick(event, link) {
2161
- this.lineClick.emit({
2162
- event,
2163
- source: link.source,
2164
- target: link.target
2165
- });
2166
- }
2167
- mouseEnterPath(link) {
2168
- if (link.color === LinkColors.default) {
2169
- link.color = LinkColors.active;
2170
- }
2171
- }
2172
- mouseLeavePath(link) {
2173
- if (link.color === LinkColors.active) {
2174
- link.color = LinkColors.default;
2175
- }
2176
- }
2177
- ngOnDestroy() {
2178
- this.unsubscribe$.next();
2179
- this.unsubscribe$.complete();
2180
- }
2181
- }
2182
- GanttLinksComponent.decorators = [
2183
- { type: Component, args: [{
2184
- selector: 'gantt-links-overlay',
2185
- template: "<svg [attr.width]=\"ganttUpper.view.width\" class=\"gantt-links-overlay-main\">\n <ng-container *ngFor=\"let link of links; let i = index; trackBy: trackBy\">\n <path [attr.d]=\"link.path\" fill=\"transparent\" stroke-width=\"2\" [attr.stroke]=\"link.color\" pointer-events=\"none\"></path>\n <g>\n <path\n class=\"link-line\"\n (click)=\"onLineClick($event, link)\"\n (mouseenter)=\"mouseEnterPath(link)\"\n (mouseleave)=\"mouseLeavePath(link)\"\n [attr.d]=\"link.path\"\n stroke=\"transparent\"\n stroke-width=\"9\"\n fill=\"none\"\n cursor=\"pointer\"\n ></path>\n </g>\n </ng-container>\n <line class=\"link-dragging-line\"></line>\n</svg>\n"
2186
- },] }
2187
- ];
2188
- GanttLinksComponent.ctorParameters = () => [
2189
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] },
2190
- { type: ChangeDetectorRef },
2191
- { type: ElementRef },
2192
- { type: GanttDragContainer }
2193
- ];
2194
- GanttLinksComponent.propDecorators = {
2195
- groups: [{ type: Input }],
2196
- items: [{ type: Input }],
2197
- lineClick: [{ type: Output }],
2198
- ganttLinksOverlay: [{ type: HostBinding, args: ['class.gantt-links-overlay',] }]
2199
- };
2200
-
2201
- class GanttPrintService {
2202
- constructor() { }
2203
- setInlineStyles(targetElem) {
2204
- const svgElements = Array.from(targetElem.getElementsByTagName('svg'));
2205
- for (const svgElement of svgElements) {
2206
- this.recursElementChildren(svgElement);
2207
- }
2208
- }
2209
- recursElementChildren(node) {
2210
- const transformProperties = [
2211
- 'fill',
2212
- 'color',
2213
- 'font-size',
2214
- 'stroke',
2215
- 'font',
2216
- 'text-anchor',
2217
- 'stroke-dasharray',
2218
- 'shape-rendering',
2219
- 'stroke-width'
2220
- ];
2221
- if (!node.style) {
2222
- return;
2223
- }
2224
- const styles = getComputedStyle(node);
2225
- for (const transformProperty of transformProperties) {
2226
- node.style[transformProperty] = styles[transformProperty];
2227
- }
2228
- for (const child of Array.from(node.childNodes)) {
2229
- this.recursElementChildren(child);
2230
- }
2231
- }
2232
- register(root) {
2233
- this.root = root.nativeElement;
2234
- this.mainContainer = this.root.getElementsByClassName('gantt-main-container')[0];
2235
- }
2236
- print(name = 'download', ignoreElementClass) {
2237
- const root = this.root;
2238
- const mainContainer = this.mainContainer;
2239
- // set print width
2240
- const printWidth = root.offsetWidth;
2241
- // set print height
2242
- const printHeight = root.offsetHeight - mainContainer.offsetHeight + mainContainer.scrollHeight;
2243
- html2canvas(root, {
2244
- logging: false,
2245
- allowTaint: true,
2246
- useCORS: true,
2247
- width: printWidth,
2248
- height: printHeight,
2249
- ignoreElements: (element) => {
2250
- if (ignoreElementClass && element.classList.contains(ignoreElementClass)) {
2251
- return true;
2252
- }
2253
- if (element.classList.contains('gantt-calendar-today-overlay')) {
2254
- return true;
2255
- }
2256
- },
2257
- onclone: (cloneDocument) => {
2258
- const ganttClass = root.className;
2259
- const cloneGanttDom = cloneDocument.querySelector(`.${ganttClass.replace(/\s+/g, '.')}`);
2260
- const cloneGanttContainerDom = cloneDocument.querySelector('.gantt-container');
2261
- const cloneCalendarOverlay = cloneDocument.querySelector('.gantt-calendar-overlay-main');
2262
- const cloneLinksOverlay = cloneDocument.querySelector('.gantt-links-overlay-main');
2263
- // change targetDom width
2264
- cloneGanttDom.style.width = `${printWidth}px`;
2265
- cloneGanttDom.style.height = `${printHeight}px`;
2266
- cloneGanttDom.style.overflow = `unset`;
2267
- cloneGanttContainerDom.style.backgroundColor = '#fff';
2268
- cloneCalendarOverlay.setAttribute('height', `${printHeight}`);
2269
- cloneCalendarOverlay.setAttribute('style', `background: transparent`);
2270
- if (cloneLinksOverlay) {
2271
- cloneLinksOverlay.setAttribute('height', `${printHeight}`);
2272
- cloneLinksOverlay.setAttribute('style', `height: ${printHeight}px`);
2273
- }
2274
- // setInlineStyles for svg
2275
- this.setInlineStyles(cloneGanttDom);
2276
- }
2277
- }).then((canvas) => {
2278
- const link = document.createElement('a');
2279
- const dataUrl = canvas.toDataURL('image/png');
2280
- link.download = `${name}.png`;
2281
- link.href = dataUrl;
2282
- link.click();
2283
- });
2284
- }
2285
- }
2286
- GanttPrintService.decorators = [
2287
- { type: Injectable }
2288
- ];
2289
- GanttPrintService.ctorParameters = () => [];
2290
-
2291
- class NgxGanttRootComponent {
2292
- constructor(elementRef, ngZone, dom, dragContainer, ganttUpper, printService) {
2293
- this.elementRef = elementRef;
2294
- this.ngZone = ngZone;
2295
- this.dom = dom;
2296
- this.dragContainer = dragContainer;
2297
- this.ganttUpper = ganttUpper;
2298
- this.printService = printService;
2299
- this.ganttClass = true;
2300
- this.unsubscribe$ = new Subject();
2301
- this.ganttUpper.dragContainer = dragContainer;
2302
- }
2303
- get view() {
2304
- return this.ganttUpper.view;
2305
- }
2306
- ngOnInit() {
2307
- this.ngZone.onStable.pipe(take(1)).subscribe(() => {
2308
- this.dom.initialize(this.elementRef);
2309
- if (this.printService) {
2310
- this.printService.register(this.elementRef);
2311
- }
2312
- this.setupScrollClass();
2313
- this.setupResize();
2314
- this.setupViewScroll();
2315
- // 优化初始化时Scroll滚动体验问题,通过透明度解决,默认透明度为0,滚动结束后恢复
2316
- this.elementRef.nativeElement.style.opacity = '1';
2317
- this.ganttUpper.viewChange.pipe(startWith(null)).subscribe(() => {
2318
- this.scrollToToday();
2319
- });
2320
- });
2321
- }
2322
- setupViewScroll() {
2323
- if (this.ganttUpper.disabledLoadOnScroll) {
2324
- return;
2325
- }
2326
- this.dom
2327
- .getViewerScroll()
2328
- .pipe(takeUntil(this.unsubscribe$))
2329
- .subscribe((event) => {
2330
- if (event.direction === ScrollDirection.LEFT) {
2331
- const dates = this.view.addStartDate();
2332
- if (dates) {
2333
- event.target.scrollLeft += this.view.getDateRangeWidth(dates.start, dates.end);
2334
- this.ngZone.run(() => {
2335
- this.ganttUpper.loadOnScroll.emit({ start: dates.start.getUnixTime(), end: dates.end.getUnixTime() });
2336
- });
2337
- }
2338
- }
2339
- if (event.direction === ScrollDirection.RIGHT) {
2340
- const dates = this.view.addEndDate();
2341
- if (dates) {
2342
- this.ngZone.run(() => {
2343
- this.ganttUpper.loadOnScroll.emit({ start: dates.start.getUnixTime(), end: dates.end.getUnixTime() });
2344
- });
2345
- }
2346
- }
2347
- });
2348
- }
2349
- setupResize() {
2350
- this.dom
2351
- .getResize()
2352
- .pipe(takeUntil(this.unsubscribe$))
2353
- .subscribe(() => {
2354
- this.setupScrollClass();
2355
- });
2356
- }
2357
- setupScrollClass() {
2358
- const mainContainer = this.dom.mainContainer;
2359
- const height = mainContainer.offsetHeight;
2360
- const scrollHeight = mainContainer.scrollHeight;
2361
- if (scrollHeight > height) {
2362
- this.elementRef.nativeElement.className = 'gantt gantt-scroll';
2363
- }
2364
- else {
2365
- this.elementRef.nativeElement.className = 'gantt';
2366
- }
2367
- }
2368
- scrollToToday() {
2369
- const x = this.view.getTodayXPoint();
2370
- this.dom.scrollMainContainer(x);
2371
- }
2372
- }
2373
- NgxGanttRootComponent.decorators = [
2374
- { type: Component, args: [{
2375
- selector: 'ngx-gantt-root',
2376
- template: "<div class=\"gantt-side\" [style.width.px]=\"sideWidth\">\n <div class=\"gantt-side-container\">\n <ng-template [ngTemplateOutlet]=\"sideTemplate\"></ng-template>\n </div>\n</div>\n<div class=\"gantt-container\">\n <gantt-calendar-overlay></gantt-calendar-overlay>\n <gantt-drag-backdrop></gantt-drag-backdrop>\n <div class=\"gantt-main\">\n <ng-template [ngTemplateOutlet]=\"mainTemplate\"></ng-template>\n </div>\n</div>\n",
2377
- providers: [GanttDomService, GanttDragContainer]
2378
- },] }
2379
- ];
2380
- NgxGanttRootComponent.ctorParameters = () => [
2381
- { type: ElementRef },
2382
- { type: NgZone },
2383
- { type: GanttDomService },
2384
- { type: GanttDragContainer },
2385
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] },
2386
- { type: GanttPrintService, decorators: [{ type: Optional }] }
2387
- ];
2388
- NgxGanttRootComponent.propDecorators = {
2389
- sideWidth: [{ type: Input }],
2390
- ganttClass: [{ type: HostBinding, args: ['class.gantt',] }],
2391
- sideTemplate: [{ type: ContentChild, args: ['sideTemplate', { static: true },] }],
2392
- mainTemplate: [{ type: ContentChild, args: ['mainTemplate', { static: true },] }]
2393
- };
2394
-
2395
- class NgxGanttRangeComponent extends GanttItemUpper {
2396
- constructor(elementRef, ganttUpper) {
2397
- super(elementRef, ganttUpper);
2398
- this.ganttRangeClass = true;
2399
- }
2400
- ngOnInit() {
2401
- super.onInit();
2402
- }
2403
- ngOnChanges() {
2404
- super.onChanges();
2405
- }
2406
- ngOnDestroy() {
2407
- super.onDestroy();
2408
- }
2409
- }
2410
- NgxGanttRangeComponent.decorators = [
2411
- { type: Component, args: [{
2412
- selector: 'ngx-gantt-range,gantt-range',
2413
- template: "<ng-container *ngIf=\"item.start && item.end\">\n <div class=\"gantt-range-main\">\n <div class=\"gantt-range-main-progress\" *ngIf=\"item.progress >= 0\" [style.width.%]=\"item.progress * 100\"></div>\n </div>\n <div class=\"gantt-range-triangle left\"></div>\n <div class=\"gantt-range-triangle right\"></div>\n <ng-template [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"{ item: item.origin, refs: item.refs }\"></ng-template>\n</ng-container>\n"
2414
- },] }
2415
- ];
2416
- NgxGanttRangeComponent.ctorParameters = () => [
2417
- { type: ElementRef },
2418
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
2419
- ];
2420
- NgxGanttRangeComponent.propDecorators = {
2421
- ganttRangeClass: [{ type: HostBinding, args: ['class.gantt-range',] }]
2422
- };
2423
-
2424
- class IsGanttRangeItemPipe {
2425
- transform(value) {
2426
- return value === GanttItemType.range;
2427
- }
2428
- }
2429
- IsGanttRangeItemPipe.decorators = [
2430
- { type: Pipe, args: [{
2431
- name: 'isGanttRangeItem'
2432
- },] }
2433
- ];
2434
- class IsGanttBarItemPipe {
2435
- transform(value) {
2436
- return value === GanttItemType.bar;
2437
- }
2438
- }
2439
- IsGanttBarItemPipe.decorators = [
2440
- { type: Pipe, args: [{
2441
- name: 'isGanttBarItem'
2442
- },] }
2443
- ];
2444
- class IsGanttCustomItemPipe {
2445
- transform(value) {
2446
- return value === GanttItemType.custom;
2447
- }
2448
- }
2449
- IsGanttCustomItemPipe.decorators = [
2450
- { type: Pipe, args: [{
2451
- name: 'isGanttCustomItem'
2452
- },] }
2453
- ];
2454
-
2455
- class NgxGanttModule {
2456
- }
2457
- NgxGanttModule.decorators = [
2458
- { type: NgModule, args: [{
2459
- imports: [CommonModule, DragDropModule],
2460
- exports: [NgxGanttComponent, NgxGanttTableComponent, NgxGanttTableColumnComponent, NgxGanttRootComponent, NgxGanttBarComponent],
2461
- declarations: [
2462
- NgxGanttComponent,
2463
- NgxGanttTableComponent,
2464
- NgxGanttTableColumnComponent,
2465
- GanttTableComponent,
2466
- GanttMainComponent,
2467
- GanttCalendarComponent,
2468
- GanttLinksComponent,
2469
- NgxGanttBarComponent,
2470
- GanttIconComponent,
2471
- GanttDragBackdropComponent,
2472
- NgxGanttRangeComponent,
2473
- NgxGanttRootComponent,
2474
- IsGanttRangeItemPipe,
2475
- IsGanttBarItemPipe,
2476
- IsGanttCustomItemPipe
2477
- ],
2478
- providers: []
2479
- },] }
2480
- ];
2481
-
2482
- /*
2483
- * Public API Surface of gantt
2484
- */
2485
-
2486
- /**
2487
- * Generated bundle index. Do not edit.
2488
- */
2489
-
2490
- export { GANTT_UPPER_TOKEN, GanttBarClickEvent, GanttDate, GanttDatePoint, GanttDragEvent, GanttGroupInternal, GanttItemInternal, GanttItemType, GanttItemUpper, GanttLineClickEvent, GanttLinkDragEvent, GanttLoadOnScrollEvent, GanttPrintService, GanttTableEvent, GanttUpper, GanttView, GanttViewType, IsGanttBarItemPipe, IsGanttCustomItemPipe, IsGanttRangeItemPipe, NgxGanttComponent, NgxGanttModule, NgxGanttRootComponent, NgxGanttTableColumnComponent, NgxGanttTableComponent, defaultColumnWidth, minColumnWidth, primaryDatePointTop, secondaryDatePointTop, GanttDomService as ɵa, GanttDragContainer as ɵb, NgxGanttBarComponent as ɵc, GanttBarDrag as ɵd, GanttTableComponent as ɵe, GanttMainComponent as ɵf, GanttCalendarComponent as ɵg, GanttLinksComponent as ɵh, GanttIconComponent as ɵi, GanttDragBackdropComponent as ɵj, NgxGanttRangeComponent as ɵk };
2491
- //# sourceMappingURL=worktile-gantt.js.map