pdfkit-table
Advanced tools
Comparing version 0.1.49 to 0.1.51
136
index.js
@@ -70,4 +70,3 @@ // jshint esversion: 6 | ||
const columnIsDefined = options.columnsSize.length ? true : false ; | ||
const columnCount = table.headers.length; // TODO if not have header | ||
const columnIsDefined = options.columnsSize.length ? true : false; | ||
const columnSpacing = options.columnSpacing || 3; // 15 | ||
@@ -90,3 +89,2 @@ let columnSizes = []; | ||
// if options.x === null | ||
// reset position to margins.left | ||
@@ -194,3 +192,3 @@ if( options.x === null || options.x === -1 ){ | ||
// validate | ||
if( typeof row !== 'object' ) return; | ||
if(typeof row !== 'object') return; | ||
@@ -221,3 +219,3 @@ // options | ||
// if row is object, content with property and options | ||
if( !Array.isArray(row) && typeof row === 'object' && !row.hasOwnProperty('property') ){ | ||
if(!Array.isArray(row) && typeof row === 'object' && !row.hasOwnProperty('property')){ | ||
const cells = []; | ||
@@ -263,12 +261,2 @@ // get all properties names on header | ||
// const columnPositions = []; // 0, 10, 20, 30, 100 | ||
// values | ||
// tableWidth 477 | ||
// columnPositions [ | ||
// 30, 180, 330, | ||
// 30, 180, 330, | ||
// 30, 180, 330, | ||
// ] | ||
let h = []; // header width | ||
@@ -293,3 +281,3 @@ let p = []; // position | ||
if(h.length === 0) { | ||
columnWidth = (w / table.headers.length); // - columnSpacing | ||
columnWidth = ( w / table.headers.length ); // - columnSpacing // define column width | ||
table.headers.forEach( () => h.push(columnWidth) ); | ||
@@ -332,3 +320,3 @@ } | ||
let rowHeight = computeRowHeight(table.headers); | ||
let lastPosition = 0; // x position head | ||
let lastPosition = startX; // x position head | ||
@@ -338,45 +326,26 @@ // Check to have enough room for header and first rows. default 3 | ||
if(table.headers && table.headers.length > 0){ | ||
if(table.headers.length > 0) { | ||
// simple header | ||
if(typeof table.headers[0] === 'string') { | ||
// we have columnSizes[] complete | ||
if(columnIsDefined) { | ||
// // background header | ||
// const rectRow = { | ||
// x: startX, | ||
// y: startY - columnSpacing - (rowDistance * 2), | ||
// width: columnWidth, | ||
// height: rowHeight + columnSpacing, | ||
// }; | ||
// sum columns sizes | ||
columnWidth = columnSizes.reduce((acc, curr, index ) => acc + curr, 0); | ||
// background header | ||
const rectRow = { | ||
x: startX, | ||
y: startY - columnSpacing - (rowDistance * 2), | ||
width: columnWidth, | ||
height: rowHeight + columnSpacing, | ||
}; | ||
// // add background | ||
// this.addBackground(rectRow); | ||
// add background | ||
this.addBackground(rectRow); | ||
// print headers | ||
table.headers.forEach((header, i) => { | ||
lastPosition = startX; | ||
// print headers | ||
table.headers.forEach((header, i) => { | ||
this.text(header, lastPosition, startY, { | ||
width: columnSizes[i] >> 0, | ||
align: "left", | ||
}); | ||
// columnPositions.push(lastPosition); | ||
lastPosition += columnSizes[i] >> 0; | ||
}); | ||
} else { | ||
// background header | ||
const rectRow = { | ||
x: startX, | ||
const rectCell = { | ||
x: lastPosition, | ||
y: startY - columnSpacing - (rowDistance * 2), | ||
width: columnWidth * table.headers.length, | ||
width: columnSizes[i], | ||
height: rowHeight + columnSpacing, | ||
@@ -386,24 +355,15 @@ }; | ||
// add background | ||
this.addBackground(rectRow); | ||
// print headers | ||
table.headers.forEach( (header, i) => { | ||
this.addBackground(rectCell); | ||
lastPosition = startX + i * columnWidth; | ||
this.text(header, lastPosition, startY, { | ||
width: columnWidth, | ||
align: "left", | ||
}); | ||
// columnSizes.push(columnWidth); | ||
// columnPositions.push(lastPosition); | ||
this.text(header, lastPosition, startY, { | ||
width: columnSizes[i] >> 0, | ||
align: "left", | ||
}); | ||
lastPosition += columnSizes[i] >> 0; | ||
} | ||
}); | ||
}else{ | ||
lastPosition = startX; | ||
// Print all headers | ||
@@ -414,3 +374,5 @@ table.headers.forEach(( dataHeader, i) => { | ||
// check defination | ||
width = width || columnWidth; | ||
width = width || columnSizes[i]; | ||
// force number | ||
width = width >> 0; | ||
@@ -420,5 +382,2 @@ if(renderer && typeof renderer === 'string') { | ||
} | ||
// force number | ||
width = width >> 0; | ||
@@ -442,4 +401,2 @@ // background header | ||
// columnSizes.push(width); | ||
// columnPositions.push(lastPosition); | ||
lastPosition += width; | ||
@@ -449,6 +406,7 @@ | ||
// set style | ||
prepareRowOptions(table.headers); | ||
} | ||
} | ||
// set style | ||
prepareRowOptions(table.headers); | ||
} | ||
@@ -459,8 +417,2 @@ | ||
// update table width | ||
// tableWidth = columnPositions[columnPositions.length-1] + columnSizes[columnSizes.length-1]; | ||
// this.logg('tableWidth',tableWidth); | ||
// this.logg('columnPositions',columnPositions); | ||
// Separation line between headers and rows | ||
@@ -471,8 +423,6 @@ separationsRow(startX, rowBottomY); | ||
// End header | ||
addHeader(); | ||
// End header | ||
// datas ---------------------------------------------------- | ||
// Datas | ||
table.datas.forEach((row, i) => { | ||
@@ -557,4 +507,3 @@ | ||
// renderer column | ||
// renderer && (text = renderer(text, index, i, row, rectRow, rectCell)) // value, index-column, index-row, row | ||
// renderer column | ||
// renderer && (text = renderer(text, index, i, row, rectRow, rectCell)) // value, index-column, index-row, row nbhmn | ||
if(typeof renderer === 'function'){ | ||
@@ -589,8 +538,7 @@ text = renderer(text, index, i, row, rectRow, rectCell); // value, index-column, index-row, row | ||
} | ||
}); | ||
// end datas | ||
// End datas | ||
// rows ---------------------------------------------------- | ||
// Rows | ||
table.rows.forEach((row, i) => { | ||
@@ -656,4 +604,4 @@ | ||
}); | ||
// end rows ---------------------------------------------------- | ||
// End rows | ||
// update position | ||
@@ -660,0 +608,0 @@ this.x = startX; |
{ | ||
"name": "pdfkit-table", | ||
"version": "0.1.49", | ||
"version": "0.1.51", | ||
"description": "PdfKit Table. Helps to draw informations in simple tables using pdfkit. #server-side. Generate pdf tables with javascript (PDFKIT plugin) ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31683
461