comparison client/src/lib/mixins.js @ 3941:7b3935a8d9ee

refactor addDiagram to mixin and remove code duplication
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 12 Jul 2019 11:02:46 +0200
parents d859ec6cf2f0
children 3c468ed76daf
comparison
equal deleted inserted replaced
3940:f56d14b9d9f1 3941:7b3935a8d9ee
12 * * Markus Kottländer <markus.kottlaender@intevation.de> 12 * * Markus Kottländer <markus.kottlaender@intevation.de>
13 * * Fadi Abbud <fadi.abbud@intevation.de> 13 * * Fadi Abbud <fadi.abbud@intevation.de>
14 * * Bernhard Reiter <bernhard.reiter@intevation.de> 14 * * Bernhard Reiter <bernhard.reiter@intevation.de>
15 */ 15 */
16 import jsPDF from "jspdf-yworks"; 16 import jsPDF from "jspdf-yworks";
17 import svg2pdf from "svg2pdf.js";
17 import locale2 from "locale2"; 18 import locale2 from "locale2";
18 import { mapState } from "vuex"; 19 import { mapState } from "vuex";
19 import { HTTP } from "@/lib/http"; 20 import { HTTP } from "@/lib/http";
20 21
21 export const sortTable = { 22 export const sortTable = {
131 computed: { 132 computed: {
132 ...mapState("application", ["logoForPDF"]), 133 ...mapState("application", ["logoForPDF"]),
133 ...mapState("user", ["user"]) 134 ...mapState("user", ["user"])
134 }, 135 },
135 methods: { 136 methods: {
137 addDiagram(position, offset, width, height) {
138 let x = offset.x,
139 y = offset.y;
140 const svgWidth = this.millimeter2pixels(width, 80);
141 const svgHeight = this.millimeter2pixels(height, 80);
142 // draw the diagram in a separated html element to get the full size
143 const offScreen = document.querySelector("#offScreen");
144 offScreen.style.width = `${svgWidth}px`;
145 offScreen.style.height = `${svgHeight}px`;
146 const layout = this.getPrintLayout(svgHeight);
147 this.renderTo({
148 element: offScreen,
149 dimensions: this.getDimensions({
150 svgWidth: svgWidth,
151 svgHeight: svgHeight,
152 ...layout
153 })
154 });
155 var svg = offScreen.querySelector("svg");
156 if (["topright", "bottomright"].indexOf(position) !== -1) {
157 x = this.pdf.width - offset.x - width;
158 }
159 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
160 y = this.pdf.height - offset.y - height;
161 }
162 svg2pdf(svg, this.pdf.doc, {
163 xOffset: x,
164 yOffset: y,
165 scale: 0.354
166 });
167 offScreen.removeChild(svg);
168 },
136 getPaperDimensions(format) { 169 getPaperDimensions(format) {
137 const dims = { 170 const dims = {
138 A3: { 171 A3: {
139 height: 297, 172 height: 297,
140 width: 420 173 width: 420