Mercurial > gemma
changeset 3141:42324626f9e2
client: add box element for pdf-template (waterlevel)
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Thu, 02 May 2019 14:44:16 +0200 |
parents | 91556825d95c |
children | 2ea307abf80b |
files | client/src/components/gauge/Waterlevel.vue client/src/lib/mixins.js |
diffstat | 2 files changed, 38 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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; + } } }); }
--- 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"); } } };