Mercurial > gemma
diff client/src/lib/mixins.js @ 3285:aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Thu, 16 May 2019 11:28:44 +0200 |
parents | 050e72ce5cf7 |
children | 76f643d20f19 |
line wrap: on
line diff
--- a/client/src/lib/mixins.js Thu May 16 11:00:19 2019 +0200 +++ b/client/src/lib/mixins.js Thu May 16 11:28:44 2019 +0200 @@ -10,6 +10,7 @@ * * Author(s): * Markus Kottländer <markus.kottlaender@intevation.de> + * * Fadi Abbud <fadi.abbud@intevation.de> */ import locale2 from "locale2"; export const sortTable = { @@ -80,7 +81,6 @@ if (["bottomright", "bottomleft"].indexOf(position) !== -1) { y = this.pdf.height - offset.y - this.getTextHeight(textLines.length); } - this.pdf.doc.text(textLines, x, y, { baseline: "hanging" }); }, replacePlaceholders(text) { @@ -149,6 +149,26 @@ this.pdf.doc.getLineHeightFactor() ); }, + // title for diagram + addDiagramTitle(position, offset, size, color, text) { + let x = offset.x, + y = offset.y; + + let width = + (this.pdf.doc.getStringUnitWidth(text) * size) / (72 / 25.6) + size / 2; + // 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 - this.getTextHeight(1); + } + this.pdf.doc.setTextColor(color); + this.pdf.doc.setFontSize(size); + this.pdf.doc.setFontStyle("bold"); + this.pdf.doc.text(text, x, y, { baseline: "hanging" }); + }, addRoundedBox(x, y, w, h, color, rounding, brcolor) { // draws a rounded background box at (x,y) width x height // using jsPDF units