comparison client/src/components/gauge/HydrologicalConditions.vue @ 3862:ecf2e5ea1464

Backed out changeset 55e503270f38
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 09 Jul 2019 15:37:42 +0200
parents 55e503270f38
children 36e85a74fca0
comparison
equal deleted inserted replaced
3858:55e503270f38 3862:ecf2e5ea1464
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";
107 import { pdfgen, templateLoader } from "@/lib/mixins"; 108 import { pdfgen, templateLoader } from "@/lib/mixins";
108 import { HTTP } from "@/lib/http"; 109 import { HTTP } from "@/lib/http";
109 import { displayError } from "@/lib/errors"; 110 import { displayError } from "@/lib/errors";
110 111
111 export default { 112 export default {
244 this.pdf.doc.save( 245 this.pdf.doc.save(
245 this.selectedGauge.properties.objname + 246 this.selectedGauge.properties.objname +
246 " Hydrological-condition Diagram.pdf" 247 " Hydrological-condition Diagram.pdf"
247 ); 248 );
248 }, 249 },
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 },
249 applyChange() { 280 applyChange() {
250 if (this.form.template.hasOwnProperty("properties")) { 281 if (this.form.template.hasOwnProperty("properties")) {
251 this.templateData = this.defaultTemplate; 282 this.templateData = this.defaultTemplate;
252 return; 283 return;
253 } 284 }