Mercurial > gemma
comparison client/src/components/gauge/HydrologicalConditions.vue @ 3858:55e503270f38
move code vor svg2pdf in mixin
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Tue, 09 Jul 2019 14:42:26 +0200 |
parents | 6ce80daf8413 |
children | ecf2e5ea1464 |
comparison
equal
deleted
inserted
replaced
3857:6ce80daf8413 | 3858:55e503270f38 |
---|---|
102 | 102 |
103 import { mapState, mapGetters } from "vuex"; | 103 import { mapState, mapGetters } from "vuex"; |
104 import * as d3 from "d3"; | 104 import * as d3 from "d3"; |
105 import debounce from "debounce"; | 105 import debounce from "debounce"; |
106 import { startOfYear, endOfYear } from "date-fns"; | 106 import { startOfYear, endOfYear } from "date-fns"; |
107 import svg2pdf from "svg2pdf.js"; | |
108 import { pdfgen, templateLoader } from "@/lib/mixins"; | 107 import { pdfgen, templateLoader } from "@/lib/mixins"; |
109 import { HTTP } from "@/lib/http"; | 108 import { HTTP } from "@/lib/http"; |
110 import { displayError } from "@/lib/errors"; | 109 import { displayError } from "@/lib/errors"; |
111 | 110 |
112 export default { | 111 export default { |
245 this.pdf.doc.save( | 244 this.pdf.doc.save( |
246 this.selectedGauge.properties.objname + | 245 this.selectedGauge.properties.objname + |
247 " Hydrological-condition Diagram.pdf" | 246 " Hydrological-condition Diagram.pdf" |
248 ); | 247 ); |
249 }, | 248 }, |
250 addDiagram(position, offset, width, height) { | |
251 let x = offset.x, | |
252 y = offset.y; | |
253 // check if there are tow diagrams on the screen | |
254 // draw the diagram in a separated html element to get the full size | |
255 const offScreen = document.querySelector("#offScreen"); | |
256 offScreen.style.width = "1550px"; | |
257 offScreen.style.height = "400px"; | |
258 this.renderTo(offScreen); | |
259 var svg = offScreen.querySelector("svg"); | |
260 // use default width,height if they are missing in the template definition | |
261 if (!width) { | |
262 width = this.templateData.properties.paperSize === "a3" ? 380 : 290; | |
263 } | |
264 if (!height) { | |
265 height = this.templateData.properties.paperSize === "a3" ? 130 : 100; | |
266 } | |
267 if (["topright", "bottomright"].indexOf(position) !== -1) { | |
268 x = this.pdf.width - offset.x - width; | |
269 } | |
270 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { | |
271 y = this.pdf.height - offset.y - height; | |
272 } | |
273 svg2pdf(svg, this.pdf.doc, { | |
274 xOffset: x, | |
275 yOffset: y, | |
276 // TODO depend on the size and aspect ration on paper | |
277 scale: this.templateData.properties.paperSize === "a3" ? 0.45 : 0.18 | |
278 }); | |
279 }, | |
280 applyChange() { | 249 applyChange() { |
281 if (this.form.template.hasOwnProperty("properties")) { | 250 if (this.form.template.hasOwnProperty("properties")) { |
282 this.templateData = this.defaultTemplate; | 251 this.templateData = this.defaultTemplate; |
283 return; | 252 return; |
284 } | 253 } |