@worktile/gantt 12.0.1 → 12.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/README.md +13 -116
  2. package/bundles/worktile-gantt.umd.js +3303 -0
  3. package/bundles/worktile-gantt.umd.js.map +1 -0
  4. package/class/date-point.d.ts +15 -0
  5. package/{packages/gantt/src/class/event.ts → class/event.d.ts} +6 -12
  6. package/class/group.d.ts +22 -0
  7. package/{packages/gantt/src/class/index.ts → class/index.d.ts} +0 -0
  8. package/class/item.d.ts +70 -0
  9. package/class/view-type.d.ts +7 -0
  10. package/components/bar/bar-drag.d.ts +37 -0
  11. package/components/bar/bar.component.d.ts +26 -0
  12. package/components/calendar/calendar.component.d.ts +28 -0
  13. package/components/drag-backdrop/drag-backdrop.component.d.ts +9 -0
  14. package/components/icon/icon.component.d.ts +13 -0
  15. package/components/icon/icons.d.ts +8 -0
  16. package/components/links/links.component.d.ts +47 -0
  17. package/components/main/gantt-main.component.d.ts +21 -0
  18. package/components/range/range.component.d.ts +13 -0
  19. package/components/table/gantt-table.component.d.ts +36 -0
  20. package/esm2015/class/date-point.js +10 -0
  21. package/esm2015/class/event.js +13 -0
  22. package/esm2015/class/group.js +17 -0
  23. package/esm2015/class/index.js +6 -0
  24. package/esm2015/class/item.js +78 -0
  25. package/esm2015/class/view-type.js +9 -0
  26. package/esm2015/components/bar/bar-drag.js +264 -0
  27. package/esm2015/components/bar/bar.component.js +98 -0
  28. package/esm2015/components/calendar/calendar.component.js +86 -0
  29. package/esm2015/components/drag-backdrop/drag-backdrop.component.js +21 -0
  30. package/esm2015/components/icon/icon.component.js +38 -0
  31. package/esm2015/components/icon/icons.js +87 -0
  32. package/esm2015/components/links/links.component.js +213 -0
  33. package/esm2015/components/main/gantt-main.component.js +53 -0
  34. package/esm2015/components/range/range.component.js +37 -0
  35. package/esm2015/components/table/gantt-table.component.js +146 -0
  36. package/esm2015/gantt-abstract.js +3 -0
  37. package/esm2015/gantt-dom.service.js +103 -0
  38. package/esm2015/gantt-drag-container.js +59 -0
  39. package/esm2015/gantt-item-upper.js +58 -0
  40. package/esm2015/gantt-print.service.js +94 -0
  41. package/esm2015/gantt-upper.js +254 -0
  42. package/esm2015/gantt.component.js +131 -0
  43. package/esm2015/gantt.module.js +74 -0
  44. package/esm2015/gantt.pipe.js +43 -0
  45. package/esm2015/gantt.styles.js +15 -0
  46. package/esm2015/public-api.js +18 -0
  47. package/esm2015/root.component.js +123 -0
  48. package/esm2015/table/gantt-column.component.js +37 -0
  49. package/esm2015/table/gantt-table.component.js +20 -0
  50. package/esm2015/utils/date.js +160 -0
  51. package/esm2015/utils/helpers.js +55 -0
  52. package/esm2015/views/day.js +54 -0
  53. package/esm2015/views/factory.js +23 -0
  54. package/esm2015/views/month.js +48 -0
  55. package/esm2015/views/quarter.js +51 -0
  56. package/esm2015/views/view.js +121 -0
  57. package/esm2015/views/week.js +49 -0
  58. package/esm2015/views/year.js +50 -0
  59. package/esm2015/worktile-gantt.js +5 -0
  60. package/fesm2015/worktile-gantt.js +2637 -0
  61. package/fesm2015/worktile-gantt.js.map +1 -0
  62. package/{packages/gantt/src/gantt-abstract.ts → gantt-abstract.d.ts} +1 -3
  63. package/gantt-dom.service.d.ts +32 -0
  64. package/gantt-drag-container.d.ts +23 -0
  65. package/gantt-item-upper.d.ts +20 -0
  66. package/gantt-print.service.d.ts +13 -0
  67. package/gantt-upper.d.ts +64 -0
  68. package/gantt.component.d.ts +29 -0
  69. package/gantt.module.d.ts +21 -0
  70. package/gantt.pipe.d.ts +18 -0
  71. package/gantt.styles.d.ts +15 -0
  72. package/main.bundle.scss +645 -0
  73. package/package.json +16 -113
  74. package/{packages/gantt/src/public-api.ts → public-api.d.ts} +0 -4
  75. package/root.component.d.ts +28 -0
  76. package/table/gantt-column.component.d.ts +15 -0
  77. package/table/gantt-table.component.d.ts +10 -0
  78. package/utils/date.d.ts +59 -0
  79. package/utils/helpers.d.ts +12 -0
  80. package/views/day.d.ts +14 -0
  81. package/views/factory.d.ts +8 -0
  82. package/views/month.d.ts +12 -0
  83. package/views/quarter.d.ts +12 -0
  84. package/views/view.d.ts +56 -0
  85. package/views/week.d.ts +12 -0
  86. package/views/year.d.ts +12 -0
  87. package/worktile-gantt.d.ts +5 -0
  88. package/.all-contributorsrc +0 -53
  89. package/.angulardoc.json +0 -4
  90. package/.circleci/config.yml +0 -17
  91. package/.coveralls.yml +0 -1
  92. package/.docgenirc.js +0 -64
  93. package/.editorconfig +0 -22
  94. package/.prettierrc +0 -24
  95. package/.travis.yml +0 -23
  96. package/CHANGELOG.md +0 -564
  97. package/Dockerfile +0 -4
  98. package/LICENSE +0 -21
  99. package/angular.json +0 -136
  100. package/docs/guides/basic/components.md +0 -54
  101. package/docs/guides/basic/event.md +0 -70
  102. package/docs/guides/basic/index.md +0 -4
  103. package/docs/guides/basic/style.md +0 -68
  104. package/docs/guides/basic/type.md +0 -70
  105. package/docs/guides/basic/usage.md +0 -189
  106. package/docs/guides/index.md +0 -5
  107. package/docs/guides/intro/getting-started.md +0 -79
  108. package/docs/guides/intro/index.md +0 -51
  109. package/docs/index.md +0 -0
  110. package/example/browserslist +0 -12
  111. package/example/src/app/app-routing.module.ts +0 -26
  112. package/example/src/app/app.component.html +0 -2
  113. package/example/src/app/app.component.ts +0 -11
  114. package/example/src/app/app.module.ts +0 -57
  115. package/example/src/app/components/components.component.html +0 -6
  116. package/example/src/app/components/components.component.ts +0 -33
  117. package/example/src/app/configuration/parameters/api/zh-cn.js +0 -350
  118. package/example/src/app/configuration/parameters/doc/zh-cn.md +0 -5
  119. package/example/src/app/gantt/gantt.component.html +0 -51
  120. package/example/src/app/gantt/gantt.component.ts +0 -119
  121. package/example/src/app/gantt-advanced/component/flat.component.html +0 -30
  122. package/example/src/app/gantt-advanced/component/flat.component.ts +0 -72
  123. package/example/src/app/gantt-advanced/component/flat.scss +0 -31
  124. package/example/src/app/gantt-advanced/gantt-advanced.component.html +0 -32
  125. package/example/src/app/gantt-advanced/gantt-advanced.component.ts +0 -34
  126. package/example/src/app/gantt-advanced/mocks.ts +0 -158
  127. package/example/src/app/gantt-groups/gantt-groups.component.html +0 -42
  128. package/example/src/app/gantt-groups/gantt-groups.component.ts +0 -62
  129. package/example/src/app/gantt-range/gantt-range.component.html +0 -66
  130. package/example/src/app/gantt-range/gantt-range.component.ts +0 -67
  131. package/example/src/app/gantt-range/mocks.ts +0 -150
  132. package/example/src/app/helper.ts +0 -38
  133. package/example/src/assets/.gitkeep +0 -0
  134. package/example/src/environments/environment.prod.ts +0 -3
  135. package/example/src/environments/environment.ts +0 -16
  136. package/example/src/favicon.ico +0 -0
  137. package/example/src/index.html +0 -13
  138. package/example/src/main.ts +0 -12
  139. package/example/src/polyfills.ts +0 -63
  140. package/example/src/styles.scss +0 -56
  141. package/example/tsconfig.app.json +0 -18
  142. package/nginx.conf +0 -17
  143. package/packages/gantt/README.md +0 -24
  144. package/packages/gantt/karma.conf.js +0 -46
  145. package/packages/gantt/ng-package.json +0 -7
  146. package/packages/gantt/ng-package.prod.json +0 -7
  147. package/packages/gantt/package.json +0 -16
  148. package/packages/gantt/src/class/date-point.ts +0 -14
  149. package/packages/gantt/src/class/group.ts +0 -36
  150. package/packages/gantt/src/class/item.ts +0 -129
  151. package/packages/gantt/src/class/test/group.spec.ts +0 -21
  152. package/packages/gantt/src/class/test/item.spec.ts +0 -102
  153. package/packages/gantt/src/class/view-type.ts +0 -7
  154. package/packages/gantt/src/components/bar/bar-drag.ts +0 -298
  155. package/packages/gantt/src/components/bar/bar.component.html +0 -17
  156. package/packages/gantt/src/components/bar/bar.component.scss +0 -169
  157. package/packages/gantt/src/components/bar/bar.component.ts +0 -109
  158. package/packages/gantt/src/components/bar/test/bar.component.spec.ts +0 -54
  159. package/packages/gantt/src/components/bar/test/bar.drag.spec.ts +0 -196
  160. package/packages/gantt/src/components/calendar/calendar.component.html +0 -52
  161. package/packages/gantt/src/components/calendar/calendar.component.scss +0 -77
  162. package/packages/gantt/src/components/calendar/calendar.component.ts +0 -100
  163. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.html +0 -6
  164. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.scss +0 -48
  165. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.ts +0 -13
  166. package/packages/gantt/src/components/icon/icon.component.scss +0 -13
  167. package/packages/gantt/src/components/icon/icon.component.ts +0 -28
  168. package/packages/gantt/src/components/icon/icons.ts +0 -86
  169. package/packages/gantt/src/components/links/links.component.html +0 -19
  170. package/packages/gantt/src/components/links/links.component.scss +0 -27
  171. package/packages/gantt/src/components/links/links.component.ts +0 -263
  172. package/packages/gantt/src/components/main/gantt-main.component.html +0 -35
  173. package/packages/gantt/src/components/main/gantt-main.component.ts +0 -35
  174. package/packages/gantt/src/components/range/range.component.html +0 -8
  175. package/packages/gantt/src/components/range/range.component.scss +0 -35
  176. package/packages/gantt/src/components/range/range.component.ts +0 -27
  177. package/packages/gantt/src/components/range/test/range.component.spec.ts +0 -80
  178. package/packages/gantt/src/components/table/gantt-table.component.html +0 -105
  179. package/packages/gantt/src/components/table/gantt-table.component.scss +0 -144
  180. package/packages/gantt/src/components/table/gantt-table.component.ts +0 -166
  181. package/packages/gantt/src/components/table/test/table.spec.ts +0 -129
  182. package/packages/gantt/src/gantt-dom.service.ts +0 -134
  183. package/packages/gantt/src/gantt-drag-container.ts +0 -73
  184. package/packages/gantt/src/gantt-item-upper.ts +0 -50
  185. package/packages/gantt/src/gantt-print.service.ts +0 -104
  186. package/packages/gantt/src/gantt-upper.ts +0 -289
  187. package/packages/gantt/src/gantt.component.html +0 -18
  188. package/packages/gantt/src/gantt.component.scss +0 -77
  189. package/packages/gantt/src/gantt.component.ts +0 -134
  190. package/packages/gantt/src/gantt.module.ts +0 -47
  191. package/packages/gantt/src/gantt.pipe.ts +0 -31
  192. package/packages/gantt/src/gantt.styles.ts +0 -28
  193. package/packages/gantt/src/root.component.html +0 -12
  194. package/packages/gantt/src/root.component.ts +0 -121
  195. package/packages/gantt/src/styles/index.scss +0 -9
  196. package/packages/gantt/src/styles/variables.scss +0 -46
  197. package/packages/gantt/src/table/gantt-column.component.ts +0 -25
  198. package/packages/gantt/src/table/gantt-table.component.ts +0 -14
  199. package/packages/gantt/src/table/test/table.spec.ts +0 -56
  200. package/packages/gantt/src/test/gantt.component.spec.ts +0 -404
  201. package/packages/gantt/src/test/mocks/data.ts +0 -303
  202. package/packages/gantt/src/test.ts +0 -21
  203. package/packages/gantt/src/utils/date.ts +0 -276
  204. package/packages/gantt/src/utils/helpers.ts +0 -66
  205. package/packages/gantt/src/utils/test/date.spec.ts +0 -105
  206. package/packages/gantt/src/utils/test/helpers.spec.ts +0 -73
  207. package/packages/gantt/src/utils/testing.ts +0 -64
  208. package/packages/gantt/src/views/day.ts +0 -74
  209. package/packages/gantt/src/views/factory.ts +0 -25
  210. package/packages/gantt/src/views/month.ts +0 -66
  211. package/packages/gantt/src/views/quarter.ts +0 -68
  212. package/packages/gantt/src/views/test/day.spec.ts +0 -45
  213. package/packages/gantt/src/views/test/factory.spec.ts +0 -41
  214. package/packages/gantt/src/views/test/mock.ts +0 -14
  215. package/packages/gantt/src/views/test/month.spec.ts +0 -45
  216. package/packages/gantt/src/views/test/quarter.spec.ts +0 -45
  217. package/packages/gantt/src/views/test/view.spec.ts +0 -144
  218. package/packages/gantt/src/views/test/week.spec.ts +0 -45
  219. package/packages/gantt/src/views/test/year.spec.ts +0 -45
  220. package/packages/gantt/src/views/view.ts +0 -186
  221. package/packages/gantt/src/views/week.ts +0 -66
  222. package/packages/gantt/src/views/year.ts +0 -62
  223. package/packages/gantt/tsconfig.lib.json +0 -20
  224. package/packages/gantt/tsconfig.lib.prod.json +0 -9
  225. package/packages/gantt/tsconfig.schematics.json +0 -25
  226. package/packages/gantt/tsconfig.spec.json +0 -17
  227. package/packages/gantt/tslint.json +0 -18
  228. package/scss-bundle.config.json +0 -7
  229. package/tsconfig.json +0 -26
  230. package/tslint.json +0 -51
@@ -1,134 +0,0 @@
1
- import { Injectable, ElementRef, OnDestroy } from '@angular/core';
2
- import { fromEvent, Subject, merge } from 'rxjs';
3
- import { pairwise, map, auditTime, takeUntil, take, startWith } from 'rxjs/operators';
4
- import { isNumber } from './utils/helpers';
5
-
6
- const scrollThreshold = 50;
7
-
8
- export enum ScrollDirection {
9
- NONE,
10
- LEFT,
11
- RIGHT
12
- }
13
-
14
- export interface ScrollEvent {
15
- target: Element;
16
- direction: ScrollDirection;
17
- }
18
-
19
- @Injectable()
20
- export class GanttDomService implements OnDestroy {
21
- public root: Element;
22
-
23
- public side: Element;
24
-
25
- public container: Element;
26
-
27
- public sideContainer: Element;
28
-
29
- public mainContainer: Element;
30
-
31
- public calendarOverlay: Element;
32
-
33
- public linksOverlay: Element;
34
-
35
- private unsubscribe$ = new Subject<void>();
36
-
37
- constructor() {}
38
-
39
- private monitorScrollChange() {
40
- merge(fromEvent(this.mainContainer, 'scroll'), fromEvent(this.sideContainer, 'scroll'))
41
- .pipe(takeUntil(this.unsubscribe$))
42
- .subscribe((event) => {
43
- this.syncScroll(event);
44
- });
45
-
46
- fromEvent(this.mainContainer, 'scroll')
47
- .pipe(startWith(), takeUntil(this.unsubscribe$))
48
- .subscribe((event) => {
49
- // if (this.mainContainer.scrollLeft > 0) {
50
- // this.side.classList.add('gantt-side-has-shadow');
51
- // } else {
52
- // this.side.classList.remove('gantt-side-has-shadow');
53
- // }
54
- });
55
- }
56
-
57
- private syncScroll(event: Event) {
58
- const target = event.currentTarget as HTMLElement;
59
- this.calendarOverlay.scrollLeft = this.mainContainer.scrollLeft;
60
-
61
- this.sideContainer.scrollTop = target.scrollTop;
62
- this.mainContainer.scrollTop = target.scrollTop;
63
- }
64
-
65
- private disableBrowserWheelEvent() {
66
- const container = this.mainContainer as HTMLElement;
67
- fromEvent(container, 'wheel')
68
- .pipe(takeUntil(this.unsubscribe$))
69
- .subscribe((event: WheelEvent) => {
70
- const delta = event.deltaX;
71
- if (!delta) {
72
- return;
73
- }
74
- if (
75
- (container.scrollLeft + container.offsetWidth === container.scrollWidth && delta > 0) ||
76
- (container.scrollLeft === 0 && delta < 0)
77
- ) {
78
- event.preventDefault();
79
- }
80
- });
81
- }
82
-
83
- initialize(root: ElementRef<HTMLElement>) {
84
- this.root = root.nativeElement;
85
- this.side = this.root.getElementsByClassName('gantt-side')[0];
86
- this.container = this.root.getElementsByClassName('gantt-container')[0];
87
- this.sideContainer = this.root.getElementsByClassName('gantt-side-container')[0];
88
- this.mainContainer = this.root.getElementsByClassName('gantt-main-container')[0];
89
- this.calendarOverlay = this.root.getElementsByClassName('gantt-calendar-overlay')[0];
90
- this.monitorScrollChange();
91
- this.disableBrowserWheelEvent();
92
- }
93
-
94
- getViewerScroll() {
95
- return fromEvent<Event>(this.mainContainer, 'scroll').pipe(
96
- map(() => this.mainContainer.scrollLeft),
97
- pairwise(),
98
- map(([previous, current]) => {
99
- const event: ScrollEvent = {
100
- target: this.mainContainer,
101
- direction: ScrollDirection.NONE
102
- };
103
- if (current - previous < 0) {
104
- if (this.mainContainer.scrollLeft < scrollThreshold && this.mainContainer.scrollLeft > 0) {
105
- event.direction = ScrollDirection.LEFT;
106
- }
107
- }
108
- if (current - previous > 0) {
109
- if (this.mainContainer.scrollWidth - this.mainContainer.clientWidth - this.mainContainer.scrollLeft < scrollThreshold) {
110
- event.direction = ScrollDirection.RIGHT;
111
- }
112
- }
113
- return event;
114
- })
115
- );
116
- }
117
-
118
- getResize() {
119
- return fromEvent(window, 'resize').pipe(auditTime(150));
120
- }
121
-
122
- scrollMainContainer(left: number) {
123
- if (isNumber(left)) {
124
- const scrollLeft = left - this.mainContainer.clientWidth / 2;
125
- this.mainContainer.scrollLeft = scrollLeft > scrollThreshold ? scrollLeft : 0;
126
- this.calendarOverlay.scrollLeft = this.mainContainer.scrollLeft;
127
- }
128
- }
129
-
130
- ngOnDestroy() {
131
- this.unsubscribe$.next();
132
- this.unsubscribe$.complete();
133
- }
134
- }
@@ -1,73 +0,0 @@
1
- import { Injectable, EventEmitter } from '@angular/core';
2
- import { GanttDragEvent, GanttLinkDragEvent } from './class/event';
3
- import { GanttItemInternal } from './class/item';
4
-
5
- export type LinkDragFrom = 'source' | 'target';
6
-
7
- @Injectable()
8
- export class GanttDragContainer {
9
- dragStarted = new EventEmitter<GanttDragEvent>();
10
-
11
- dragEnded = new EventEmitter<GanttDragEvent>();
12
-
13
- linkDragStarted = new EventEmitter<GanttLinkDragEvent>();
14
-
15
- linkDragEntered = new EventEmitter<GanttLinkDragEvent>();
16
-
17
- linkDragEnded = new EventEmitter<GanttLinkDragEvent>();
18
-
19
- linkDraggingId: string;
20
-
21
- private linkDragSource: GanttItemInternal;
22
-
23
- private linkDragTarget: GanttItemInternal;
24
-
25
- private linkDragFrom: LinkDragFrom;
26
-
27
- constructor() {}
28
-
29
- emitLinkDragStarted(from: LinkDragFrom, item: GanttItemInternal) {
30
- this.linkDraggingId = item.id;
31
- this.linkDragFrom = from;
32
- this.linkDragSource = this.linkDragFrom === 'source' ? item : null;
33
- this.linkDragTarget = this.linkDragFrom === 'target' ? item : null;
34
- this.linkDragStarted.emit({
35
- source: this.linkDragSource && this.linkDragSource.origin,
36
- target: this.linkDragTarget && this.linkDragTarget.origin
37
- });
38
- }
39
-
40
- emitLinkDragEntered(item: GanttItemInternal) {
41
- if (this.linkDragFrom === 'source') {
42
- this.linkDragTarget = item;
43
- } else {
44
- this.linkDragSource = item;
45
- }
46
- this.linkDragEntered.emit({
47
- source: this.linkDragSource.origin,
48
- target: this.linkDragTarget.origin
49
- });
50
- }
51
-
52
- emitLinkDragLeaved() {
53
- if (this.linkDragFrom === 'source') {
54
- this.linkDragTarget = null;
55
- } else {
56
- this.linkDragSource = null;
57
- }
58
- }
59
-
60
- emitLinkDragEnded() {
61
- this.linkDraggingId = null;
62
- if (this.linkDragSource && this.linkDragTarget) {
63
- this.linkDragSource.addLink(this.linkDragTarget.id);
64
-
65
- this.linkDragEnded.emit({
66
- source: this.linkDragSource.origin,
67
- target: this.linkDragTarget.origin
68
- });
69
- }
70
- this.linkDragSource = null;
71
- this.linkDragTarget = null;
72
- }
73
- }
@@ -1,50 +0,0 @@
1
- import { Input, ElementRef, Inject, TemplateRef, Directive } from '@angular/core';
2
- import { GanttItemInternal, GanttItemType } from './class';
3
- import { Subject } from 'rxjs';
4
- import { takeUntil } from 'rxjs/operators';
5
- import { rangeHeight } from './gantt.styles';
6
- import { GANTT_UPPER_TOKEN, GanttUpper } from './gantt-upper';
7
-
8
- @Directive()
9
- export abstract class GanttItemUpper {
10
- @Input() template: TemplateRef<any>;
11
-
12
- @Input() item: GanttItemInternal;
13
-
14
- public firstChange = true;
15
-
16
- public unsubscribe$ = new Subject();
17
-
18
- constructor(protected elementRef: ElementRef<HTMLElement>, @Inject(GANTT_UPPER_TOKEN) protected ganttUpper: GanttUpper) {}
19
-
20
- onInit() {
21
- this.firstChange = false;
22
- this.item.refs$.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
23
- this.setPositions();
24
- });
25
- }
26
-
27
- onChanges(): void {
28
- if (!this.firstChange) {
29
- this.setPositions();
30
- }
31
- }
32
-
33
- private setPositions() {
34
- const itemElement = this.elementRef.nativeElement;
35
- itemElement.style.left = this.item.refs.x + 'px';
36
- itemElement.style.top = this.item.refs.y + 'px';
37
- itemElement.style.width = this.item.refs.width + 'px';
38
- if (this.item.type === GanttItemType.bar) {
39
- itemElement.style.height = this.ganttUpper.styles.barHeight + 'px';
40
- } else if (this.item.type === GanttItemType.range) {
41
- itemElement.style.height = rangeHeight + 'px';
42
- } else {
43
- }
44
- }
45
-
46
- onDestroy() {
47
- this.unsubscribe$.next();
48
- this.unsubscribe$.complete();
49
- }
50
- }
@@ -1,104 +0,0 @@
1
- import { Injectable, ElementRef } from '@angular/core';
2
- import html2canvas from 'html2canvas';
3
-
4
- @Injectable()
5
- export class GanttPrintService {
6
- private root: HTMLElement;
7
-
8
- private mainContainer: HTMLElement;
9
-
10
- constructor() {}
11
-
12
- private setInlineStyles(targetElem: Element) {
13
- const svgElements = Array.from(targetElem.getElementsByTagName('svg'));
14
- for (const svgElement of svgElements) {
15
- this.recursElementChildren(svgElement);
16
- }
17
- }
18
-
19
- private recursElementChildren(node: SVGSVGElement | HTMLElement) {
20
- const transformProperties = [
21
- 'fill',
22
- 'color',
23
- 'font-size',
24
- 'stroke',
25
- 'font',
26
- 'text-anchor',
27
- 'stroke-dasharray',
28
- 'shape-rendering',
29
- 'stroke-width'
30
- ];
31
- if (!node.style) {
32
- return;
33
- }
34
- const styles = getComputedStyle(node);
35
- for (const transformProperty of transformProperties) {
36
- node.style[transformProperty] = styles[transformProperty];
37
- }
38
- for (const child of Array.from(node.childNodes)) {
39
- this.recursElementChildren(child as SVGSVGElement);
40
- }
41
- }
42
-
43
- register(root: ElementRef<HTMLElement>) {
44
- this.root = root.nativeElement;
45
- this.mainContainer = this.root.getElementsByClassName('gantt-main-container')[0] as HTMLElement;
46
- }
47
-
48
- print(name: string = 'download', ignoreElementClass?: string) {
49
- const root = this.root as HTMLElement;
50
-
51
- const mainContainer = this.mainContainer as HTMLElement;
52
- // set print width
53
- const printWidth = root.offsetWidth;
54
-
55
- // set print height
56
- const printHeight = root.offsetHeight - mainContainer.offsetHeight + mainContainer.scrollHeight;
57
-
58
- html2canvas(root, {
59
- logging: false,
60
- allowTaint: true,
61
- useCORS: true,
62
- width: printWidth,
63
- height: printHeight,
64
- ignoreElements: (element) => {
65
- if (ignoreElementClass && element.classList.contains(ignoreElementClass)) {
66
- return true;
67
- }
68
- if (element.classList.contains('gantt-calendar-today-overlay')) {
69
- return true;
70
- }
71
- },
72
-
73
- onclone: (cloneDocument: Document) => {
74
- const ganttClass = root.className;
75
- const cloneGanttDom = cloneDocument.querySelector(`.${ganttClass.replace(/\s+/g, '.')}`) as HTMLElement;
76
- const cloneGanttContainerDom = cloneDocument.querySelector('.gantt-container') as HTMLElement;
77
- const cloneCalendarOverlay = cloneDocument.querySelector('.gantt-calendar-overlay-main') as HTMLElement;
78
- const cloneLinksOverlay = cloneDocument.querySelector('.gantt-links-overlay-main') as HTMLElement;
79
-
80
- // change targetDom width
81
- cloneGanttDom.style.width = `${printWidth}px`;
82
- cloneGanttDom.style.height = `${printHeight}px`;
83
- cloneGanttDom.style.overflow = `unset`;
84
- cloneGanttContainerDom.style.backgroundColor = '#fff';
85
- cloneCalendarOverlay.setAttribute('height', `${printHeight}`);
86
- cloneCalendarOverlay.setAttribute('style', `background: transparent`);
87
-
88
- if (cloneLinksOverlay) {
89
- cloneLinksOverlay.setAttribute('height', `${printHeight}`);
90
- cloneLinksOverlay.setAttribute('style', `height: ${printHeight}px`);
91
- }
92
-
93
- // setInlineStyles for svg
94
- this.setInlineStyles(cloneGanttDom);
95
- }
96
- }).then((canvas: HTMLCanvasElement) => {
97
- const link = document.createElement('a');
98
- const dataUrl = canvas.toDataURL('image/png');
99
- link.download = `${name}.png`;
100
- link.href = dataUrl;
101
- link.click();
102
- });
103
- }
104
- }
@@ -1,289 +0,0 @@
1
- import {
2
- Input,
3
- TemplateRef,
4
- Output,
5
- EventEmitter,
6
- ContentChild,
7
- ElementRef,
8
- HostBinding,
9
- ChangeDetectorRef,
10
- NgZone,
11
- SimpleChanges,
12
- InjectionToken,
13
- Directive
14
- } from '@angular/core';
15
- import { Subject } from 'rxjs';
16
- import { takeUntil, take, skip } from 'rxjs/operators';
17
- import {
18
- GanttItem,
19
- GanttGroup,
20
- GanttViewType,
21
- GanttLoadOnScrollEvent,
22
- GanttDragEvent,
23
- GanttGroupInternal,
24
- GanttItemInternal,
25
- GanttBarClickEvent,
26
- GanttLinkDragEvent
27
- } from './class';
28
- import { GanttView, GanttViewOptions } from './views/view';
29
- import { createViewFactory } from './views/factory';
30
- import { GanttDate } from './utils/date';
31
- import { GanttStyles, defaultStyles } from './gantt.styles';
32
- import { uniqBy, flatten, recursiveItems, getFlatItems } from './utils/helpers';
33
- import { GanttDragContainer } from './gantt-drag-container';
34
-
35
- @Directive()
36
- export abstract class GanttUpper {
37
- @Input('items') originItems: GanttItem[] = [];
38
-
39
- @Input('groups') originGroups: GanttGroup[] = [];
40
-
41
- @Input() viewType: GanttViewType = GanttViewType.month;
42
-
43
- @Input() start: number;
44
-
45
- @Input() end: number;
46
-
47
- @Input() showTodayLine = true;
48
-
49
- @Input() draggable: boolean;
50
-
51
- @Input() styles: GanttStyles;
52
-
53
- @Input() viewOptions: GanttViewOptions;
54
-
55
- @Input() disabledLoadOnScroll: boolean;
56
-
57
- @Output() loadOnScroll = new EventEmitter<GanttLoadOnScrollEvent>();
58
-
59
- @Output() dragStarted = new EventEmitter<GanttDragEvent>();
60
-
61
- @Output() dragEnded = new EventEmitter<GanttDragEvent>();
62
-
63
- @Output() barClick = new EventEmitter<GanttBarClickEvent>();
64
-
65
- @ContentChild('bar', { static: true }) barTemplate: TemplateRef<any>;
66
-
67
- @ContentChild('range', { static: true }) rangeTemplate: TemplateRef<any>;
68
-
69
- @ContentChild('item', { static: true }) itemTemplate: TemplateRef<any>;
70
-
71
- @ContentChild('group', { static: true }) groupTemplate: TemplateRef<any>;
72
-
73
- @ContentChild('groupHeader', { static: true }) groupHeaderTemplate: TemplateRef<any>;
74
-
75
- public linkable: boolean;
76
-
77
- public linkDragEnded = new EventEmitter<GanttLinkDragEvent>();
78
-
79
- public view: GanttView;
80
-
81
- public items: GanttItemInternal[] = [];
82
-
83
- public groups: GanttGroupInternal[] = [];
84
-
85
- public viewChange = new EventEmitter<GanttView>();
86
-
87
- public expandChange = new EventEmitter<void>();
88
-
89
- public get element() {
90
- return this.elementRef.nativeElement;
91
- }
92
-
93
- public firstChange = true;
94
-
95
- public dragContainer: GanttDragContainer;
96
-
97
- public unsubscribe$ = new Subject();
98
-
99
- private groupsMap: { [key: string]: GanttGroupInternal };
100
-
101
- @HostBinding('class.gantt') ganttClass = true;
102
-
103
- constructor(protected elementRef: ElementRef<HTMLElement>, protected cdr: ChangeDetectorRef, protected ngZone: NgZone) {}
104
-
105
- private createView() {
106
- const viewDate = this.getViewDate();
107
- this.view = createViewFactory(this.viewType, viewDate.start, viewDate.end, this.viewOptions);
108
- }
109
-
110
- private setupGroups() {
111
- const collapsedIds = this.groups.filter((group) => group.expanded === false).map((group) => group.id);
112
- this.groupsMap = {};
113
- this.groups = [];
114
- this.originGroups.forEach((origin) => {
115
- const group = new GanttGroupInternal(origin);
116
- group.expanded = !collapsedIds.includes(group.id);
117
- this.groupsMap[group.id] = group;
118
- this.groups.push(group);
119
- });
120
- }
121
-
122
- private setupItems() {
123
- this.originItems = uniqBy(this.originItems, 'id');
124
- this.items = [];
125
- if (this.groups.length > 0) {
126
- this.originItems.forEach((origin) => {
127
- const group = this.groupsMap[origin.group_id];
128
- if (group) {
129
- const item = new GanttItemInternal(origin, { viewType: this.viewType });
130
- group.items.push(item);
131
- }
132
- });
133
- } else {
134
- this.originItems.forEach((origin) => {
135
- const item = new GanttItemInternal(origin, { viewType: this.viewType });
136
- this.items.push(item);
137
- });
138
- }
139
- }
140
-
141
- private setupExpandedState() {
142
- this.originItems = uniqBy(this.originItems, 'id');
143
- let items: GanttItemInternal[] = [];
144
- const flatOriginItems = getFlatItems(this.originItems);
145
-
146
- if (this.items.length > 0) {
147
- items = recursiveItems(this.items);
148
- } else {
149
- items = flatten(this.groups.map((group) => recursiveItems(group.items)));
150
- }
151
- items.forEach((item) => {
152
- if (item.origin.expanded) {
153
- const newItem = flatOriginItems.find((originItem) => originItem.id === item.id);
154
- if (newItem) {
155
- if (newItem.expanded === undefined) {
156
- newItem.expanded = true;
157
- }
158
- }
159
- }
160
- });
161
- }
162
-
163
- private getViewDate() {
164
- let start = this.start;
165
- let end = this.end;
166
- if (!this.start || !this.end) {
167
- this.originItems.forEach((item) => {
168
- if (item.start && !this.start) {
169
- start = start ? Math.min(start, item.start) : item.start;
170
- }
171
- if (item.end && !this.end) {
172
- end = end ? Math.max(end, item.end) : item.end;
173
- }
174
- });
175
- }
176
- return {
177
- start: {
178
- date: new GanttDate(start),
179
- isCustom: this.start ? true : false
180
- },
181
- end: {
182
- date: new GanttDate(end),
183
- isCustom: this.end ? true : false
184
- }
185
- };
186
- }
187
-
188
- computeRefs() {
189
- this.groups.forEach((group) => {
190
- const groupItems = recursiveItems(group.items);
191
- this.computeItemsRefs(...groupItems);
192
- });
193
- const items = recursiveItems(this.items);
194
- this.computeItemsRefs(...items);
195
- }
196
-
197
- private expandGroups(expanded: boolean) {
198
- this.groups.forEach((group) => {
199
- group.setExpand(expanded);
200
- });
201
- this.expandChange.next();
202
- this.cdr.detectChanges();
203
- }
204
-
205
- onInit() {
206
- this.styles = Object.assign({}, defaultStyles, this.styles);
207
- this.createView();
208
- this.setupGroups();
209
- this.setupItems();
210
- this.computeRefs();
211
- this.firstChange = false;
212
-
213
- this.ngZone.onStable.pipe(take(1)).subscribe(() => {
214
- this.element.style.opacity = '1';
215
-
216
- this.dragContainer.dragStarted.subscribe((event) => {
217
- this.dragStarted.emit(event);
218
- });
219
- this.dragContainer.dragEnded.subscribe((event) => {
220
- this.dragEnded.emit(event);
221
- this.computeRefs();
222
- this.detectChanges();
223
- });
224
- });
225
-
226
- this.view.start$.pipe(skip(1), takeUntil(this.unsubscribe$)).subscribe(() => {
227
- this.computeRefs();
228
- });
229
- }
230
-
231
- onChanges(changes: SimpleChanges) {
232
- if (!this.firstChange) {
233
- if (changes.viewType && changes.viewType.currentValue) {
234
- this.createView();
235
- this.setupGroups();
236
- this.setupItems();
237
- this.computeRefs();
238
- this.viewChange.emit(this.view);
239
- }
240
- if (changes.originItems || changes.originGroups) {
241
- this.setupExpandedState();
242
- this.setupGroups();
243
- this.setupItems();
244
- this.computeRefs();
245
- }
246
- }
247
- }
248
-
249
- onDestroy() {
250
- this.unsubscribe$.next();
251
- this.unsubscribe$.complete();
252
- }
253
-
254
- computeItemsRefs(...items: GanttItemInternal[]) {
255
- items.forEach((item) => {
256
- item.updateRefs({
257
- width: item.start && item.end ? this.view.getDateRangeWidth(item.start.startOfDay(), item.end.endOfDay()) : 0,
258
- x: item.start ? this.view.getXPointByDate(item.start) : 0,
259
- y: (this.styles.lineHeight - this.styles.barHeight) / 2 - 1
260
- });
261
- });
262
- }
263
-
264
- trackBy(item: GanttGroupInternal | GanttItemInternal, index: number) {
265
- return item.id || index;
266
- }
267
-
268
- detectChanges() {
269
- this.cdr.detectChanges();
270
- }
271
-
272
- expandGroup(group: GanttGroupInternal) {
273
- group.setExpand(!group.expanded);
274
- this.expandChange.emit();
275
- this.cdr.detectChanges();
276
- }
277
-
278
- // public functions
279
-
280
- expandAll() {
281
- this.expandGroups(true);
282
- }
283
-
284
- collapseAll() {
285
- this.expandGroups(false);
286
- }
287
- }
288
-
289
- export const GANTT_UPPER_TOKEN = new InjectionToken<GanttUpper>('GANTT_UPPER_TOKEN');
@@ -1,18 +0,0 @@
1
- <ngx-gantt-root>
2
- <ng-template #sideTemplate>
3
- <gantt-table [groups]="groups" [items]="items" [columns]="columns" [groupTemplate]="groupTemplate" [emptyTemplate]="tableEmptyTemplate"></gantt-table>
4
- </ng-template>
5
- <ng-template #mainTemplate>
6
- <gantt-main
7
- [groups]="groups"
8
- [items]="items"
9
- [groupHeaderTemplate]="groupHeaderTemplate"
10
- [itemTemplate]="itemTemplate"
11
- [barTemplate]="barTemplate"
12
- [rangeTemplate]="rangeTemplate"
13
- (barClick)="barClick.emit($event)"
14
- (lineClick)="lineClick.emit($event)"
15
- >
16
- </gantt-main>
17
- </ng-template>
18
- </ngx-gantt-root>