annotate client/src/components/fairway/AvailableFairwayDepth.vue @ 3811:37e896990c99 yworks-svg2pdf

client: improve pdf generation towards vector diagrams * Moving AvailableFairwayDepth.vue addDiagram to svg2pdf. * Mark the scaling and aspect ration as todos for both vector diagrams in pdf generation AvailableFairwayDepth.vue and Waterlevel.vue.
author Bernhard Reiter <bernhard@intevation.de>
date Fri, 05 Jul 2019 10:50:55 +0200
parents cc80a37173f8
children ff8ca2d80ce9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
1 <template>
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
2 <div class="d-flex flex-column flex-fill">
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
3 <UIBoxHeader icon="chart-area" :title="title" :closeCallback="close" />
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
4 <UISpinnerOverlay v-if="loading" />
3279
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
5 <div class="d-flex flex-fill">
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
6 <DiagramLegend>
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
7 <div v-for="(entry, index) in legend" :key="index" class="legend">
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
8 <span
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
9 :style="
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
10 `${legendStyle(
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
11 index
3280
8fb81b45085f available_fairway_depth: use rounded border for legend
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3279
diff changeset
12 )}; border-radius: 0.25rem; width: 40px; height: 20px;`
3279
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
13 "
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
14 ></span>
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
15 {{ entry }}
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
16 </div>
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
17 <div>
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
18 <select
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
19 @change="applyChange"
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
20 v-model="form.template"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
21 class="form-control d-block custom-select-sm w-100 mt-1"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
22 >
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
23 <option
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
24 v-for="template in templates"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
25 :value="template"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
26 :key="template.name"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
27 >
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
28 {{ template.name }}
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
29 </option>
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
30 </select>
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
31 <button
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
32 @click="downloadPDF"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
33 type="button"
3466
dfa97aad1134 client: unify the buttons style for diagram legend
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3464
diff changeset
34 class="btn btn-sm btn-info d-block w-100 mt-2"
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
35 >
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
36 <translate>Export to PDF</translate>
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
37 </button>
3437
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
38 <a
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
39 :href="dataLink"
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
40 :download="csvFileName"
3466
dfa97aad1134 client: unify the buttons style for diagram legend
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3464
diff changeset
41 class="mt-2 btn btn-sm btn-info w-100"
3437
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
42 >Download CSV</a
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
43 >
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
44 </div>
3279
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
45 </DiagramLegend>
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
46 <div
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
47 ref="diagramContainer"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
48 :id="containerId"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
49 class="mx-auto my-auto diagram-container"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
50 ></div>
3135
Thomas Junk <thomas.junk@intevation.de>
parents: 3134
diff changeset
51 </div>
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
52 </div>
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
53 </template>
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
54
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
55 <style></style>
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
56
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
57 <script>
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
58 /* This is Free Software under GNU Affero General Public License v >= 3.0
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
59 * without warranty, see README.md and license for details.
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
60 *
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
61 * SPDX-License-Identifier: AGPL-3.0-or-later
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
62 * License-Filename: LICENSES/AGPL-3.0.txt
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
63 *
3800
26325370ba18 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3780
diff changeset
64 * Copyright (C) 2018, 2019 by via donau
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
65 * – Österreichische Wasserstraßen-Gesellschaft mbH
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
66 * Software engineering by Intevation GmbH
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
67 *
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
68 * Author(s):
3800
26325370ba18 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3780
diff changeset
69 * * Thomas Junk <thomas.junk@intevation.de>
26325370ba18 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3780
diff changeset
70 * * Markus Kottländer <markus.kottlaender@intevation.de>
26325370ba18 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3780
diff changeset
71 * * Fadi Abbud <fadi.abbud@intevation.de>
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
72 */
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
73 import * as d3 from "d3";
3135
Thomas Junk <thomas.junk@intevation.de>
parents: 3134
diff changeset
74 import app from "@/main";
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
75 import debounce from "debounce";
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
76 import { mapState } from "vuex";
3191
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
77 import filters from "@/lib/filters.js";
3811
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
78 import svg2pdf from "svg2pdf.js";
3806
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
79 import { diagram, pdfgen, templateLoader } from "@/lib/mixins";
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
80 import { HTTP } from "@/lib/http";
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
81 import { displayError } from "@/lib/errors";
3327
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
82 import { FREQUENCIES } from "@/store/fairwayavailability";
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
83
3213
b3a1ecdda797 available_fairway_depth: hours in days
Thomas Junk <thomas.junk@intevation.de>
parents: 3210
diff changeset
84 const hoursInDays = x => x / 24;
b3a1ecdda797 available_fairway_depth: hours in days
Thomas Junk <thomas.junk@intevation.de>
parents: 3210
diff changeset
85
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
86 export default {
3806
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
87 mixins: [diagram, pdfgen, templateLoader],
3279
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
88 components: {
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
89 DiagramLegend: () => import("@/components/DiagramLegend")
215173f62900 available_fairway_depth: improve legend layout
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3273
diff changeset
90 },
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
91 data() {
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
92 return {
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
93 containerId: "availablefairwaydepth",
3682
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
94 resizeListenerFunction: null,
3134
ab00165540fe available_fairway_depths: Component made visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3131
diff changeset
95 loading: false,
3135
Thomas Junk <thomas.junk@intevation.de>
parents: 3134
diff changeset
96 width: 1000,
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
97 height: 600,
3701
519c6e01607f client: available fairway depth diagram: show date labels below bar charts like in other diagram
Markus Kottlaender <markus@intevation.de>
parents: 3688
diff changeset
98 labelPaddingBottom: 10,
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
99 scalePaddingLeft: 50,
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
100 paddingTop: 10,
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
101 diagram: null,
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
102 yScale: null,
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
103 dimensions: null,
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
104 pdf: {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
105 doc: null,
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
106 width: null,
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
107 height: null
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
108 },
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
109 form: {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
110 template: null
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
111 },
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
112 templateData: null,
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
113 templates: [],
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
114 defaultTemplate: {
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
115 name: "Default",
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
116 properties: {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
117 paperSize: "a4"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
118 },
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
119 elements: [
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
120 {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
121 type: "diagram",
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
122 position: "topleft",
3811
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
123 offset: { x: 20, y: 30 },
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
124 width: 290,
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
125 height: 100
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
126 },
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
127 {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
128 type: "diagramtitle",
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
129 position: "topleft",
3285
aac1ca73e92a client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3282
diff changeset
130 offset: { x: 70, y: 20 },
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
131 fontsize: 20,
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
132 color: "steelblue"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
133 },
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
134 {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
135 type: "diagramlegend",
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
136 position: "topleft",
3811
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
137 offset: { x: 30, y: 170 },
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
138 color: "black"
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
139 }
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
140 ]
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
141 }
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
142 };
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
143 },
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
144 created() {
3682
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
145 this.resizeListenerFunction = debounce(this.drawDiagram, 100);
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
146 window.addEventListener("resize", this.resizeListenerFunction);
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
147 },
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
148 destroyed() {
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
149 window.removeEventListener("resize", this.resizeListenerFunction);
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
150 },
3134
ab00165540fe available_fairway_depths: Component made visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3131
diff changeset
151 mounted() {
3688
af06045e87c9 client: diagrams: wait (longer) for legend child component to render before rendering diagram (see comments for explanation)
Markus Kottlaender <markus@intevation.de>
parents: 3682
diff changeset
152 // Nasty but necessary if we don't want to use the updated hook to re-draw
af06045e87c9 client: diagrams: wait (longer) for legend child component to render before rendering diagram (see comments for explanation)
Markus Kottlaender <markus@intevation.de>
parents: 3682
diff changeset
153 // the diagram because this would re-draw it also for irrelevant reasons.
af06045e87c9 client: diagrams: wait (longer) for legend child component to render before rendering diagram (see comments for explanation)
Markus Kottlaender <markus@intevation.de>
parents: 3682
diff changeset
154 // In this case we need to wait for the child component (DiagramLegend) to
af06045e87c9 client: diagrams: wait (longer) for legend child component to render before rendering diagram (see comments for explanation)
Markus Kottlaender <markus@intevation.de>
parents: 3682
diff changeset
155 // render. According to the docs (https://vuejs.org/v2/api/#mounted) this
af06045e87c9 client: diagrams: wait (longer) for legend child component to render before rendering diagram (see comments for explanation)
Markus Kottlaender <markus@intevation.de>
parents: 3682
diff changeset
156 // should be possible with $nextTick() but it doesn't work because it does
af06045e87c9 client: diagrams: wait (longer) for legend child component to render before rendering diagram (see comments for explanation)
Markus Kottlaender <markus@intevation.de>
parents: 3682
diff changeset
157 // not guarantee that the DOM is not only updated but also re-painted on the
af06045e87c9 client: diagrams: wait (longer) for legend child component to render before rendering diagram (see comments for explanation)
Markus Kottlaender <markus@intevation.de>
parents: 3682
diff changeset
158 // screen.
af06045e87c9 client: diagrams: wait (longer) for legend child component to render before rendering diagram (see comments for explanation)
Markus Kottlaender <markus@intevation.de>
parents: 3682
diff changeset
159 setTimeout(this.drawDiagram, 150);
af06045e87c9 client: diagrams: wait (longer) for legend child component to render before rendering diagram (see comments for explanation)
Markus Kottlaender <markus@intevation.de>
parents: 3682
diff changeset
160
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
161 this.templates[0] = this.defaultTemplate;
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
162 this.form.template = this.templates[0];
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
163 this.templateData = this.form.template;
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
164 HTTP.get("/templates/diagram", {
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
165 headers: {
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
166 "X-Gemma-Auth": localStorage.getItem("token"),
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
167 "Content-type": "text/xml; charset=UTF-8"
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
168 }
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
169 })
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
170 .then(response => {
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
171 if (response.data.length) {
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
172 this.templates = response.data;
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
173 this.form.template = this.templates[0];
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
174 this.templates[this.templates.length] = this.defaultTemplate;
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
175 this.applyChange();
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
176 }
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
177 })
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
178 .catch(e => {
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
179 const { status, data } = e.response;
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
180 displayError({
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
181 title: this.$gettext("Backend Error"),
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
182 message: `${status}: ${data.message || data}`
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
183 });
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
184 });
3134
ab00165540fe available_fairway_depths: Component made visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3131
diff changeset
185 },
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
186 computed: {
3210
66e90b48387a available_fairway-depth: store refactored
Thomas Junk <thomas.junk@intevation.de>
parents: 3192
diff changeset
187 ...mapState("fairwayavailability", [
3191
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
188 "selectedFairwayAvailabilityFeature",
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
189 "fwData",
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
190 "from",
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
191 "to",
3216
ee6a4e8af766 available_fairway_depth: legend POC
Thomas Junk <thomas.junk@intevation.de>
parents: 3213
diff changeset
192 "frequency",
3476
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
193 "csv",
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
194 "depthlimit1",
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
195 "depthlimit2",
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
196 "widthlimit1",
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
197 "widthlimit2"
3191
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
198 ]),
3476
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
199 legend() {
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
200 const d = [this.depthlimit1, this.depthlimit2].sort();
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
201 const w = [this.widthlimit1, this.widthlimit2].sort();
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
202 const lowerBound = [d[0], w[0]].filter(x => x).join(", ");
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
203 const upperBound = [d[1], w[1]].filter(x => x).join(", ");
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
204 return [
3493
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
205 `> LDC`,
3476
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
206 `< ${lowerBound}`,
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
207 `< ${upperBound}`,
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
208 `>= ${upperBound}`
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
209 ];
cc11f207e060 afd: omit legend generation from CSV. Legend is generated from known inputs
Thomas Junk <thomas.junk@intevation.de>
parents: 3466
diff changeset
210 },
3437
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
211 dataLink() {
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
212 return `data:text/csv;charset=utf-8, ${encodeURIComponent(this.csv)}`;
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
213 },
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
214 csvFileName() {
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
215 return `${this.$gettext("fairwayavailability")}-${
3481
ba26adce0ce8 afd: robust legend name
Thomas Junk <thomas.junk@intevation.de>
parents: 3476
diff changeset
216 this.featureName
3437
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
217 }-${filters.surveyDate(this.fromDate)}-${filters.surveyDate(
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
218 this.toDate
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
219 )}-${this.$gettext(this.frequency)}-.csv`;
6a044d6c2cdc afd: csv download
Thomas Junk <thomas.junk@intevation.de>
parents: 3410
diff changeset
220 },
3327
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
221 frequencyToRange() {
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
222 const frequencies = {
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
223 [FREQUENCIES.MONTHLY]: [-33, 33],
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
224 [FREQUENCIES.QUARTERLY]: [-93, 93],
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
225 [FREQUENCIES.YEARLY]: [-370, 370]
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
226 };
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
227 return frequencies[this.frequency];
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
228 },
3191
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
229 fromDate() {
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
230 return this.from;
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
231 },
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
232 toDate() {
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
233 return this.to;
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
234 },
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
235 availability() {
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
236 return this.plainAvailability;
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
237 },
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
238 title() {
3191
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
239 return `Available Fairway Depth: ${
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
240 this.featureName
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
241 } (${filters.surveyDate(this.fromDate)} - ${filters.surveyDate(
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
242 this.toDate
3268
1a97a079ef1b client: diagram-template: fix typo
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3267
diff changeset
243 )}) ${this.$gettext(this.frequency)}`;
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
244 },
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
245 featureName() {
3481
ba26adce0ce8 afd: robust legend name
Thomas Junk <thomas.junk@intevation.de>
parents: 3476
diff changeset
246 if (this.selectedFairwayAvailabilityFeature == null) return "";
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
247 return this.selectedFairwayAvailabilityFeature.properties.name;
3716
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
248 },
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
249 widthPerItem() {
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
250 return Math.min(
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
251 (this.dimensions.width - this.scalePaddingLeft) / this.fwData.length,
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
252 180
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
253 );
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
254 },
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
255 spaceBetween() {
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
256 return this.widthPerItem * 0.2;
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
257 },
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
258 ldcOffset() {
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
259 return this.widthPerItem * 0.1;
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
260 }
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
261 },
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
262 methods: {
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
263 applyChange() {
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
264 if (this.form.template.hasOwnProperty("properties")) {
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
265 this.templateData = this.defaultTemplate;
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
266 return;
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
267 }
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
268 if (this.form.template) {
3806
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
269 this.loadTemplates("/templates/diagram/" + this.form.template.name)
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
270 .then(response => {
3806
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
271 this.prepareImages(response.data.template_data.elements).then(
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
272 values => {
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
273 values.forEach(v => {
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
274 response.data.template_data.elements[v.index].url = v.url;
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
275 });
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
276 this.templateData = response.data.template_data;
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
277 }
cc80a37173f8 Available-fairway-depth(both): use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3800
diff changeset
278 );
3273
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
279 })
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
280 .catch(e => {
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
281 const { status, data } = e.response;
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
282 displayError({
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
283 title: this.$gettext("Backend Error"),
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
284 message: `${status}: ${data.message || data}`
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
285 });
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
286 });
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
287 }
050e72ce5cf7 client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3268
diff changeset
288 },
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
289 downloadPDF() {
3800
26325370ba18 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3780
diff changeset
290 let title = `Available Fairway Depth: ${this.featureName}`;
26325370ba18 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3780
diff changeset
291 this.generatePDF({
26325370ba18 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3780
diff changeset
292 templateData: this.templateData,
26325370ba18 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3780
diff changeset
293 diagramTitle: title
26325370ba18 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3780
diff changeset
294 });
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
295 this.pdf.doc.save(`Available Fairway Depth: ${this.featureName}`);
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
296 },
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
297 addDiagram(position, offset, width, height) {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
298 let x = offset.x,
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
299 y = offset.y;
3811
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
300 var svgElement = this.$refs.diagramContainer.firstElementChild;
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
301
3544
067ad32fba69 client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3493
diff changeset
302 // use default width,height if they are missing in the template definition
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
303 if (!width) {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
304 width = this.templateData.properties.paperSize === "a3" ? 380 : 290;
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
305 }
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
306 if (!height) {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
307 height = this.templateData.properties.paperSize === "a3" ? 130 : 100;
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
308 }
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
309 if (["topright", "bottomright"].indexOf(position) !== -1) {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
310 x = this.pdf.width - offset.x - width;
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
311 }
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
312 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
313 y = this.pdf.height - offset.y - height;
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
314 }
3811
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
315
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
316 svg2pdf(svgElement, this.pdf.doc, {
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
317 xOffset: x,
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
318 yOffset: y,
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
319 scale: 0.4 // TODO depend on the size and aspect ration on paper
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
320 });
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
321 },
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
322 addDiagramLegend(position, offset, color) {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
323 let x = offset.x,
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
324 y = offset.y;
3333
d5dbfba9faae clinet: pdf-template: fix positioning of diagramlegend (FairwayAvailability,AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3330
diff changeset
325 this.pdf.doc.setFontSize(10);
d5dbfba9faae clinet: pdf-template: fix positioning of diagramlegend (FairwayAvailability,AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3330
diff changeset
326 let width =
3493
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
327 (this.pdf.doc.getStringUnitWidth(">= LDC") * 10) / (72 / 25.6) + 15;
3333
d5dbfba9faae clinet: pdf-template: fix positioning of diagramlegend (FairwayAvailability,AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3330
diff changeset
328 // if position is on the right, x needs to be calculate with pdf width and
d5dbfba9faae clinet: pdf-template: fix positioning of diagramlegend (FairwayAvailability,AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3330
diff changeset
329 // the size of the element
d5dbfba9faae clinet: pdf-template: fix positioning of diagramlegend (FairwayAvailability,AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3330
diff changeset
330 if (["topright", "bottomright"].indexOf(position) !== -1) {
d5dbfba9faae clinet: pdf-template: fix positioning of diagramlegend (FairwayAvailability,AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3330
diff changeset
331 x = this.pdf.width - offset.x - width;
d5dbfba9faae clinet: pdf-template: fix positioning of diagramlegend (FairwayAvailability,AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3330
diff changeset
332 }
d5dbfba9faae clinet: pdf-template: fix positioning of diagramlegend (FairwayAvailability,AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3330
diff changeset
333 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
3493
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
334 y = this.pdf.height - offset.y - this.getTextHeight(6);
3333
d5dbfba9faae clinet: pdf-template: fix positioning of diagramlegend (FairwayAvailability,AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3330
diff changeset
335 }
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
336
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
337 this.pdf.doc.setTextColor(color);
3493
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
338 this.pdf.doc.setDrawColor(this.$options.COLORS.LDC);
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
339 this.pdf.doc.setFillColor(this.$options.COLORS.LDC);
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
340 this.pdf.doc.roundedRect(x, y, 10, 4, 1.5, 1.5, "FD");
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
341 this.pdf.doc.text(this.legend[0], x + 12, y + 3);
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
342
3493
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
343 this.pdf.doc.setDrawColor(this.$options.COLORS.REST[0]);
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
344 this.pdf.doc.setFillColor(this.$options.COLORS.REST[0]);
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
345 this.pdf.doc.roundedRect(x, y + 5, 10, 4, 1.5, 1.5, "FD");
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
346 this.pdf.doc.text(this.legend[1], x + 12, y + 8);
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
347
3493
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
348 this.pdf.doc.setDrawColor(this.$options.COLORS.REST[1]);
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
349 this.pdf.doc.setFillColor(this.$options.COLORS.REST[1]);
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
350 this.pdf.doc.roundedRect(x, y + 10, 10, 4, 1.5, 1.5, "FD");
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
351 this.pdf.doc.text(this.legend[2], x + 12, y + 13);
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
352
3493
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
353 this.pdf.doc.setDrawColor(this.$options.COLORS.HIGHEST);
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
354 this.pdf.doc.setFillColor(this.$options.COLORS.HIGHEST);
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
355 this.pdf.doc.roundedRect(x, y + 15, 10, 4, 1.5, 1.5, "FD");
da58cf951342 client: diagram-template: improve diagramlegend element (AvailableFairwayDepth)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3484
diff changeset
356 this.pdf.doc.text(this.legend[3], x + 12, y + 18);
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
357 },
3239
a7d44d1ae57d available_fairway_depth: legend
Thomas Junk <thomas.junk@intevation.de>
parents: 3235
diff changeset
358 legendStyle(index) {
3441
d7ec52232702 afd: improve legend coloring
Thomas Junk <thomas.junk@intevation.de>
parents: 3437
diff changeset
359 const style = {
d7ec52232702 afd: improve legend coloring
Thomas Junk <thomas.junk@intevation.de>
parents: 3437
diff changeset
360 0: `background-color: ${this.$options.COLORS.LDC};`,
d7ec52232702 afd: improve legend coloring
Thomas Junk <thomas.junk@intevation.de>
parents: 3437
diff changeset
361 1: `background-color: ${this.$options.COLORS.REST[0]};`,
d7ec52232702 afd: improve legend coloring
Thomas Junk <thomas.junk@intevation.de>
parents: 3437
diff changeset
362 2: `background-color: ${this.$options.COLORS.REST[1]};`,
d7ec52232702 afd: improve legend coloring
Thomas Junk <thomas.junk@intevation.de>
parents: 3437
diff changeset
363 3: `background-color: ${this.$options.COLORS.HIGHEST};`
d7ec52232702 afd: improve legend coloring
Thomas Junk <thomas.junk@intevation.de>
parents: 3437
diff changeset
364 };
d7ec52232702 afd: improve legend coloring
Thomas Junk <thomas.junk@intevation.de>
parents: 3437
diff changeset
365 return style[index];
3239
a7d44d1ae57d available_fairway_depth: legend
Thomas Junk <thomas.junk@intevation.de>
parents: 3235
diff changeset
366 },
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
367 close() {
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
368 this.$store.commit("application/paneSetup", "DEFAULT");
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents: 3180
diff changeset
369 },
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
370 drawDiagram() {
3235
0c5a28ffe9ee available_fairway_depth: flexible layouting options
Thomas Junk <thomas.junk@intevation.de>
parents: 3216
diff changeset
371 this.dimensions = this.getDimensions({
0c5a28ffe9ee available_fairway_depth: flexible layouting options
Thomas Junk <thomas.junk@intevation.de>
parents: 3216
diff changeset
372 main: { top: 20, right: 20, bottom: 110, left: 200 }
0c5a28ffe9ee available_fairway_depth: flexible layouting options
Thomas Junk <thomas.junk@intevation.de>
parents: 3216
diff changeset
373 });
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
374 this.yScale = d3
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
375 .scaleLinear()
3327
7ab8a176db92 available_fairway_depth: adjust scale according to selected timerange
Thomas Junk <thomas.junk@intevation.de>
parents: 3291
diff changeset
376 .domain(this.frequencyToRange)
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
377 .range([this.dimensions.mainHeight - 30, 0]);
3134
ab00165540fe available_fairway_depths: Component made visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3131
diff changeset
378 d3.select(".diagram-container svg").remove();
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
379 this.generateDiagramContainer();
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
380 this.drawBars();
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
381 this.drawScaleLabel();
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
382 this.drawScale();
3360
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
383 this.drawTooltip();
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
384 },
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
385 generateDiagramContainer() {
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
386 const diagram = d3
3134
ab00165540fe available_fairway_depths: Component made visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3131
diff changeset
387 .select(".diagram-container")
ab00165540fe available_fairway_depths: Component made visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3131
diff changeset
388 .append("svg")
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
389 .attr("width", this.dimensions.width)
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
390 .attr("height", this.dimensions.mainHeight);
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
391 this.diagram = diagram
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
392 .append("g")
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
393 .attr("transform", `translate(0 ${this.paddingTop})`);
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
394 },
3360
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
395 drawTooltip() {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
396 this.diagram
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
397 .append("text")
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
398 .text("banane")
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
399 .attr("font-size", "0.8em")
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
400 .attr("opacity", 0)
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
401 .attr("id", "tooltip");
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
402 },
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
403 drawBars() {
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
404 const everyBar = this.diagram
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
405 .selectAll("g")
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
406 .data(this.fwData)
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
407 .enter()
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
408 .append("g")
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
409 .attr("transform", (d, i) => {
3716
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
410 const dx = this.scalePaddingLeft + i * this.widthPerItem;
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
411 return `translate(${dx})`;
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
412 });
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
413 this.drawSingleBars(everyBar);
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
414 this.drawLabelPerBar(everyBar);
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
415 },
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
416 drawSingleBars(everyBar) {
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
417 this.drawLDC(everyBar);
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
418 this.drawHighestLevel(everyBar);
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
419 this.drawLowerLevels(everyBar);
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
420 },
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
421 drawLowerLevels(everyBar) {
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
422 everyBar
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
423 .selectAll("g")
3330
0e442b547f6d mocking fairway_availability
Thomas Junk <thomas.junk@intevation.de>
parents: 3327
diff changeset
424 .data(d => d.lowerLevels)
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
425 .enter()
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
426 .append("rect")
3360
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
427 .on("mouseover", function() {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
428 d3.select(this).attr("opacity", "0.8");
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
429 d3.select("#tooltip").attr("opacity", 1);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
430 })
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
431 .on("mouseout", function() {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
432 d3.select(this).attr("opacity", 1);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
433 d3.select("#tooltip").attr("opacity", 0);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
434 })
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
435 .on("mousemove", function(d) {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
436 let y = d3.mouse(this)[1];
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
437 const dy = document
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
438 .querySelector(".diagram-container")
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
439 .getBoundingClientRect().left;
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
440 const value = Number.parseFloat(hoursInDays(d.height)).toFixed(2);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
441 d3.select("#tooltip")
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
442 .text(value)
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
443 .attr("y", y - 10)
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
444 .attr("x", d3.event.pageX - dy);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
445 //d3.event.pageX gives coordinates relative to SVG
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
446 //dy gives offset of svg on page
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
447 })
3347
cd745be63f71 available_fairway_depth: draw lower levels refactored
Thomas Junk <thomas.junk@intevation.de>
parents: 3333
diff changeset
448 .attr("y", d => {
cd745be63f71 available_fairway_depth: draw lower levels refactored
Thomas Junk <thomas.junk@intevation.de>
parents: 3333
diff changeset
449 return 2 * this.yScale(0) - this.yScale(hoursInDays(d.translateY));
cd745be63f71 available_fairway_depth: draw lower levels refactored
Thomas Junk <thomas.junk@intevation.de>
parents: 3333
diff changeset
450 })
3128
1610d3042bbb fairway_availability: generative code fixed
Thomas Junk <thomas.junk@intevation.de>
parents: 3125
diff changeset
451 .attr("height", d => {
3347
cd745be63f71 available_fairway_depth: draw lower levels refactored
Thomas Junk <thomas.junk@intevation.de>
parents: 3333
diff changeset
452 return this.yScale(0) - this.yScale(hoursInDays(d.height));
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
453 })
3716
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
454 .attr("x", this.ldcOffset + this.spaceBetween)
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
455 .attr("width", this.widthPerItem - this.ldcOffset - this.spaceBetween)
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
456 .attr("fill", (d, i) => {
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
457 return this.$options.COLORS.REST[i];
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
458 });
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
459 },
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
460 fnheight(name) {
3213
b3a1ecdda797 available_fairway_depth: hours in days
Thomas Junk <thomas.junk@intevation.de>
parents: 3210
diff changeset
461 return d => this.yScale(0) - this.yScale(hoursInDays(d[name]));
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
462 },
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
463 drawLDC(everyBar) {
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
464 const height = this.fnheight("ldc");
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
465 everyBar
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
466 .append("rect")
3360
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
467 .on("mouseover", function() {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
468 d3.select(this).attr("opacity", "0.8");
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
469 d3.select("#tooltip").attr("opacity", 1);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
470 })
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
471 .on("mouseout", function() {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
472 d3.select(this).attr("opacity", 1);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
473 d3.select("#tooltip").attr("opacity", 0);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
474 })
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
475 .on("mousemove", function(d) {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
476 let y = d3.mouse(this)[1];
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
477 const dy = document
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
478 .querySelector(".diagram-container")
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
479 .getBoundingClientRect().left;
3371
f76a694f7f7b available_fairway_depth: fix tooltip
Thomas Junk <thomas.junk@intevation.de>
parents: 3360
diff changeset
480 const value = Number.parseFloat(hoursInDays(d.ldc)).toFixed(2);
3360
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
481 d3.select("#tooltip")
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
482 .text(value)
3410
e5bc8f4924cb afd: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3408
diff changeset
483 .attr("y", y - 50)
3360
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
484 .attr("x", d3.event.pageX - dy);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
485 //d3.event.pageX gives coordinates relative to SVG
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
486 //dy gives offset of svg on page
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
487 })
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
488 .attr("y", this.yScale(0))
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
489 .attr("height", height)
3716
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
490 .attr("x", this.spaceBetween)
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
491 .attr("width", this.widthPerItem - this.spaceBetween)
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
492 .attr("transform", d => `translate(0 ${-1 * height(d)})`)
3216
ee6a4e8af766 available_fairway_depth: legend POC
Thomas Junk <thomas.junk@intevation.de>
parents: 3213
diff changeset
493 .attr("fill", this.$options.COLORS.LDC)
ee6a4e8af766 available_fairway_depth: legend POC
Thomas Junk <thomas.junk@intevation.de>
parents: 3213
diff changeset
494 .attr("id", "ldc");
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
495 },
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
496 drawHighestLevel(everyBar) {
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
497 const height = this.fnheight("highestLevel");
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
498 everyBar
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
499 .append("rect")
3360
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
500 .on("mouseover", function() {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
501 d3.select(this).attr("opacity", "0.8");
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
502 d3.select("#tooltip").attr("opacity", 1);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
503 })
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
504 .on("mouseout", function() {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
505 d3.select(this).attr("opacity", 1);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
506 d3.select("#tooltip").attr("opacity", 0);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
507 })
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
508 .on("mousemove", function(d) {
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
509 let y = d3.mouse(this)[1];
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
510 const dy = document
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
511 .querySelector(".diagram-container")
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
512 .getBoundingClientRect().left;
3371
f76a694f7f7b available_fairway_depth: fix tooltip
Thomas Junk <thomas.junk@intevation.de>
parents: 3360
diff changeset
513 const value = Number.parseFloat(hoursInDays(d.highestLevel)).toFixed(
f76a694f7f7b available_fairway_depth: fix tooltip
Thomas Junk <thomas.junk@intevation.de>
parents: 3360
diff changeset
514 2
f76a694f7f7b available_fairway_depth: fix tooltip
Thomas Junk <thomas.junk@intevation.de>
parents: 3360
diff changeset
515 );
3360
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
516 d3.select("#tooltip")
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
517 .text(value)
3410
e5bc8f4924cb afd: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3408
diff changeset
518 .attr("y", y - 50)
3360
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
519 .attr("x", d3.event.pageX - dy);
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
520 //d3.event.pageX gives coordinates relative to SVG
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
521 //dy gives offset of svg on page
b2ccfebd5616 available_fairway_depth: tooltips
Thomas Junk <thomas.junk@intevation.de>
parents: 3349
diff changeset
522 })
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
523 .attr("y", this.yScale(0))
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
524 .attr("height", height)
3716
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
525 .attr("x", this.ldcOffset + this.spaceBetween)
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
526 .attr("width", this.widthPerItem - this.ldcOffset - this.spaceBetween)
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
527 .attr("transform", d => `translate(0 ${-1 * height(d)})`)
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
528 .attr("fill", this.$options.COLORS.HIGHEST);
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
529 },
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
530 drawLabelPerBar(everyBar) {
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
531 everyBar
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
532 .append("text")
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
533 .text(d => d.label)
3716
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
534 .attr("y", this.dimensions.mainHeight - this.labelPaddingBottom)
047a5e971ccd client: available fairway depth diagram: made width of bar charts adjust to diagram width to prevent overflow
Markus Kottlaender <markus@intevation.de>
parents: 3701
diff changeset
535 .attr("x", this.widthPerItem / 2)
3717
eab5e934c37d client: available fairway depth diagram: decreased label font-size to avoid overlapping at least a little bit better
Markus Kottlaender <markus@intevation.de>
parents: 3716
diff changeset
536 .attr("text-anchor", "middle")
3811
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
537 .attr("font-size", "9");
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
538 },
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
539 drawScaleLabel() {
3180
429e28295902 available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents: 3153
diff changeset
540 const center = this.dimensions.mainHeight / 2;
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
541 this.diagram
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
542 .append("text")
3135
Thomas Junk <thomas.junk@intevation.de>
parents: 3134
diff changeset
543 .text(this.$options.LEGEND)
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
544 .attr("text-anchor", "middle")
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
545 .attr("x", 0)
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
546 .attr("y", 0)
3811
37e896990c99 client: improve pdf generation towards vector diagrams
Bernhard Reiter <bernhard@intevation.de>
parents: 3806
diff changeset
547 .attr("dy", "10")
3135
Thomas Junk <thomas.junk@intevation.de>
parents: 3134
diff changeset
548 .attr("transform", `translate(0, ${center}), rotate(-90)`);
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
549 },
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
550 drawScale() {
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
551 const yAxis = d3.axisLeft().scale(this.yScale);
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
552 this.diagram
3125
383720d8d98e fairway_availability: generative code for diagram added
Thomas Junk <thomas.junk@intevation.de>
parents: 3033
diff changeset
553 .append("g")
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
554 .attr("transform", `translate(${this.scalePaddingLeft})`)
3267
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
555 .call(yAxis)
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
556 .selectAll(".tick text")
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
557 .attr("fill", "black")
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
558 .select(function() {
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
559 return this.parentNode;
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
560 })
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
561 .selectAll(".tick line")
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
562 .attr("stroke", "black");
b07b4cca5e34 client: diagram-template: implement pdf-template for fairway availability diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3239
diff changeset
563 this.diagram.selectAll(".domain").attr("stroke", "black");
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
564 }
3135
Thomas Junk <thomas.junk@intevation.de>
parents: 3134
diff changeset
565 },
3282
707d4435aff3 redraw diagram on change of data
Thomas Junk <thomas.junk@intevation.de>
parents: 3280
diff changeset
566 watch: {
707d4435aff3 redraw diagram on change of data
Thomas Junk <thomas.junk@intevation.de>
parents: 3280
diff changeset
567 fwData() {
707d4435aff3 redraw diagram on change of data
Thomas Junk <thomas.junk@intevation.de>
parents: 3280
diff changeset
568 this.drawDiagram();
707d4435aff3 redraw diagram on change of data
Thomas Junk <thomas.junk@intevation.de>
parents: 3280
diff changeset
569 }
707d4435aff3 redraw diagram on change of data
Thomas Junk <thomas.junk@intevation.de>
parents: 3280
diff changeset
570 },
3216
ee6a4e8af766 available_fairway_depth: legend POC
Thomas Junk <thomas.junk@intevation.de>
parents: 3213
diff changeset
571 LEGEND: app.$gettext("Sum of days"),
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
572 COLORS: {
3288
c2d753ef5aa1 fairway_availability: sane defaults and ISC colors for diagram
Thomas Junk <thomas.junk@intevation.de>
parents: 3287
diff changeset
573 LDC: "#cdcdcd",
c2d753ef5aa1 fairway_availability: sane defaults and ISC colors for diagram
Thomas Junk <thomas.junk@intevation.de>
parents: 3287
diff changeset
574 HIGHEST: "#3675ff",
3291
6996aa1d2df9 available_fairway_depth: switched colors
Thomas Junk <thomas.junk@intevation.de>
parents: 3288
diff changeset
575 REST: ["#782121", "#ff6c6c", "#ffaaaa"]
3153
8159bd2aaf93 fairway_depth_diagram: display of mockdata
Thomas Junk <thomas.junk@intevation.de>
parents: 3135
diff changeset
576 }
3033
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
577 };
c2c1e3e3af1c Available fairway depth: rudimentary thoughts / prototype. Tbd;
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
578 </script>