-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
demo33.js
346 lines (335 loc) · 10.3 KB
/
demo33.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/***
* This report tests using a pageBreak, "before" and "after" values
*/
"use strict";
// This test is currently Broken because of Page Breaking Code does not change the Absolute values back down by the size of the page...
// Technically this should print like the "originals" shows.
global.skipTesting = true;
const ReportBuilder = require('../lib/fluentReportsBuilder').ReportBuilder;
const displayReport = require('./reportDisplayer');
const data = [
{
"id": 1,
"name": "John Doe",
"emphours": [
{
"week": 20,
"day": "Monday",
"hours": 4
},
{
"week": 20,
"day": "Tuesday",
"hours": 8
},
{
"week": 20,
"day": "Wednesday",
"hours": 8
},
{
"week": 21,
"day": "Thursday",
"hours": -2
},
{
"week": 21,
"day": "Friday",
"hours": 8
},
{
"week": 22,
"day": "Monday",
"hours": 4
},
{
"week": 22,
"day": "Tuesday",
"hours": 8
},
{
"week": 22,
"day": "Wednesday",
"hours": 8
},
{
"week": 23,
"day": "Thursday",
"hours": 2
},
{
"week": 23,
"day": "Friday",
"hours": 8
},
{
"week": 25,
"day": "Monday",
"hours": 4
},
{
"week": 25,
"day": "Tuesday",
"hours": 8
},
{
"week": 25,
"day": "Wednesday",
"hours": 8
},
{
"week": 26,
"day": "Thursday",
"hours": 2
},
{
"week": 26,
"day": "Friday",
"hours": 8
}
]
},
{
"id": 3,
"name": "Sarah Williams",
"emphours": [
{
"week": 20,
"day": "Monday",
"hours": 8
}
]
}
];
const reportData = {
"type": "report",
"dataUUID": 10002,
"version": 1,
"fontSize": 8,
"autoPrint": false,
"name": "demo33.pdf",
"paperSize": "letter",
"paperOrientation": "portrait",
"fonts": [],
"variables": {
"counter": 0
},
"subReports": [
{
"dataUUID": 10003,
"dataType": "parent",
"data": "emphours",
"type": "report",
"detail": {
"children": [
{
"type": "function",
"function": "vars.counter++;",
"name": "increase counter"
},
{
"settings": {
"fillOpacity": 1,
"absoluteX": 0,
"absoluteY": 0,
"fill": {
"type": "function",
"function": "return (vars.counter % 2 === 0 ? '#f0f0f0' : '#e0e0e0');",
"name": "fill"
},
"textColor": "#0000ff",
"wrap": true
},
"type": "band",
"fields": [
{
"text": "",
"width": 80
},
{
"field": "day",
"width": 100
},
{
"field": "hours",
"width": 100,
"align": 3,
"textColor": {
"type": "function",
"function": "return data.hours < 0 ? '#FF0000' : '#000000';",
"name": "textColor"
},
"formatFunction": "NumberFunction"
}
]
}
]
},
"calcs": {
"sum": [
"hours"
]
}
}
],
"pageHeader": {
"children": [
{
"type": "raw",
"values": [
"Employee Hours"
]
}
]
},
"groupBy": [
{
"type": "group",
"groupOn": "name",
"header": {
"children": [
{
"field": "name",
"settings": {
"formatFunction": "NameDisplay",
"absoluteX": 0,
"absoluteY": 0,
"fontBold": true,
"fill": "#6f6f6f",
"textColor": "#ffffff",
"link": "http://www.fluentReports.com/"
},
"type": "print"
}
]
},
"detail": {
"children": [
{
"text": "Label",
"settings": {
"absoluteX": 0,
"absoluteY": 0
},
"type": "print"
},
{
"text": "Label",
"settings": {
"absoluteX": 0,
"absoluteY": 21
},
"type": "print"
},
{
"text": "Label",
"settings": {
"absoluteX": 0,
"absoluteY": 42
},
"type": "print"
},
{
"active": {
"type": "function",
"name": "Function",
"function": "return vars.counter % 5 === 0;",
"async": false
},
"type": "newPage"
},
{
"text": "Label",
"settings": {
"absoluteX": 0,
"absoluteY": 80
},
"type": "print"
},
{
"text": "Label",
"settings": {
"absoluteX": 0,
"absoluteY": 102
},
"type": "print"
}
]
},
"footer": {
"children": [
{
"type": "calculation",
"op": "concat",
"name": "totals",
"fields": [
{
"text": "Totals for "
},
{
"field": "name"
}
]
},
{
"settings": {
"fillOpacity": 1,
"absoluteX": 0,
"absoluteY": 0
},
"type": "band",
"fields": [
{
"function": {
"type": "function",
"name": "Totals for data.name",
"function": "return `Totals for ${data.name}`",
"async": false
},
"width": 180
},
{
"total": "hours",
"width": 100,
"align": 3
}
]
},
{
"type": "newLine"
}
]
}
}
],
"finalSummary": {
"children": [
{
"type": "raw",
"values": [
"Total Hours:",
"hours",
3
]
}
]
},
"formatterFunctions": {
"NameDisplay": "callback('Name: ' + row.name)",
"HoursDisplay": "callback('Hours: ' + input)"
}
};
let rpt = new ReportBuilder(reportData, data);
// These two lines are not normally needed for any normal reports unless you want to use your own fonts...
// We need to add this because of TESTING and making the report consistent for CI environments
rpt.registerFont("Arimo", {normal: __dirname+'/Fonts/Arimo-Regular.ttf', bold: __dirname+'/Fonts/Arimo-Bold.ttf', 'italic': __dirname+'/Fonts/Arimo-Italic.ttf'})
.font("Arimo");
if (typeof process.env.TESTING === "undefined") { rpt.printStructure(); }
console.time("Rendered");
rpt.render().then((name) => {
console.timeEnd("Rendered");
const testing = {images: 1, blocks: ["120,130,300,100"]};
displayReport(null, name, testing);
}).catch((err) => {
console.error("Your report had errors while running", err);
});