comparison client/src/components/fairway/Fairwayprofile.vue @ 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 246754028bf4
children de0d0685a17b
comparison
equal deleted inserted replaced
3284:7ae1892773a2 3285:aac1ca73e92a
60 * Software engineering by Intevation GmbH 60 * Software engineering by Intevation GmbH
61 * 61 *
62 * Author(s): 62 * Author(s):
63 * Thomas Junk <thomas.junk@intevation.de> 63 * Thomas Junk <thomas.junk@intevation.de>
64 * Markus Kottländer <markus.kottlaender@intevation.de> 64 * Markus Kottländer <markus.kottlaender@intevation.de>
65 * Fadi Abbud <fadi.abbud@intevation.de>
65 */ 66 */
66 import * as d3 from "d3"; 67 import * as d3 from "d3";
67 import { mapState, mapGetters } from "vuex"; 68 import { mapState, mapGetters } from "vuex";
68 import debounce from "debounce"; 69 import debounce from "debounce";
69 import jsPDF from "jspdf"; 70 import jsPDF from "jspdf";
295 e.color || defaultTextColor 296 e.color || defaultTextColor
296 ); 297 );
297 break; 298 break;
298 } 299 }
299 case "diagramtitle": { 300 case "diagramtitle": {
300 this.addDiagramTitle(e.position, e.offset, e.fontsize, e.color); 301 let fairwayInfo =
302 this.selectedBottleneck +
303 " (" +
304 this.selectedSurvey.date_info +
305 ")";
306 this.addDiagramTitle(
307 e.position,
308 e.offset,
309 e.fontsize,
310 e.color,
311 fairwayInfo
312 );
301 break; 313 break;
302 } 314 }
303 case "image": { 315 case "image": {
304 this.addImage( 316 this.addImage(
305 e.url, 317 e.url,
384 ignoreDimensions: true 396 ignoreDimensions: true
385 }); 397 });
386 var imgData = canvas.toDataURL("image/png"); 398 var imgData = canvas.toDataURL("image/png");
387 this.pdf.doc.addImage(imgData, "PNG", x, y, width, height); 399 this.pdf.doc.addImage(imgData, "PNG", x, y, width, height);
388 }, 400 },
389 addDiagramTitle(position, offset, size, color) {
390 let x = offset.x,
391 y = offset.y;
392 let fairwayInfo =
393 this.selectedBottleneck + " (" + this.selectedSurvey.date_info + ")";
394 let width =
395 (this.pdf.doc.getStringUnitWidth(fairwayInfo) * size) / (72 / 25.6) +
396 size / 2;
397 // if position is on the right, x needs to be calculate with pdf width and
398 // the size of the element
399 if (["topright", "bottomright"].indexOf(position) !== -1) {
400 x = this.pdf.width - offset.x - width;
401 }
402 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
403 y = this.pdf.height - offset.y - this.getTextHeight(1);
404 }
405 this.pdf.doc.setTextColor(color);
406 this.pdf.doc.setFontSize(size);
407 this.pdf.doc.setFontStyle("bold");
408 this.pdf.doc.text(fairwayInfo, x, y, { baseline: "hanging" });
409 },
410 // Diagram legend 401 // Diagram legend
411 addDiagramLegend(position, offset, color) { 402 addDiagramLegend(position, offset, color) {
412 let x = offset.x, 403 let x = offset.x,
413 y = offset.y; 404 y = offset.y;
414 let width = 405 let width =
429 this.pdf.doc.circle(x, y + 5, 2, "FD"); 420 this.pdf.doc.circle(x, y + 5, 2, "FD");
430 this.pdf.doc.text(x + 3, y + 6, "Fairway"); 421 this.pdf.doc.text(x + 3, y + 6, "Fairway");
431 this.pdf.doc.setFillColor("#4a2f06"); 422 this.pdf.doc.setFillColor("#4a2f06");
432 this.pdf.doc.circle(x, y + 10, 2, "FD"); 423 this.pdf.doc.circle(x, y + 10, 2, "FD");
433 this.pdf.doc.text(x + 3, y + 11, "Ground"); 424 this.pdf.doc.text(x + 3, y + 11, "Ground");
434 },
435 getTextHeight(numberOfLines) {
436 return (
437 numberOfLines *
438 ((this.pdf.doc.getFontSize() * 25.4) / 80) *
439 this.pdf.doc.getLineHeightFactor()
440 );
441 }, 425 },
442 calcRelativeDepth(depth) { 426 calcRelativeDepth(depth) {
443 /* takes a depth value and substracts the delta of the relative waterlevel 427 /* takes a depth value and substracts the delta of the relative waterlevel
444 * say the reference level is above the current level, the ground is nearer, 428 * say the reference level is above the current level, the ground is nearer,
445 * thus, the depth is lower. 429 * thus, the depth is lower.