fng-reports 0.12.0-beta.21 → 0.12.0-beta.211

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.
@@ -1,441 +1,441 @@
1
- /** ====================================================================
2
- * jsPDF Cell plugin
3
- * Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
4
- * 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
5
- * 2013 Lee Driscoll, https://github.com/lsdriscoll
6
- * 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
7
- * 2014 James Hall, james@parall.ax
8
- *
9
- * Permission is hereby granted, free of charge, to any person obtaining
10
- * a copy of this software and associated documentation files (the
11
- * "Software"), to deal in the Software without restriction, including
12
- * without limitation the rights to use, copy, modify, merge, publish,
13
- * distribute, sublicense, and/or sell copies of the Software, and to
14
- * permit persons to whom the Software is furnished to do so, subject to
15
- * the following conditions:
16
- *
17
- * The above copyright notice and this permission notice shall be
18
- * included in all copies or substantial portions of the Software.
19
- *
20
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
- * ====================================================================
28
- */
29
-
30
- (function (jsPDFAPI) {
31
- 'use strict';
32
- /*jslint browser:true */
33
- /*global document: false, jsPDF */
34
-
35
- var fontName,
36
- fontSize,
37
- fontStyle,
38
- padding = 3,
39
- margin = 13,
40
- headerFunction,
41
- lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
42
- pages = 1,
43
- setLastCellPosition = function (x, y, w, h, ln) {
44
- lastCellPos = { 'x': x, 'y': y, 'w': w, 'h': h, 'ln': ln };
45
- },
46
- getLastCellPosition = function () {
47
- return lastCellPos;
48
- };
49
-
50
- jsPDFAPI.setHeaderFunction = function (func) {
51
- headerFunction = func;
52
- };
53
-
54
- jsPDFAPI.getTextDimensions = function (txt) {
55
- fontName = this.internal.getFont().fontName;
56
- fontSize = this.table_font_size || this.internal.getFontSize();
57
- fontStyle = this.internal.getFont().fontStyle;
58
- // 1 pixel = 0.264583 mm and 1 mm = 72/25.4 point
59
- var px2pt = 0.264583 * 72 / 25.4,
60
- dimensions,
61
- text;
62
-
63
- text = document.createElement('font');
64
- text.id = "jsPDFCell";
65
- text.style.fontStyle = fontStyle;
66
- text.style.fontName = fontName;
67
- text.style.fontSize = fontSize + 'pt';
68
- text.innerText = txt;
69
-
70
- document.body.appendChild(text);
71
-
72
- dimensions = { w: (text.offsetWidth + 1) * px2pt, h: (text.offsetHeight + 1) * px2pt};
73
-
74
- document.body.removeChild(text);
75
-
76
- return dimensions;
77
- };
78
-
79
- jsPDFAPI.cellAddPage = function () {
80
- this.addPage();
81
-
82
- setLastCellPosition(this.margins.left, this.margins.top, undefined, undefined);
83
- //setLastCellPosition(undefined, undefined, undefined, undefined, undefined);
84
- pages += 1;
85
- };
86
-
87
- jsPDFAPI.cellInitialize = function () {
88
- lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined };
89
- pages = 1;
90
- };
91
-
92
- jsPDFAPI.cell = function (x, y, w, h, txt, ln, align) {
93
- var curCell = getLastCellPosition();
94
-
95
- // If this is not the first cell, we must change its position
96
- if (curCell.ln !== undefined) {
97
- if (curCell.ln === ln) {
98
- //Same line
99
- x = curCell.x + curCell.w;
100
- y = curCell.y;
101
- } else {
102
- //New line
103
- if ((curCell.y + curCell.h + h + margin) >= this.internal.pageSize.height - this.margins.bottom) {
104
- this.cellAddPage();
105
- if (this.printHeaders && this.tableHeaderRow) {
106
- this.printHeaderRow(ln, true);
107
- }
108
- }
109
- //We ignore the passed y: the lines may have diferent heights
110
- y = (getLastCellPosition().y + getLastCellPosition().h);
111
-
112
- }
113
- }
114
-
115
- if (txt[0] !== undefined) {
116
- if (this.printingHeaderRow) {
117
- this.rect(x, y, w, h, 'FD');
118
- } else {
119
- this.rect(x, y, w, h);
120
- }
121
- if (align === 'right') {
122
- var textSize;
123
- if (txt instanceof Array) {
124
- for (var i = 0; i < txt.length; i++) {
125
- var currentLine = txt[i];
126
- textSize = this.getStringUnitWidth(currentLine) * this.internal.getFontSize() / (72 / 25.6);
127
- this.text(currentLine, x + w - textSize - padding, y + this.internal.getLineHeight() * (i + 1));
128
- }
129
- } else {
130
- textSize = this.getStringUnitWidth(txt) * this.internal.getFontSize() / (72 / 25.6);
131
- this.text(txt, x + w - textSize - padding, y + this.internal.getLineHeight());
132
- }
133
- } else {
134
- this.text(txt, x + padding, y + this.internal.getLineHeight());
135
- }
136
- }
137
- setLastCellPosition(x, y, w, h, ln);
138
- return this;
139
- };
140
-
141
- /**
142
- * Return an array containing all of the owned keys of an Object
143
- * @type {Function}
144
- * @return {String[]} of Object keys
145
- */
146
- jsPDFAPI.getKeys = (typeof Object.keys === 'function')
147
- ? function (object) {
148
- if (!object) {
149
- return [];
150
- }
151
- return Object.keys(object);
152
- }
153
- : function (object) {
154
- var keys = [],
155
- property;
156
-
157
- for (property in object) {
158
- if (object.hasOwnProperty(property)) {
159
- keys.push(property);
160
- }
161
- }
162
-
163
- return keys;
164
- };
165
-
166
- /**
167
- * Return the maximum value from an array
168
- * @param array
169
- * @param comparisonFn
170
- * @returns {*}
171
- */
172
- jsPDFAPI.arrayMax = function (array, comparisonFn) {
173
- var max = array[0],
174
- i,
175
- ln,
176
- item;
177
-
178
- for (i = 0, ln = array.length; i < ln; i += 1) {
179
- item = array[i];
180
-
181
- if (comparisonFn) {
182
- if (comparisonFn(max, item) === -1) {
183
- max = item;
184
- }
185
- } else {
186
- if (item > max) {
187
- max = item;
188
- }
189
- }
190
- }
191
-
192
- return max;
193
- };
194
-
195
- /**
196
- * Create a table from a set of data.
197
- * @param {Integer} [x] : left-position for top-left corner of table
198
- * @param {Integer} [y] top-position for top-left corner of table
199
- * @param {Object[]} [data] As array of objects containing key-value pairs corresponding to a row of data.
200
- * @param {Object} [config.headers] String[] Omit or null to auto-generate headers at a performance cost
201
- * @param {Object} [config.footers] Object containing key-value pairs. Omit or null if not required
202
- * @param {Object} [config.printHeaders] True to print column headers at the top of every page
203
- * @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value
204
- * @param {Object} [config.margins] margin values for left, top, bottom, and width
205
- * @param {Object} [config.fontSize] Integer fontSize to use (optional)
206
- */
207
-
208
- jsPDFAPI.table = function (x, y, data, config) {
209
- if (!data) {
210
- throw 'No data for PDF table';
211
- }
212
-
213
- var headerNames = [],
214
- headerPrompts = [],
215
- header,
216
- i,
217
- ln,
218
- cln,
219
- columnMatrix = {},
220
- columnWidths = {},
221
- columnData,
222
- column,
223
- columnMinWidths = [],
224
- columnAligns = [],
225
- j,
226
- tableHeaderConfigs = [],
227
- model,
228
- jln,
229
- func,
230
-
231
- //set up defaults. If a value is provided in config, defaults will be overwritten:
232
- autoSize = false,
233
- printHeaders = true,
234
- fontSize = 12,
235
- headers = null,
236
- footers = null,
237
- margins = {left: 0, top: 0, bottom: 0, width: this.internal.pageSize.width};
238
-
239
- if (config) {
240
- //override config defaults if the user has specified non-default behavior:
241
- if (config.autoSize === true) {
242
- autoSize = true;
243
- }
244
- if (config.printHeaders === false) {
245
- printHeaders = false;
246
- }
247
- if (config.fontSize) {
248
- fontSize = config.fontSize;
249
- }
250
- if (config.margins) {
251
- margins = config.margins;
252
- }
253
- if (config.headers) {
254
- headers = config.headers;
255
- }
256
- if (config.footers) {
257
- footers = config.footers;
258
- }
259
- }
260
-
261
- /**
262
- * @property {Number} lnMod
263
- * Keep track of the current line number modifier used when creating cells
264
- */
265
- this.lnMod = 0;
266
- lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
267
- pages = 1;
268
-
269
- this.printHeaders = printHeaders;
270
- this.margins = margins;
271
- this.setFontSize(fontSize);
272
- this.table_font_size = fontSize;
273
-
274
- // Set header values
275
- if (headers === undefined || (headers === null)) {
276
- // No headers defined so we derive from data
277
- headerNames = this.getKeys(data[0]);
278
-
279
- } else if (headers[0] && (typeof headers[0] !== 'string')) {
280
- // var px2pt = 0.264583 * 72 / 25.4;
281
- var constant = 1.5; // arrived at by trial and error
282
-
283
- // Split header configs into names and prompts
284
- for (i = 0, ln = headers.length; i < ln; i += 1) {
285
- header = headers[i];
286
- headerNames.push(header.name);
287
- headerPrompts.push(header.prompt);
288
- columnWidths[header.name] = header.width * constant;
289
- columnAligns[header.name] = header.align;
290
- }
291
-
292
- } else {
293
- headerNames = headers;
294
- }
295
- if (autoSize) {
296
- // Create a matrix of columns e.g., {column_title: [row1_Record, row2_Record]}
297
- func = function (rec) {
298
- return rec[header];
299
- };
300
-
301
- for (i = 0, ln = headerNames.length; i < ln; i += 1) {
302
- header = headerNames[i];
303
-
304
- columnMatrix[header] = data.map(
305
- func
306
- );
307
-
308
- // get header width
309
- columnMinWidths.push(this.getTextDimensions(headerPrompts[i] || header).w);
310
- column = columnMatrix[header];
311
-
312
- // get cell widths
313
- for (j = 0, cln = column.length; j < cln; j += 1) {
314
- columnData = column[j];
315
- columnMinWidths.push(this.getTextDimensions(columnData).w);
316
- }
317
-
318
- // get footer width
319
- if (footers) {
320
- columnMinWidths.push(this.getTextDimensions(footers[i]).w);
321
- }
322
-
323
- // get final column width
324
- columnWidths[header] = jsPDFAPI.arrayMax(columnMinWidths);
325
- }
326
- }
327
-
328
- // -- Construct the table
329
-
330
- if (printHeaders) {
331
- var lineHeight = this.calculateLineHeight(headerNames, columnWidths, headerPrompts.length ? headerPrompts : headerNames);
332
-
333
- // Construct the header row
334
- for (i = 0, ln = headerNames.length; i < ln; i += 1) {
335
- header = headerNames[i];
336
- tableHeaderConfigs.push([x, y, columnWidths[header], lineHeight, String(headerPrompts.length ? headerPrompts[i] : header), 0, columnAligns[header]]);
337
- }
338
-
339
- // Store the table header config
340
- this.setTableHeaderRow(tableHeaderConfigs);
341
-
342
- // Print the header for the start of the table
343
- this.printHeaderRow(1, false);
344
- }
345
-
346
- // Construct the data rows
347
- for (i = 0, ln = data.length; i < ln; i += 1) {
348
- var lineHeight;
349
- model = data[i];
350
- lineHeight = this.calculateLineHeight(headerNames, columnWidths, model);
351
-
352
- for (j = 0, jln = headerNames.length; j < jln; j += 1) {
353
- header = headerNames[j];
354
- this.cell(x, y, columnWidths[header], lineHeight, model[header], i + 2, columnAligns[header]);
355
- }
356
- }
357
-
358
- if (footers) {
359
- // Construct the header row
360
- for (var fi = 0; fi < headerNames.length; fi++) {
361
- header = headerNames[fi];
362
- tableHeaderConfigs[fi][4] = footers[header] || ' ';
363
- }
364
-
365
- // Print the header for the start of the table
366
- this.printHeaderRow(i + 2, false);
367
- }
368
- this.table_x = x;
369
- this.table_y = y;
370
- return this;
371
- };
372
- /**
373
- * Calculate the height for containing the highest column
374
- * @param {String[]} headerNames is the header, used as keys to the data
375
- * @param {Integer[]} columnWidths is size of each column
376
- * @param {Object[]} model is the line of data we want to calculate the height of
377
- */
378
- jsPDFAPI.calculateLineHeight = function (headerNames, columnWidths, model) {
379
- var header, lineHeight = 0;
380
- for (var j = 0; j < headerNames.length; j++) {
381
- header = headerNames[j];
382
- model[header] = this.splitTextToSize(String(model[header]), columnWidths[header] - padding);
383
- var h = this.internal.getLineHeight() * model[header].length + padding;
384
- if (h > lineHeight)
385
- lineHeight = h;
386
- }
387
- return lineHeight;
388
- };
389
-
390
- /**
391
- * Store the config for outputting a table header
392
- * @param {Object[]} config
393
- * An array of cell configs that would define a header row: Each config matches the config used by jsPDFAPI.cell
394
- * except the ln parameter is excluded
395
- */
396
- jsPDFAPI.setTableHeaderRow = function (config) {
397
- this.tableHeaderRow = config;
398
- };
399
-
400
- /**
401
- * Output the store header row
402
- * @param lineNumber The line number to output the header at
403
- */
404
- jsPDFAPI.printHeaderRow = function (lineNumber, new_page) {
405
- if (!this.tableHeaderRow) {
406
- throw 'Property tableHeaderRow does not exist.';
407
- }
408
-
409
- var tableHeaderCell,
410
- tmpArray,
411
- i,
412
- ln;
413
-
414
- this.printingHeaderRow = true;
415
- if (headerFunction !== undefined) {
416
- var position = headerFunction(this, pages);
417
- setLastCellPosition(position[0], position[1], position[2], position[3], -1);
418
- }
419
- this.setFontStyle('bold');
420
- var tempHeaderConf = [];
421
- for (i = 0, ln = this.tableHeaderRow.length; i < ln; i += 1) {
422
- this.setFillColor(200, 200, 200);
423
-
424
- tableHeaderCell = this.tableHeaderRow[i];
425
- if (new_page) {
426
- tableHeaderCell[1] = this.margins.top;
427
- tempHeaderConf.push(tableHeaderCell);
428
- }
429
- tmpArray = [].concat(tableHeaderCell);
430
- tmpArray[5] = lineNumber;
431
- this.cell.apply(this, tmpArray);
432
- }
433
- if (tempHeaderConf.length > 0) {
434
- this.setTableHeaderRow(tempHeaderConf);
435
- }
436
- this.setFontStyle('normal');
437
- this.printingHeaderRow = false;
438
- };
439
-
440
- })(jsPDF.API);
441
-
1
+ // /** ====================================================================
2
+ // * jsPDF Cell plugin
3
+ // * Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
4
+ // * 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
5
+ // * 2013 Lee Driscoll, https://github.com/lsdriscoll
6
+ // * 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
7
+ // * 2014 James Hall, james@parall.ax
8
+ // *
9
+ // * Permission is hereby granted, free of charge, to any person obtaining
10
+ // * a copy of this software and associated documentation files (the
11
+ // * "Software"), to deal in the Software without restriction, including
12
+ // * without limitation the rights to use, copy, modify, merge, publish,
13
+ // * distribute, sublicense, and/or sell copies of the Software, and to
14
+ // * permit persons to whom the Software is furnished to do so, subject to
15
+ // * the following conditions:
16
+ // *
17
+ // * The above copyright notice and this permission notice shall be
18
+ // * included in all copies or substantial portions of the Software.
19
+ // *
20
+ // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ // * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ // * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
+ // * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
+ // * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
+ // * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ // * ====================================================================
28
+ // */
29
+ //
30
+ // (function (jsPDFAPI) {
31
+ // 'use strict';
32
+ // /*jslint browser:true */
33
+ // /*global document: false, jsPDF */
34
+ //
35
+ // var fontName,
36
+ // fontSize,
37
+ // fontStyle,
38
+ // padding = 3,
39
+ // margin = 13,
40
+ // headerFunction,
41
+ // lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
42
+ // pages = 1,
43
+ // setLastCellPosition = function (x, y, w, h, ln) {
44
+ // lastCellPos = { 'x': x, 'y': y, 'w': w, 'h': h, 'ln': ln };
45
+ // },
46
+ // getLastCellPosition = function () {
47
+ // return lastCellPos;
48
+ // };
49
+ //
50
+ // jsPDFAPI.setHeaderFunction = function (func) {
51
+ // headerFunction = func;
52
+ // };
53
+ //
54
+ // jsPDFAPI.getTextDimensions = function (txt) {
55
+ // fontName = this.internal.getFont().fontName;
56
+ // fontSize = this.table_font_size || this.internal.getFontSize();
57
+ // fontStyle = this.internal.getFont().fontStyle;
58
+ // // 1 pixel = 0.264583 mm and 1 mm = 72/25.4 point
59
+ // var px2pt = 0.264583 * 72 / 25.4,
60
+ // dimensions,
61
+ // text;
62
+ //
63
+ // text = document.createElement('font');
64
+ // text.id = "jsPDFCell";
65
+ // text.style.fontStyle = fontStyle;
66
+ // text.style.fontName = fontName;
67
+ // text.style.fontSize = fontSize + 'pt';
68
+ // text.innerText = txt;
69
+ //
70
+ // document.body.appendChild(text);
71
+ //
72
+ // dimensions = { w: (text.offsetWidth + 1) * px2pt, h: (text.offsetHeight + 1) * px2pt};
73
+ //
74
+ // document.body.removeChild(text);
75
+ //
76
+ // return dimensions;
77
+ // };
78
+ //
79
+ // jsPDFAPI.cellAddPage = function () {
80
+ // this.addPage();
81
+ //
82
+ // setLastCellPosition(this.margins.left, this.margins.top, undefined, undefined);
83
+ // //setLastCellPosition(undefined, undefined, undefined, undefined, undefined);
84
+ // pages += 1;
85
+ // };
86
+ //
87
+ // jsPDFAPI.cellInitialize = function () {
88
+ // lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined };
89
+ // pages = 1;
90
+ // };
91
+ //
92
+ // jsPDFAPI.cell = function (x, y, w, h, txt, ln, align) {
93
+ // var curCell = getLastCellPosition();
94
+ //
95
+ // // If this is not the first cell, we must change its position
96
+ // if (curCell.ln !== undefined) {
97
+ // if (curCell.ln === ln) {
98
+ // //Same line
99
+ // x = curCell.x + curCell.w;
100
+ // y = curCell.y;
101
+ // } else {
102
+ // //New line
103
+ // if ((curCell.y + curCell.h + h + margin) >= this.internal.pageSize.height - this.margins.bottom) {
104
+ // this.cellAddPage();
105
+ // if (this.printHeaders && this.tableHeaderRow) {
106
+ // this.printHeaderRow(ln, true);
107
+ // }
108
+ // }
109
+ // //We ignore the passed y: the lines may have diferent heights
110
+ // y = (getLastCellPosition().y + getLastCellPosition().h);
111
+ //
112
+ // }
113
+ // }
114
+ //
115
+ // if (txt[0] !== undefined) {
116
+ // if (this.printingHeaderRow) {
117
+ // this.rect(x, y, w, h, 'FD');
118
+ // } else {
119
+ // this.rect(x, y, w, h);
120
+ // }
121
+ // if (align === 'right') {
122
+ // var textSize;
123
+ // if (txt instanceof Array) {
124
+ // for (var i = 0; i < txt.length; i++) {
125
+ // var currentLine = txt[i];
126
+ // textSize = this.getStringUnitWidth(currentLine) * this.internal.getFontSize() / (72 / 25.6);
127
+ // this.text(currentLine, x + w - textSize - padding, y + this.internal.getLineHeight() * (i + 1));
128
+ // }
129
+ // } else {
130
+ // textSize = this.getStringUnitWidth(txt) * this.internal.getFontSize() / (72 / 25.6);
131
+ // this.text(txt, x + w - textSize - padding, y + this.internal.getLineHeight());
132
+ // }
133
+ // } else {
134
+ // this.text(txt, x + padding, y + this.internal.getLineHeight());
135
+ // }
136
+ // }
137
+ // setLastCellPosition(x, y, w, h, ln);
138
+ // return this;
139
+ // };
140
+ //
141
+ // /**
142
+ // * Return an array containing all of the owned keys of an Object
143
+ // * @type {Function}
144
+ // * @return {String[]} of Object keys
145
+ // */
146
+ // jsPDFAPI.getKeys = (typeof Object.keys === 'function')
147
+ // ? function (object) {
148
+ // if (!object) {
149
+ // return [];
150
+ // }
151
+ // return Object.keys(object);
152
+ // }
153
+ // : function (object) {
154
+ // var keys = [],
155
+ // property;
156
+ //
157
+ // for (property in object) {
158
+ // if (object.hasOwnProperty(property)) {
159
+ // keys.push(property);
160
+ // }
161
+ // }
162
+ //
163
+ // return keys;
164
+ // };
165
+ //
166
+ // /**
167
+ // * Return the maximum value from an array
168
+ // * @param array
169
+ // * @param comparisonFn
170
+ // * @returns {*}
171
+ // */
172
+ // jsPDFAPI.arrayMax = function (array, comparisonFn) {
173
+ // var max = array[0],
174
+ // i,
175
+ // ln,
176
+ // item;
177
+ //
178
+ // for (i = 0, ln = array.length; i < ln; i += 1) {
179
+ // item = array[i];
180
+ //
181
+ // if (comparisonFn) {
182
+ // if (comparisonFn(max, item) === -1) {
183
+ // max = item;
184
+ // }
185
+ // } else {
186
+ // if (item > max) {
187
+ // max = item;
188
+ // }
189
+ // }
190
+ // }
191
+ //
192
+ // return max;
193
+ // };
194
+ //
195
+ // /**
196
+ // * Create a table from a set of data.
197
+ // * @param {Integer} [x] : left-position for top-left corner of table
198
+ // * @param {Integer} [y] top-position for top-left corner of table
199
+ // * @param {Object[]} [data] As array of objects containing key-value pairs corresponding to a row of data.
200
+ // * @param {Object} [config.headers] String[] Omit or null to auto-generate headers at a performance cost
201
+ // * @param {Object} [config.footers] Object containing key-value pairs. Omit or null if not required
202
+ // * @param {Object} [config.printHeaders] True to print column headers at the top of every page
203
+ // * @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value
204
+ // * @param {Object} [config.margins] margin values for left, top, bottom, and width
205
+ // * @param {Object} [config.fontSize] Integer fontSize to use (optional)
206
+ // */
207
+ //
208
+ // jsPDFAPI.table = function (x, y, data, config) {
209
+ // if (!data) {
210
+ // throw 'No data for PDF table';
211
+ // }
212
+ //
213
+ // var headerNames = [],
214
+ // headerPrompts = [],
215
+ // header,
216
+ // i,
217
+ // ln,
218
+ // cln,
219
+ // columnMatrix = {},
220
+ // columnWidths = {},
221
+ // columnData,
222
+ // column,
223
+ // columnMinWidths = [],
224
+ // columnAligns = [],
225
+ // j,
226
+ // tableHeaderConfigs = [],
227
+ // model,
228
+ // jln,
229
+ // func,
230
+ //
231
+ // //set up defaults. If a value is provided in config, defaults will be overwritten:
232
+ // autoSize = false,
233
+ // printHeaders = true,
234
+ // fontSize = 12,
235
+ // headers = null,
236
+ // footers = null,
237
+ // margins = {left: 0, top: 0, bottom: 0, width: this.internal.pageSize.width};
238
+ //
239
+ // if (config) {
240
+ // //override config defaults if the user has specified non-default behavior:
241
+ // if (config.autoSize === true) {
242
+ // autoSize = true;
243
+ // }
244
+ // if (config.printHeaders === false) {
245
+ // printHeaders = false;
246
+ // }
247
+ // if (config.fontSize) {
248
+ // fontSize = config.fontSize;
249
+ // }
250
+ // if (config.margins) {
251
+ // margins = config.margins;
252
+ // }
253
+ // if (config.headers) {
254
+ // headers = config.headers;
255
+ // }
256
+ // if (config.footers) {
257
+ // footers = config.footers;
258
+ // }
259
+ // }
260
+ //
261
+ // /**
262
+ // * @property {Number} lnMod
263
+ // * Keep track of the current line number modifier used when creating cells
264
+ // */
265
+ // this.lnMod = 0;
266
+ // lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined },
267
+ // pages = 1;
268
+ //
269
+ // this.printHeaders = printHeaders;
270
+ // this.margins = margins;
271
+ // this.setFontSize(fontSize);
272
+ // this.table_font_size = fontSize;
273
+ //
274
+ // // Set header values
275
+ // if (headers === undefined || (headers === null)) {
276
+ // // No headers defined so we derive from data
277
+ // headerNames = this.getKeys(data[0]);
278
+ //
279
+ // } else if (headers[0] && (typeof headers[0] !== 'string')) {
280
+ // // var px2pt = 0.264583 * 72 / 25.4;
281
+ // var constant = 1.5; // arrived at by trial and error
282
+ //
283
+ // // Split header configs into names and prompts
284
+ // for (i = 0, ln = headers.length; i < ln; i += 1) {
285
+ // header = headers[i];
286
+ // headerNames.push(header.name);
287
+ // headerPrompts.push(header.prompt);
288
+ // columnWidths[header.name] = header.width * constant;
289
+ // columnAligns[header.name] = header.align;
290
+ // }
291
+ //
292
+ // } else {
293
+ // headerNames = headers;
294
+ // }
295
+ // if (autoSize) {
296
+ // // Create a matrix of columns e.g., {column_title: [row1_Record, row2_Record]}
297
+ // func = function (rec) {
298
+ // return rec[header];
299
+ // };
300
+ //
301
+ // for (i = 0, ln = headerNames.length; i < ln; i += 1) {
302
+ // header = headerNames[i];
303
+ //
304
+ // columnMatrix[header] = data.map(
305
+ // func
306
+ // );
307
+ //
308
+ // // get header width
309
+ // columnMinWidths.push(this.getTextDimensions(headerPrompts[i] || header).w);
310
+ // column = columnMatrix[header];
311
+ //
312
+ // // get cell widths
313
+ // for (j = 0, cln = column.length; j < cln; j += 1) {
314
+ // columnData = column[j];
315
+ // columnMinWidths.push(this.getTextDimensions(columnData).w);
316
+ // }
317
+ //
318
+ // // get footer width
319
+ // if (footers) {
320
+ // columnMinWidths.push(this.getTextDimensions(footers[i]).w);
321
+ // }
322
+ //
323
+ // // get final column width
324
+ // columnWidths[header] = jsPDFAPI.arrayMax(columnMinWidths);
325
+ // }
326
+ // }
327
+ //
328
+ // // -- Construct the table
329
+ //
330
+ // if (printHeaders) {
331
+ // var lineHeight = this.calculateLineHeight(headerNames, columnWidths, headerPrompts.length ? headerPrompts : headerNames);
332
+ //
333
+ // // Construct the header row
334
+ // for (i = 0, ln = headerNames.length; i < ln; i += 1) {
335
+ // header = headerNames[i];
336
+ // tableHeaderConfigs.push([x, y, columnWidths[header], lineHeight, String(headerPrompts.length ? headerPrompts[i] : header), 0, columnAligns[header]]);
337
+ // }
338
+ //
339
+ // // Store the table header config
340
+ // this.setTableHeaderRow(tableHeaderConfigs);
341
+ //
342
+ // // Print the header for the start of the table
343
+ // this.printHeaderRow(1, false);
344
+ // }
345
+ //
346
+ // // Construct the data rows
347
+ // for (i = 0, ln = data.length; i < ln; i += 1) {
348
+ // var lineHeight;
349
+ // model = data[i];
350
+ // lineHeight = this.calculateLineHeight(headerNames, columnWidths, model);
351
+ //
352
+ // for (j = 0, jln = headerNames.length; j < jln; j += 1) {
353
+ // header = headerNames[j];
354
+ // this.cell(x, y, columnWidths[header], lineHeight, model[header], i + 2, columnAligns[header]);
355
+ // }
356
+ // }
357
+ //
358
+ // if (footers) {
359
+ // // Construct the header row
360
+ // for (var fi = 0; fi < headerNames.length; fi++) {
361
+ // header = headerNames[fi];
362
+ // tableHeaderConfigs[fi][4] = footers[header] || ' ';
363
+ // }
364
+ //
365
+ // // Print the header for the start of the table
366
+ // this.printHeaderRow(i + 2, false);
367
+ // }
368
+ // this.table_x = x;
369
+ // this.table_y = y;
370
+ // return this;
371
+ // };
372
+ // /**
373
+ // * Calculate the height for containing the highest column
374
+ // * @param {String[]} headerNames is the header, used as keys to the data
375
+ // * @param {Integer[]} columnWidths is size of each column
376
+ // * @param {Object[]} model is the line of data we want to calculate the height of
377
+ // */
378
+ // jsPDFAPI.calculateLineHeight = function (headerNames, columnWidths, model) {
379
+ // var header, lineHeight = 0;
380
+ // for (var j = 0; j < headerNames.length; j++) {
381
+ // header = headerNames[j];
382
+ // model[header] = this.splitTextToSize(String(model[header]), columnWidths[header] - padding);
383
+ // var h = this.internal.getLineHeight() * model[header].length + padding;
384
+ // if (h > lineHeight)
385
+ // lineHeight = h;
386
+ // }
387
+ // return lineHeight;
388
+ // };
389
+ //
390
+ // /**
391
+ // * Store the config for outputting a table header
392
+ // * @param {Object[]} config
393
+ // * An array of cell configs that would define a header row: Each config matches the config used by jsPDFAPI.cell
394
+ // * except the ln parameter is excluded
395
+ // */
396
+ // jsPDFAPI.setTableHeaderRow = function (config) {
397
+ // this.tableHeaderRow = config;
398
+ // };
399
+ //
400
+ // /**
401
+ // * Output the store header row
402
+ // * @param lineNumber The line number to output the header at
403
+ // */
404
+ // jsPDFAPI.printHeaderRow = function (lineNumber, new_page) {
405
+ // if (!this.tableHeaderRow) {
406
+ // throw 'Property tableHeaderRow does not exist.';
407
+ // }
408
+ //
409
+ // var tableHeaderCell,
410
+ // tmpArray,
411
+ // i,
412
+ // ln;
413
+ //
414
+ // this.printingHeaderRow = true;
415
+ // if (headerFunction !== undefined) {
416
+ // var position = headerFunction(this, pages);
417
+ // setLastCellPosition(position[0], position[1], position[2], position[3], -1);
418
+ // }
419
+ // this.setFontStyle('bold');
420
+ // var tempHeaderConf = [];
421
+ // for (i = 0, ln = this.tableHeaderRow.length; i < ln; i += 1) {
422
+ // this.setFillColor(200, 200, 200);
423
+ //
424
+ // tableHeaderCell = this.tableHeaderRow[i];
425
+ // if (new_page) {
426
+ // tableHeaderCell[1] = this.margins.top;
427
+ // tempHeaderConf.push(tableHeaderCell);
428
+ // }
429
+ // tmpArray = [].concat(tableHeaderCell);
430
+ // tmpArray[5] = lineNumber;
431
+ // this.cell.apply(this, tmpArray);
432
+ // }
433
+ // if (tempHeaderConf.length > 0) {
434
+ // this.setTableHeaderRow(tempHeaderConf);
435
+ // }
436
+ // this.setFontStyle('normal');
437
+ // this.printingHeaderRow = false;
438
+ // };
439
+ //
440
+ // })(jsPDF.API);
441
+ //