@contrail/document-generation 2.0.50 → 2.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/board-document-generator.d.ts +23 -23
- package/lib/board-document-generator.js +241 -241
- package/lib/components/component-generator.d.ts +6 -6
- package/lib/components/component-generator.js +55 -55
- package/lib/components/component-grid-generator.d.ts +7 -7
- package/lib/components/component-grid-generator.js +94 -84
- package/lib/components/component-util.d.ts +5 -5
- package/lib/components/component-util.js +43 -43
- package/lib/document-generator.d.ts +6 -6
- package/lib/document-generator.js +11 -11
- package/lib/frames/frame-generator.d.ts +12 -12
- package/lib/frames/frame-generator.js +141 -141
- package/lib/frames/frame.d.ts +18 -16
- package/lib/frames/frame.js +71 -67
- package/lib/frames/index.d.ts +2 -2
- package/lib/frames/index.js +18 -18
- package/lib/index.d.ts +6 -6
- package/lib/index.js +22 -22
- package/lib/info-panel/info-panel-generator.d.ts +6 -6
- package/lib/info-panel/info-panel-generator.js +56 -56
- package/lib/interfaces.d.ts +73 -72
- package/lib/interfaces.js +8 -8
- package/lib/scripts/test-board.d.ts +1 -1
- package/lib/scripts/test-board.js +230 -230
- package/lib/scripts/test-showcase.d.ts +1 -1
- package/lib/scripts/test-showcase.js +257 -257
- package/lib/showcase-frame-generator.d.ts +8 -8
- package/lib/showcase-frame-generator.js +44 -44
- package/lib/test-data.d.ts +72 -72
- package/lib/test-data.js +187 -187
- package/lib/util/document-dynamic-text-element-util.d.ts +8 -8
- package/lib/util/document-dynamic-text-element-util.js +77 -77
- package/lib/util/document-property-util.d.ts +9 -9
- package/lib/util/document-property-util.js +102 -102
- package/lib/util/document-text-element-util.d.ts +12 -12
- package/lib/util/document-text-element-util.js +148 -148
- package/lib/util/document-util.d.ts +8 -8
- package/lib/util/document-util.js +22 -22
- package/lib/util/index.d.ts +2 -2
- package/lib/util/index.js +18 -18
- package/lib/util/text-util.d.ts +4 -4
- package/lib/util/text-util.js +28 -28
- package/package.json +1 -1
- package/testdocument.json +25972 -25972
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Library for use with @contrail/documents that allows for the quick/automation generation of
|
|
2
|
-
documents based on templates and layout options.
|
|
1
|
+
Library for use with @contrail/documents that allows for the quick/automation generation of
|
|
2
|
+
documents based on templates and layout options.
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { DocumentElement, PositionDefinition } from '@contrail/documents';
|
|
2
|
-
import { DocumentGenerationOptions, DocumentTemplate, FrameDocumentTemplate } from './interfaces';
|
|
3
|
-
import { DataGroup } from '@contrail/data-grouping';
|
|
4
|
-
export declare class BoardDocumentGenerator {
|
|
5
|
-
static secondaryGroupPadding: number;
|
|
6
|
-
constructor();
|
|
7
|
-
static generateDocumentElements(options: DocumentGenerationOptions, typeMap: any): Array<DocumentElement>;
|
|
8
|
-
static adjustPositionBasedGroupHeaderSpan(currentPosition: PositionDefinition, template: DocumentTemplate, subGroup: DataGroup, totalDepth: number, currentDepth: number, containsSecondaryGroup: any): {
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
};
|
|
12
|
-
static adjustPositionBasedOnGroupHeaderSize(currentPosition: PositionDefinition, template: DocumentTemplate): {
|
|
13
|
-
x: number;
|
|
14
|
-
y: number;
|
|
15
|
-
};
|
|
16
|
-
static generateBoardGroupHeaders(group: DataGroup, template: DocumentTemplate, startingPosition: PositionDefinition, totalDepth: number, currentDepth: number, containsSecondaryGroup?: boolean): any[];
|
|
17
|
-
static generateBoardFrames(group: DataGroup, template: DocumentTemplate, frameTemplate: FrameDocumentTemplate, startingPosition: PositionDefinition, totalDepth: number, currentDepth: number, containsSecondaryGroup: boolean, frameTitle: string): any[];
|
|
18
|
-
static getGroupSpan(group: DataGroup, totalDepth: any, currentDepth: any, stopAtSecondary: any): number;
|
|
19
|
-
private static findDeepestSubgroups;
|
|
20
|
-
static generateFrameGroup(dataGroup: DataGroup, template: DocumentTemplate, frameTemplate: any, position: PositionDefinition, frameTitle: string): Array<DocumentElement>;
|
|
21
|
-
static generateBoardGroupHeader(dataGroup: DataGroup, template: DocumentTemplate, position: PositionDefinition, span: any, containsSecondaryGroup?: boolean): any[];
|
|
22
|
-
static generateSecondaryGroupHeader(dataGroup: any, template: any, position: any, span: any): any[];
|
|
23
|
-
}
|
|
1
|
+
import { DocumentElement, PositionDefinition } from '@contrail/documents';
|
|
2
|
+
import { DocumentGenerationOptions, DocumentTemplate, FrameDocumentTemplate } from './interfaces';
|
|
3
|
+
import { DataGroup } from '@contrail/data-grouping';
|
|
4
|
+
export declare class BoardDocumentGenerator {
|
|
5
|
+
static secondaryGroupPadding: number;
|
|
6
|
+
constructor();
|
|
7
|
+
static generateDocumentElements(options: DocumentGenerationOptions, typeMap: any): Array<DocumentElement>;
|
|
8
|
+
static adjustPositionBasedGroupHeaderSpan(currentPosition: PositionDefinition, template: DocumentTemplate, subGroup: DataGroup, totalDepth: number, currentDepth: number, containsSecondaryGroup: any): {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
static adjustPositionBasedOnGroupHeaderSize(currentPosition: PositionDefinition, template: DocumentTemplate): {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
};
|
|
16
|
+
static generateBoardGroupHeaders(group: DataGroup, template: DocumentTemplate, startingPosition: PositionDefinition, totalDepth: number, currentDepth: number, containsSecondaryGroup?: boolean): any[];
|
|
17
|
+
static generateBoardFrames(group: DataGroup, template: DocumentTemplate, frameTemplate: FrameDocumentTemplate, startingPosition: PositionDefinition, totalDepth: number, currentDepth: number, containsSecondaryGroup: boolean, frameTitle: string): any[];
|
|
18
|
+
static getGroupSpan(group: DataGroup, totalDepth: any, currentDepth: any, stopAtSecondary: any): number;
|
|
19
|
+
private static findDeepestSubgroups;
|
|
20
|
+
static generateFrameGroup(dataGroup: DataGroup, template: DocumentTemplate, frameTemplate: any, position: PositionDefinition, frameTitle: string): Array<DocumentElement>;
|
|
21
|
+
static generateBoardGroupHeader(dataGroup: DataGroup, template: DocumentTemplate, position: PositionDefinition, span: any, containsSecondaryGroup?: boolean): any[];
|
|
22
|
+
static generateSecondaryGroupHeader(dataGroup: any, template: any, position: any, span: any): any[];
|
|
23
|
+
}
|
|
@@ -1,241 +1,241 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BoardDocumentGenerator = void 0;
|
|
4
|
-
const documents_1 = require("@contrail/documents");
|
|
5
|
-
const interfaces_1 = require("./interfaces");
|
|
6
|
-
const util_1 = require("@contrail/util");
|
|
7
|
-
const frame_generator_1 = require("./frames/frame-generator");
|
|
8
|
-
const document_util_1 = require("./util/document-util");
|
|
9
|
-
const document_dynamic_text_element_util_1 = require("./util/document-dynamic-text-element-util");
|
|
10
|
-
class BoardDocumentGenerator {
|
|
11
|
-
constructor() { }
|
|
12
|
-
static generateDocumentElements(options, typeMap) {
|
|
13
|
-
if (typeMap && document_dynamic_text_element_util_1.DocumentDynamicTextElementUtil.typeMap === undefined) {
|
|
14
|
-
document_dynamic_text_element_util_1.DocumentDynamicTextElementUtil.typeMap = typeMap;
|
|
15
|
-
}
|
|
16
|
-
const elements = [];
|
|
17
|
-
const structure = options.data.dataGroup;
|
|
18
|
-
const template = options.documentTemplateDefinition;
|
|
19
|
-
const frameTemplate = options.frameTemplate;
|
|
20
|
-
if (frameTemplate) {
|
|
21
|
-
template.frameSize = frameTemplate.document.size;
|
|
22
|
-
}
|
|
23
|
-
console.log('generateDocumentElements: ', structure.depth, structure.groupingProperties.length);
|
|
24
|
-
let position = options.startingCoordinates || { x: 0, y: 0 };
|
|
25
|
-
const group = structure.rootGroup;
|
|
26
|
-
const deepestSubgroups = [];
|
|
27
|
-
this.findDeepestSubgroups(group, deepestSubgroups, structure.depth, 0, true);
|
|
28
|
-
let containsSecondaryGroup = deepestSubgroups.length > 0 && deepestSubgroups[0].isSecondaryGroup;
|
|
29
|
-
elements.push(...this.generateBoardGroupHeaders(group, template, position, structure.depth, 0, containsSecondaryGroup));
|
|
30
|
-
elements.push(...this.generateBoardFrames(group, template, frameTemplate, position, structure.depth, 0, containsSecondaryGroup, null));
|
|
31
|
-
return elements;
|
|
32
|
-
}
|
|
33
|
-
static adjustPositionBasedGroupHeaderSpan(currentPosition, template, subGroup, totalDepth, currentDepth, containsSecondaryGroup) {
|
|
34
|
-
let frameSetMultiple = this.getGroupSpan(subGroup, totalDepth, currentDepth + 1, !subGroup.isSecondaryGroup);
|
|
35
|
-
let paddingMultiple = 1;
|
|
36
|
-
if (currentDepth < totalDepth) {
|
|
37
|
-
paddingMultiple = frameSetMultiple;
|
|
38
|
-
}
|
|
39
|
-
let adjustment = 0;
|
|
40
|
-
if (!subGroup.isSecondaryGroup && containsSecondaryGroup) {
|
|
41
|
-
adjustment = this.secondaryGroupPadding * paddingMultiple;
|
|
42
|
-
}
|
|
43
|
-
if ((template.frameOrientation === interfaces_1.Orientation.HORIZONTAL && !subGroup.isSecondaryGroup) ||
|
|
44
|
-
(template.frameOrientation === interfaces_1.Orientation.VERTICAL && subGroup.isSecondaryGroup)) {
|
|
45
|
-
return {
|
|
46
|
-
x: currentPosition.x,
|
|
47
|
-
y: currentPosition.y +
|
|
48
|
-
template.frameSize.height * frameSetMultiple +
|
|
49
|
-
template.framePadding * paddingMultiple +
|
|
50
|
-
adjustment,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
else if ((template.frameOrientation === interfaces_1.Orientation.HORIZONTAL && subGroup.isSecondaryGroup) ||
|
|
54
|
-
(template.frameOrientation === interfaces_1.Orientation.VERTICAL && !subGroup.isSecondaryGroup)) {
|
|
55
|
-
return {
|
|
56
|
-
x: currentPosition.x +
|
|
57
|
-
template.frameSize.width * frameSetMultiple +
|
|
58
|
-
template.framePadding * paddingMultiple +
|
|
59
|
-
adjustment,
|
|
60
|
-
y: currentPosition.y,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
static adjustPositionBasedOnGroupHeaderSize(currentPosition, template) {
|
|
65
|
-
let groupHeaderDimensions = {
|
|
66
|
-
width: template.frameSize.width,
|
|
67
|
-
height: template.frameGroupHeaderTemplate.size.height,
|
|
68
|
-
};
|
|
69
|
-
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
70
|
-
return { x: currentPosition.x + groupHeaderDimensions.height + template.framePadding, y: currentPosition.y };
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return { x: currentPosition.x, y: currentPosition.y + groupHeaderDimensions.height + template.framePadding };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
static generateBoardGroupHeaders(group, template, startingPosition, totalDepth, currentDepth, containsSecondaryGroup = false) {
|
|
77
|
-
const elements = [];
|
|
78
|
-
let position = {
|
|
79
|
-
x: startingPosition.x,
|
|
80
|
-
y: startingPosition.y,
|
|
81
|
-
};
|
|
82
|
-
if (currentDepth > 0) {
|
|
83
|
-
let groupHeaderPosition = { x: position.x + template.framePadding, y: position.y + template.framePadding };
|
|
84
|
-
let span = this.getGroupSpan(group, totalDepth, currentDepth, true);
|
|
85
|
-
elements.push(...this.generateBoardGroupHeader(group, template, groupHeaderPosition, span, containsSecondaryGroup));
|
|
86
|
-
position = this.adjustPositionBasedOnGroupHeaderSize(position, template);
|
|
87
|
-
}
|
|
88
|
-
if (currentDepth < totalDepth) {
|
|
89
|
-
for (let subGroup of group.subGroups) {
|
|
90
|
-
if (!subGroup.isSecondaryGroup) {
|
|
91
|
-
elements.push(...this.generateBoardGroupHeaders(subGroup, template, position, totalDepth, currentDepth + 1, containsSecondaryGroup));
|
|
92
|
-
const adjustedPosition = this.adjustPositionBasedGroupHeaderSpan(position, template, subGroup, totalDepth, currentDepth, containsSecondaryGroup);
|
|
93
|
-
position = {
|
|
94
|
-
x: adjustedPosition.x,
|
|
95
|
-
y: adjustedPosition.y,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return elements;
|
|
101
|
-
}
|
|
102
|
-
static generateBoardFrames(group, template, frameTemplate, startingPosition, totalDepth, currentDepth, containsSecondaryGroup, frameTitle) {
|
|
103
|
-
if (currentDepth > 0) {
|
|
104
|
-
frameTitle = !frameTitle ? group.name : frameTitle + ' / ' + group.name;
|
|
105
|
-
}
|
|
106
|
-
const elements = [];
|
|
107
|
-
let position = {
|
|
108
|
-
x: startingPosition.x,
|
|
109
|
-
y: startingPosition.y,
|
|
110
|
-
};
|
|
111
|
-
if (currentDepth > 0 && !group.isSecondaryGroup) {
|
|
112
|
-
position = this.adjustPositionBasedOnGroupHeaderSize(position, template);
|
|
113
|
-
}
|
|
114
|
-
if (currentDepth === totalDepth) {
|
|
115
|
-
elements.push(...this.generateFrameGroup(group, template, frameTemplate, position, frameTitle));
|
|
116
|
-
}
|
|
117
|
-
if (currentDepth < totalDepth) {
|
|
118
|
-
for (let subGroup of group.subGroups) {
|
|
119
|
-
elements.push(...this.generateBoardFrames(subGroup, template, frameTemplate, position, totalDepth, currentDepth + 1, containsSecondaryGroup, frameTitle));
|
|
120
|
-
const adjustedPosition = this.adjustPositionBasedGroupHeaderSpan(position, template, subGroup, totalDepth, currentDepth, containsSecondaryGroup);
|
|
121
|
-
position = {
|
|
122
|
-
x: adjustedPosition.x,
|
|
123
|
-
y: adjustedPosition.y,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return elements;
|
|
128
|
-
}
|
|
129
|
-
static getGroupSpan(group, totalDepth, currentDepth, stopAtSecondary) {
|
|
130
|
-
const deepestSubgroups = [];
|
|
131
|
-
this.findDeepestSubgroups(group, deepestSubgroups, totalDepth, currentDepth, stopAtSecondary);
|
|
132
|
-
return deepestSubgroups.length;
|
|
133
|
-
}
|
|
134
|
-
static findDeepestSubgroups(group, subgroups, totalDepth, currentDepth, stopAtSecondary) {
|
|
135
|
-
if (currentDepth === totalDepth && group.subGroups.length > 0) {
|
|
136
|
-
if (!group.isSecondaryGroup &&
|
|
137
|
-
group.subGroups.filter((subgroup) => subgroup.name === group.subGroups[0].name).length > 1) {
|
|
138
|
-
subgroups.push(group.subGroups[0]);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
subgroups.push(...group.subGroups);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
for (let i = 0; i < group.subGroups.length; i++) {
|
|
145
|
-
if (group.subGroups[i].isSecondaryGroup && stopAtSecondary) {
|
|
146
|
-
subgroups.push(group.subGroups[0]);
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
this.findDeepestSubgroups(group.subGroups[i], subgroups, totalDepth, currentDepth + 1, stopAtSecondary);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
static generateFrameGroup(dataGroup, template, frameTemplate, position, frameTitle) {
|
|
153
|
-
const elements = [];
|
|
154
|
-
let framePosition = { x: position.x + template.framePadding, y: position.y + template.framePadding };
|
|
155
|
-
if (dataGroup.isSecondaryGroup) {
|
|
156
|
-
elements.push(...this.generateSecondaryGroupHeader(dataGroup, template, util_1.ObjectUtil.cloneDeep(framePosition), dataGroup.subGroups.length));
|
|
157
|
-
if (template.frameOrientation === interfaces_1.Orientation.VERTICAL) {
|
|
158
|
-
framePosition.x = framePosition.x + template.frameGroupHeaderTemplate.size.height + 20;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
framePosition.y = framePosition.y + template.frameGroupHeaderTemplate.size.height + 20;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
for (let group of dataGroup.subGroups) {
|
|
165
|
-
let frame = frame_generator_1.FrameGenerator.generateBoardFrameForDataGroup(group, framePosition, template, frameTemplate, frameTitle);
|
|
166
|
-
elements.push(...frame.toDocumentElements());
|
|
167
|
-
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
168
|
-
framePosition.x = framePosition.x + template.frameSize.width + template.framePadding || 10;
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
framePosition.y = framePosition.y + template.frameSize.height + template.framePadding || 10;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return elements;
|
|
175
|
-
}
|
|
176
|
-
static generateBoardGroupHeader(dataGroup, template, position, span, containsSecondaryGroup = false) {
|
|
177
|
-
const elements = [];
|
|
178
|
-
const heading = documents_1.DocumentElementFactory.createTextElement('Placeholder', {});
|
|
179
|
-
heading.style = {
|
|
180
|
-
border: { width: 1, color: 'rgba(0,0,0,0)' },
|
|
181
|
-
color: '#000000',
|
|
182
|
-
backgroundColor: template.frameGroupHeaderTemplate.style.backgroundColor || 'black',
|
|
183
|
-
};
|
|
184
|
-
heading.text = `<p><span style=\"font-size: ${template.frameGroupHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.frameGroupHeaderTemplate.style.color};\">${document_util_1.DocumentUtil.sanitizeHTML(dataGroup.name)}</span></strong></span></p>`;
|
|
185
|
-
heading.position = position;
|
|
186
|
-
let adjustment = containsSecondaryGroup ? this.secondaryGroupPadding : 0;
|
|
187
|
-
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
188
|
-
let sizeDim = (template.frameSize.height + adjustment) * span;
|
|
189
|
-
if (span > 1) {
|
|
190
|
-
sizeDim += (span - 1) * template.framePadding;
|
|
191
|
-
}
|
|
192
|
-
heading.size = { width: sizeDim, height: template.frameGroupHeaderTemplate.size.height };
|
|
193
|
-
heading.rotate = { angle: 270 };
|
|
194
|
-
heading.position.x = heading.position.x - heading.size.width / 2 + heading.size.height / 2;
|
|
195
|
-
heading.position.y = heading.position.y + heading.size.width / 2 - heading.size.height / 2;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
let sizeDim = (template.frameSize.width + adjustment) * span;
|
|
199
|
-
if (span > 1) {
|
|
200
|
-
sizeDim += (span - 1) * template.framePadding;
|
|
201
|
-
}
|
|
202
|
-
heading.rotate = { angle: 0 };
|
|
203
|
-
heading.size = { width: sizeDim, height: template.frameGroupHeaderTemplate.size.height };
|
|
204
|
-
}
|
|
205
|
-
elements.push(heading);
|
|
206
|
-
return elements;
|
|
207
|
-
}
|
|
208
|
-
static generateSecondaryGroupHeader(dataGroup, template, position, span) {
|
|
209
|
-
const elements = [];
|
|
210
|
-
const heading = documents_1.DocumentElementFactory.createTextElement('Placeholder', {});
|
|
211
|
-
heading.style = {
|
|
212
|
-
border: { width: 1, color: 'rgba(0,0,0,0)' },
|
|
213
|
-
color: '#000000',
|
|
214
|
-
backgroundColor: template.secondaryFrameGroupHeaderTemplate.style.backgroundColor || 'black',
|
|
215
|
-
};
|
|
216
|
-
heading.text = `<p><span style=\"font-size: ${template.secondaryFrameGroupHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.secondaryFrameGroupHeaderTemplate.style.color};\">${document_util_1.DocumentUtil.sanitizeHTML(dataGroup.name)}</span></strong></span></p>`;
|
|
217
|
-
heading.position = position;
|
|
218
|
-
if (template.frameOrientation === interfaces_1.Orientation.VERTICAL) {
|
|
219
|
-
let sizeDim = template.frameSize.height * span;
|
|
220
|
-
if (span > 1) {
|
|
221
|
-
sizeDim += (span - 1) * template.framePadding;
|
|
222
|
-
}
|
|
223
|
-
heading.size = { width: sizeDim, height: template.secondaryFrameGroupHeaderTemplate.size.height };
|
|
224
|
-
heading.rotate = { angle: 270 };
|
|
225
|
-
heading.position.x = heading.position.x - heading.size.width / 2 + heading.size.height / 2;
|
|
226
|
-
heading.position.y = heading.position.y + heading.size.width / 2 - heading.size.height / 2;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
let sizeDim = template.frameSize.width * span;
|
|
230
|
-
if (span > 1) {
|
|
231
|
-
sizeDim += (span - 1) * template.framePadding;
|
|
232
|
-
}
|
|
233
|
-
heading.rotate = { angle: 0 };
|
|
234
|
-
heading.size = { width: sizeDim, height: template.secondaryFrameGroupHeaderTemplate.size.height };
|
|
235
|
-
}
|
|
236
|
-
elements.push(heading);
|
|
237
|
-
return elements;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
exports.BoardDocumentGenerator = BoardDocumentGenerator;
|
|
241
|
-
BoardDocumentGenerator.secondaryGroupPadding = 80;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BoardDocumentGenerator = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const interfaces_1 = require("./interfaces");
|
|
6
|
+
const util_1 = require("@contrail/util");
|
|
7
|
+
const frame_generator_1 = require("./frames/frame-generator");
|
|
8
|
+
const document_util_1 = require("./util/document-util");
|
|
9
|
+
const document_dynamic_text_element_util_1 = require("./util/document-dynamic-text-element-util");
|
|
10
|
+
class BoardDocumentGenerator {
|
|
11
|
+
constructor() { }
|
|
12
|
+
static generateDocumentElements(options, typeMap) {
|
|
13
|
+
if (typeMap && document_dynamic_text_element_util_1.DocumentDynamicTextElementUtil.typeMap === undefined) {
|
|
14
|
+
document_dynamic_text_element_util_1.DocumentDynamicTextElementUtil.typeMap = typeMap;
|
|
15
|
+
}
|
|
16
|
+
const elements = [];
|
|
17
|
+
const structure = options.data.dataGroup;
|
|
18
|
+
const template = options.documentTemplateDefinition;
|
|
19
|
+
const frameTemplate = options.frameTemplate;
|
|
20
|
+
if (frameTemplate) {
|
|
21
|
+
template.frameSize = frameTemplate.document.size;
|
|
22
|
+
}
|
|
23
|
+
console.log('generateDocumentElements: ', structure.depth, structure.groupingProperties.length);
|
|
24
|
+
let position = options.startingCoordinates || { x: 0, y: 0 };
|
|
25
|
+
const group = structure.rootGroup;
|
|
26
|
+
const deepestSubgroups = [];
|
|
27
|
+
this.findDeepestSubgroups(group, deepestSubgroups, structure.depth, 0, true);
|
|
28
|
+
let containsSecondaryGroup = deepestSubgroups.length > 0 && deepestSubgroups[0].isSecondaryGroup;
|
|
29
|
+
elements.push(...this.generateBoardGroupHeaders(group, template, position, structure.depth, 0, containsSecondaryGroup));
|
|
30
|
+
elements.push(...this.generateBoardFrames(group, template, frameTemplate, position, structure.depth, 0, containsSecondaryGroup, null));
|
|
31
|
+
return elements;
|
|
32
|
+
}
|
|
33
|
+
static adjustPositionBasedGroupHeaderSpan(currentPosition, template, subGroup, totalDepth, currentDepth, containsSecondaryGroup) {
|
|
34
|
+
let frameSetMultiple = this.getGroupSpan(subGroup, totalDepth, currentDepth + 1, !subGroup.isSecondaryGroup);
|
|
35
|
+
let paddingMultiple = 1;
|
|
36
|
+
if (currentDepth < totalDepth) {
|
|
37
|
+
paddingMultiple = frameSetMultiple;
|
|
38
|
+
}
|
|
39
|
+
let adjustment = 0;
|
|
40
|
+
if (!subGroup.isSecondaryGroup && containsSecondaryGroup) {
|
|
41
|
+
adjustment = this.secondaryGroupPadding * paddingMultiple;
|
|
42
|
+
}
|
|
43
|
+
if ((template.frameOrientation === interfaces_1.Orientation.HORIZONTAL && !subGroup.isSecondaryGroup) ||
|
|
44
|
+
(template.frameOrientation === interfaces_1.Orientation.VERTICAL && subGroup.isSecondaryGroup)) {
|
|
45
|
+
return {
|
|
46
|
+
x: currentPosition.x,
|
|
47
|
+
y: currentPosition.y +
|
|
48
|
+
template.frameSize.height * frameSetMultiple +
|
|
49
|
+
template.framePadding * paddingMultiple +
|
|
50
|
+
adjustment,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else if ((template.frameOrientation === interfaces_1.Orientation.HORIZONTAL && subGroup.isSecondaryGroup) ||
|
|
54
|
+
(template.frameOrientation === interfaces_1.Orientation.VERTICAL && !subGroup.isSecondaryGroup)) {
|
|
55
|
+
return {
|
|
56
|
+
x: currentPosition.x +
|
|
57
|
+
template.frameSize.width * frameSetMultiple +
|
|
58
|
+
template.framePadding * paddingMultiple +
|
|
59
|
+
adjustment,
|
|
60
|
+
y: currentPosition.y,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static adjustPositionBasedOnGroupHeaderSize(currentPosition, template) {
|
|
65
|
+
let groupHeaderDimensions = {
|
|
66
|
+
width: template.frameSize.width,
|
|
67
|
+
height: template.frameGroupHeaderTemplate.size.height,
|
|
68
|
+
};
|
|
69
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
70
|
+
return { x: currentPosition.x + groupHeaderDimensions.height + template.framePadding, y: currentPosition.y };
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return { x: currentPosition.x, y: currentPosition.y + groupHeaderDimensions.height + template.framePadding };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
static generateBoardGroupHeaders(group, template, startingPosition, totalDepth, currentDepth, containsSecondaryGroup = false) {
|
|
77
|
+
const elements = [];
|
|
78
|
+
let position = {
|
|
79
|
+
x: startingPosition.x,
|
|
80
|
+
y: startingPosition.y,
|
|
81
|
+
};
|
|
82
|
+
if (currentDepth > 0) {
|
|
83
|
+
let groupHeaderPosition = { x: position.x + template.framePadding, y: position.y + template.framePadding };
|
|
84
|
+
let span = this.getGroupSpan(group, totalDepth, currentDepth, true);
|
|
85
|
+
elements.push(...this.generateBoardGroupHeader(group, template, groupHeaderPosition, span, containsSecondaryGroup));
|
|
86
|
+
position = this.adjustPositionBasedOnGroupHeaderSize(position, template);
|
|
87
|
+
}
|
|
88
|
+
if (currentDepth < totalDepth) {
|
|
89
|
+
for (let subGroup of group.subGroups) {
|
|
90
|
+
if (!subGroup.isSecondaryGroup) {
|
|
91
|
+
elements.push(...this.generateBoardGroupHeaders(subGroup, template, position, totalDepth, currentDepth + 1, containsSecondaryGroup));
|
|
92
|
+
const adjustedPosition = this.adjustPositionBasedGroupHeaderSpan(position, template, subGroup, totalDepth, currentDepth, containsSecondaryGroup);
|
|
93
|
+
position = {
|
|
94
|
+
x: adjustedPosition.x,
|
|
95
|
+
y: adjustedPosition.y,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return elements;
|
|
101
|
+
}
|
|
102
|
+
static generateBoardFrames(group, template, frameTemplate, startingPosition, totalDepth, currentDepth, containsSecondaryGroup, frameTitle) {
|
|
103
|
+
if (currentDepth > 0) {
|
|
104
|
+
frameTitle = !frameTitle ? group.name : frameTitle + ' / ' + group.name;
|
|
105
|
+
}
|
|
106
|
+
const elements = [];
|
|
107
|
+
let position = {
|
|
108
|
+
x: startingPosition.x,
|
|
109
|
+
y: startingPosition.y,
|
|
110
|
+
};
|
|
111
|
+
if (currentDepth > 0 && !group.isSecondaryGroup) {
|
|
112
|
+
position = this.adjustPositionBasedOnGroupHeaderSize(position, template);
|
|
113
|
+
}
|
|
114
|
+
if (currentDepth === totalDepth) {
|
|
115
|
+
elements.push(...this.generateFrameGroup(group, template, frameTemplate, position, frameTitle));
|
|
116
|
+
}
|
|
117
|
+
if (currentDepth < totalDepth) {
|
|
118
|
+
for (let subGroup of group.subGroups) {
|
|
119
|
+
elements.push(...this.generateBoardFrames(subGroup, template, frameTemplate, position, totalDepth, currentDepth + 1, containsSecondaryGroup, frameTitle));
|
|
120
|
+
const adjustedPosition = this.adjustPositionBasedGroupHeaderSpan(position, template, subGroup, totalDepth, currentDepth, containsSecondaryGroup);
|
|
121
|
+
position = {
|
|
122
|
+
x: adjustedPosition.x,
|
|
123
|
+
y: adjustedPosition.y,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return elements;
|
|
128
|
+
}
|
|
129
|
+
static getGroupSpan(group, totalDepth, currentDepth, stopAtSecondary) {
|
|
130
|
+
const deepestSubgroups = [];
|
|
131
|
+
this.findDeepestSubgroups(group, deepestSubgroups, totalDepth, currentDepth, stopAtSecondary);
|
|
132
|
+
return deepestSubgroups.length;
|
|
133
|
+
}
|
|
134
|
+
static findDeepestSubgroups(group, subgroups, totalDepth, currentDepth, stopAtSecondary) {
|
|
135
|
+
if (currentDepth === totalDepth && group.subGroups.length > 0) {
|
|
136
|
+
if (!group.isSecondaryGroup &&
|
|
137
|
+
group.subGroups.filter((subgroup) => subgroup.name === group.subGroups[0].name).length > 1) {
|
|
138
|
+
subgroups.push(group.subGroups[0]);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
subgroups.push(...group.subGroups);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (let i = 0; i < group.subGroups.length; i++) {
|
|
145
|
+
if (group.subGroups[i].isSecondaryGroup && stopAtSecondary) {
|
|
146
|
+
subgroups.push(group.subGroups[0]);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
this.findDeepestSubgroups(group.subGroups[i], subgroups, totalDepth, currentDepth + 1, stopAtSecondary);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
static generateFrameGroup(dataGroup, template, frameTemplate, position, frameTitle) {
|
|
153
|
+
const elements = [];
|
|
154
|
+
let framePosition = { x: position.x + template.framePadding, y: position.y + template.framePadding };
|
|
155
|
+
if (dataGroup.isSecondaryGroup) {
|
|
156
|
+
elements.push(...this.generateSecondaryGroupHeader(dataGroup, template, util_1.ObjectUtil.cloneDeep(framePosition), dataGroup.subGroups.length));
|
|
157
|
+
if (template.frameOrientation === interfaces_1.Orientation.VERTICAL) {
|
|
158
|
+
framePosition.x = framePosition.x + template.frameGroupHeaderTemplate.size.height + 20;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
framePosition.y = framePosition.y + template.frameGroupHeaderTemplate.size.height + 20;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (let group of dataGroup.subGroups) {
|
|
165
|
+
let frame = frame_generator_1.FrameGenerator.generateBoardFrameForDataGroup(group, framePosition, template, frameTemplate, frameTitle);
|
|
166
|
+
elements.push(...frame.toDocumentElements());
|
|
167
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
168
|
+
framePosition.x = framePosition.x + template.frameSize.width + template.framePadding || 10;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
framePosition.y = framePosition.y + template.frameSize.height + template.framePadding || 10;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return elements;
|
|
175
|
+
}
|
|
176
|
+
static generateBoardGroupHeader(dataGroup, template, position, span, containsSecondaryGroup = false) {
|
|
177
|
+
const elements = [];
|
|
178
|
+
const heading = documents_1.DocumentElementFactory.createTextElement('Placeholder', {});
|
|
179
|
+
heading.style = {
|
|
180
|
+
border: { width: 1, color: 'rgba(0,0,0,0)' },
|
|
181
|
+
color: '#000000',
|
|
182
|
+
backgroundColor: template.frameGroupHeaderTemplate.style.backgroundColor || 'black',
|
|
183
|
+
};
|
|
184
|
+
heading.text = `<p><span style=\"font-size: ${template.frameGroupHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.frameGroupHeaderTemplate.style.color};\">${document_util_1.DocumentUtil.sanitizeHTML(dataGroup.name)}</span></strong></span></p>`;
|
|
185
|
+
heading.position = position;
|
|
186
|
+
let adjustment = containsSecondaryGroup ? this.secondaryGroupPadding : 0;
|
|
187
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
188
|
+
let sizeDim = (template.frameSize.height + adjustment) * span;
|
|
189
|
+
if (span > 1) {
|
|
190
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
191
|
+
}
|
|
192
|
+
heading.size = { width: sizeDim, height: template.frameGroupHeaderTemplate.size.height };
|
|
193
|
+
heading.rotate = { angle: 270 };
|
|
194
|
+
heading.position.x = heading.position.x - heading.size.width / 2 + heading.size.height / 2;
|
|
195
|
+
heading.position.y = heading.position.y + heading.size.width / 2 - heading.size.height / 2;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
let sizeDim = (template.frameSize.width + adjustment) * span;
|
|
199
|
+
if (span > 1) {
|
|
200
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
201
|
+
}
|
|
202
|
+
heading.rotate = { angle: 0 };
|
|
203
|
+
heading.size = { width: sizeDim, height: template.frameGroupHeaderTemplate.size.height };
|
|
204
|
+
}
|
|
205
|
+
elements.push(heading);
|
|
206
|
+
return elements;
|
|
207
|
+
}
|
|
208
|
+
static generateSecondaryGroupHeader(dataGroup, template, position, span) {
|
|
209
|
+
const elements = [];
|
|
210
|
+
const heading = documents_1.DocumentElementFactory.createTextElement('Placeholder', {});
|
|
211
|
+
heading.style = {
|
|
212
|
+
border: { width: 1, color: 'rgba(0,0,0,0)' },
|
|
213
|
+
color: '#000000',
|
|
214
|
+
backgroundColor: template.secondaryFrameGroupHeaderTemplate.style.backgroundColor || 'black',
|
|
215
|
+
};
|
|
216
|
+
heading.text = `<p><span style=\"font-size: ${template.secondaryFrameGroupHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.secondaryFrameGroupHeaderTemplate.style.color};\">${document_util_1.DocumentUtil.sanitizeHTML(dataGroup.name)}</span></strong></span></p>`;
|
|
217
|
+
heading.position = position;
|
|
218
|
+
if (template.frameOrientation === interfaces_1.Orientation.VERTICAL) {
|
|
219
|
+
let sizeDim = template.frameSize.height * span;
|
|
220
|
+
if (span > 1) {
|
|
221
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
222
|
+
}
|
|
223
|
+
heading.size = { width: sizeDim, height: template.secondaryFrameGroupHeaderTemplate.size.height };
|
|
224
|
+
heading.rotate = { angle: 270 };
|
|
225
|
+
heading.position.x = heading.position.x - heading.size.width / 2 + heading.size.height / 2;
|
|
226
|
+
heading.position.y = heading.position.y + heading.size.width / 2 - heading.size.height / 2;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
let sizeDim = template.frameSize.width * span;
|
|
230
|
+
if (span > 1) {
|
|
231
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
232
|
+
}
|
|
233
|
+
heading.rotate = { angle: 0 };
|
|
234
|
+
heading.size = { width: sizeDim, height: template.secondaryFrameGroupHeaderTemplate.size.height };
|
|
235
|
+
}
|
|
236
|
+
elements.push(heading);
|
|
237
|
+
return elements;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.BoardDocumentGenerator = BoardDocumentGenerator;
|
|
241
|
+
BoardDocumentGenerator.secondaryGroupPadding = 80;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DocumentElement } from '@contrail/documents';
|
|
2
|
-
import { ComponentPropertyTemplate, ComponentTemplate } from '../interfaces';
|
|
3
|
-
export declare class ComponentGenerator {
|
|
4
|
-
static generateComponent(data: any, options: DocumentElement, template: ComponentTemplate): any;
|
|
5
|
-
static generateComponentFromPropertyTemplate(data: any, options: DocumentElement, template: ComponentPropertyTemplate): DocumentElement;
|
|
6
|
-
}
|
|
1
|
+
import { DocumentElement } from '@contrail/documents';
|
|
2
|
+
import { ComponentPropertyTemplate, ComponentTemplate } from '../interfaces';
|
|
3
|
+
export declare class ComponentGenerator {
|
|
4
|
+
static generateComponent(data: any, options: DocumentElement, template: ComponentTemplate): any;
|
|
5
|
+
static generateComponentFromPropertyTemplate(data: any, options: DocumentElement, template: ComponentPropertyTemplate): DocumentElement;
|
|
6
|
+
}
|