annotate client/src/lib/mixins.js @ 5437:eeee1c411576 marking-single-beam

Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 13 Jul 2021 12:24:29 +0200
parents 660147046ddd
children a857d6ae1264
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2738
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1 /* This is Free Software under GNU Affero General Public License v >= 3.0
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
2 * without warranty, see README.md and license for details.
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
3 *
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
4 * SPDX-License-Identifier: AGPL-3.0-or-later
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
5 * License-Filename: LICENSES/AGPL-3.0.txt
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
6 *
3792
3878bc0c8e58 client: update attribution infos on lib/mixins.js
Bernhard Reiter <bernhard@intevation.de>
parents: 3790
diff changeset
7 * Copyright (C) 2018, 2019 by via donau
2738
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
8 * – Österreichische Wasserstraßen-Gesellschaft mbH
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
9 * Software engineering by Intevation GmbH
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
10 *
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
11 * Author(s):
3792
3878bc0c8e58 client: update attribution infos on lib/mixins.js
Bernhard Reiter <bernhard@intevation.de>
parents: 3790
diff changeset
12 * * Markus Kottländer <markus.kottlaender@intevation.de>
3878bc0c8e58 client: update attribution infos on lib/mixins.js
Bernhard Reiter <bernhard@intevation.de>
parents: 3790
diff changeset
13 * * Fadi Abbud <fadi.abbud@intevation.de>
3878bc0c8e58 client: update attribution infos on lib/mixins.js
Bernhard Reiter <bernhard@intevation.de>
parents: 3790
diff changeset
14 * * Bernhard Reiter <bernhard.reiter@intevation.de>
2738
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
15 */
3796
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
16 import jsPDF from "jspdf-yworks";
3941
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
17 import svg2pdf from "svg2pdf.js";
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
18 import locale2 from "locale2";
3406
1ba669cbbee6 client: pdf-template:(minor) add missed parameter for image element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3396
diff changeset
19 import { mapState } from "vuex";
3802
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
20 import { HTTP } from "@/lib/http";
4001
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
21 import * as d3 from "d3";
4677
fa55e48bbca1 client: improve filename generation for downloads
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4486
diff changeset
22 import sanitize from "sanitize-filename";
4792
9412bc2545e8 client: implement exporting of diagram as image (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4677
diff changeset
23 import canvg from "canvg";
4001
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
24
4456
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
25 /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "[debugSVG|_]" }]*/
4001
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
26 const debugSVG = ({ svg, svgWidth, svgHeight }) => {
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
27 d3.select(svg)
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
28 .append("rect")
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
29 .attr("width", svgWidth)
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
30 .attr("height", svgHeight)
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
31 .attr("fill-opacity", 0)
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
32 .attr("stroke", "#ff0000");
bf86f9a08733 improve fairwaydiagram printing positioning
Thomas Junk <thomas.junk@intevation.de>
parents: 4000
diff changeset
33 };
3796
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
34
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
35 export const sortTable = {
2738
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
36 data() {
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
37 return {
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
38 sortColumn: "",
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
39 sortDirection: "ASC",
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
40 pageSize: 20,
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
41 page: 1
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
42 };
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
43 },
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
44 methods: {
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
45 sortTable(sorting) {
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
46 this.sortColumn = sorting.sortColumn;
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
47 this.sortDirection = sorting.sortDirection;
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
48 }
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
49 }
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
50 };
4153
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
51 /**
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
52 * Since the names of LDC and HDC aren't normalized, we have to do guesswork
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
53 * best fit is key with HDC or LDC in it
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
54 */
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
55 export const refwaterlevels = {
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
56 methods: {
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
57 determineLDCHDC(refWaterLevels) {
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
58 let HDC =
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
59 refWaterLevels[Object.keys(refWaterLevels).find(e => /HDC/.test(e))];
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
60 let LDC =
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
61 refWaterLevels[Object.keys(refWaterLevels).find(e => /LDC/.test(e))];
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
62 return { LDC, HDC };
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
63 }
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
64 }
7c44af0b9370 client: Waterleveldiagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4112
diff changeset
65 };
2738
add2d47c2567 client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
66
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
67 export const diagram = {
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
68 methods: {
3992
2f024d6189ca Reverted merge with diagram-cleanup -- its not yet ready.
Sascha Wilde <wilde@intevation.de>
parents: 3967
diff changeset
69 getDimensions({ svgWidth, svgHeight, main, nav }) {
2f024d6189ca Reverted merge with diagram-cleanup -- its not yet ready.
Sascha Wilde <wilde@intevation.de>
parents: 3967
diff changeset
70 const mainMargin = main || {
4138
33deb8634783 mixin: set relative defaults for margins
Thomas Junk <thomas.junk@intevation.de>
parents: 4135
diff changeset
71 top: Math.floor(0.08 * svgHeight),
33deb8634783 mixin: set relative defaults for margins
Thomas Junk <thomas.junk@intevation.de>
parents: 4135
diff changeset
72 right: Math.floor(0.08 * svgWidth),
33deb8634783 mixin: set relative defaults for margins
Thomas Junk <thomas.junk@intevation.de>
parents: 4135
diff changeset
73 bottom: Math.floor(0.2 * svgHeight),
33deb8634783 mixin: set relative defaults for margins
Thomas Junk <thomas.junk@intevation.de>
parents: 4135
diff changeset
74 left: Math.floor(0.08 * svgWidth)
3936
d859ec6cf2f0 Fairwayprofile enhanced
Thomas Junk <thomas.junk@intevation.de>
parents: 3919
diff changeset
75 };
3992
2f024d6189ca Reverted merge with diagram-cleanup -- its not yet ready.
Sascha Wilde <wilde@intevation.de>
parents: 3967
diff changeset
76 const navMargin = nav || {
4138
33deb8634783 mixin: set relative defaults for margins
Thomas Junk <thomas.junk@intevation.de>
parents: 4135
diff changeset
77 top: Math.floor(0.78 * svgHeight),
33deb8634783 mixin: set relative defaults for margins
Thomas Junk <thomas.junk@intevation.de>
parents: 4135
diff changeset
78 right: Math.floor(0.013 * svgWidth),
33deb8634783 mixin: set relative defaults for margins
Thomas Junk <thomas.junk@intevation.de>
parents: 4135
diff changeset
79 bottom: Math.floor(0.095 * svgHeight),
33deb8634783 mixin: set relative defaults for margins
Thomas Junk <thomas.junk@intevation.de>
parents: 4135
diff changeset
80 left: Math.floor(0.07 * svgWidth)
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
81 };
3478
afab8d87932c mixin: assume when element not in DOM width and height are 0
Thomas Junk <thomas.junk@intevation.de>
parents: 3429
diff changeset
82 const width = Number(svgWidth) - mainMargin.left - mainMargin.right;
afab8d87932c mixin: assume when element not in DOM width and height are 0
Thomas Junk <thomas.junk@intevation.de>
parents: 3429
diff changeset
83 const mainHeight = Number(svgHeight) - mainMargin.top - mainMargin.bottom;
afab8d87932c mixin: assume when element not in DOM width and height are 0
Thomas Junk <thomas.junk@intevation.de>
parents: 3429
diff changeset
84 const navHeight = Number(svgHeight) - navMargin.top - navMargin.bottom;
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
85 return { width, mainHeight, navHeight, mainMargin, navMargin };
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
86 }
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
87 }
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
88 };
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
89
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
90 export const pane = {
3077
db890b71f070 client: panes: added paneId to mixin
Markus Kottlaender <markus@intevation.de>
parents: 3072
diff changeset
91 computed: {
db890b71f070 client: panes: added paneId to mixin
Markus Kottlaender <markus@intevation.de>
parents: 3072
diff changeset
92 paneId() {
db890b71f070 client: panes: added paneId to mixin
Markus Kottlaender <markus@intevation.de>
parents: 3072
diff changeset
93 return this.$parent.pane.id;
db890b71f070 client: panes: added paneId to mixin
Markus Kottlaender <markus@intevation.de>
parents: 3072
diff changeset
94 }
3072
0233845cadb7 client: improved splitscreen mechanis
Markus Kottlaender <markus@intevation.de>
parents: 2989
diff changeset
95 }
0233845cadb7 client: improved splitscreen mechanis
Markus Kottlaender <markus@intevation.de>
parents: 2989
diff changeset
96 };
0233845cadb7 client: improved splitscreen mechanis
Markus Kottlaender <markus@intevation.de>
parents: 2989
diff changeset
97
3802
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
98 export const templateLoader = {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
99 methods: {
4677
fa55e48bbca1 client: improve filename generation for downloads
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4486
diff changeset
100 downloadFilename(type, name) {
fa55e48bbca1 client: improve filename generation for downloads
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4486
diff changeset
101 return `${type}-${sanitize(name).replace(
fa55e48bbca1 client: improve filename generation for downloads
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4486
diff changeset
102 / /g,
fa55e48bbca1 client: improve filename generation for downloads
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4486
diff changeset
103 "-"
fa55e48bbca1 client: improve filename generation for downloads
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4486
diff changeset
104 )}-${this.dateForPDF()}`;
fa55e48bbca1 client: improve filename generation for downloads
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4486
diff changeset
105 },
3802
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
106 loadTemplates(url) {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
107 return new Promise((resolve, reject) => {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
108 HTTP.get(url, {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
109 headers: {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
110 "X-Gemma-Auth": localStorage.getItem("token"),
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
111 "Content-type": "text/xml; charset=UTF-8"
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
112 }
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
113 })
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
114 .then(response => {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
115 resolve(response);
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
116 })
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
117 .catch(error => {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
118 reject(error);
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
119 });
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
120 });
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
121 },
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
122 prepareImages(elements) {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
123 /**
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
124 * In order to render the images from the template, we need to convert
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
125 * each image to dataURIs. Since this happens asynchronous,
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
126 * we need to wrap each image into its own promise and only after all are
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
127 * finished, we continue with the flow.
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
128 */
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
129 return new Promise(resolve => {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
130 const imageElementLoaders = elements.reduce((o, n, i) => {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
131 if (n.type === "image") {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
132 o.push(
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
133 new Promise(resolve => {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
134 const image = new Image();
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
135 image.onload = function() {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
136 var canvas = document.createElement("canvas");
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
137 canvas.width = this.naturalWidth; // or 'width' if you want a special/scaled size
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
138 canvas.height = this.naturalHeight; // or 'height' if you want a special/scaled size
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
139 canvas.getContext("2d").drawImage(this, 0, 0);
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
140 resolve({
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
141 index: i,
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
142 url: canvas.toDataURL("image/png")
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
143 });
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
144 };
3881
7db6999962db mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents: 3862
diff changeset
145 let URL = n.URL;
7db6999962db mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents: 3862
diff changeset
146 if (!URL) {
7db6999962db mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents: 3862
diff changeset
147 URL = this.logoForPDF
7db6999962db mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents: 3862
diff changeset
148 ? this.logoForPDF
7db6999962db mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents: 3862
diff changeset
149 : "/img/gemma-logo-for-pdf.png";
7db6999962db mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents: 3862
diff changeset
150 }
7db6999962db mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents: 3862
diff changeset
151 image.src = URL;
3802
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
152 })
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
153 );
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
154 }
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
155 return o;
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
156 }, []);
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
157 Promise.all(imageElementLoaders).then(values => {
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
158 resolve(values);
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
159 });
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
160 });
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
161 }
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
162 }
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
163 };
e8a950cf6c02 Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3801
diff changeset
164
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3154
diff changeset
165 export const pdfgen = {
3406
1ba669cbbee6 client: pdf-template:(minor) add missed parameter for image element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3396
diff changeset
166 computed: {
3408
a26c1d745fc3 client: pdf-template: fix display of user and move property to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3406
diff changeset
167 ...mapState("application", ["logoForPDF"]),
5310
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
168 ...mapState("user", ["user"]),
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
169 ...mapState("bottlenecks", ["soundingInfo"])
3406
1ba669cbbee6 client: pdf-template:(minor) add missed parameter for image element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3396
diff changeset
170 },
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
171 methods: {
4808
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
172 downloadImage(elementName, title) {
4807
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
173 const offScreen = document.querySelector("#offScreen");
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
174 const DPI = 96;
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
175 const svgWidth = this.millimeter2pixels(428, DPI);
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
176 const svgHeight = this.millimeter2pixels(119, DPI);
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
177 offScreen.style.width = `${svgWidth}px`;
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
178 offScreen.style.height = `${svgHeight}px`;
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
179 let zoomLevel = this.zoomStore;
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
180 const layout = this.getPrintLayout(svgHeight, svgWidth);
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
181 this.renderTo({
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
182 element: offScreen,
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
183 dimensions: this.getDimensions({
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
184 svgWidth: svgWidth,
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
185 svgHeight: svgHeight,
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
186 ...layout
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
187 }),
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
188 zoomLevel // passing the zoom level to draw the diagram on pdf at this point
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
189 });
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
190 const diagramContainer = document.getElementById("offScreen");
4792
9412bc2545e8 client: implement exporting of diagram as image (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4677
diff changeset
191 const { clientHeight, clientWidth } = diagramContainer;
4807
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
192 diagramContainer.querySelector("svg").setAttribute("width", clientWidth);
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
193 diagramContainer
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
194 .querySelector("svg")
4809
b6d8570b8480 client: image-export: add diagram legend
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4808
diff changeset
195 .setAttribute("height", clientHeight + 180);
4807
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
196 const svg = diagramContainer.querySelector("svg").outerHTML;
4792
9412bc2545e8 client: implement exporting of diagram as image (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4677
diff changeset
197 const canvas = document.createElement("canvas");
4808
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
198 canvg(canvas, svg, { offsetY: 70 });
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
199 const ctx = canvas.getContext("2d");
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
200 // Draw white rectangular and place the title on it
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
201 ctx.beginPath();
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
202 ctx.fillStyle = "#ffffff";
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
203 ctx.fillRect(0, 0, clientWidth, 70);
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
204 ctx.stroke();
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
205 ctx.fillStyle = "steelblue";
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
206 ctx.font = "500 30px sans-serif";
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
207 ctx.textAlign = "center";
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
208 ctx.fillText(title, clientWidth / 2, 35);
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
209 ctx.closePath();
4809
b6d8570b8480 client: image-export: add diagram legend
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4808
diff changeset
210 // Add diagramlegend
b6d8570b8480 client: image-export: add diagram legend
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4808
diff changeset
211 this.addLegendToCanvas(ctx, {
b6d8570b8480 client: image-export: add diagram legend
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4808
diff changeset
212 height: clientHeight + 100,
b6d8570b8480 client: image-export: add diagram legend
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4808
diff changeset
213 width: clientWidth
b6d8570b8480 client: image-export: add diagram legend
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4808
diff changeset
214 });
4808
db450fcc8ed7 client: add title for the exported image
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4807
diff changeset
215
4792
9412bc2545e8 client: implement exporting of diagram as image (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4677
diff changeset
216 const imgData = canvas.toDataURL("image/png");
4805
7de099c4824c client: image-export: improve hyperlink ids for download
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4792
diff changeset
217 document.getElementById(elementName).setAttribute("href", imgData);
4807
7cd40008124b client: image-export: render diagram offscreen and use mixins in fairway-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4805
diff changeset
218 offScreen.removeChild(offScreen.firstChild);
4792
9412bc2545e8 client: implement exporting of diagram as image (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4677
diff changeset
219 },
3941
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
220 addDiagram(position, offset, width, height) {
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
221 let x = offset.x,
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
222 y = offset.y;
4135
a6eda41e7724 hydrological_conditions: use offsets relative to svgwidth and svgheight
Thomas Junk <thomas.junk@intevation.de>
parents: 4112
diff changeset
223 const DPI = 80;
a6eda41e7724 hydrological_conditions: use offsets relative to svgwidth and svgheight
Thomas Junk <thomas.junk@intevation.de>
parents: 4112
diff changeset
224 const svgWidth = this.millimeter2pixels(width, DPI);
a6eda41e7724 hydrological_conditions: use offsets relative to svgwidth and svgheight
Thomas Junk <thomas.junk@intevation.de>
parents: 4112
diff changeset
225 const svgHeight = this.millimeter2pixels(height, DPI);
3941
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
226 // draw the diagram in a separated html element to get the full size
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
227 const offScreen = document.querySelector("#offScreen");
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
228 offScreen.style.width = `${svgWidth}px`;
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
229 offScreen.style.height = `${svgHeight}px`;
4225
92c2f93fef3c client: pdf-gen: export the selected time-range of diagram on pdf(waterlevels)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4155
diff changeset
230 let zoomLevel = this.zoomStore;
4135
a6eda41e7724 hydrological_conditions: use offsets relative to svgwidth and svgheight
Thomas Junk <thomas.junk@intevation.de>
parents: 4112
diff changeset
231 const layout = this.getPrintLayout(svgHeight, svgWidth);
3941
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
232 this.renderTo({
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
233 element: offScreen,
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
234 dimensions: this.getDimensions({
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
235 svgWidth: svgWidth,
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
236 svgHeight: svgHeight,
3992
2f024d6189ca Reverted merge with diagram-cleanup -- its not yet ready.
Sascha Wilde <wilde@intevation.de>
parents: 3967
diff changeset
237 ...layout
4225
92c2f93fef3c client: pdf-gen: export the selected time-range of diagram on pdf(waterlevels)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4155
diff changeset
238 }),
92c2f93fef3c client: pdf-gen: export the selected time-range of diagram on pdf(waterlevels)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4155
diff changeset
239 zoomLevel // passing the zoom level to draw the diagram on pdf at this point
3941
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
240 });
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
241 var svg = offScreen.querySelector("svg");
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
242 if (["topright", "bottomright"].indexOf(position) !== -1) {
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
243 x = this.pdf.width - offset.x - width;
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
244 }
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
245 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
246 y = this.pdf.height - offset.y - height;
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
247 }
4135
a6eda41e7724 hydrological_conditions: use offsets relative to svgwidth and svgheight
Thomas Junk <thomas.junk@intevation.de>
parents: 4112
diff changeset
248 //debugSVG({ svg, svgWidth, svgHeight });
3941
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
249 svg2pdf(svg, this.pdf.doc, {
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
250 xOffset: x,
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
251 yOffset: y,
4135
a6eda41e7724 hydrological_conditions: use offsets relative to svgwidth and svgheight
Thomas Junk <thomas.junk@intevation.de>
parents: 4112
diff changeset
252 scale: this.pixel2millimeter(1, DPI)
3941
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
253 });
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
254 offScreen.removeChild(svg);
7b3935a8d9ee refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents: 3936
diff changeset
255 },
3906
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
256 getPaperDimensions(format) {
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
257 const dims = {
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
258 A3: {
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
259 height: 297,
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
260 width: 420
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
261 },
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
262 A4: {
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
263 height: 210,
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
264 width: 297
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
265 }
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
266 };
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
267 return dims[format.toUpperCase()];
ec1d91fdd6a2 fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents: 3886
diff changeset
268 },
3886
9fa9a485c182 mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents: 3881
diff changeset
269 millimeter2pixels(length, dpi) {
9fa9a485c182 mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents: 3881
diff changeset
270 return (dpi * length) / 25.4;
9fa9a485c182 mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents: 3881
diff changeset
271 },
9fa9a485c182 mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents: 3881
diff changeset
272 pixel2millimeter(pixels, dpi) {
9fa9a485c182 mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents: 3881
diff changeset
273 return (pixels * 25.4) / dpi;
9fa9a485c182 mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents: 3881
diff changeset
274 },
4456
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
275 isrsInfo(gauge) {
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
276 // See https://www.elwis.de/DE/Service/Daten-und-Fakten/RIS-Index/RIS-Index-node.html
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
277 const [
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
278 _,
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
279 countryCode,
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
280 loCode,
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
281 fairwaySection,
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
282 orc,
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
283 hectometre
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
284 ] = gauge.properties.isrs_code.match(
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
285 /(\w{2})(\w{3})(\w{5})(\w{5})(\w{5})/
3798
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3796
diff changeset
286 );
4456
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
287 return {
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
288 countryCode: countryCode,
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
289 loCode: loCode,
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
290 fairwaySection: fairwaySection,
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
291 orc: orc,
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
292 hectometre: hectometre
acb21e7362ce client: pdf-gen: fix diagram title for pdf (waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4341
diff changeset
293 };
3798
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3796
diff changeset
294 },
3992
2f024d6189ca Reverted merge with diagram-cleanup -- its not yet ready.
Sascha Wilde <wilde@intevation.de>
parents: 3967
diff changeset
295 generatePDF(params) {
3796
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
296 // creates a new jsPDF object into this.pdf.doc
3799
f4deb4aae485 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3798
diff changeset
297 // will call functions that the calling context has to provide
f4deb4aae485 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3798
diff changeset
298 // as specified in the templateData
3992
2f024d6189ca Reverted merge with diagram-cleanup -- its not yet ready.
Sascha Wilde <wilde@intevation.de>
parents: 3967
diff changeset
299 let templateData = params["templateData"];
2f024d6189ca Reverted merge with diagram-cleanup -- its not yet ready.
Sascha Wilde <wilde@intevation.de>
parents: 3967
diff changeset
300 let diagramTitle = params["diagramTitle"];
3796
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
301
3799
f4deb4aae485 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3798
diff changeset
302 this.pdf.doc = new jsPDF("l", "mm", templateData.properties.paperSize);
3796
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
303 // pdf width and height in millimeter (landscape)
3798
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3796
diff changeset
304 if (templateData.properties.paperSize === "a3") {
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3796
diff changeset
305 this.pdf.width = 420;
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3796
diff changeset
306 this.pdf.height = 297;
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3796
diff changeset
307 } else {
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3796
diff changeset
308 this.pdf.width = 297;
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3796
diff changeset
309 this.pdf.height = 210;
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3796
diff changeset
310 }
3796
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
311 // check the template elements
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
312 if (templateData) {
3801
1399d31531f7 client: improve pdf generation to use linbiolinum font
Bernhard Reiter <bernhard@intevation.de>
parents: 3799
diff changeset
313 this.pdf.doc.setFont("linbiolinum", "normal");
3796
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
314 let defaultFontSize = 11,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
315 defaultColor = "black",
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
316 defaultTextColor = "black",
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
317 defaultBorderColor = "white",
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
318 defaultBgColor = "white",
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
319 defaultRounding = 2,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
320 defaultPadding = 2,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
321 defaultOffset = { x: 0, y: 0 };
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
322 templateData.elements.forEach(e => {
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
323 switch (e.type) {
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
324 case "diagram": {
3807
876dc90c2825 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3802
diff changeset
325 this.addDiagram(
876dc90c2825 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3802
diff changeset
326 e.position,
876dc90c2825 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3802
diff changeset
327 e.offset || defaultOffset,
3943
3c468ed76daf client:pdf-gen: correct default values of diagram size on pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3941
diff changeset
328 // use default width,height if they are missing in template definition
3c468ed76daf client:pdf-gen: correct default values of diagram size on pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3941
diff changeset
329 e.width ||
3992
2f024d6189ca Reverted merge with diagram-cleanup -- its not yet ready.
Sascha Wilde <wilde@intevation.de>
parents: 3967
diff changeset
330 (this.templateData.properties.paperSize === "a3" ? 318 : 230),
3943
3c468ed76daf client:pdf-gen: correct default values of diagram size on pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3941
diff changeset
331 e.height ||
3992
2f024d6189ca Reverted merge with diagram-cleanup -- its not yet ready.
Sascha Wilde <wilde@intevation.de>
parents: 3967
diff changeset
332 (this.templateData.properties.paperSize === "a3" ? 104 : 110)
3807
876dc90c2825 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3802
diff changeset
333 );
3796
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
334 break;
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
335 }
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
336 case "diagramlegend": {
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
337 this.addDiagramLegend(
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
338 e.position,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
339 e.offset || defaultOffset,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
340 e.color || defaultColor
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
341 );
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
342 break;
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
343 }
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
344 case "diagramtitle": {
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
345 this.addDiagramTitle(
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
346 e.position,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
347 e.offset || defaultOffset,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
348 e.fontsize || defaultFontSize,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
349 e.color || defaultColor,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
350 diagramTitle
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
351 );
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
352 break;
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
353 }
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
354 case "text": {
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
355 this.addText(
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
356 e.position,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
357 e.offset || defaultOffset,
3993
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
358 e.width,
3796
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
359 e.fontsize || defaultFontSize,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
360 e.color || defaultTextColor,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
361 e.text || ""
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
362 );
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
363 break;
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
364 }
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
365 case "image": {
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
366 this.addImage(
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
367 e.url,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
368 e.format || "",
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
369 e.position,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
370 e.offset || defaultOffset,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
371 e.width || 90,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
372 e.height || 60
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
373 );
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
374 break;
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
375 }
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
376 case "box": {
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
377 this.addBox(
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
378 e.position,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
379 e.offset || defaultOffset,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
380 e.width || 90,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
381 e.height || 60,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
382 e.rounding === 0 || e.rounding ? e.rounding : defaultRounding,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
383 e.color || defaultBgColor,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
384 e.brcolor || defaultBorderColor
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
385 );
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
386 break;
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
387 }
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
388 case "textbox": {
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
389 this.addTextBox(
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
390 e.position,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
391 e.offset || defaultOffset,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
392 e.width,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
393 e.height,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
394 e.rounding === 0 || e.rounding ? e.rounding : defaultRounding,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
395 e.padding || defaultPadding,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
396 e.fontsize || defaultFontSize,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
397 e.color || defaultTextColor,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
398 e.background || defaultBgColor,
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
399 e.text || "",
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
400 e.brcolor || defaultBorderColor
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
401 );
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
402 break;
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
403 }
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
404 }
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
405 });
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
406 }
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
407 },
243316850889 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3792
diff changeset
408 // add text at specific coordinates and do line breaks
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
409 addText(position, offset, width, fontSize, color, text) {
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
410 text = this.replacePlaceholders(text);
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
411 // split the incoming string to an array, each element is a string of
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
412 // words in a single line
3396
169680c3698b client: pdf-template: set font style for the text element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3350
diff changeset
413 this.pdf.doc.setFontStyle("normal");
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
414 this.pdf.doc.setTextColor(color);
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
415 this.pdf.doc.setFontSize(fontSize);
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
416 // x/y defaults to offset for topleft corner (normal x/y coordinates)
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
417 let x = offset.x;
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
418 let y = offset.y;
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
419 // if position is on the right, x needs to be calculate with pdf width and
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
420 // the size of the element
3993
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
421 if (!width) {
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
422 width = this.pdf.doc.getTextWidth(text);
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
423 }
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
424 var textLines = this.pdf.doc.splitTextToSize(text, width);
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
425 if (
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
426 ["topright", "topleft"].indexOf(position) !== -1 &&
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
427 y < this.getTextHeight(1)
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
428 ) {
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
429 y = this.getTextHeight(1);
6672b780722f client: pdf-gen: improve addtext for pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3992
diff changeset
430 }
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
431 if (["topright", "bottomright"].indexOf(position) !== -1) {
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
432 x = this.pdf.width - offset.x - width;
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
433 }
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
434 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
4000
c40f8b026de3 clinet: pdf-gen: fix positioning of text for template-textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3993
diff changeset
435 y = this.pdf.height - offset.y - this.getTextHeight(textLines.length);
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
436 }
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
437 this.pdf.doc.text(textLines, x, y, { baseline: "hanging" });
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
438 },
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
439 replacePlaceholders(text) {
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
440 if (text.includes("{date}")) {
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
441 text = text.replace("{date}", new Date().toLocaleString(locale2));
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
442 }
5437
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
443 const hasVisibleSurvey =
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
444 this.soundingInfo &&
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
445 this.bottleneckForPrint &&
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
446 this.selectedSurvey &&
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
447 this.openLayersMap()
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
448 .getLayer("BOTTLENECKISOLINE")
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
449 .getVisible();
3350
8da2f7b9a04b client: diagram-template:remove unnecessary template properties and typo
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3344
diff changeset
450 // get only day,month and year from the Date object
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
451 if (text.includes("{date-minor}")) {
5437
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
452 var date;
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
453 if (hasVisibleSurvey) {
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
454 date = new Date(this.selectedSurvey["date_info"]);
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
455 } else {
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
456 date = new Date();
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
457 }
eeee1c411576 Pdf-Template: Use survey-date for {date-minor} when bottleneck survey is visible.
Thomas Junk <thomas.junk@intevation.de>
parents: 5310
diff changeset
458
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
459 var dt =
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
460 (date.getDate() < 10 ? "0" : "") +
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
461 date.getDate() +
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
462 "." +
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
463 (date.getMonth() + 1 < 10 ? "0" : "") +
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
464 (date.getMonth() + 1) +
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
465 "." +
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
466 date.getFullYear();
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
467 text = text.replace("{date-minor}", dt.toLocaleString(locale2));
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
468 }
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
469 if (text.includes("{user}")) {
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
470 text = text.replace("{user}", this.user);
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
471 }
5310
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
472 if (text.includes("{zpg-exception}")) {
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
473 // Print the text followed by "zpg-exception" if this value set to true
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
474 if (
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
475 this.soundingInfo &&
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
476 this.soundingInfo.number > 0 &&
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
477 this.soundingInfo.feature.properties.zpg_exception
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
478 ) {
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
479 text = text.replace("{zpg-exception}", "");
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
480 // Otherwise nothing to print
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
481 } else {
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
482 text = "";
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
483 }
660147046ddd Client: Implement handling zpg-exception info in pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4809
diff changeset
484 }
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
485 return text;
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
486 },
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
487 addImage(url, format, position, offset, width, height) {
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
488 let x = offset.x;
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
489 let y = offset.y;
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
490 if (["topright", "bottomright"].indexOf(position) !== -1) {
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
491 x = this.pdf.width - offset.x - width;
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
492 }
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
493 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
494 y = this.pdf.height - offset.y - height;
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
495 }
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
496 let image = new Image();
3881
7db6999962db mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents: 3862
diff changeset
497 image.src = url;
3544
067ad32fba69 client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3500
diff changeset
498 if (format === "") {
067ad32fba69 client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3500
diff changeset
499 let tmp = image.src.split(".");
067ad32fba69 client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3500
diff changeset
500 format = tmp[tmp.length - 1].toUpperCase();
067ad32fba69 client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3500
diff changeset
501 }
3429
7bbab09cdf71 client: pdf-template:(minor) add missing parameter
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3408
diff changeset
502 this.pdf.doc.addImage(image, format, x, y, width, height);
3141
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
503 },
3293
76f643d20f19 clinet: pdf-gen: (cleanup) remove some pdf-functions from pdftool
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
504 // add text at specific coordinates with a background box
3141
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
505 addBox(position, offset, width, height, rounding, color, brcolor) {
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
506 // x/y defaults to offset for topleft corner (normal x/y coordinates)
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
507 let x = offset.x;
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
508 let y = offset.y;
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
509
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
510 // if position is on the right, x needs to be calculate with pdf width and
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
511 // the size of the element
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
512 if (["topright", "bottomright"].indexOf(position) !== -1) {
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
513 x = this.pdf.width - offset.x - width;
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
514 }
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
515 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
516 y = this.pdf.height - offset.y - height;
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
517 }
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
518 this.addRoundedBox(x, y, width, height, color, rounding, brcolor);
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
519 },
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3235
diff changeset
520 getTextHeight(numberOfLines) {
3790
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
521 // Return estimated height in mm.
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
522
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
523 // FontSize is given in desktop publishing points defined as 1/72 inch.
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
524 // aka 25.4 / 72 mm
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
525 let fontSize = this.pdf.doc.getFontSize();
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
526 let lineHeightFactor = 1.15; // default from jspdf-yworks 2.0.2
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
527 if (typeof this.pdf.doc.getLineHeightFactor !== "undefined") {
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
528 lineHeightFactor = this.pdf.doc.getLineHeightFactor();
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
529 }
60977e18e227 client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents: 3788
diff changeset
530 return numberOfLines * fontSize * (25.4 / 72) * lineHeightFactor;
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3235
diff changeset
531 },
3285
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
532 // title for diagram
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
533 addDiagramTitle(position, offset, size, color, text) {
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
534 let x = offset.x,
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
535 y = offset.y;
3336
db1dc197dc43 client: diagram-template: cleanup
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3293
diff changeset
536 this.pdf.doc.setFontSize(size);
3344
107de6def0c3 client: diagram-template: cleanup
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3336
diff changeset
537 this.pdf.doc.setFontStyle("bold");
107de6def0c3 client: diagram-template: cleanup
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3336
diff changeset
538 this.pdf.doc.setTextColor(color);
3285
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
539 let width =
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
540 (this.pdf.doc.getStringUnitWidth(text) * size) / (72 / 25.6) + size / 2;
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
541 // if position is on the right, x needs to be calculate with pdf width and
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
542 // the size of the element
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
543 if (["topright", "bottomright"].indexOf(position) !== -1) {
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
544 x = this.pdf.width - offset.x - width;
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
545 }
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
546 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
547 y = this.pdf.height - offset.y - this.getTextHeight(1);
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
548 }
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
549 this.pdf.doc.text(text, x, y, { baseline: "hanging" });
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
550 },
3141
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
551 addRoundedBox(x, y, w, h, color, rounding, brcolor) {
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
552 this.pdf.doc.setDrawColor(brcolor);
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
553 this.pdf.doc.setFillColor(color);
42324626f9e2 client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3137
diff changeset
554 this.pdf.doc.roundedRect(x, y, w, h, rounding, rounding, "FD");
3154
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
555 },
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
556 addTextBox(
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
557 position,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
558 offset,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
559 width,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
560 height,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
561 rounding,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
562 padding,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
563 fontSize,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
564 color,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
565 background,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
566 text,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
567 brcolor
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
568 ) {
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
569 this.pdf.doc.setFontSize(fontSize);
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
570 text = this.replacePlaceholders(text);
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
571
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
572 if (!width) {
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
573 width = this.pdf.doc.getTextWidth(text) + 2 * padding;
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
574 }
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
575 let textWidth = width - 2 * padding;
4341
e58affd956c5 pdf-gen: adjust place of text for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4225
diff changeset
576 let textLines = this.pdf.doc.splitTextToSize(text, textWidth);
3154
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
577 if (!height) {
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
578 height = this.getTextHeight(textLines.length) + 2 * padding;
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
579 }
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
580 this.addBox(
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
581 position,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
582 offset,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
583 width,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
584 height,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
585 rounding,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
586 background,
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
587 brcolor
b6c10b30d6bd client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3145
diff changeset
588 );
4486
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
589 let yForText =
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
590 ["bottomright", "bottomleft"].indexOf(position) !== -1
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
591 ? offset.y
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
592 : offset.y + height - this.getTextHeight(textLines.length);
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
593 this.addText(
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
594 position,
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
595 { x: offset.x + padding, y: yForText },
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
596 textWidth,
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
597 fontSize,
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
598 color,
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
599 text
e58fc3a62118 client: pdf-gen: improve code for textbox element
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4473
diff changeset
600 );
4473
3543af71d04c client: pdf-gen: improve file naming for the exported pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4456
diff changeset
601 },
3543af71d04c client: pdf-gen: improve file naming for the exported pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4456
diff changeset
602 dateForPDF() {
3543af71d04c client: pdf-gen: improve file naming for the exported pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4456
diff changeset
603 return new Date()
3543af71d04c client: pdf-gen: improve file naming for the exported pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4456
diff changeset
604 .toISOString()
3543af71d04c client: pdf-gen: improve file naming for the exported pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4456
diff changeset
605 .slice(0, 10)
3543af71d04c client: pdf-gen: improve file naming for the exported pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents: 4456
diff changeset
606 .replace(/-/g, "");
3137
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
607 }
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
608 }
35c0da49eb89 client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3079
diff changeset
609 };