Mercurial > gemma
comparison 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 |
comparison
equal
deleted
inserted
replaced
3284:7ae1892773a2 | 3285:aac1ca73e92a |
---|---|
8 * – Österreichische Wasserstraßen-Gesellschaft mbH | 8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
9 * Software engineering by Intevation GmbH | 9 * Software engineering by Intevation GmbH |
10 * | 10 * |
11 * Author(s): | 11 * Author(s): |
12 * Markus Kottländer <markus.kottlaender@intevation.de> | 12 * Markus Kottländer <markus.kottlaender@intevation.de> |
13 * * Fadi Abbud <fadi.abbud@intevation.de> | |
13 */ | 14 */ |
14 import locale2 from "locale2"; | 15 import locale2 from "locale2"; |
15 export const sortTable = { | 16 export const sortTable = { |
16 data() { | 17 data() { |
17 return { | 18 return { |
78 x = this.pdf.width - offset.x - width; | 79 x = this.pdf.width - offset.x - width; |
79 } | 80 } |
80 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { | 81 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
81 y = this.pdf.height - offset.y - this.getTextHeight(textLines.length); | 82 y = this.pdf.height - offset.y - this.getTextHeight(textLines.length); |
82 } | 83 } |
83 | |
84 this.pdf.doc.text(textLines, x, y, { baseline: "hanging" }); | 84 this.pdf.doc.text(textLines, x, y, { baseline: "hanging" }); |
85 }, | 85 }, |
86 replacePlaceholders(text) { | 86 replacePlaceholders(text) { |
87 if (text.includes("{date}")) { | 87 if (text.includes("{date}")) { |
88 text = text.replace("{date}", new Date().toLocaleString(locale2)); | 88 text = text.replace("{date}", new Date().toLocaleString(locale2)); |
146 return ( | 146 return ( |
147 numberOfLines * | 147 numberOfLines * |
148 ((this.pdf.doc.getFontSize() * 25.4) / 80) * | 148 ((this.pdf.doc.getFontSize() * 25.4) / 80) * |
149 this.pdf.doc.getLineHeightFactor() | 149 this.pdf.doc.getLineHeightFactor() |
150 ); | 150 ); |
151 }, | |
152 // title for diagram | |
153 addDiagramTitle(position, offset, size, color, text) { | |
154 let x = offset.x, | |
155 y = offset.y; | |
156 | |
157 let width = | |
158 (this.pdf.doc.getStringUnitWidth(text) * size) / (72 / 25.6) + size / 2; | |
159 // if position is on the right, x needs to be calculate with pdf width and | |
160 // the size of the element | |
161 if (["topright", "bottomright"].indexOf(position) !== -1) { | |
162 x = this.pdf.width - offset.x - width; | |
163 } | |
164 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { | |
165 y = this.pdf.height - offset.y - this.getTextHeight(1); | |
166 } | |
167 this.pdf.doc.setTextColor(color); | |
168 this.pdf.doc.setFontSize(size); | |
169 this.pdf.doc.setFontStyle("bold"); | |
170 this.pdf.doc.text(text, x, y, { baseline: "hanging" }); | |
151 }, | 171 }, |
152 addRoundedBox(x, y, w, h, color, rounding, brcolor) { | 172 addRoundedBox(x, y, w, h, color, rounding, brcolor) { |
153 // draws a rounded background box at (x,y) width x height | 173 // draws a rounded background box at (x,y) width x height |
154 // using jsPDF units | 174 // using jsPDF units |
155 this.pdf.doc.setDrawColor(brcolor); | 175 this.pdf.doc.setDrawColor(brcolor); |