Mercurial > gemma
annotate client/src/components/gauge/HydrologicalConditions.vue @ 3963:feb53713bc2f diagram-cleanup
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Fri, 12 Jul 2019 15:14:16 +0200 |
parents | 7b3935a8d9ee |
children | afc7bca44df4 |
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"> |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3941
diff
changeset
|
3 <UIBoxHeader icon="ruler-vertical" :title="title" :closeCallback="close" /> |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
4 <div class="d-flex flex-fill"> |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3941
diff
changeset
|
5 <DiagramLegend> |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
6 <div class="legend"> |
3323
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
7 <span |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
8 style="background-color: red; width: 20px; height: 20px;" |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
9 ></span> |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
10 {{ yearCompare }} |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
11 </div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
12 <div class="legend"> |
3323
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
13 <span |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
14 style="background-color: orange; width: 20px; height: 20px;" |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
15 ></span> |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
16 Q25% |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
17 </div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
18 <div class="legend"> |
3323
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
19 <span |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
20 style="background-color: black; width: 20px; height: 20px;" |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
21 ></span> |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
22 Median |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
23 </div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
24 <div class="legend"> |
3323
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
25 <span |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
26 style="background-color: purple; width: 20px; height: 20px;" |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
27 ></span> |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
28 Q75% |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
29 </div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
30 <div class="legend"> |
3323
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
31 <span |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
32 style="background-color: lightsteelblue; width: 20px; height: 20px;" |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
33 ></span> |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
34 Long-term Amplitude |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
35 </div> |
3197
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
36 <select |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
37 @change="applyChange" |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
38 v-model="form.template" |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
39 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
|
40 > |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
41 <option |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
42 v-for="template in templates" |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
43 :value="template" |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
44 :key="template.name" |
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 {{ template.name }} |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
47 </option> |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
48 </select> |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
49 <div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
50 <button |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
51 @click="downloadPDF" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
52 type="button" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
53 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
|
54 :disabled="!longtermWaterlevels.length" |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
55 > |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
56 <translate>Export to PDF</translate> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
57 </button> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
58 </div> |
3403
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
59 <a |
3404
0c9467003d14
client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents:
3403
diff
changeset
|
60 :class="[ |
0c9467003d14
client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents:
3403
diff
changeset
|
61 '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
|
62 { disabled: !longtermWaterlevels.length } |
0c9467003d14
client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents:
3403
diff
changeset
|
63 ]" |
3403
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
64 :href="csvLink" |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
65 :download="csvFileName" |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
66 > |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
67 <translate>Export as CSV</translate> |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
68 </a> |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
69 </DiagramLegend> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
70 <div |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
71 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
|
72 :id="containerId" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
73 > |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
74 <div v-if="!longtermWaterlevels.length"> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
75 <translate>No data available.</translate> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
76 </div> |
2839
162804509c3e
client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents:
2829
diff
changeset
|
77 </div> |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
78 </div> |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
79 </div> |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
80 </template> |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
81 |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
82 <script> |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
83 /* 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
|
84 * without warranty, see README.md and license for details. |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
85 * |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
86 * SPDX-License-Identifier: AGPL-3.0-or-later |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
87 * License-Filename: LICENSES/AGPL-3.0.txt |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
88 * |
3112
e838609bc10d
client: fix license header for waterlevel.vue and hydrologicalconditions.vue
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3111
diff
changeset
|
89 * Copyright (C) 2019 by via donau |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
90 * – Österreichische Wasserstraßen-Gesellschaft mbH |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
91 * Software engineering by Intevation GmbH |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
92 * |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
93 * Author(s): |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
94 * 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
|
95 * Fadi Abbud <fadi.abbud@intevation.de> |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
96 */ |
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 import { mapState, mapGetters } from "vuex"; |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
99 import * as d3 from "d3"; |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
100 import { startOfYear, endOfYear } from "date-fns"; |
3937
de4c557bbc47
hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3927
diff
changeset
|
101 import { diagram, pdfgen, templateLoader } from "@/lib/mixins"; |
2761
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 export default { |
3937
de4c557bbc47
hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3927
diff
changeset
|
104 mixins: [diagram, pdfgen, templateLoader], |
2839
162804509c3e
client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents:
2829
diff
changeset
|
105 components: { |
162804509c3e
client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents:
2829
diff
changeset
|
106 DiagramLegend: () => import("@/components/DiagramLegend") |
162804509c3e
client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents:
2829
diff
changeset
|
107 }, |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
108 data() { |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
109 return { |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3941
diff
changeset
|
110 containerId: "hydrologicalconditions-diagram-container" |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
111 }; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
112 }, |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
113 computed: { |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
114 ...mapState("application", ["paneSetup"]), |
2829
4a1211727d5f
client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents:
2824
diff
changeset
|
115 ...mapState("gauges", [ |
4a1211727d5f
client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents:
2824
diff
changeset
|
116 "longtermWaterlevels", |
4a1211727d5f
client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents:
2824
diff
changeset
|
117 "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
|
118 "yearCompare", |
7a1a33fcec64
client: add infos and diagram legend for the generated pdf(hydrological diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
119 "longtermInterval" |
2829
4a1211727d5f
client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents:
2824
diff
changeset
|
120 ]), |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
121 ...mapGetters("gauges", ["selectedGauge"]), |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
122 title() { |
3148
cdfb0093b7b1
client: gauge diagrams: added information to titles
Markus Kottlaender <markus@intevation.de>
parents:
3147
diff
changeset
|
123 return `${this.selectedGauge.properties.objname}: ${this.$gettext( |
cdfb0093b7b1
client: gauge diagrams: added information to titles
Markus Kottlaender <markus@intevation.de>
parents:
3147
diff
changeset
|
124 "Hydrological Conditions" |
cdfb0093b7b1
client: gauge diagrams: added information to titles
Markus Kottlaender <markus@intevation.de>
parents:
3147
diff
changeset
|
125 )} (${this.longtermInterval.join(" - ")})`; |
3403
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
126 }, |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
127 csvLink() { |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
128 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
|
129 }, |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
130 csvFileName() { |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
131 return `${this.$gettext("hydrological-conditions")}-${ |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
132 this.selectedGauge.properties.objname |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
133 }-${this.longtermInterval.join(" - ")}.csv`; |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
134 }, |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
135 csvData() { |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
136 // 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
|
137 // 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
|
138 // 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
|
139 let merged = this.longtermWaterlevels |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
140 .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
|
141 .map(d => { |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
142 let yearData = this.yearWaterlevels.find(y => { |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
143 return d.date.getTime() === y.date.getTime(); |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
144 }); |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
145 d[this.yearCompare] = yearData ? yearData.mean : ""; |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
146 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
|
147 d.max |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
148 };${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
|
149 }) |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
150 .join("\n"); |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
151 return `#Interval: ${this.longtermInterval.join( |
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 )}\n#date;#min;#max;#mean;#median;#q25;#q75;#${ |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
154 this.yearCompare |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
155 }\n${merged}`; |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
156 } |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
157 }, |
3068
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
158 watch: { |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
159 paneSetup() { |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
160 this.$nextTick(() => this.drawDiagram()); |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
161 }, |
3068
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
162 longtermWaterlevels() { |
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
163 this.drawDiagram(); |
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
164 }, |
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
165 yearWaterlevels() { |
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
166 this.drawDiagram(); |
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
167 } |
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
168 }, |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
169 methods: { |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
170 close() { |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
171 this.$store.commit( |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
172 "application/paneSetup", |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
173 this.paneSetup === "GAUGE_WATERLEVEL_HYDROLOGICALCONDITIONS" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
174 ? "GAUGE_WATERLEVEL" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
175 : "DEFAULT" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
176 ); |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
177 }, |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
178 downloadPDF() { |
3798
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3789
diff
changeset
|
179 let diagramTitle = |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3789
diff
changeset
|
180 this.gaugeInfo(this.selectedGauge) + |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3789
diff
changeset
|
181 ": Hydrological Conditions " + |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3789
diff
changeset
|
182 this.longtermInterval.join(" - "); |
3544
067ad32fba69
client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3440
diff
changeset
|
183 |
3798
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3789
diff
changeset
|
184 this.generatePDF({ |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3789
diff
changeset
|
185 templateData: this.templateData, |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3789
diff
changeset
|
186 diagramTitle: diagramTitle |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3789
diff
changeset
|
187 }); |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3789
diff
changeset
|
188 |
3197
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
189 this.pdf.doc.save( |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
190 this.selectedGauge.properties.objname + |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
191 " Hydrological-condition Diagram.pdf" |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
192 ); |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
193 }, |
3129
136b86794453
client: improve pdf-gen code for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3112
diff
changeset
|
194 // Diagram legend |
3197
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
195 addDiagramLegend(position, offset, color) { |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
196 let x = offset.x, |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
197 y = offset.y; |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
198 let width = |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
199 (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
|
200 (72 / 25.6) + |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
201 5; |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
202 // 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
|
203 // the size of the element |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
204 if (["topright", "bottomright"].indexOf(position) !== -1) { |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
205 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
|
206 } |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
207 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
208 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
|
209 } |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
210 this.pdf.doc.setFontSize(10); |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
211 this.pdf.doc.setTextColor(color); |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
212 this.pdf.doc.setDrawColor("white"); |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
213 this.pdf.doc.setFillColor("red"); |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
214 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
|
215 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
|
216 this.pdf.doc.setFillColor("orange"); |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
217 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
|
218 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
|
219 this.pdf.doc.setFillColor("black"); |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
220 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
|
221 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
|
222 this.pdf.doc.setFillColor("purple"); |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
223 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
|
224 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
|
225 this.pdf.doc.setFillColor("lightsteelblue"); |
9d38df37c1f8
client: implemnt pdf-template for hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3148
diff
changeset
|
226 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
|
227 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
|
228 }, |
3941
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
229 getPrintLayout(svgHeight) { |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
230 return { |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
231 main: { top: 20, right: 50, bottom: 110, left: 80 }, |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
232 nav: { |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
233 top: svgHeight - 85, |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
234 right: 20, |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
235 bottom: 30, |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
236 left: 80 |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
237 } |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
238 }; |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
239 }, |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
240 drawDiagram() { |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
241 // remove old diagram |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3129
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 return; |
f7f09f32d6e0
hydrological conditions: omit rendering, when container isn't visible
Thomas Junk <thomas.junk@intevation.de>
parents:
3910
diff
changeset
|
246 const svgWidth = el.clientWidth; |
f7f09f32d6e0
hydrological conditions: omit rendering, when container isn't visible
Thomas Junk <thomas.junk@intevation.de>
parents:
3910
diff
changeset
|
247 const svgHeight = el.clientHeight; |
3941
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
248 const layout = this.getPrintLayout(svgHeight); |
3872
a7a75e003b78
hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents:
3869
diff
changeset
|
249 this.renderTo({ |
a7a75e003b78
hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents:
3869
diff
changeset
|
250 element: `#${this.containerId}`, |
a7a75e003b78
hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents:
3869
diff
changeset
|
251 dimensions: this.getDimensions({ |
3915
f7f09f32d6e0
hydrological conditions: omit rendering, when container isn't visible
Thomas Junk <thomas.junk@intevation.de>
parents:
3910
diff
changeset
|
252 svgWidth: svgWidth, |
3937
de4c557bbc47
hydrological_conditions: leverage mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3927
diff
changeset
|
253 svgHeight: svgHeight, |
3941
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3937
diff
changeset
|
254 ...layout |
3872
a7a75e003b78
hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents:
3869
diff
changeset
|
255 }) |
a7a75e003b78
hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents:
3869
diff
changeset
|
256 }); |
3857
6ce80daf8413
Hydrological conditions: render svg in offscreen element
Thomas Junk <thomas.junk@intevation.de>
parents:
3849
diff
changeset
|
257 }, |
3872
a7a75e003b78
hydrological conditions: factor out setting of dimensions
Thomas Junk <thomas.junk@intevation.de>
parents:
3869
diff
changeset
|
258 renderTo({ element, dimensions }) { |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
259 // PREPARE HELPERS |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
260 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
261 // HDC/LDC/MW for the selected gauge |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
262 const refWaterLevels = JSON.parse( |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
263 this.selectedGauge.properties.reference_water_levels |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
264 ); |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
265 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
266 // dimensions (widths, heights, margins) |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
267 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
268 // 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
|
269 const extent = this.getExtent(refWaterLevels); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
270 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
271 // scaling helpers |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
272 const scale = this.getScale({ dimensions, extent }); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
273 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
274 // 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
|
275 const axes = this.getAxes({ scale, dimensions }); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
276 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
277 // DRAW DIAGRAM/NAVIGATION AREAS |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
278 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
279 // create svg |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
280 const svg = d3 |
3857
6ce80daf8413
Hydrological conditions: render svg in offscreen element
Thomas Junk <thomas.junk@intevation.de>
parents:
3849
diff
changeset
|
281 .select(element) |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
282 .append("svg") |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
283 .attr("width", "100%") |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
284 .attr("height", "100%"); |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
285 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
286 // 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
|
287 const diagram = svg |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
288 .append("g") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
289 .attr("class", "main") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
290 .attr( |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
291 "transform", |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
292 `translate(${dimensions.mainMargin.left}, ${ |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
293 dimensions.mainMargin.top |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
294 })` |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
295 ); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
296 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
297 // 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
|
298 const navigation = svg |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
299 .append("g") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
300 .attr("class", "nav") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
301 .attr( |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
302 "transform", |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
303 `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
|
304 ); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
305 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
306 // 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
|
307 svg |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
308 .append("defs") |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
309 .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
|
310 .attr("id", "hydrocond-clip") |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
311 .append("rect") |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
312 .attr("width", dimensions.width) |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
313 .attr("height", dimensions.mainHeight); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
314 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
315 // DRAW DIAGRAM PARTS |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
316 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
317 // 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
|
318 // 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
|
319 // 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
|
320 const updaters = []; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
321 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
322 // draw |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
323 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
|
324 updaters.push( |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
325 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
|
326 ); |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
327 updaters.push( |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
328 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
|
329 ); |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
330 updaters.push( |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
331 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
|
332 ); |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
333 updaters.push( |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
334 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
|
335 ); |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
336 updaters.push( |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
337 this.drawWaterlevelLineChart({ |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
338 type: "mean", |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
339 data: this.yearWaterlevels, |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
340 scale, |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
341 diagram |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
342 }) |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
343 ); |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
344 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
|
345 |
3722
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
346 if (refWaterLevels) { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
347 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
|
348 } |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
349 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
350 // INTERACTIONS |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
351 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
352 // 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
|
353 const eventRect = svg |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
354 .append("rect") |
3212
f87fd173f750
client: waterlevel diagrams: fixed tooltip bug
Markus Kottlaender <markus@intevation.de>
parents:
3211
diff
changeset
|
355 .attr("id", "zoom-hydrocond") |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
356 .attr("class", "zoom") |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
357 .attr("width", dimensions.width) |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
358 .attr("height", dimensions.mainHeight) |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
359 .attr( |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
360 "transform", |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
361 `translate(${dimensions.mainMargin.left}, ${ |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
362 dimensions.mainMargin.top |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
363 })` |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
364 ); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
365 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
366 this.createZoom({ |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
367 updaters, |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
368 eventRect, |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
369 dimensions, |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
370 scale, |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
371 svg, |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
372 navigation |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
373 }); |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
374 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
|
375 this.setInlineStyles(svg); |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
376 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
377 setInlineStyles(svg) { |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
378 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
|
379 svg |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
380 .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
|
381 .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
|
382 .attr("stroke-width", 2) |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
383 .attr("fill", "none"); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
384 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
|
385 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
|
386 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
|
387 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
|
388 svg |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
389 .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
|
390 .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
|
391 .attr("stroke", "none") |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
392 .attr("fill", "lightsteelblue"); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
393 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
|
394 .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
|
395 .attr("stroke-width", 1) |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
396 .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
|
397 .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
|
398 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
|
399 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
|
400 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
|
401 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
|
402 svg |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
403 .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
|
404 .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
|
405 .attr("fill", "black"); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
406 svg |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
407 .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
|
408 .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
|
409 svg |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
410 .selectAll(".now-line") |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
411 .attr("stroke", "#999") |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
412 .attr("stroke-width", 1) |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
413 .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
|
414 .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
|
415 svg |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
416 .selectAll(".now-line-label") |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
417 .attr("fill", "#999") |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
418 .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
|
419 svg |
3902
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
420 .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
|
421 .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
|
422 .attr("stroke", "#ccc"); |
3902
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
427 svg |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
428 .selectAll(".zoom") |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
429 .attr("cursor", "move") |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
430 .attr("fill", "none") |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
431 .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
|
432 svg |
3111
f269bd001e78
client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
433 .selectAll(".brush .selection") |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
434 .attr("stroke", "none") |
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
435 .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
|
436 svg |
3111
f269bd001e78
client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
437 .selectAll(".brush .handle") |
3025
37cc0d75ad84
client:implemented pdf-gen for hydrological conditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
438 .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
|
439 .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
|
440 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
|
441 svg |
3111
f269bd001e78
client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
442 .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
|
443 .attr("fill", "black") |
f269bd001e78
client: remove css classes and adjust styles for hydrological-diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
444 .attr("stroke", "black") |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
445 .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
|
446 .style("pointer-events", "none") |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
447 .attr("fill-opacity", 0) |
3046
c764c73f44b4
client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3045
diff
changeset
|
448 .transition() |
c764c73f44b4
client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3045
diff
changeset
|
449 .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
|
450 svg |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
451 .selectAll(".chart-tooltip") |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
452 .attr("fill-opacity", 0) |
3046
c764c73f44b4
client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3045
diff
changeset
|
453 .transition() |
c764c73f44b4
client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3045
diff
changeset
|
454 .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
|
455 svg |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
456 .selectAll(".chart-tooltip rect") |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
457 .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
|
458 .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
|
459 // 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
|
460 // 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
|
461 .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
|
462 .attr("height", "0px"); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
463 svg |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
464 .selectAll(".chart-tooltip text") |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
465 .attr("fill", "666") |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
466 .style("font-size", "0.8em"); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
467 }, |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
468 getExtent(refWaterLevels) { |
3722
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
469 const waterlevelValues = []; |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
470 this.longtermWaterlevels.forEach(wl => { |
3722
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
471 waterlevelValues.push(wl.min, wl.max); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
472 }); |
3722
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
473 if (refWaterLevels) { |
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
474 waterlevelValues.push( |
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
475 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
|
476 Math.max( |
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
477 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
|
478 0 |
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
479 ) |
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
480 ); |
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
481 } else { |
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
482 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
|
483 waterlevelValues.push( |
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
484 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
|
485 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
|
486 ); |
f180de37903c
client: hydrological conditions diagram: handle gauges without reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
3691
diff
changeset
|
487 } |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
488 return { |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
489 // 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
|
490 date: [startOfYear(new Date()), endOfYear(new Date())], |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
491 // 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
|
492 // 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
|
493 waterlevel: d3.extent(waterlevelValues) |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
494 }; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
495 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
496 getScale({ dimensions, extent }) { |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
497 // 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
|
498 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
|
499 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
|
500 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
|
501 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
|
502 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
503 // 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
|
504 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
|
505 y.domain(extent.waterlevel); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
506 x2.domain(x.domain()); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
507 y2.domain(y.domain()); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
508 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
509 return { x, y, x2, y2 }; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
510 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
511 getAxes({ scale, dimensions }) { |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
512 return { |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
513 x: d3 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
514 .axisTop(scale.x) |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
515 .tickSizeInner(dimensions.mainHeight) |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
516 .tickSizeOuter(0) |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
517 .tickFormat(date => { |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
518 // 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
|
519 // 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
|
520 // this diagram |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
521 return (d3.timeSecond(date) < date |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
522 ? d3.timeFormat(".%L") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
523 : d3.timeMinute(date) < date |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
524 ? d3.timeFormat(":%S") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
525 : d3.timeHour(date) < date |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
526 ? d3.timeFormat("%I:%M") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
527 : d3.timeDay(date) < date |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
528 ? d3.timeFormat("%I %p") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
529 : d3.timeMonth(date) < date |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
530 ? d3.timeWeek(date) < date |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
531 ? d3.timeFormat("%a %d") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
532 : d3.timeFormat("%b %d") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
533 : d3.timeFormat("%B"))(date); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
534 }), |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
535 y: d3 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
536 .axisRight(scale.y) |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
537 .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
|
538 .tickSizeOuter(0) |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3544
diff
changeset
|
539 .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
|
540 yRight: d3 |
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
541 .axisRight(scale.y) |
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
542 .tickSizeInner(3) |
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
543 .tickSizeOuter(0) |
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
544 .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
|
545 x2: d3.axisBottom(scale.x2) |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
546 }; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
547 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
548 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
|
549 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
|
550 const nowCoords = [ |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
551 { 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
|
552 { 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
|
553 ]; |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
554 const nowLine = d3 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
555 .line() |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
556 .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
|
557 .y(d => scale.y(d.y)); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
558 const nowLabel = selection => { |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
559 selection.attr( |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
560 "transform", |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
561 `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
|
562 ); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
563 }; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
564 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
565 // draw in main |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
566 diagram |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
567 .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
|
568 .datum(nowCoords) |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
569 .attr("class", "now-line") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
570 .attr("d", nowLine); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
571 diagram // label |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
572 .append("text") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
573 .text(this.$gettext("Now")) |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
574 .attr("class", "now-line-label") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
575 .attr("text-anchor", "middle") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
576 .call(nowLabel); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
577 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
578 // draw in nav |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
579 navigation |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
580 .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
|
581 .datum(nowCoords) |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
582 .attr("class", "now-line") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
583 .attr( |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
584 "d", |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
585 d3 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
586 .line() |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
587 .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
|
588 .y(d => scale.y2(d.y)) |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
589 ); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
590 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
591 return () => { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
592 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
|
593 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
|
594 }; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
595 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
596 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
|
597 diagram |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
598 .append("g") |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
599 .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
|
600 .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
|
601 .call(axes.x) |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
602 .selectAll(".tick text") |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
603 .attr("y", 15); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
604 diagram // label |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
605 .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
|
606 .text(this.$gettext("Waterlevel [m]")) |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
607 .attr("text-anchor", "middle") |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
608 .attr( |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
609 "transform", |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
610 `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
|
611 ); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
612 diagram |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
613 .append("g") |
3902
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
614 .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
|
615 .call(axes.y) |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
616 .selectAll(".tick text") |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
617 .attr("x", -25); |
3902
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
618 diagram |
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
619 .append("g") |
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
620 .attr("class", "axis--y-right") |
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
621 .attr("transform", `translate(${dimensions.width})`) |
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
622 .call(axes.yRight) |
0149b68a4f7e
client: hydrological conditions diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
623 .selectAll(".tick text"); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
624 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
625 navigation |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
626 .append("g") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
627 .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
|
628 .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
|
629 .call(axes.x2); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
630 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
631 return () => { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
632 diagram |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
633 .select(".axis--x") |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
634 .call(axes.x) |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
635 .selectAll(".tick text") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
636 .attr("y", 15); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
637 }; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
638 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
639 drawWaterlevelMinMaxAreaChart({ scale, diagram, navigation }) { |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
640 const areaChart = isNav => |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
641 d3 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
642 .area() |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
643 .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
|
644 .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
|
645 .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
|
646 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
647 diagram |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
648 .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
|
649 .datum(this.longtermWaterlevels) |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
650 .attr("class", "area") |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
651 .attr("d", areaChart()); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
652 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
653 navigation |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
654 .append("path") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
655 .datum(this.longtermWaterlevels) |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
656 .attr("class", "area") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
657 .attr("d", areaChart(true)); |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
658 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
659 return () => { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
660 diagram.select(".area").attr("d", areaChart()); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
661 }; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
662 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
663 drawWaterlevelLineChart({ type, data, scale, diagram }) { |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
664 const lineChart = type => |
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.x(d.date)) |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
668 .y(d => scale.y(d[type])) |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
669 .curve(d3.curveLinear); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
670 diagram |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
671 .append("path") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
672 .attr("class", "line " + type) |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
673 .datum(data || this.longtermWaterlevels) |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
674 .attr("d", lineChart(type)); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
675 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
676 return () => { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
677 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
|
678 }; |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
679 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
680 drawRefLines({ refWaterLevels, scale, diagram, extent }) { |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
681 const refWaterlevelLine = d3 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
682 .line() |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
683 .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
|
684 .y(d => scale.y(d.y)); |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
685 |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
686 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
|
687 if (refWaterLevels[ref]) { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
688 diagram |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
689 .append("path") |
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
690 .datum([ |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
691 { 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
|
692 { 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
|
693 ]) |
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
694 .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
|
695 .attr("d", refWaterlevelLine); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
696 diagram // label |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
697 .append("rect") |
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
698 .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
|
699 .attr("x", 1) |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
700 .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
|
701 .attr("width", 55) |
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
702 .attr("height", 12); |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
703 diagram |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
704 .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
|
705 .text( |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3544
diff
changeset
|
706 `${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
|
707 refWaterLevels[ref] |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3544
diff
changeset
|
708 )})` |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3544
diff
changeset
|
709 ) |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
710 .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
|
711 .attr("x", 5) |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
712 .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
|
713 } |
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
|
714 } |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
715 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
716 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
|
717 const brush = d3 |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
718 .brushX() |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
719 .handleSize(4) |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
720 .extent([[0, 0], [dimensions.width, dimensions.navHeight]]); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
721 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
722 const zoom = d3 |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
723 .zoom() |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
724 .scaleExtent([1, Infinity]) |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
725 .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
|
726 .extent([[0, 0], [dimensions.width, dimensions.mainHeight]]); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
727 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
728 brush.on("brush end", () => { |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
729 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
|
730 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
|
731 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
|
732 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
|
733 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
|
734 this.setInlineStyles(svg); |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
735 svg |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
736 .select(".zoom") |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
737 .call( |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
738 zoom.transform, |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
739 d3.zoomIdentity |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
740 .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
|
741 .translate(-s[0], 0) |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
742 ); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
743 }); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
744 |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
745 zoom.on("zoom", () => { |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
746 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
|
747 return; // ignore zoom-by-brush |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
748 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
|
749 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
|
750 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
|
751 this.setInlineStyles(svg); |
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
752 navigation |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
753 .select(".brush") |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
754 .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
|
755 }); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
756 zoom.on("start", () => { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
757 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
|
758 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
|
759 }); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
760 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
761 navigation |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
762 .append("g") |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
763 .attr("class", "brush") |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
764 .call(brush) |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
765 .call(brush.move, scale.x.range()); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
766 |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
767 eventRect.call(zoom); |
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
768 }, |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
769 createTooltips({ eventRect, diagram, scale, dimensions }) { |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
770 // 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
|
771 diagram |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
772 .append("g") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
773 .attr("class", "chart-dots") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
774 .append("circle") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
775 .attr("class", "chart-dot") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
776 .attr("r", 4); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
777 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
778 // 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
|
779 const tooltip = diagram.append("g").attr("class", "chart-tooltip"); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
780 tooltip |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
781 .append("rect") |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
782 .attr("rx", "0.25em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
783 .attr("ry", "0.25em"); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
784 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
785 // create container for multiple text rows |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
786 const tooltipText = tooltip.append("text").attr("text-anchor", "middle"); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
787 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
788 // 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
|
789 // 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
|
790 const tooltipPadding = 10; |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
791 const diagramPadding = 5; |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
792 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
793 eventRect |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
794 .on("mouseover", () => { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
795 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
|
796 diagram.select(".chart-tooltip").style("opacity", 1); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
797 }) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
798 .on("mouseout", () => { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
799 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
|
800 diagram.select(".chart-tooltip").style("opacity", 0); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
801 }) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
802 .on("mousemove", () => { |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
803 // 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
|
804 const x0 = scale.x.invert( |
3212
f87fd173f750
client: waterlevel diagrams: fixed tooltip bug
Markus Kottlaender <markus@intevation.de>
parents:
3211
diff
changeset
|
805 d3.mouse(document.getElementById("zoom-hydrocond"))[0] |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
806 ), |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
807 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
|
808 d0 = this.longtermWaterlevels[i - 1], |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
809 d1 = this.longtermWaterlevels[i] || d0, |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
810 d = x0 - d0.date > d1.date - x0 ? d1 : d0; |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
811 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
812 const coords = { |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
813 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
|
814 y: scale.y(d.median) |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
815 }; |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
816 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
817 // position the dot |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
818 diagram |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
819 .select(".chart-dot") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
820 .style("opacity", 1) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
821 .attr("transform", `translate(${coords.x}, ${coords.y})`); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
822 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
823 // remove current texts |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
824 tooltipText.selectAll("tspan").remove(); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
825 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
826 // write date |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
827 tooltipText |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
828 .append("tspan") |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
829 .attr("dominant-baseline", "hanging") |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
830 .attr("text-anchor", "middle") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
831 .text( |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
832 d.date.toLocaleString([], { |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
833 year: "2-digit", |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
834 month: "2-digit", |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
835 day: "2-digit" |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
836 }) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
837 ); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
838 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
839 tooltipText |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
840 .append("tspan") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
841 .attr("x", 0) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
842 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
843 .attr("dy", "1.4em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
844 .attr("dominant-baseline", "hanging") |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
845 .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
|
846 .text(`Q75%: ${this.$options.filters.waterlevel(d.q75)} m`); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
847 tooltipText |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
848 .append("tspan") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
849 .attr("x", 0) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
850 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
851 .attr("dy", "2.6em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
852 .attr("dominant-baseline", "hanging") |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
853 .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
|
854 .text(`Median: ${this.$options.filters.waterlevel(d.median)} m`); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
855 tooltipText |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
856 .append("tspan") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
857 .attr("x", 0) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
858 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
859 .attr("dy", "3.8em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
860 .attr("dominant-baseline", "hanging") |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
861 .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
|
862 .text(`Q25%: ${this.$options.filters.waterlevel(d.q25)} m`); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
863 tooltipText |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
864 .append("tspan") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
865 .attr("x", 0) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
866 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
867 .attr("dy", "5em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
868 .attr("dominant-baseline", "hanging") |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
869 .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
|
870 .text(`Max: ${this.$options.filters.waterlevel(d.max)} m`); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
871 tooltipText |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
872 .append("tspan") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
873 .attr("x", 0) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
874 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
875 .attr("dy", "6.2em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
876 .attr("dominant-baseline", "hanging") |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
877 .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
|
878 .text(`Min: ${this.$options.filters.waterlevel(d.min)} m`); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
879 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
880 const dYear = this.yearWaterlevels.find( |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
881 ywl => ywl.date.getTime() === d.date.getTime() |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
882 ); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
883 if (dYear) { |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
884 tooltipText |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
885 .append("tspan") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
886 .attr("x", 0) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
887 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
888 .attr("dy", "7.4em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
889 .attr("dominant-baseline", "hanging") |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
890 .attr("text-anchor", "middle") |
2829
4a1211727d5f
client: spuc8: implemented year controls
Markus Kottlaender <markus@intevation.de>
parents:
2824
diff
changeset
|
891 .text(`${this.yearCompare}: ${dYear.mean.toFixed(1)} cm`); |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
892 } |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
893 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
894 // get text dimensions |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
895 const textBBox = tooltipText.node().getBBox(); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
896 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
897 diagram |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
898 .selectAll(".chart-tooltip text tspan") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
899 .attr("x", textBBox.width / 2 + tooltipPadding) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
900 .attr("y", tooltipPadding); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
901 |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
902 // position and scale tooltip box |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
903 const xMax = |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
904 dimensions.width - |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
905 (textBBox.width + diagramPadding + tooltipPadding * 2); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
906 const tooltipX = Math.max( |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
907 diagramPadding, |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
908 Math.min(coords.x - (textBBox.width + tooltipPadding * 2) / 2, xMax) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
909 ); |
2824
d7c4169516fa
client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents:
2822
diff
changeset
|
910 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
|
911 if (coords.y < textBBox.height + tooltipPadding * 2) { |
d7c4169516fa
client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents:
2822
diff
changeset
|
912 tooltipY = coords.y + 10; |
d7c4169516fa
client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents:
2822
diff
changeset
|
913 } |
d7c4169516fa
client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents:
2822
diff
changeset
|
914 |
3869
7d86beedfb00
hydrological conditions: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3865
diff
changeset
|
915 diagram |
2822
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
916 .select(".chart-tooltip") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
917 .style("opacity", 1) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
918 .attr("transform", `translate(${tooltipX}, ${tooltipY})`) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
919 .select("rect") |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
920 .attr("width", textBBox.width + tooltipPadding * 2) |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
921 .attr("height", textBBox.height + tooltipPadding * 2); |
f2e4c39cdcfa
client: spuc8: implemented tooltips
Markus Kottlaender <markus@intevation.de>
parents:
2815
diff
changeset
|
922 }); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
923 } |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
924 } |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
925 }; |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
926 </script> |