# HG changeset patch # User Fadi Abbud # Date 1556801056 -7200 # Node ID 42324626f9e24c03b01dbf40d3182c26ec7c32db # Parent 91556825d95c0a44c90c26db3adef367bd3b7df6 client: add box element for pdf-template (waterlevel) diff -r 91556825d95c -r 42324626f9e2 client/src/components/gauge/Waterlevel.vue --- a/client/src/components/gauge/Waterlevel.vue Thu May 02 12:59:52 2019 +0200 +++ b/client/src/components/gauge/Waterlevel.vue Thu May 02 14:44:16 2019 +0200 @@ -179,6 +179,9 @@ defaultColor = "black", defaultWidth = 70, defaultTextColor = "black", + defaultBorderColor = "white", + defaultBgColor = "white", + defaultRounding = 2, defaultOffset = { x: 0, y: 0 }; this.templateData.elements.forEach(e => { switch (e.type) { @@ -216,6 +219,18 @@ ); break; } + case "box": { + this.addBox( + e.position, + e.offset, + e.width, + e.height, + e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, + e.color || defaultBgColor, + e.brcolor || defaultBorderColor + ); + break; + } } }); } diff -r 91556825d95c -r 42324626f9e2 client/src/lib/mixins.js --- a/client/src/lib/mixins.js Thu May 02 12:59:52 2019 +0200 +++ b/client/src/lib/mixins.js Thu May 02 14:44:16 2019 +0200 @@ -120,6 +120,29 @@ } } this.pdf.doc.addImage(image, x, y, width, height); + }, + addBox(position, offset, width, height, rounding, color, brcolor) { + // x/y defaults to offset for topleft corner (normal x/y coordinates) + let x = offset.x; + let y = offset.y; + + // if position is on the right, x needs to be calculate with pdf width and + // the size of the element + if (["topright", "bottomright"].indexOf(position) !== -1) { + x = this.pdf.width - offset.x - width; + } + if (["bottomright", "bottomleft"].indexOf(position) !== -1) { + y = this.pdf.height - offset.y - height; + } + + this.addRoundedBox(x, y, width, height, color, rounding, brcolor); + }, + addRoundedBox(x, y, w, h, color, rounding, brcolor) { + // draws a rounded background box at (x,y) width x height + // using jsPDF units + this.pdf.doc.setDrawColor(brcolor); + this.pdf.doc.setFillColor(color); + this.pdf.doc.roundedRect(x, y, w, h, rounding, rounding, "FD"); } } };