Mercurial > gemma
comparison client/src/lib/mixins.js @ 3798:e008197e2215 yworks-svg2pdf
client: improve pdf generation
* Use generatePDF() from HydrologicalConditions.vue to unify code.
* Split out formatting of gaugeInfo, used from Waterlevel.vue
and HydrologicalConditions.vue.
* Make paper width and size setting in generatePDF() more readable
by grouping the conditions more logically.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Thu, 04 Jul 2019 10:15:46 +0200 |
parents | 243316850889 |
children | f4deb4aae485 |
comparison
equal
deleted
inserted
replaced
3797:20c1ac8ab8a2 | 3798:e008197e2215 |
---|---|
68 computed: { | 68 computed: { |
69 ...mapState("application", ["logoForPDF"]), | 69 ...mapState("application", ["logoForPDF"]), |
70 ...mapState("user", ["user"]) | 70 ...mapState("user", ["user"]) |
71 }, | 71 }, |
72 methods: { | 72 methods: { |
73 gaugeInfo(selectedGauge) { | |
74 // returns string with formatted gauge info | |
75 return ( | |
76 selectedGauge.properties.objname + | |
77 " (" + | |
78 selectedGauge.id | |
79 .split(".")[1] | |
80 .replace(/[()]/g, "") | |
81 .split(",")[3] + | |
82 ")" | |
83 ); | |
84 }, | |
73 generatePDF(params) { | 85 generatePDF(params) { |
74 // creates a new jsPDF object into this.pdf.doc | 86 // creates a new jsPDF object into this.pdf.doc |
75 let templateData = params["templateData"]; | 87 let templateData = params["templateData"]; |
76 let diagramTitle = params["diagramTitle"]; | 88 let diagramTitle = params["diagramTitle"]; |
77 | 89 |
79 "l", | 91 "l", |
80 "mm", | 92 "mm", |
81 this.templateData.properties.paperSize | 93 this.templateData.properties.paperSize |
82 ); | 94 ); |
83 // pdf width and height in millimeter (landscape) | 95 // pdf width and height in millimeter (landscape) |
84 this.pdf.width = templateData.properties.paperSize === "a3" ? 420 : 297; | 96 if (templateData.properties.paperSize === "a3") { |
85 this.pdf.height = templateData.properties.paperSize === "a4" ? 297 : 210; | 97 this.pdf.width = 420; |
98 this.pdf.height = 297; | |
99 } else { | |
100 this.pdf.width = 297; | |
101 this.pdf.height = 210; | |
102 } | |
86 // check the template elements | 103 // check the template elements |
87 if (templateData) { | 104 if (templateData) { |
88 let defaultFontSize = 11, | 105 let defaultFontSize = 11, |
89 defaultColor = "black", | 106 defaultColor = "black", |
90 defaultWidth = 70, | 107 defaultWidth = 70, |