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