annotate client/src/components/gauge/HydrologicalConditions.vue @ 3937:de4c557bbc47

hydrological_conditions: leverage mixin
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 12 Jul 2019 10:03:11 +0200
parents 03f37e64701c
children 7b3935a8d9ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1 <template>
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
2 <div class="d-flex flex-column flex-fill">
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
3 <UIBoxHeader
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
4 icon="ruler-vertical"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
5 :title="title"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
6 :closeCallback="close"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
7 class="rounded-0"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
8 />
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
9 <div class="d-flex flex-fill">
3440
8801811bf9f5 client: diagram-template: fix the size of renderd Diagram in case two diagrams are shown on the screen
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3404
diff changeset
10 <DiagramLegend id="diagramlegendId">
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
11 <div class="legend">
3323
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
12 <span
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
13 style="background-color: red; width: 20px; height: 20px;"
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
14 ></span>
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
15 {{ yearCompare }}
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
16 </div>
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
17 <div class="legend">
3323
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
18 <span
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
19 style="background-color: orange; width: 20px; height: 20px;"
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
20 ></span>
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
21 Q25%
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
22 </div>
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
23 <div class="legend">
3323
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
24 <span
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
25 style="background-color: black; width: 20px; height: 20px;"
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
26 ></span>
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
27 Median
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
28 </div>
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
29 <div class="legend">
3323
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
30 <span
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
31 style="background-color: purple; width: 20px; height: 20px;"
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
32 ></span>
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
33 Q75%
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
34 </div>
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
35 <div class="legend">
3323
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
36 <span
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
37 style="background-color: lightsteelblue; width: 20px; height: 20px;"
de0d0685a17b client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3285
diff changeset
38 ></span>
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
39 Long-term Amplitude
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
40 </div>
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
41 <select
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
42 @change="applyChange"
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
43 v-model="form.template"
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
44 class="form-control d-block custom-select-sm w-100"
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
45 >
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
46 <option
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
47 v-for="template in templates"
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
48 :value="template"
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
49 :key="template.name"
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
50 >
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
51 {{ template.name }}
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
52 </option>
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
53 </select>
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
54 <div>
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
55 <button
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
56 @click="downloadPDF"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
57 type="button"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
58 class="btn btn-sm btn-info d-block w-100 mt-2"
3404
0c9467003d14 client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents: 3403
diff changeset
59 :disabled="!longtermWaterlevels.length"
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
60 >
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
61 <translate>Export to PDF</translate>
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
62 </button>
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
63 </div>
3403
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
64 <a
3404
0c9467003d14 client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents: 3403
diff changeset
65 :class="[
0c9467003d14 client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents: 3403
diff changeset
66 'btn btn-sm btn-info d-block w-100 mt-2',
0c9467003d14 client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents: 3403
diff changeset
67 { disabled: !longtermWaterlevels.length }
0c9467003d14 client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents: 3403
diff changeset
68 ]"
3403
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
69 :href="csvLink"
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
70 :download="csvFileName"
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
71 >
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
72 <translate>Export as CSV</translate>
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
73 </a>
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
74 </DiagramLegend>
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
75 <div
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
76 class="d-flex flex-fill justify-content-center align-items-center"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
77 :id="containerId"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
78 >
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
79 <div v-if="!longtermWaterlevels.length">
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
80 <translate>No data available.</translate>
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
81 </div>
2839
162804509c3e client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents: 2829
diff changeset
82 </div>
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
83 </div>
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
84 </div>
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
85 </template>
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
86
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
87 <script>
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
88 /* This is Free Software under GNU Affero General Public License v >= 3.0
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
89 * without warranty, see README.md and license for details.
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
90 *
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
91 * SPDX-License-Identifier: AGPL-3.0-or-later
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
92 * License-Filename: LICENSES/AGPL-3.0.txt
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
93 *
3112
e838609bc10d client: fix license header for waterlevel.vue and hydrologicalconditions.vue
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3111
diff changeset
94 * Copyright (C) 2019 by via donau
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
95 * – Österreichische Wasserstraßen-Gesellschaft mbH
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
96 * Software engineering by Intevation GmbH
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
97 *
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
98 * Author(s):
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
99 * Markus Kottländer <markus.kottlaender@intevation.de>
3112
e838609bc10d client: fix license header for waterlevel.vue and hydrologicalconditions.vue
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3111
diff changeset
100 * Fadi Abbud <fadi.abbud@intevation.de>
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
101 */
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
102
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
103 import { mapState, mapGetters } from "vuex";
2791
2b79c0871138 client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents: 2761
diff changeset
104 import * as d3 from "d3";
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
105 import debounce from "debounce";
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
106 import { startOfYear, endOfYear } from "date-fns";
3862
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
107 import svg2pdf from "svg2pdf.js";
3937
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
108 import { diagram, pdfgen, templateLoader } from "@/lib/mixins";
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
109 import { HTTP } from "@/lib/http";
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
110 import { displayError } from "@/lib/errors";
3927
03f37e64701c Factored out default template for diagrams in a single file.
Sascha Wilde <wilde@intevation.de>
parents: 3923
diff changeset
111 import { defaultDiagramTemplate } from "@/lib/DefaultDiagramTemplate";
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
112
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
113 export default {
3937
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
114 mixins: [diagram, pdfgen, templateLoader],
2839
162804509c3e client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents: 2829
diff changeset
115 components: {
162804509c3e client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents: 2829
diff changeset
116 DiagramLegend: () => import("@/components/DiagramLegend")
162804509c3e client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents: 2829
diff changeset
117 },
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
118 data() {
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
119 return {
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
120 containerId: "hydrologicalconditions-diagram-container",
3682
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3576
diff changeset
121 resizeListenerFunction: null,
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
122 templateData: null,
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
123 form: {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
124 template: null,
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
125 form: null
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
126 },
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
127 templates: [],
3927
03f37e64701c Factored out default template for diagrams in a single file.
Sascha Wilde <wilde@intevation.de>
parents: 3923
diff changeset
128 defaultTemplate: defaultDiagramTemplate,
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
129 pdf: {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
130 doc: null,
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
131 width: 420,
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
132 height: 297
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
133 }
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
134 };
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
135 },
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
136 computed: {
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
137 ...mapState("application", ["paneSetup"]),
2829
4a1211727d5f client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents: 2824
diff changeset
138 ...mapState("gauges", [
4a1211727d5f client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents: 2824
diff changeset
139 "longtermWaterlevels",
4a1211727d5f client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents: 2824
diff changeset
140 "yearWaterlevels",
3058
7a1a33fcec64 client: add infos and diagram legend for the generated pdf(hydrological diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3046
diff changeset
141 "yearCompare",
7a1a33fcec64 client: add infos and diagram legend for the generated pdf(hydrological diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3046
diff changeset
142 "longtermInterval"
2829
4a1211727d5f client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents: 2824
diff changeset
143 ]),
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
144 ...mapGetters("gauges", ["selectedGauge"]),
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
145 title() {
3148
cdfb0093b7b1 client: gauge diagrams: added information to titles
Markus Kottlaender <markus@intevation.de>
parents: 3147
diff changeset
146 return `${this.selectedGauge.properties.objname}: ${this.$gettext(
cdfb0093b7b1 client: gauge diagrams: added information to titles
Markus Kottlaender <markus@intevation.de>
parents: 3147
diff changeset
147 "Hydrological Conditions"
cdfb0093b7b1 client: gauge diagrams: added information to titles
Markus Kottlaender <markus@intevation.de>
parents: 3147
diff changeset
148 )} (${this.longtermInterval.join(" - ")})`;
3403
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
149 },
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
150 csvLink() {
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
151 return "data:text/csv;charset=utf-8," + encodeURIComponent(this.csvData);
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
152 },
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
153 csvFileName() {
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
154 return `${this.$gettext("hydrological-conditions")}-${
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
155 this.selectedGauge.properties.objname
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
156 }-${this.longtermInterval.join(" - ")}.csv`;
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
157 },
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
158 csvData() {
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
159 // We cannot directly use the csv data provided by the backend because the
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
160 // diagram uses data from two endpoints, longterm- and yearWaterlevels.
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
161 // So we need to merge them here to have them in one csv export.
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
162 let merged = this.longtermWaterlevels
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
163 .filter(d => d) // copy array, don't mutate original
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
164 .map(d => {
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
165 let yearData = this.yearWaterlevels.find(y => {
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
166 return d.date.getTime() === y.date.getTime();
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
167 });
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
168 d[this.yearCompare] = yearData ? yearData.mean : "";
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
169 return `${d.date.getMonth() + 1}-${d.date.getDate()};${d.min};${
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
170 d.max
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
171 };${d.mean};${d.median};${d.q25};${d.q75};${d[this.yearCompare]}`;
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
172 })
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
173 .join("\n");
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
174 return `#Interval: ${this.longtermInterval.join(
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
175 " - "
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
176 )}\n#date;#min;#max;#mean;#median;#q25;#q75;#${
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
177 this.yearCompare
d7cc5cda82a9 client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents: 3350
diff changeset
178 }\n${merged}`;
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
179 }
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
180 },
3068
492c30ca3142 client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents: 3067
diff changeset
181 watch: {
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
182 paneSetup() {
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
183 this.$nextTick(() => this.drawDiagram());
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
184 },
3068
492c30ca3142 client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents: 3067
diff changeset
185 longtermWaterlevels() {
492c30ca3142 client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents: 3067
diff changeset
186 this.drawDiagram();
492c30ca3142 client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents: 3067
diff changeset
187 },
492c30ca3142 client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents: 3067
diff changeset
188 yearWaterlevels() {
492c30ca3142 client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents: 3067
diff changeset
189 this.drawDiagram();
492c30ca3142 client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents: 3067
diff changeset
190 }
492c30ca3142 client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents: 3067
diff changeset
191 },
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
192 methods: {
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
193 close() {
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
194 this.$store.commit(
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
195 "application/paneSetup",
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
196 this.paneSetup === "GAUGE_WATERLEVEL_HYDROLOGICALCONDITIONS"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
197 ? "GAUGE_WATERLEVEL"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
198 : "DEFAULT"
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
199 );
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
200 },
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
201 downloadPDF() {
3798
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3789
diff changeset
202 let diagramTitle =
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3789
diff changeset
203 this.gaugeInfo(this.selectedGauge) +
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3789
diff changeset
204 ": Hydrological Conditions " +
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3789
diff changeset
205 this.longtermInterval.join(" - ");
3544
067ad32fba69 client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3440
diff changeset
206
3798
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3789
diff changeset
207 this.generatePDF({
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3789
diff changeset
208 templateData: this.templateData,
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3789
diff changeset
209 diagramTitle: diagramTitle
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3789
diff changeset
210 });
e008197e2215 client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents: 3789
diff changeset
211
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
212 this.pdf.doc.save(
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
213 this.selectedGauge.properties.objname +
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
214 " Hydrological-condition Diagram.pdf"
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
215 );
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
216 },
3862
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
217 addDiagram(position, offset, width, height) {
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
218 let x = offset.x,
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
219 y = offset.y;
3887
83c4672369a2 hydrological conditions: diagram size dynamic - taken from template
Thomas Junk <thomas.junk@intevation.de>
parents: 3884
diff changeset
220 const svgWidth = this.millimeter2pixels(width, 80);
83c4672369a2 hydrological conditions: diagram size dynamic - taken from template
Thomas Junk <thomas.junk@intevation.de>
parents: 3884
diff changeset
221 const svgHeight = this.millimeter2pixels(height, 80);
3862
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
222 // draw the diagram in a separated html element to get the full size
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
223 const offScreen = document.querySelector("#offScreen");
3872
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
224 offScreen.style.width = `${svgWidth}px`;
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
225 offScreen.style.height = `${svgHeight}px`;
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
226 this.renderTo({
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
227 element: offScreen,
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
228 dimensions: this.getDimensions({
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
229 svgWidth: svgWidth,
3937
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
230 svgHeight: svgHeight,
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
231 main: { top: 20, right: 50, bottom: 110, left: 80 },
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
232 nav: {
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
233 top: svgHeight - 85,
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
234 right: 20,
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
235 bottom: 30,
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
236 left: 80
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
237 }
3872
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
238 })
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
239 });
3862
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
240 var svg = offScreen.querySelector("svg");
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
241 if (["topright", "bottomright"].indexOf(position) !== -1) {
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
242 x = this.pdf.width - offset.x - width;
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
243 }
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
244 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
245 y = this.pdf.height - offset.y - height;
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
246 }
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
247 svg2pdf(svg, this.pdf.doc, {
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
248 xOffset: x,
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
249 yOffset: y,
3910
29b294e77a5c client: pdf-gen: set diagram scale on pdf and adjust default template value(waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3902
diff changeset
250 scale: 0.353
3862
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
251 });
3865
36e85a74fca0 hydrolgical condition: remove old diagram
Thomas Junk <thomas.junk@intevation.de>
parents: 3862
diff changeset
252 offScreen.removeChild(svg);
3862
ecf2e5ea1464 Backed out changeset 55e503270f38
Thomas Junk <thomas.junk@intevation.de>
parents: 3858
diff changeset
253 },
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
254 applyChange() {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
255 if (this.form.template.hasOwnProperty("properties")) {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
256 this.templateData = this.defaultTemplate;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
257 return;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
258 }
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
259 if (this.form.template) {
3803
9b9140c65a96 hydrological_conditions: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3798
diff changeset
260 this.loadTemplates("/templates/diagram/" + this.form.template.name)
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
261 .then(response => {
3803
9b9140c65a96 hydrological_conditions: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3798
diff changeset
262 this.prepareImages(response.data.template_data.elements).then(
9b9140c65a96 hydrological_conditions: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3798
diff changeset
263 values => {
9b9140c65a96 hydrological_conditions: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3798
diff changeset
264 values.forEach(v => {
9b9140c65a96 hydrological_conditions: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3798
diff changeset
265 response.data.template_data.elements[v.index].url = v.url;
9b9140c65a96 hydrological_conditions: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3798
diff changeset
266 });
9b9140c65a96 hydrological_conditions: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3798
diff changeset
267 this.templateData = response.data.template_data;
9b9140c65a96 hydrological_conditions: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents: 3798
diff changeset
268 }
3789
c66cdde873b5 Hydrological_Conditions: prefetch images of template and convert to dataURI
Thomas Junk <thomas.junk@intevation.de>
parents: 3780
diff changeset
269 );
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
270 })
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
271 .catch(e => {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
272 const { status, data } = e.response;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
273 displayError({
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
274 title: this.$gettext("Backend Error"),
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
275 message: `${status}: ${data.message || data}`
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
276 });
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
277 });
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
278 }
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
279 },
3129
136b86794453 client: improve pdf-gen code for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3112
diff changeset
280 // Diagram legend
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
281 addDiagramLegend(position, offset, color) {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
282 let x = offset.x,
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
283 y = offset.y;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
284 let width =
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
285 (this.pdf.doc.getStringUnitWidth("Long-term Amplitude") * 10) /
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
286 (72 / 25.6) +
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
287 5;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
288 // if position is on the right, x needs to be calculate with pdf width and
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
289 // the size of the element
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
290 if (["topright", "bottomright"].indexOf(position) !== -1) {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
291 x = this.pdf.width - offset.x - width;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
292 }
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
293 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
294 y = this.pdf.height - offset.y - this.getTextHeight(4);
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
295 }
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
296 this.pdf.doc.setFontSize(10);
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
297 this.pdf.doc.setTextColor(color);
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
298 this.pdf.doc.setDrawColor("white");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
299 this.pdf.doc.setFillColor("red");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
300 this.pdf.doc.circle(x, y, 2, "FD");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
301 this.pdf.doc.text(x + 3, y + 1, "" + this.yearCompare);
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
302 this.pdf.doc.setFillColor("orange");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
303 this.pdf.doc.circle(x, y + 5, 2, "FD");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
304 this.pdf.doc.text(x + 3, y + 6, "Q25%");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
305 this.pdf.doc.setFillColor("black");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
306 this.pdf.doc.circle(x, y + 10, 2, "FD");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
307 this.pdf.doc.text(x + 3, y + 11, "Median ");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
308 this.pdf.doc.setFillColor("purple");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
309 this.pdf.doc.circle(x, y + 15, 2, "FD");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
310 this.pdf.doc.text(x + 3, y + 16, "Q75%");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
311 this.pdf.doc.setFillColor("lightsteelblue");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
312 this.pdf.doc.circle(x, y + 20, 2, "FD");
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
313 this.pdf.doc.text(x + 3, y + 21, "Long-term Amplitude");
3129
136b86794453 client: improve pdf-gen code for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3112
diff changeset
314 },
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
315 drawDiagram() {
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
316 // remove old diagram
3146
b6cc4838d2c0 client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3129
diff changeset
317 d3.select("#" + this.containerId + " svg").remove();
3915
f7f09f32d6e0 hydrological conditions: omit rendering, when container isn't visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3910
diff changeset
318 const el = document.querySelector("#" + this.containerId);
f7f09f32d6e0 hydrological conditions: omit rendering, when container isn't visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3910
diff changeset
319 if (!this.selectedGauge || !this.longtermWaterlevels.length || !el)
f7f09f32d6e0 hydrological conditions: omit rendering, when container isn't visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3910
diff changeset
320 return;
f7f09f32d6e0 hydrological conditions: omit rendering, when container isn't visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3910
diff changeset
321 const svgWidth = el.clientWidth;
f7f09f32d6e0 hydrological conditions: omit rendering, when container isn't visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3910
diff changeset
322 const svgHeight = el.clientHeight;
3872
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
323 this.renderTo({
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
324 element: `#${this.containerId}`,
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
325 dimensions: this.getDimensions({
3915
f7f09f32d6e0 hydrological conditions: omit rendering, when container isn't visible
Thomas Junk <thomas.junk@intevation.de>
parents: 3910
diff changeset
326 svgWidth: svgWidth,
3937
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
327 svgHeight: svgHeight,
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
328 main: { top: 20, right: 50, bottom: 110, left: 80 },
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
329 nav: {
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
330 top: svgHeight - 85,
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
331 right: 20,
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
332 bottom: 30,
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
333 left: 80
de4c557bbc47 hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents: 3927
diff changeset
334 }
3872
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
335 })
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
336 });
3857
6ce80daf8413 Hydrological conditions: render svg in offscreen element
Thomas Junk <thomas.junk@intevation.de>
parents: 3849
diff changeset
337 },
3872
a7a75e003b78 hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents: 3869
diff changeset
338 renderTo({ element, dimensions }) {
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
339 // PREPARE HELPERS
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
340
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
341 // HDC/LDC/MW for the selected gauge
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
342 const refWaterLevels = JSON.parse(
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
343 this.selectedGauge.properties.reference_water_levels
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
344 );
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
345
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
346 // dimensions (widths, heights, margins)
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
347
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
348 // get min/max values for date and waterlevel axis
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
349 const extent = this.getExtent(refWaterLevels);
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
350
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
351 // scaling helpers
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
352 const scale = this.getScale({ dimensions, extent });
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
353
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
354 // creating the axes based on the scales
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
355 const axes = this.getAxes({ scale, dimensions });
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
356
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
357 // DRAW DIAGRAM/NAVIGATION AREAS
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
358
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
359 // create svg
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
360 const svg = d3
3857
6ce80daf8413 Hydrological conditions: render svg in offscreen element
Thomas Junk <thomas.junk@intevation.de>
parents: 3849
diff changeset
361 .select(element)
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
362 .append("svg")
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
363 .attr("width", "100%")
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
364 .attr("height", "100%");
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
365
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
366 // create container for main diagram
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
367 const diagram = svg
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
368 .append("g")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
369 .attr("class", "main")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
370 .attr(
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
371 "transform",
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
372 `translate(${dimensions.mainMargin.left}, ${
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
373 dimensions.mainMargin.top
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
374 })`
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
375 );
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
376
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
377 // create container for navigation diagram
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
378 const navigation = svg
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
379 .append("g")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
380 .attr("class", "nav")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
381 .attr(
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
382 "transform",
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
383 `translate(${dimensions.navMargin.left}, ${dimensions.navMargin.top})`
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
384 );
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
385
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
386 // define visible area, everything outside this area will be hidden
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
387 svg
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
388 .append("defs")
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
389 .append("clipPath")
3147
25c0cbfcc515 client: gauge diagrams: fixed bug related to same clippath id in multiple diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3146
diff changeset
390 .attr("id", "hydrocond-clip")
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
391 .append("rect")
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
392 .attr("width", dimensions.width)
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
393 .attr("height", dimensions.mainHeight);
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
394
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
395 // DRAW DIAGRAM PARTS
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
396
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
397 // Each drawSomething function (with the exception of drawRefLines)
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
398 // returns a fuction to update the respective chart/area/etc. These
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
399 // updater functions are used by the zoom feature to rescale all elements.
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
400 const updaters = [];
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
401
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
402 // draw
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
403 updaters.push(this.drawAxes({ diagram, dimensions, axes, navigation }));
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
404 updaters.push(
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
405 this.drawWaterlevelMinMaxAreaChart({ scale, diagram, navigation })
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
406 );
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
407 updaters.push(
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
408 this.drawWaterlevelLineChart({ type: "median", scale, diagram })
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
409 );
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
410 updaters.push(
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
411 this.drawWaterlevelLineChart({ type: "q25", scale, diagram })
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
412 );
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
413 updaters.push(
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
414 this.drawWaterlevelLineChart({ type: "q75", scale, diagram })
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
415 );
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
416 updaters.push(
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
417 this.drawWaterlevelLineChart({
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
418 type: "mean",
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
419 data: this.yearWaterlevels,
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
420 scale,
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
421 diagram
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
422 })
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
423 );
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
424 updaters.push(this.drawNowLines({ extent, diagram, scale, navigation }));
3726
be939dcdfdfd client: waterlevel diagrams: make now line label not update its position when zooming
Markus Kottlaender <markus@intevation.de>
parents: 3724
diff changeset
425
3722
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
426 if (refWaterLevels) {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
427 this.drawRefLines({ refWaterLevels, scale, diagram, extent }); // static, doesn't need an updater
3722
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
428 }
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
429
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
430 // INTERACTIONS
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
431
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
432 // create rectanlge on the main chart area to capture mouse events
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
433 const eventRect = svg
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
434 .append("rect")
3212
f87fd173f750 client: waterlevel diagrams: fixed tooltip bug
Markus Kottlaender <markus@intevation.de>
parents: 3211
diff changeset
435 .attr("id", "zoom-hydrocond")
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
436 .attr("class", "zoom")
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
437 .attr("width", dimensions.width)
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
438 .attr("height", dimensions.mainHeight)
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
439 .attr(
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
440 "transform",
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
441 `translate(${dimensions.mainMargin.left}, ${
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
442 dimensions.mainMargin.top
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
443 })`
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
444 );
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
445
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
446 this.createZoom({
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
447 updaters,
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
448 eventRect,
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
449 dimensions,
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
450 scale,
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
451 svg,
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
452 navigation
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
453 });
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
454 this.createTooltips({ eventRect, diagram, scale, dimensions });
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
455 this.setInlineStyles(svg);
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
456 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
457 setInlineStyles(svg) {
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
458 svg.selectAll(".hide").attr("fill-opacity", 0);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
459 svg
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
460 .selectAll(".line")
3147
25c0cbfcc515 client: gauge diagrams: fixed bug related to same clippath id in multiple diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3146
diff changeset
461 .attr("clip-path", "url(#hydrocond-clip)")
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
462 .attr("stroke-width", 2)
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
463 .attr("fill", "none");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
464 svg.selectAll(".line.mean").attr("stroke", "red");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
465 svg.selectAll(".line.median").attr("stroke", "black");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
466 svg.selectAll(".line.q25").attr("stroke", "orange");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
467 svg.selectAll(".line.q75").attr("stroke", "purple");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
468 svg
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
469 .selectAll(".area")
3147
25c0cbfcc515 client: gauge diagrams: fixed bug related to same clippath id in multiple diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3146
diff changeset
470 .attr("clip-path", "url(#hydrocond-clip)")
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
471 .attr("stroke", "none")
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
472 .attr("fill", "lightsteelblue");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
473 svg
3209
5b8916b78cea client: waterlevel diagrams: check which reference waterlevels are available and added RN as possible option
Markus Kottlaender <markus@intevation.de>
parents: 3197
diff changeset
474 .selectAll(".hdc-line, .ldc-line, .mw-line, .rn-line")
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
475 .attr("stroke-width", 1)
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
476 .attr("fill", "none")
3147
25c0cbfcc515 client: gauge diagrams: fixed bug related to same clippath id in multiple diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3146
diff changeset
477 .attr("clip-path", "url(#hydrocond-clip)");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
478 svg.selectAll(".hdc-line").attr("stroke", "red");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
479 svg.selectAll(".ldc-line").attr("stroke", "green");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
480 svg.selectAll(".mw-line").attr("stroke", "grey");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
481 svg.selectAll(".rn-line").attr("stroke", "grey");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
482 svg
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
483 .selectAll(".ref-waterlevel-label")
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
484 .style("font-size", "10px")
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
485 .attr("fill", "black");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
486 svg
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
487 .selectAll(".ref-waterlevel-label-background")
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
488 .attr("fill", "rgba(255, 255, 255, 0.6)");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
489 svg
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
490 .selectAll(".now-line")
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
491 .attr("stroke", "#999")
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
492 .attr("stroke-width", 1)
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
493 .attr("stroke-dasharray", "5, 5")
3147
25c0cbfcc515 client: gauge diagrams: fixed bug related to same clippath id in multiple diagrams
Markus Kottlaender <markus@intevation.de>
parents: 3146
diff changeset
494 .attr("clip-path", "url(#hydrocond-clip)");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
495 svg
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
496 .selectAll(".now-line-label")
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
497 .attr("fill", "#999")
3045
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
498 .style("font-size", "11px");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
499 svg
3902
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
500 .selectAll(".axis--x .tick line, .axis--y .tick line")
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
501 .attr("stroke-dasharray", 5)
3842
22f7677337a5 client:pdf-gen: fix drawing of axises on pdf (hydrologicalconditions diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3820
diff changeset
502 .attr("stroke", "#ccc");
3902
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
503 svg.selectAll(".axis--y-right .tick line").attr("stroke", "transparent");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
504 svg.selectAll(".tick text").attr("fill", "black");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
505 svg.selectAll(".domain").attr("stroke", "black");
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
506
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
507 svg
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
508 .selectAll(".zoom")
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
509 .attr("cursor", "move")
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
510 .attr("fill", "none")
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
511 .attr("pointer-events", "all");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
512 svg
3111
f269bd001e78 client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3068
diff changeset
513 .selectAll(".brush .selection")
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
514 .attr("stroke", "none")
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
515 .attr("fill-opacity", 0.2);
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
516 svg
3111
f269bd001e78 client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3068
diff changeset
517 .selectAll(".brush .handle")
3025
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
518 .attr("stroke", "rgba(23, 162, 184, 0.5)")
37cc0d75ad84 client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 2986
diff changeset
519 .attr("fill", "rgba(23, 162, 184, 0.5)");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
520 svg.selectAll(".chart-dots").attr("clip-path", "url(#hydrocond-clip)");
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
521 svg
3111
f269bd001e78 client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3068
diff changeset
522 .selectAll(".chart-dots .chart-dot")
f269bd001e78 client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3068
diff changeset
523 .attr("fill", "black")
f269bd001e78 client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3068
diff changeset
524 .attr("stroke", "black")
3045
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
525 .attr("stroke-opacity", 0)
3111
f269bd001e78 client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3068
diff changeset
526 .style("pointer-events", "none")
3045
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
527 .attr("fill-opacity", 0)
3046
c764c73f44b4 client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3045
diff changeset
528 .transition()
c764c73f44b4 client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3045
diff changeset
529 .attr("fill-opacity", "0.1s");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
530 svg
3045
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
531 .selectAll(".chart-tooltip")
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
532 .attr("fill-opacity", 0)
3046
c764c73f44b4 client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3045
diff changeset
533 .transition()
c764c73f44b4 client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3045
diff changeset
534 .attr("fill-opacity", "0.3s");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
535 svg
3045
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
536 .selectAll(".chart-tooltip rect")
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
537 .attr("fill", "#fff")
3884
db24b4347604 client: pdf-gen: fix bug of not rendering some elements on pdf(hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3872
diff changeset
538 .attr("stroke", "#ccc")
db24b4347604 client: pdf-gen: fix bug of not rendering some elements on pdf(hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3872
diff changeset
539 // set width,height attributes for rect element in case d3 does not
db24b4347604 client: pdf-gen: fix bug of not rendering some elements on pdf(hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3872
diff changeset
540 // generate them to let svg2pdf continue rendernig of the following elements
db24b4347604 client: pdf-gen: fix bug of not rendering some elements on pdf(hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3872
diff changeset
541 .attr("width", "0px")
db24b4347604 client: pdf-gen: fix bug of not rendering some elements on pdf(hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3872
diff changeset
542 .attr("height", "0px");
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
543 svg
3045
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
544 .selectAll(".chart-tooltip text")
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
545 .attr("fill", "666")
44dc837638d9 client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3032
diff changeset
546 .style("font-size", "0.8em");
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
547 },
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
548 getExtent(refWaterLevels) {
3722
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
549 const waterlevelValues = [];
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
550 this.longtermWaterlevels.forEach(wl => {
3722
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
551 waterlevelValues.push(wl.min, wl.max);
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
552 });
3722
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
553 if (refWaterLevels) {
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
554 waterlevelValues.push(
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
555 refWaterLevels.HDC + (refWaterLevels.HDC - refWaterLevels.LDC) / 8,
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
556 Math.max(
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
557 refWaterLevels.LDC - (refWaterLevels.HDC - refWaterLevels.LDC) / 4,
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
558 0
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
559 )
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
560 );
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
561 } else {
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
562 let delta = d3.max(waterlevelValues) - d3.min(waterlevelValues);
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
563 waterlevelValues.push(
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
564 d3.max(waterlevelValues) + delta * 0.1,
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
565 d3.min(waterlevelValues) - delta * 0.1
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
566 );
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
567 }
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
568 return {
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
569 // set min/max values for the date axis
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
570 date: [startOfYear(new Date()), endOfYear(new Date())],
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
571 // set min/max values for the waterlevel axis
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
572 // including HDC (+ 1/8 HDC-LDC) and LDC (- 1/4 HDC-LDC)
3722
f180de37903c client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents: 3691
diff changeset
573 waterlevel: d3.extent(waterlevelValues)
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
574 };
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
575 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
576 getScale({ dimensions, extent }) {
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
577 // scaling helpers to convert real world values into pixels
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
578 const x = d3.scaleTime().range([0, dimensions.width]);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
579 const y = d3.scaleLinear().range([dimensions.mainHeight, 0]);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
580 const x2 = d3.scaleTime().range([0, dimensions.width]);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
581 const y2 = d3.scaleLinear().range([dimensions.navHeight, 0]);
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
582
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
583 // setting the min and max values for the diagram axes
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
584 x.domain(d3.extent(extent.date));
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
585 y.domain(extent.waterlevel);
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
586 x2.domain(x.domain());
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
587 y2.domain(y.domain());
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
588
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
589 return { x, y, x2, y2 };
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
590 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
591 getAxes({ scale, dimensions }) {
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
592 return {
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
593 x: d3
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
594 .axisTop(scale.x)
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
595 .tickSizeInner(dimensions.mainHeight)
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
596 .tickSizeOuter(0)
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
597 .tickFormat(date => {
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
598 // make the x-axis label formats dynamic, based on zoom
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
599 // but never display year numbers since they don't make any sense in
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
600 // this diagram
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
601 return (d3.timeSecond(date) < date
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
602 ? d3.timeFormat(".%L")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
603 : d3.timeMinute(date) < date
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
604 ? d3.timeFormat(":%S")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
605 : d3.timeHour(date) < date
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
606 ? d3.timeFormat("%I:%M")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
607 : d3.timeDay(date) < date
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
608 ? d3.timeFormat("%I %p")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
609 : d3.timeMonth(date) < date
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
610 ? d3.timeWeek(date) < date
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
611 ? d3.timeFormat("%a %d")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
612 : d3.timeFormat("%b %d")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
613 : d3.timeFormat("%B"))(date);
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
614 }),
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
615 y: d3
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
616 .axisRight(scale.y)
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
617 .tickSizeInner(dimensions.width)
3576
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
618 .tickSizeOuter(0)
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
619 .tickFormat(d => this.$options.filters.waterlevel(d)),
3902
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
620 yRight: d3
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
621 .axisRight(scale.y)
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
622 .tickSizeInner(3)
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
623 .tickSizeOuter(0)
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
624 .tickFormat(d => this.$options.filters.waterlevel(d)),
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
625 x2: d3.axisBottom(scale.x2)
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
626 };
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
627 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
628 drawNowLines({ extent, diagram, scale, navigation }) {
3726
be939dcdfdfd client: waterlevel diagrams: make now line label not update its position when zooming
Markus Kottlaender <markus@intevation.de>
parents: 3724
diff changeset
629 const now = new Date();
be939dcdfdfd client: waterlevel diagrams: make now line label not update its position when zooming
Markus Kottlaender <markus@intevation.de>
parents: 3724
diff changeset
630 const nowCoords = [
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
631 { x: now, y: extent.waterlevel[0] },
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
632 { x: now, y: extent.waterlevel[1] }
3726
be939dcdfdfd client: waterlevel diagrams: make now line label not update its position when zooming
Markus Kottlaender <markus@intevation.de>
parents: 3724
diff changeset
633 ];
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
634 const nowLine = d3
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
635 .line()
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
636 .x(d => scale.x(d.x))
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
637 .y(d => scale.y(d.y));
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
638 const nowLabel = selection => {
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
639 selection.attr(
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
640 "transform",
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
641 `translate(${scale.x(now)}, ${scale.y(extent.waterlevel[1])})`
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
642 );
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
643 };
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
644
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
645 // draw in main
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
646 diagram
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
647 .append("path")
3726
be939dcdfdfd client: waterlevel diagrams: make now line label not update its position when zooming
Markus Kottlaender <markus@intevation.de>
parents: 3724
diff changeset
648 .datum(nowCoords)
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
649 .attr("class", "now-line")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
650 .attr("d", nowLine);
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
651 diagram // label
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
652 .append("text")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
653 .text(this.$gettext("Now"))
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
654 .attr("class", "now-line-label")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
655 .attr("text-anchor", "middle")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
656 .call(nowLabel);
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
657
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
658 // draw in nav
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
659 navigation
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
660 .append("path")
3726
be939dcdfdfd client: waterlevel diagrams: make now line label not update its position when zooming
Markus Kottlaender <markus@intevation.de>
parents: 3724
diff changeset
661 .datum(nowCoords)
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
662 .attr("class", "now-line")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
663 .attr(
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
664 "d",
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
665 d3
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
666 .line()
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
667 .x(d => scale.x2(d.x))
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
668 .y(d => scale.y2(d.y))
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
669 );
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
670
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
671 return () => {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
672 diagram.select(".now-line").attr("d", nowLine);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
673 diagram.select(".now-line-label").call(nowLabel);
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
674 };
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
675 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
676 drawAxes({ diagram, dimensions, axes, navigation }) {
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
677 diagram
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
678 .append("g")
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
679 .attr("class", "axis--x")
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
680 .attr("transform", `translate(0, ${dimensions.mainHeight})`)
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
681 .call(axes.x)
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
682 .selectAll(".tick text")
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
683 .attr("y", 15);
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
684 diagram // label
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
685 .append("text")
3576
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
686 .text(this.$gettext("Waterlevel [m]"))
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
687 .attr("text-anchor", "middle")
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
688 .attr(
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
689 "transform",
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
690 `translate(-45, ${dimensions.mainHeight / 2}) rotate(-90)`
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
691 );
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
692 diagram
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
693 .append("g")
3902
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
694 .attr("class", "axis--y")
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
695 .call(axes.y)
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
696 .selectAll(".tick text")
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
697 .attr("x", -25);
3902
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
698 diagram
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
699 .append("g")
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
700 .attr("class", "axis--y-right")
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
701 .attr("transform", `translate(${dimensions.width})`)
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
702 .call(axes.yRight)
0149b68a4f7e client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents: 3894
diff changeset
703 .selectAll(".tick text");
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
704
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
705 navigation
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
706 .append("g")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
707 .attr("class", "axis axis--x")
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
708 .attr("transform", `translate(0, ${dimensions.navHeight})`)
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
709 .call(axes.x2);
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
710
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
711 return () => {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
712 diagram
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
713 .select(".axis--x")
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
714 .call(axes.x)
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
715 .selectAll(".tick text")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
716 .attr("y", 15);
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
717 };
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
718 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
719 drawWaterlevelMinMaxAreaChart({ scale, diagram, navigation }) {
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
720 const areaChart = isNav =>
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
721 d3
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
722 .area()
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
723 .x(d => scale[isNav ? "x2" : "x"](d.date))
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
724 .y0(d => scale[isNav ? "y2" : "y"](d.min))
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
725 .y1(d => scale[isNav ? "y2" : "y"](d.max));
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
726
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
727 diagram
2791
2b79c0871138 client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents: 2761
diff changeset
728 .append("path")
2813
49c1570919ae client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents: 2791
diff changeset
729 .datum(this.longtermWaterlevels)
2791
2b79c0871138 client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents: 2761
diff changeset
730 .attr("class", "area")
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
731 .attr("d", areaChart());
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
732
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
733 navigation
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
734 .append("path")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
735 .datum(this.longtermWaterlevels)
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
736 .attr("class", "area")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
737 .attr("d", areaChart(true));
2791
2b79c0871138 client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents: 2761
diff changeset
738
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
739 return () => {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
740 diagram.select(".area").attr("d", areaChart());
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
741 };
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
742 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
743 drawWaterlevelLineChart({ type, data, scale, diagram }) {
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
744 const lineChart = type =>
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
745 d3
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
746 .line()
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
747 .x(d => scale.x(d.date))
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
748 .y(d => scale.y(d[type]))
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
749 .curve(d3.curveLinear);
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
750 diagram
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
751 .append("path")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
752 .attr("class", "line " + type)
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
753 .datum(data || this.longtermWaterlevels)
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
754 .attr("d", lineChart(type));
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
755
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
756 return () => {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
757 diagram.select(".line." + type).attr("d", lineChart(type));
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
758 };
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
759 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
760 drawRefLines({ refWaterLevels, scale, diagram, extent }) {
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
761 const refWaterlevelLine = d3
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
762 .line()
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
763 .x(d => scale.x(d.x))
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
764 .y(d => scale.y(d.y));
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
765
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
766 for (let ref in refWaterLevels) {
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
767 if (refWaterLevels[ref]) {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
768 diagram
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
769 .append("path")
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
770 .datum([
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
771 { x: extent.date[0], y: refWaterLevels[ref] },
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
772 { x: extent.date[1], y: refWaterLevels[ref] }
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
773 ])
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
774 .attr("class", ref.toLowerCase() + "-line")
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
775 .attr("d", refWaterlevelLine);
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
776 diagram // label
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
777 .append("rect")
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
778 .attr("class", "ref-waterlevel-label-background")
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
779 .attr("x", 1)
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
780 .attr("y", scale.y(refWaterLevels[ref]) - 13)
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
781 .attr("width", 55)
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
782 .attr("height", 12);
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
783 diagram
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
784 .append("text")
3576
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
785 .text(
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
786 `${ref} (${this.$options.filters.waterlevel(
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
787 refWaterLevels[ref]
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
788 )})`
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
789 )
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
790 .attr("class", "ref-waterlevel-label")
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
791 .attr("x", 5)
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
792 .attr("y", scale.y(refWaterLevels[ref]) - 3);
3211
f76927849ef8 client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents: 3209
diff changeset
793 }
3209
5b8916b78cea client: waterlevel diagrams: check which reference waterlevels are available and added RN as possible option
Markus Kottlaender <markus@intevation.de>
parents: 3197
diff changeset
794 }
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
795 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
796 createZoom({ updaters, eventRect, dimensions, scale, svg, navigation }) {
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
797 const brush = d3
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
798 .brushX()
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
799 .handleSize(4)
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
800 .extent([[0, 0], [dimensions.width, dimensions.navHeight]]);
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
801
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
802 const zoom = d3
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
803 .zoom()
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
804 .scaleExtent([1, Infinity])
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
805 .translateExtent([[0, 0], [dimensions.width, dimensions.mainHeight]])
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
806 .extent([[0, 0], [dimensions.width, dimensions.mainHeight]]);
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
807
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
808 brush.on("brush end", () => {
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
809 if (d3.event.sourceEvent && d3.event.sourceEvent.type === "zoom")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
810 return; // ignore brush-by-zoom
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
811 let s = d3.event.selection || scale.x2.range();
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
812 scale.x.domain(s.map(scale.x2.invert, scale.x2));
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
813 updaters.forEach(u => u && u());
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
814 this.setInlineStyles(svg);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
815 svg
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
816 .select(".zoom")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
817 .call(
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
818 zoom.transform,
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
819 d3.zoomIdentity
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
820 .scale(dimensions.width / (s[1] - s[0]))
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
821 .translate(-s[0], 0)
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
822 );
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
823 });
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
824
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
825 zoom.on("zoom", () => {
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
826 if (d3.event.sourceEvent && d3.event.sourceEvent.type === "brush")
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
827 return; // ignore zoom-by-brush
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
828 let t = d3.event.transform;
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
829 scale.x.domain(t.rescaleX(scale.x2).domain());
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
830 updaters.forEach(u => u && u());
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
831 this.setInlineStyles(svg);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
832 navigation
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
833 .select(".brush")
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
834 .call(brush.move, scale.x.range().map(t.invertX, t));
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
835 });
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
836 zoom.on("start", () => {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
837 svg.select(".chart-dot").style("opacity", 0);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
838 svg.select(".chart-tooltip").style("opacity", 0);
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
839 });
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
840
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
841 navigation
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
842 .append("g")
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
843 .attr("class", "brush")
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
844 .call(brush)
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
845 .call(brush.move, scale.x.range());
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
846
2815
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
847 eventRect.call(zoom);
12f053763be2 client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents: 2813
diff changeset
848 },
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
849 createTooltips({ eventRect, diagram, scale, dimensions }) {
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
850 // create clippable container for the dot
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
851 diagram
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
852 .append("g")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
853 .attr("class", "chart-dots")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
854 .append("circle")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
855 .attr("class", "chart-dot")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
856 .attr("r", 4);
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
857
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
858 // create container for the tooltip
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
859 const tooltip = diagram.append("g").attr("class", "chart-tooltip");
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
860 tooltip
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
861 .append("rect")
2842
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
862 .attr("rx", "0.25em")
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
863 .attr("ry", "0.25em");
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
864
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
865 // create container for multiple text rows
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
866 const tooltipText = tooltip.append("text").attr("text-anchor", "middle");
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
867
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
868 // padding inside the tooltip box and diagram padding to determine left
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
869 // and right offset from the diagram boundaries for the tooltip position.
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
870 const tooltipPadding = 10;
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
871 const diagramPadding = 5;
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
872
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
873 eventRect
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
874 .on("mouseover", () => {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
875 diagram.select(".chart-dot").style("opacity", 1);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
876 diagram.select(".chart-tooltip").style("opacity", 1);
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
877 })
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
878 .on("mouseout", () => {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
879 diagram.select(".chart-dot").style("opacity", 0);
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
880 diagram.select(".chart-tooltip").style("opacity", 0);
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
881 })
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
882 .on("mousemove", () => {
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
883 // find data point closest to mouse
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
884 const x0 = scale.x.invert(
3212
f87fd173f750 client: waterlevel diagrams: fixed tooltip bug
Markus Kottlaender <markus@intevation.de>
parents: 3211
diff changeset
885 d3.mouse(document.getElementById("zoom-hydrocond"))[0]
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
886 ),
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
887 i = d3.bisector(d => d.date).left(this.longtermWaterlevels, x0, 1),
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
888 d0 = this.longtermWaterlevels[i - 1],
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
889 d1 = this.longtermWaterlevels[i] || d0,
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
890 d = x0 - d0.date > d1.date - x0 ? d1 : d0;
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
891
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
892 const coords = {
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
893 x: scale.x(d.date),
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
894 y: scale.y(d.median)
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
895 };
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
896
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
897 // position the dot
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
898 diagram
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
899 .select(".chart-dot")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
900 .style("opacity", 1)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
901 .attr("transform", `translate(${coords.x}, ${coords.y})`);
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
902
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
903 // remove current texts
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
904 tooltipText.selectAll("tspan").remove();
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
905
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
906 // write date
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
907 tooltipText
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
908 .append("tspan")
2842
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
909 .attr("dominant-baseline", "hanging")
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
910 .attr("text-anchor", "middle")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
911 .text(
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
912 d.date.toLocaleString([], {
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
913 year: "2-digit",
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
914 month: "2-digit",
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
915 day: "2-digit"
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
916 })
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
917 );
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
918
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
919 tooltipText
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
920 .append("tspan")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
921 .attr("x", 0)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
922 .attr("y", 0)
2842
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
923 .attr("dy", "1.4em")
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
924 .attr("dominant-baseline", "hanging")
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
925 .attr("text-anchor", "middle")
3576
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
926 .text(`Q75%: ${this.$options.filters.waterlevel(d.q75)} m`);
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
927 tooltipText
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
928 .append("tspan")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
929 .attr("x", 0)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
930 .attr("y", 0)
2842
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
931 .attr("dy", "2.6em")
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
932 .attr("dominant-baseline", "hanging")
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
933 .attr("text-anchor", "middle")
3576
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
934 .text(`Median: ${this.$options.filters.waterlevel(d.median)} m`);
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
935 tooltipText
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
936 .append("tspan")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
937 .attr("x", 0)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
938 .attr("y", 0)
2842
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
939 .attr("dy", "3.8em")
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
940 .attr("dominant-baseline", "hanging")
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
941 .attr("text-anchor", "middle")
3576
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
942 .text(`Q25%: ${this.$options.filters.waterlevel(d.q25)} m`);
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
943 tooltipText
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
944 .append("tspan")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
945 .attr("x", 0)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
946 .attr("y", 0)
2842
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
947 .attr("dy", "5em")
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
948 .attr("dominant-baseline", "hanging")
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
949 .attr("text-anchor", "middle")
3576
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
950 .text(`Max: ${this.$options.filters.waterlevel(d.max)} m`);
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
951 tooltipText
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
952 .append("tspan")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
953 .attr("x", 0)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
954 .attr("y", 0)
2842
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
955 .attr("dy", "6.2em")
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
956 .attr("dominant-baseline", "hanging")
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
957 .attr("text-anchor", "middle")
3576
1109a38f7ff1 client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents: 3544
diff changeset
958 .text(`Min: ${this.$options.filters.waterlevel(d.min)} m`);
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
959
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
960 const dYear = this.yearWaterlevels.find(
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
961 ywl => ywl.date.getTime() === d.date.getTime()
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
962 );
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
963 if (dYear) {
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
964 tooltipText
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
965 .append("tspan")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
966 .attr("x", 0)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
967 .attr("y", 0)
2842
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
968 .attr("dy", "7.4em")
37c2a73ed001 client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents: 2839
diff changeset
969 .attr("dominant-baseline", "hanging")
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
970 .attr("text-anchor", "middle")
2829
4a1211727d5f client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents: 2824
diff changeset
971 .text(`${this.yearCompare}: ${dYear.mean.toFixed(1)} cm`);
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
972 }
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
973
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
974 // get text dimensions
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
975 const textBBox = tooltipText.node().getBBox();
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
976
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
977 diagram
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
978 .selectAll(".chart-tooltip text tspan")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
979 .attr("x", textBBox.width / 2 + tooltipPadding)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
980 .attr("y", tooltipPadding);
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
981
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
982 // position and scale tooltip box
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
983 const xMax =
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
984 dimensions.width -
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
985 (textBBox.width + diagramPadding + tooltipPadding * 2);
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
986 const tooltipX = Math.max(
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
987 diagramPadding,
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
988 Math.min(coords.x - (textBBox.width + tooltipPadding * 2) / 2, xMax)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
989 );
2824
d7c4169516fa client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents: 2822
diff changeset
990 let tooltipY = coords.y - (textBBox.height + tooltipPadding * 2) - 10;
d7c4169516fa client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents: 2822
diff changeset
991 if (coords.y < textBBox.height + tooltipPadding * 2) {
d7c4169516fa client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents: 2822
diff changeset
992 tooltipY = coords.y + 10;
d7c4169516fa client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents: 2822
diff changeset
993 }
d7c4169516fa client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents: 2822
diff changeset
994
3869
7d86beedfb00 hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents: 3865
diff changeset
995 diagram
2822
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
996 .select(".chart-tooltip")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
997 .style("opacity", 1)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
998 .attr("transform", `translate(${tooltipX}, ${tooltipY})`)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
999 .select("rect")
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
1000 .attr("width", textBBox.width + tooltipPadding * 2)
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
1001 .attr("height", textBBox.height + tooltipPadding * 2);
f2e4c39cdcfa client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents: 2815
diff changeset
1002 });
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1003 }
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1004 },
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1005 created() {
3682
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3576
diff changeset
1006 this.resizeListenerFunction = debounce(this.drawDiagram, 100);
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3576
diff changeset
1007 window.addEventListener("resize", this.resizeListenerFunction);
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1008 },
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1009 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
1010 // 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
1011 // 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
1012 // 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
1013 // 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
1014 // 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
1015 // 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
1016 // 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
1017 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
1018
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1019 this.templates[0] = this.defaultTemplate;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1020 this.form.template = this.templates[0];
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1021 this.templateData = this.form.template;
3229
5e773e0c05be client: diagram-template: adjust the routes for waterlevels and hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3222
diff changeset
1022 HTTP.get("/templates/diagram", {
3197
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1023 headers: {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1024 "X-Gemma-Auth": localStorage.getItem("token"),
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1025 "Content-type": "text/xml; charset=UTF-8"
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1026 }
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1027 })
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1028 .then(response => {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1029 if (response.data.length) {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1030 this.templates = response.data;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1031 this.form.template = this.templates[0];
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1032 this.templates[this.templates.length] = this.defaultTemplate;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1033 this.applyChange();
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1034 }
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1035 })
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1036 .catch(e => {
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1037 const { status, data } = e.response;
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1038 displayError({
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1039 title: this.$gettext("Backend Error"),
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1040 message: `${status}: ${data.message || data}`
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1041 });
9d38df37c1f8 client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 3148
diff changeset
1042 });
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1043 },
2986
7ee9a3ef90d4 client: remove resize event listener from diagrams after they are closed
Markus Kottlaender <markus@intevation.de>
parents: 2843
diff changeset
1044 destroyed() {
3682
c086f5176ef2 client: diagrams: fixed removal of resize listener
Markus Kottlaender <markus@intevation.de>
parents: 3576
diff changeset
1045 window.removeEventListener("resize", this.resizeListenerFunction);
2761
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1046 }
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1047 };
71e7237110ba client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
1048 </script>