Mercurial > gemma
annotate client/src/components/gauge/Waterlevel.vue @ 3924:2efda3391fa8
client: waterlevel diagram: fixed handing of resize listener
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Thu, 11 Jul 2019 16:18:58 +0200 |
parents | 29b294e77a5c |
children | 4f93bfb5725d |
rev | line source |
---|---|
2590
1686ec185155
client: added gauge waterlevel example 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:
3143
diff
changeset
|
2 <div class="d-flex flex-column flex-fill"> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
3 <UIBoxHeader |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
4 icon="ruler-vertical" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
5 :title="title" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
6 :closeCallback="close" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
7 class="rounded-0" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
8 /> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
9 <div class="d-flex flex-fill"> |
3440
8801811bf9f5
client: diagram-template: fix the size of renderd Diagram in case two diagrams are shown on the screen
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3408
diff
changeset
|
10 <DiagramLegend id="diagramlegendId"> |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
11 <div class="legend"> |
3323
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3304
diff
changeset
|
12 <span |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3304
diff
changeset
|
13 style="background-color: steelblue; width: 20px; height: 20px;" |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3304
diff
changeset
|
14 ></span> |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3304
diff
changeset
|
15 Waterlevel |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
16 </div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
17 <div class="legend"> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
18 <span |
3323
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3304
diff
changeset
|
19 style="width: 8px; height: 8px; background-color: rgba(70, 130, 180, 0.6); border: solid 7px rgba(70, 130, 180, 0.2); background-clip: padding-box; box-sizing: content-box;" |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
20 ></span> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
21 Prediction |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
22 </div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
23 <div class="legend"> |
3323
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3304
diff
changeset
|
24 <span |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3304
diff
changeset
|
25 style="background-color: rgba(0, 255, 0, 0.1); width: 20px; height: 20px;" |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3304
diff
changeset
|
26 ></span> |
de0d0685a17b
client: improve diagram-legends style
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3304
diff
changeset
|
27 Navigable Range |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
28 </div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
29 <div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
30 <select |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
31 @change="applyChange" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
32 v-model="form.template" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
33 class="form-control d-block custom-select-sm w-100" |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
34 > |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
35 <option |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
36 v-for="template in templates" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
37 :value="template" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
38 :key="template.name" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
39 > |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
40 {{ template.name }} |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
41 </option> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
42 </select> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
43 <button |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
44 @click="downloadPDF" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
45 type="button" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
46 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
|
47 :disabled="!waterlevels.length" |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
48 > |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
49 <translate>Export to PDF</translate> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
50 </button> |
3403
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
51 <a |
3404
0c9467003d14
client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents:
3403
diff
changeset
|
52 :class="[ |
0c9467003d14
client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents:
3403
diff
changeset
|
53 '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
|
54 { disabled: !waterlevels.length } |
0c9467003d14
client: waterlevel diagrams: disabled export buttons when no data is available
Markus Kottlaender <markus@intevation.de>
parents:
3403
diff
changeset
|
55 ]" |
3403
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
56 :href="csvLink" |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
57 :download="csvFileName" |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
58 > |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
59 <translate>Export as CSV</translate> |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
60 </a> |
3565
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
61 |
3793
d428f283fe10
client: remove `export SVG` button for waterlevel
Bernhard Reiter <bernhard@intevation.de>
parents:
3787
diff
changeset
|
62 <!-- |
3565
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
63 <button |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
64 @click="downloadSVG" |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
65 type="button" |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
66 class="btn btn-sm btn-info d-block w-100 mt-2" |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
67 :disabled="!waterlevels.length" |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
68 > |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
69 <translate>Export as SVG</translate> |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
70 </button> |
3793
d428f283fe10
client: remove `export SVG` button for waterlevel
Bernhard Reiter <bernhard@intevation.de>
parents:
3787
diff
changeset
|
71 --> |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
72 </div> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
73 </DiagramLegend> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
74 <div |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
75 class="d-flex flex-fill justify-content-center align-items-center" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
76 :id="containerId" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
77 > |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
78 <div v-if="!waterlevels.length"> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
79 <translate>No data available.</translate> |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
80 </div> |
2839
162804509c3e
client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents:
2824
diff
changeset
|
81 </div> |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2695
diff
changeset
|
82 </div> |
3179
6ddd3755350c
client: fix the rendering of diagram on pdf by splitscreen case (waterlevels)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3160
diff
changeset
|
83 <div |
6ddd3755350c
client: fix the rendering of diagram on pdf by splitscreen case (waterlevels)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3160
diff
changeset
|
84 id="pdfContainer" |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
85 style="position: absolute; z-index: -1; top: -9999px; width: 387mm; height: 100mm;" |
3179
6ddd3755350c
client: fix the rendering of diagram on pdf by splitscreen case (waterlevels)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3160
diff
changeset
|
86 ></div> |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2695
diff
changeset
|
87 </div> |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
88 </template> |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
89 |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
90 <script> |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
91 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
92 * without warranty, see README.md and license for details. |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
93 * |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
94 * SPDX-License-Identifier: AGPL-3.0-or-later |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
95 * License-Filename: LICENSES/AGPL-3.0.txt |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
96 * |
3112
e838609bc10d
client: fix license header for waterlevel.vue and hydrologicalconditions.vue
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3110
diff
changeset
|
97 * Copyright (C) 2019 by via donau |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
98 * – Österreichische Wasserstraßen-Gesellschaft mbH |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
99 * Software engineering by Intevation GmbH |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
100 * |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
101 * Author(s): |
3564
f50bde7eed0d
client: improve copyright header for gauge/Waterlevel.vue
Bernhard Reiter <bernhard@intevation.de>
parents:
3563
diff
changeset
|
102 * * Bernhard Reiter <bernhard@intevation.de> |
f50bde7eed0d
client: improve copyright header for gauge/Waterlevel.vue
Bernhard Reiter <bernhard@intevation.de>
parents:
3563
diff
changeset
|
103 * * Markus Kottländer <markus.kottlaender@intevation.de> |
f50bde7eed0d
client: improve copyright header for gauge/Waterlevel.vue
Bernhard Reiter <bernhard@intevation.de>
parents:
3563
diff
changeset
|
104 * * Fadi Abbud <fadi.abbud@intevation.de> |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
105 */ |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
106 |
2604
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
107 import { mapState, mapGetters } from "vuex"; |
2684
c4da269238a4
client: waterlevel diagram: visualize data gaps
Markus Kottlaender <markus@intevation.de>
parents:
2653
diff
changeset
|
108 import * as d3Base from "d3"; |
c4da269238a4
client: waterlevel diagram: visualize data gaps
Markus Kottlaender <markus@intevation.de>
parents:
2653
diff
changeset
|
109 import { lineChunked } from "d3-line-chunked"; |
3050
c739b81b8f41
client: gauge waterlevel diagram: fixed date extent
Markus Kottlaender <markus@intevation.de>
parents:
3049
diff
changeset
|
110 import { endOfDay } from "date-fns"; |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
111 import debounce from "debounce"; |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
112 import svg2pdf from "svg2pdf.js"; |
3565
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
113 import { saveAs } from "file-saver"; |
3804
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
114 import { pdfgen, templateLoader } from "@/lib/mixins"; |
3140
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
115 import { HTTP } from "@/lib/http"; |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
116 import { displayError } from "@/lib/errors"; |
2684
c4da269238a4
client: waterlevel diagram: visualize data gaps
Markus Kottlaender <markus@intevation.de>
parents:
2653
diff
changeset
|
117 // we should load only d3 modules we need but for now we'll go with the lazy way |
c4da269238a4
client: waterlevel diagram: visualize data gaps
Markus Kottlaender <markus@intevation.de>
parents:
2653
diff
changeset
|
118 // https://www.giacomodebidda.com/how-to-import-d3-plugins-with-webpack/ |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
119 // d3-line-chunked plugin: https://github.com/pbeshai/d3-line-chunked |
2684
c4da269238a4
client: waterlevel diagram: visualize data gaps
Markus Kottlaender <markus@intevation.de>
parents:
2653
diff
changeset
|
120 const d3 = Object.assign(d3Base, { lineChunked }); |
c4da269238a4
client: waterlevel diagram: visualize data gaps
Markus Kottlaender <markus@intevation.de>
parents:
2653
diff
changeset
|
121 |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
122 export default { |
3804
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
123 mixins: [pdfgen, templateLoader], |
2839
162804509c3e
client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents:
2824
diff
changeset
|
124 components: { |
162804509c3e
client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents:
2824
diff
changeset
|
125 DiagramLegend: () => import("@/components/DiagramLegend") |
162804509c3e
client: spuc7/8: added legends
Markus Kottlaender <markus@intevation.de>
parents:
2824
diff
changeset
|
126 }, |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
127 data() { |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
128 return { |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
129 containerId: "waterlevel-diagram-container", |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
130 form: { |
3249
d91c1200dc6b
client: diagram-template: cleanup code
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3248
diff
changeset
|
131 template: null |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
132 }, |
3143
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
133 templates: [], |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
134 defaultTemplate: { |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
135 name: "Default", |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
136 properties: { |
3350
8da2f7b9a04b
client: diagram-template:remove unnecessary template properties and typo
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3348
diff
changeset
|
137 paperSize: "a4" |
3143
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
138 }, |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
139 elements: [ |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
140 { |
3160
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
141 type: "diagram", |
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
142 position: "topleft", |
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
143 offset: { x: 15, y: 50 }, |
3910
29b294e77a5c
client: pdf-gen: set diagram scale on pdf and adjust default template value(waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3901
diff
changeset
|
144 width: 240, |
3160
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
145 height: 100 |
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
146 }, |
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
147 { |
3143
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
148 type: "diagramlegend", |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
149 position: "topleft", |
3910
29b294e77a5c
client: pdf-gen: set diagram scale on pdf and adjust default template value(waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3901
diff
changeset
|
150 offset: { x: 42, y: 172 }, |
3143
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
151 color: "black" |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
152 }, |
3143
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
153 { |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
154 type: "diagramtitle", |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
155 position: "topleft", |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
156 offset: { x: 50, y: 26 }, |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
157 fontsize: 22, |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
158 color: "steelblue" |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
159 }, |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
160 { |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
161 type: "text", |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
162 position: "topleft", |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
163 offset: { x: 3, y: 3 }, |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
164 fontsize: 8, |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
165 width: 90, |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
166 color: "gray", |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
167 text: this.$gettext("Generated by") + " " + "{user}, {date}" |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
168 } |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
169 ] |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
170 }, |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
171 pdf: { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
172 doc: null, |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
173 width: 420, |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
174 height: 297 |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
175 }, |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
176 templateData: null |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
177 }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
178 }, |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
179 computed: { |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
180 ...mapState("application", ["paneSetup"]), |
3403
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
181 ...mapState("gauges", [ |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
182 "dateFrom", |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
183 "waterlevels", |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
184 "waterlevelsCSV", |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
185 "nashSutcliffe" |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
186 ]), |
3049
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
187 ...mapGetters("gauges", ["selectedGauge"]), |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
188 title() { |
3148
cdfb0093b7b1
client: gauge diagrams: added information to titles
Markus Kottlaender <markus@intevation.de>
parents:
3147
diff
changeset
|
189 return `${this.selectedGauge.properties.objname}: ${this.$gettext( |
cdfb0093b7b1
client: gauge diagrams: added information to titles
Markus Kottlaender <markus@intevation.de>
parents:
3147
diff
changeset
|
190 "Waterlevel" |
cdfb0093b7b1
client: gauge diagrams: added information to titles
Markus Kottlaender <markus@intevation.de>
parents:
3147
diff
changeset
|
191 )} (${this.dateFrom.toLocaleDateString()} - ${this.dateTo.toLocaleDateString()})`; |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
192 }, |
3049
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
193 dateFrom: { |
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
194 get() { |
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
195 return this.$store.state.gauges.dateFrom; |
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
196 } |
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
197 }, |
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
198 dateTo: { |
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
199 get() { |
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
200 return this.$store.state.gauges.dateTo; |
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
201 } |
3403
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
202 }, |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
203 csvLink() { |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
204 return ( |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
205 "data:text/csv;charset=utf-8," + encodeURIComponent(this.waterlevelsCSV) |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
206 ); |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
207 }, |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
208 csvFileName() { |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
209 return `${this.$gettext("waterlevels")}-${ |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
210 this.selectedGauge.properties.objname |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
211 }-${this.dateFrom.toISOString().split("T")[0]}-${ |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
212 this.dateTo.toISOString().split("T")[0] |
d7cc5cda82a9
client: waterlevel diagrams: implemented csv export
Markus Kottlaender <markus@intevation.de>
parents:
3350
diff
changeset
|
213 }.csv`; |
3618
c03170a1c333
client: waterlevel: check if there is prediction data before drawing the predictionarea
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3576
diff
changeset
|
214 }, |
c03170a1c333
client: waterlevel: check if there is prediction data before drawing the predictionarea
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3576
diff
changeset
|
215 hasPredictions() { |
c03170a1c333
client: waterlevel: check if there is prediction data before drawing the predictionarea
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3576
diff
changeset
|
216 return this.waterlevels.find(d => d.predicted); |
3049
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
217 } |
2596
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
218 }, |
3068
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
219 watch: { |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
220 paneSetup() { |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
221 this.$nextTick(() => this.drawDiagram()); |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
222 }, |
3068
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
223 waterlevels() { |
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
224 this.drawDiagram(); |
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
225 } |
492c30ca3142
client: diagrams: added watchers to ensure diagram update when data changes
Markus Kottlaender <markus@intevation.de>
parents:
3067
diff
changeset
|
226 }, |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
227 methods: { |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
228 close() { |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
229 this.$store.commit( |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
230 "application/paneSetup", |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
231 this.paneSetup === "GAUGE_WATERLEVEL_HYDROLOGICALCONDITIONS" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
232 ? "GAUGE_HYDROLOGICALCONDITIONS" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
233 : "DEFAULT" |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
234 ); |
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
235 }, |
3565
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
236 downloadSVG() { |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
237 let svg = document.getElementById(this.containerId).firstElementChild; |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
238 let svgXML = new XMLSerializer().serializeToString(svg); |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
239 let blog = new Blob([svgXML], { type: "image/svg+xml;charset=utf-8" }); |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
240 let filename = |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
241 this.selectedGauge.properties.objname + "-waterlevel-diagram.svg"; |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
242 saveAs(blog, filename); |
f6d67697f158
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3564
diff
changeset
|
243 }, |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
244 downloadPDF() { |
3798
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
245 let diagramTitle = |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
246 this.gaugeInfo(this.selectedGauge) + |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
247 ": Waterlevel " + |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3794
diff
changeset
|
248 this.dateFrom.toLocaleDateString() + |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3794
diff
changeset
|
249 " - " + |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3794
diff
changeset
|
250 this.dateTo.toLocaleDateString(); |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3794
diff
changeset
|
251 |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3794
diff
changeset
|
252 this.generatePDF({ |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3794
diff
changeset
|
253 templateData: this.templateData, |
3798
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
254 diagramTitle: diagramTitle |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3794
diff
changeset
|
255 }); |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3794
diff
changeset
|
256 |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
257 this.pdf.doc.save( |
3049
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
258 this.selectedGauge.properties.objname + " Waterlevel-Diagram.pdf" |
7e6ecb6d0796
client: add headline info for the waterlevel generated diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3046
diff
changeset
|
259 ); |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
260 }, |
3140
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
261 applyChange() { |
3143
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
262 if (this.form.template.hasOwnProperty("properties")) { |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
263 this.templateData = this.defaultTemplate; |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
264 return; |
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
265 } |
3140
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
266 if (this.form.template) { |
3804
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
267 this.loadTemplates("/templates/diagram/" + this.form.template.name) |
3140
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
268 .then(response => { |
3804
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
269 this.prepareImages(response.data.template_data.elements).then( |
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
270 values => { |
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
271 values.forEach(v => { |
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
272 response.data.template_data.elements[v.index].url = v.url; |
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
273 }); |
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
274 this.templateData = response.data.template_data; |
7f2c5576ec0a
waterlevel_diagram: use mixin for template loading and image processing
Thomas Junk <thomas.junk@intevation.de>
parents:
3798
diff
changeset
|
275 } |
3787
f86220aa8a72
Waterlevel: prefetch images of template and convert to dataURI
Thomas Junk <thomas.junk@intevation.de>
parents:
3782
diff
changeset
|
276 ); |
3140
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
277 }) |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
278 .catch(e => { |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
279 const { status, data } = e.response; |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
280 displayError({ |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
281 title: this.$gettext("Backend Error"), |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
282 message: `${status}: ${data.message || data}` |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
283 }); |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
284 }); |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
285 } |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
286 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
287 addDiagram(position, offset, width, height) { |
3160
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
288 let x = offset.x, |
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
289 y = offset.y; |
3888
ccd77fe5072c
client: waterlevels: diagram size dynamic, taken from tamplate
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3885
diff
changeset
|
290 const svgWidth = this.millimeter2pixels( |
ccd77fe5072c
client: waterlevels: diagram size dynamic, taken from tamplate
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3885
diff
changeset
|
291 width, |
ccd77fe5072c
client: waterlevels: diagram size dynamic, taken from tamplate
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3885
diff
changeset
|
292 this.templateData.properties.resolution || 80 |
ccd77fe5072c
client: waterlevels: diagram size dynamic, taken from tamplate
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3885
diff
changeset
|
293 ); |
ccd77fe5072c
client: waterlevels: diagram size dynamic, taken from tamplate
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3885
diff
changeset
|
294 const svgHeight = this.millimeter2pixels( |
ccd77fe5072c
client: waterlevels: diagram size dynamic, taken from tamplate
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3885
diff
changeset
|
295 height, |
ccd77fe5072c
client: waterlevels: diagram size dynamic, taken from tamplate
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3885
diff
changeset
|
296 this.templateData.properties.resolution || 80 |
ccd77fe5072c
client: waterlevels: diagram size dynamic, taken from tamplate
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3885
diff
changeset
|
297 ); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
298 // draw the diagram in a separated html element to get the full size |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
299 const offScreen = document.querySelector("#offScreen"); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
300 offScreen.style.width = `${svgWidth}px`; |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
301 offScreen.style.height = `${svgHeight}px`; |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
302 this.renderTo({ |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
303 element: offScreen, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
304 dimensions: this.getDimensions({ |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
305 svgWidth: svgWidth, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
306 svgHeight: svgHeight |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
307 }) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
308 }); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
309 var svg = offScreen.querySelector("svg"); |
3160
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
310 if (["topright", "bottomright"].indexOf(position) !== -1) { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
311 x = this.pdf.width - offset.x - width; |
3160
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
312 } |
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
313 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
314 y = this.pdf.height - offset.y - height; |
3160
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
315 } |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
316 svg2pdf(svg, this.pdf.doc, { |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
317 xOffset: x, |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
318 yOffset: y, |
3910
29b294e77a5c
client: pdf-gen: set diagram scale on pdf and adjust default template value(waterlevels, hydrologicalconditions)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3901
diff
changeset
|
319 scale: 0.353 |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
320 }); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
321 offScreen.removeChild(svg); |
3160
94935895e6d7
client: add diagram-element to template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3154
diff
changeset
|
322 }, |
3129
136b86794453
client: improve pdf-gen code for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3112
diff
changeset
|
323 // Diagram legend |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
324 addDiagramLegend(position, offset, color) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
325 let x = offset.x; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
326 let y = offset.y; |
3343
13bb0ff62ac8
client: diagram-template: cleanup (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3323
diff
changeset
|
327 this.pdf.doc.setFontSize(10); |
13bb0ff62ac8
client: diagram-template: cleanup (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3323
diff
changeset
|
328 let width = |
13bb0ff62ac8
client: diagram-template: cleanup (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3323
diff
changeset
|
329 (this.pdf.doc.getStringUnitWidth("Navigable Range") * 10) / |
13bb0ff62ac8
client: diagram-template: cleanup (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3323
diff
changeset
|
330 (72 / 25.6) + |
13bb0ff62ac8
client: diagram-template: cleanup (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3323
diff
changeset
|
331 5; |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
332 if (["topright", "bottomright"].indexOf(position) !== -1) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
333 x = this.pdf.width - offset.x - width; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
334 } |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
335 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
3343
13bb0ff62ac8
client: diagram-template: cleanup (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3323
diff
changeset
|
336 y = this.pdf.height - offset.y - this.getTextHeight(4); |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
337 } |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
338 this.pdf.doc.setTextColor(color); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
339 this.pdf.doc.setDrawColor("white"); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
340 this.pdf.doc.setFillColor("steelblue"); |
3853
abc15a3182c7
client: pdf-gen: adjust diagramlegend size (waterlevel diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3820
diff
changeset
|
341 this.pdf.doc.circle(x, y, 2, "FD"); |
abc15a3182c7
client: pdf-gen: adjust diagramlegend size (waterlevel diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3820
diff
changeset
|
342 this.pdf.doc.text(x + 3, y + 1, "Waterlevel"); |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
343 this.pdf.doc.setFillColor("#dae6f0"); |
3853
abc15a3182c7
client: pdf-gen: adjust diagramlegend size (waterlevel diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3820
diff
changeset
|
344 this.pdf.doc.circle(x, y + 5, 2, "FD"); |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
345 this.pdf.doc.setFillColor("#e5ffe5"); |
3853
abc15a3182c7
client: pdf-gen: adjust diagramlegend size (waterlevel diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3820
diff
changeset
|
346 this.pdf.doc.circle(x, y + 10, 2, "FD"); |
abc15a3182c7
client: pdf-gen: adjust diagramlegend size (waterlevel diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3820
diff
changeset
|
347 this.pdf.doc.text(x + 3, y + 11, "Navigable Range"); |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
348 this.pdf.doc.setDrawColor("#90b4d2"); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
349 this.pdf.doc.setFillColor("#90b4d2"); |
3853
abc15a3182c7
client: pdf-gen: adjust diagramlegend size (waterlevel diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3820
diff
changeset
|
350 this.pdf.doc.circle(x, y + 5, 0.6, "FD"); |
abc15a3182c7
client: pdf-gen: adjust diagramlegend size (waterlevel diagram)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3820
diff
changeset
|
351 this.pdf.doc.text(x + 3, y + 6, "Prediction"); |
3129
136b86794453
client: improve pdf-gen code for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3112
diff
changeset
|
352 }, |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
353 drawDiagram() { |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
354 // remove old diagram and exit if necessary data is missing |
3146
b6cc4838d2c0
client: implemented pane mechanic for diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3143
diff
changeset
|
355 d3.select("#" + this.containerId + " svg").remove(); |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2695
diff
changeset
|
356 if (!this.selectedGauge || !this.waterlevels.length) return; |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
357 this.renderTo({ |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
358 element: `#${this.containerId}`, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
359 dimensions: this.getDimensions({ |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
360 svgWidth: document.querySelector("#" + this.containerId).clientWidth, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
361 svgHeight: document.querySelector("#" + this.containerId).clientHeight |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
362 }) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
363 }); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
364 }, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
365 renderTo({ element, dimensions }) { |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
366 // PREPARE HELPERS |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
367 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
368 // HDC/LDC/MW for the selected gauge |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
369 const refWaterLevels = JSON.parse( |
2604
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
370 this.selectedGauge.properties.reference_water_levels |
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
371 ); |
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
372 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
373 // get min/max values for date and waterlevel axis |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
374 const extent = this.getExtent(refWaterLevels); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
375 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
376 // scaling helpers |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
377 const scale = this.getScale({ dimensions, extent }); |
2610
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
378 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
379 // creating the axes based on the scales |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
380 const axes = { |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
381 x: d3 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
382 .axisTop(scale.x) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
383 .tickSizeInner(dimensions.mainHeight) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
384 .tickSizeOuter(0), |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
385 y: d3 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
386 .axisRight(scale.y) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
387 .tickSizeInner(dimensions.width) |
3576
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
388 .tickSizeOuter(0) |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
389 .tickFormat(d => this.$options.filters.waterlevel(d)), |
3901
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
390 yRight: d3 |
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
391 .axisRight(scale.y) |
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
392 .tickSizeInner(3) |
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
393 .tickSizeOuter(0) |
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
394 .tickFormat(d => this.$options.filters.waterlevel(d)), |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
395 x2: d3.axisBottom(scale.x2) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
396 }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
397 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
398 // DRAW DIAGRAM/NAVIGATION AREAS |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
399 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
400 // create svg |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
401 const svg = d3 |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
402 .select(element) |
2610
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
403 .append("svg") |
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
404 .attr("width", "100%") |
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
405 .attr("height", "100%"); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
406 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
407 // create container for main diagram |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
408 const diagram = svg |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
409 .append("g") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
410 .attr("class", "main") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
411 .attr( |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
412 "transform", |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
413 `translate(${dimensions.mainMargin.left}, ${ |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
414 dimensions.mainMargin.top |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
415 })` |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
416 ); |
2756
ee2530ee1c0b
client: waterlevel diagram: use chunkedLine for nav chart too
Markus Kottlaender <markus@intevation.de>
parents:
2751
diff
changeset
|
417 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
418 // create container for navigation diagram |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
419 const navigation = svg |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
420 .append("g") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
421 .attr("class", "nav") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
422 .attr( |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
423 "transform", |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
424 `translate(${dimensions.navMargin.left}, ${dimensions.navMargin.top})` |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
425 ); |
2775
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
426 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
427 // define visible area, everything outside this area will be hidden |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
428 svg |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
429 .append("defs") |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
430 .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
|
431 .attr("id", "waterlevel-clip") |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
432 .append("rect") |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
433 .attr("width", dimensions.width) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
434 .attr("height", dimensions.mainHeight); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
435 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
436 // DRAW DIAGRAM PARTS |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
437 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
438 // Each drawSomething function (with the exception of drawRefLines) |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
439 // returns a fuction to update the respective chart/area/etc. These |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
440 // updater functions are used by the zoom feature to rescale all elements. |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
441 const updaters = []; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
442 |
3346
83210507aaca
client: waterlevel diagram: improved readability of nash sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
3343
diff
changeset
|
443 // draw (order matters) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
444 updaters.push(this.drawAxes({ diagram, dimensions, axes, navigation })); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
445 updaters.push(this.drawWaterlevelChart({ scale, diagram })); |
3618
c03170a1c333
client: waterlevel: check if there is prediction data before drawing the predictionarea
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3576
diff
changeset
|
446 if (this.hasPredictions) { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
447 updaters.push(this.drawPredictionAreas({ scale, diagram, navigation })); |
3618
c03170a1c333
client: waterlevel: check if there is prediction data before drawing the predictionarea
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3576
diff
changeset
|
448 } |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
449 updaters.push(this.drawNowLines({ scale, extent, diagram, navigation })); |
3253
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
450 |
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
451 // static, don't need updater |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
452 this.drawNavigationChart({ scale, navigation }); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
453 this.drawRefLines({ refWaterLevels, diagram, scale, dimensions, extent }); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
454 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
455 updaters.push( |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
456 this.drawNashSutcliffe({ hours: 72, diagram, scale, dimensions }) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
457 ); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
458 updaters.push( |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
459 this.drawNashSutcliffe({ hours: 48, diagram, scale, dimensions }) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
460 ); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
461 updaters.push( |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
462 this.drawNashSutcliffe({ hours: 24, diagram, scale, dimensions }) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
463 ); |
3346
83210507aaca
client: waterlevel diagram: improved readability of nash sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
3343
diff
changeset
|
464 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
465 // INTERACTIONS |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
466 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
467 // create rectanlge on the main chart area to capture mouse events |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
468 const eventRect = svg |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
469 .append("rect") |
3212
f87fd173f750
client: waterlevel diagrams: fixed tooltip bug
Markus Kottlaender <markus@intevation.de>
parents:
3211
diff
changeset
|
470 .attr("id", "zoom-waterlevels") |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
471 .attr("class", "zoom") |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
472 .attr("width", dimensions.width) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
473 .attr("height", dimensions.mainHeight) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
474 .attr( |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
475 "transform", |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
476 `translate(${dimensions.mainMargin.left}, ${ |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
477 dimensions.mainMargin.top |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
478 })` |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
479 ); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
480 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
481 this.createZoom({ |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
482 updaters, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
483 eventRect, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
484 dimensions, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
485 scale, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
486 navigation, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
487 svg |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
488 }); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
489 this.createTooltips({ eventRect, diagram, scale, dimensions }); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
490 this.setInlineStyles(svg); |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
491 }, |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
492 //set the styles of the diagrams to include them in the pdf |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
493 setInlineStyles(svg) { |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
494 svg |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
495 .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
|
496 .attr("clip-path", "url(#waterlevel-clip)") |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
497 .selectAll("path") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
498 .attr("stroke", "steelblue") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
499 .attr("stroke-width", 2) |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
500 .attr("fill", "none"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
501 svg |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
502 .selectAll(".line") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
503 .selectAll("path.d3-line-chunked-chunk-gap") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
504 .attr("stroke-opacity", 0); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
505 svg |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
506 .selectAll(".line") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
507 .selectAll("circle") |
3107
8e364945a390
client: adjust some styles for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
508 .attr("fill", "steelblue") |
8e364945a390
client: adjust some styles for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
509 .attr("stroke-width", 0); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
510 svg |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
511 .selectAll(".line") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
512 .selectAll("circle.d3-line-chunked-chunk-predicted-point") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
513 .attr("fill-opacity", 0.6); |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
514 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
515 svg |
3209
5b8916b78cea
client: waterlevel diagrams: check which reference waterlevels are available and added RN as possible option
Markus Kottlaender <markus@intevation.de>
parents:
3179
diff
changeset
|
516 .selectAll(".hdc-line, .mw-line, .ldc-line, .rn-line") |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
517 .attr("stroke-width", 1) |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
518 .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
|
519 .attr("clip-path", "url(#waterlevel-clip)"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
520 svg.selectAll(".hdc-line").attr("stroke", "red"); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
521 svg.selectAll(".ldc-line").attr("stroke", "green"); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
522 svg.selectAll(".mw-line").attr("stroke", "grey"); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
523 svg.selectAll(".rn-line").attr("stroke", "grey"); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
524 svg |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
525 .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
|
526 .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
|
527 .attr("fill", "black"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
528 svg |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
529 .selectAll(".ref-waterlevel-label-background") |
3563
f65ef9148d00
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3544
diff
changeset
|
530 .attr("fill", "rgb(255, 255, 255)") |
f65ef9148d00
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3544
diff
changeset
|
531 .attr("fill-opacity", 0.6); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
532 svg |
3563
f65ef9148d00
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3544
diff
changeset
|
533 .selectAll(".hdc-ldc-area") |
f65ef9148d00
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3544
diff
changeset
|
534 .attr("fill", "rgb(0, 255, 0)") |
f65ef9148d00
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3544
diff
changeset
|
535 .attr("fill-opacity", 0.1); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
536 svg |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
537 .selectAll(".now-line") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
538 .attr("stroke", "#999") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
539 .attr("stroke-width", 1) |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
540 .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
|
541 .attr("clip-path", "url(#waterlevel-clip)"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
542 svg |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
543 .selectAll(".now-line-label") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
544 .attr("font-size", "11px") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
545 .attr("fill", "#999"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
546 svg |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
547 .selectAll(".prediction-area") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
548 .attr("fill", "steelblue") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
549 .attr("fill-opacity", 0.2) |
3147
25c0cbfcc515
client: gauge diagrams: fixed bug related to same clippath id in multiple diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3146
diff
changeset
|
550 .attr("clip-path", "url(#waterlevel-clip)"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
551 svg |
3107
8e364945a390
client: adjust some styles for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
552 .selectAll("path.nash-sutcliffe") |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
553 .attr("fill", "none") |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
554 .attr("stroke", "darkgrey") |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
555 .attr("stroke-width", 1) |
3147
25c0cbfcc515
client: gauge diagrams: fixed bug related to same clippath id in multiple diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3146
diff
changeset
|
556 .attr("clip-path", "url(#waterlevel-clip)"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
557 svg |
3107
8e364945a390
client: adjust some styles for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
558 .selectAll("path.nash-sutcliffe.ns72") |
3563
f65ef9148d00
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3544
diff
changeset
|
559 .attr("fill", "rgb(255, 255, 255)") |
f65ef9148d00
client: improve waterlevel diagram
Bernhard Reiter <bernhard@intevation.de>
parents:
3544
diff
changeset
|
560 .attr("fill-opacity", 0.5); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
561 svg |
3107
8e364945a390
client: adjust some styles for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
562 .selectAll("text.nash-sutcliffe") |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
563 .style("font-size", "10px") |
3147
25c0cbfcc515
client: gauge diagrams: fixed bug related to same clippath id in multiple diagrams
Markus Kottlaender <markus@intevation.de>
parents:
3146
diff
changeset
|
564 .attr("clip-path", "url(#waterlevel-clip)") |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
565 .selectAll("tspan:last-child, tspan:first-child") |
3346
83210507aaca
client: waterlevel diagram: improved readability of nash sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
3343
diff
changeset
|
566 .attr("fill", "#555"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
567 svg |
3901
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
568 .selectAll(".axis--x .tick line, .axis--y .tick line") |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
569 .attr("stroke-dasharray", 5) |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
570 .attr("stroke", "#ccc"); |
3901
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
571 svg.selectAll(".axis--y-right .tick line").attr("stroke", "transparent"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
572 svg.selectAll(".tick text").attr("fill", "black"); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
573 svg.selectAll(".domain").attr("stroke", "black"); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
574 svg |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
575 .selectAll(".domain") |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
576 .attr("stroke", "black") |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
577 .attr("fill", "none"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
578 svg |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
579 .selectAll(".zoom") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
580 .attr("cursor", "move") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
581 .attr("fill", "none") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
582 .attr("pointer-events", "all"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
583 svg |
3107
8e364945a390
client: adjust some styles for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
584 .selectAll(".brush .selection") |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
585 .attr("stroke", "none") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
586 .attr("fill-opacity", 0.2); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
587 svg |
3107
8e364945a390
client: adjust some styles for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
588 .selectAll(".brush .handle") |
3015
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
589 .attr("stroke", "rgba(23, 162, 184, 0.5)") |
fe88a9b151ca
client: implemented pdf-generation for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
2986
diff
changeset
|
590 .attr("fill", "rgba(23, 162, 184, 0.5)"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
591 svg.selectAll(".brush .overlay").attr("fill", "none"); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
592 svg.selectAll(".chart-dots").attr("clip-path", "url(#waterlevel-clip)"); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
593 svg |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
594 .selectAll(".chart-dots .chart-dot") |
3107
8e364945a390
client: adjust some styles for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
595 .attr("fill", "steelblue") |
8e364945a390
client: adjust some styles for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3068
diff
changeset
|
596 .attr("stroke", "steelblue") |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
597 .attr("stroke-opacity", 0) |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
598 .style("pointer-events", "none") |
3046
c764c73f44b4
client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3045
diff
changeset
|
599 .transition() |
c764c73f44b4
client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3045
diff
changeset
|
600 .attr("fill-opacity", "0.1s"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
601 svg |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
602 .selectAll(".chart-tooltip") |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
603 .attr("fill-opacity", 0) |
3046
c764c73f44b4
client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3045
diff
changeset
|
604 .transition() |
c764c73f44b4
client: fix chart-tooltip style for diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3045
diff
changeset
|
605 .attr("fill-opacity", "0.3s"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
606 svg |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
607 .selectAll(".chart-tooltip rect") |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
608 .attr("fill", "#fff") |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
609 .attr("stroke", "#ccc"); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
610 svg |
3045
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
611 .selectAll(".chart-tooltip text") |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
612 .attr("fill", "666") |
44dc837638d9
client: improve styles for pdf-gen of diagrams
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3032
diff
changeset
|
613 .style("font-size", "0.8em"); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
614 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
615 getDimensions({ svgWidth, svgHeight }) { |
3901
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
616 const mainMargin = { top: 20, right: 50, bottom: 110, left: 80 }; |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
617 const navMargin = { |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
618 top: svgHeight - mainMargin.top - 65, |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
619 right: 20, |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
620 bottom: 30, |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
621 left: 80 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
622 }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
623 const width = +svgWidth - mainMargin.left - mainMargin.right; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
624 const mainHeight = +svgHeight - mainMargin.top - mainMargin.bottom; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
625 const navHeight = +svgHeight - navMargin.top - navMargin.bottom; |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
626 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
627 return { width, mainHeight, navHeight, mainMargin, navMargin }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
628 }, |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
629 getExtent(refWaterLevels) { |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
630 return { |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
631 // set min/max values for the date axis |
2820
d973d6f04eb6
client: spuc7: use newest data entry as right boundary for diagram instead of the selected toDate
Markus Kottlaender <markus@intevation.de>
parents:
2819
diff
changeset
|
632 date: [ |
3050
c739b81b8f41
client: gauge waterlevel diagram: fixed date extent
Markus Kottlaender <markus@intevation.de>
parents:
3049
diff
changeset
|
633 this.waterlevels[0].date, |
2820
d973d6f04eb6
client: spuc7: use newest data entry as right boundary for diagram instead of the selected toDate
Markus Kottlaender <markus@intevation.de>
parents:
2819
diff
changeset
|
634 endOfDay(this.waterlevels[this.waterlevels.length - 1].date) |
d973d6f04eb6
client: spuc7: use newest data entry as right boundary for diagram instead of the selected toDate
Markus Kottlaender <markus@intevation.de>
parents:
2819
diff
changeset
|
635 ], |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
636 // set min/max values for the waterlevel axis |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
637 // including HDC (+ 1/8 HDC-LDC) and LDC (- 1/4 HDC-LDC) |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
638 waterlevel: d3.extent( |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
639 [ |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
640 ...this.waterlevels, |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
641 { |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
642 waterlevel: |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
643 refWaterLevels.HDC + |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
644 (refWaterLevels.HDC - refWaterLevels.LDC) / 8 |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
645 }, |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
646 { |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
647 waterlevel: Math.max( |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
648 refWaterLevels.LDC - |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
649 (refWaterLevels.HDC - refWaterLevels.LDC) / 4, |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
650 0 |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
651 ) |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
652 } |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
653 ], |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
654 d => d.waterlevel |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
655 ) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
656 }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
657 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
658 getScale({ dimensions, extent }) { |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
659 // scaling helpers to convert real world values into pixels |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
660 const x = d3.scaleTime().range([0, dimensions.width]); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
661 const y = d3.scaleLinear().range([dimensions.mainHeight, 0]); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
662 const x2 = d3.scaleTime().range([0, dimensions.width]); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
663 const y2 = d3.scaleLinear().range([dimensions.navHeight, 0]); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
664 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
665 // setting the min and max values for the diagram axes |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
666 x.domain(d3.extent(extent.date)); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
667 y.domain(extent.waterlevel); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
668 x2.domain(x.domain()); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
669 y2.domain(y.domain()); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
670 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
671 return { x, y, x2, y2 }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
672 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
673 drawAxes({ diagram, dimensions, axes, navigation }) { |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
674 diagram |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
675 .append("g") |
2652
a2dd96c305be
client: waterlevel diagram: fixed animated x-axis in mainchart when zooming
Markus Kottlaender <markus@intevation.de>
parents:
2648
diff
changeset
|
676 .attr("class", "axis--x") |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
677 .attr("transform", `translate(0, ${dimensions.mainHeight})`) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
678 .call(axes.x) |
2648
4ffae834276e
client: waterlevel diagram: added background grid to chart
Markus Kottlaender <markus@intevation.de>
parents:
2646
diff
changeset
|
679 .selectAll(".tick text") |
4ffae834276e
client: waterlevel diagram: added background grid to chart
Markus Kottlaender <markus@intevation.de>
parents:
2646
diff
changeset
|
680 .attr("y", 15); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
681 diagram // label |
2641
a735119e4f5c
client: waterlevel diagram: added y-axis label
Markus Kottlaender <markus@intevation.de>
parents:
2611
diff
changeset
|
682 .append("text") |
3576
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
683 .text(this.$gettext("Waterlevel [m]")) |
2641
a735119e4f5c
client: waterlevel diagram: added y-axis label
Markus Kottlaender <markus@intevation.de>
parents:
2611
diff
changeset
|
684 .attr("text-anchor", "middle") |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
685 .attr( |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
686 "transform", |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
687 `translate(-45, ${dimensions.mainHeight / 2}) rotate(-90)` |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
688 ); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
689 diagram |
2648
4ffae834276e
client: waterlevel diagram: added background grid to chart
Markus Kottlaender <markus@intevation.de>
parents:
2646
diff
changeset
|
690 .append("g") |
3901
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
691 .attr("class", "axis--y") |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
692 .call(axes.y) |
2648
4ffae834276e
client: waterlevel diagram: added background grid to chart
Markus Kottlaender <markus@intevation.de>
parents:
2646
diff
changeset
|
693 .selectAll(".tick text") |
4ffae834276e
client: waterlevel diagram: added background grid to chart
Markus Kottlaender <markus@intevation.de>
parents:
2646
diff
changeset
|
694 .attr("x", -25); |
3901
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
695 diagram |
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
696 .append("g") |
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
697 .attr("class", "axis--y-right") |
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
698 .attr("transform", `translate(${dimensions.width})`) |
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
699 .call(axes.yRight) |
fe0d62727c41
client: waterlevel diagram: added right y axis
Markus Kottlaender <markus@intevation.de>
parents:
3894
diff
changeset
|
700 .selectAll(".tick text"); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
701 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
702 navigation |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
703 .append("g") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
704 .attr("class", "axis axis--x") |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
705 .attr("transform", `translate(0, ${dimensions.navHeight})`) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
706 .call(axes.x2); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
707 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
708 return () => { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
709 diagram |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
710 .select(".axis--x") |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
711 .call(axes.x) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
712 .selectAll(".tick text") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
713 .attr("y", 15); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
714 }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
715 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
716 drawWaterlevelChart({ scale, diagram }) { |
3253
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
717 const waterlevelChartDrawer = () => { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
718 let domainLeft = new Date(scale.x.domain()[0].getTime()); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
719 let domainRight = new Date(scale.x.domain()[1].getTime()); |
3253
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
720 domainLeft.setDate(domainLeft.getDate() - 1); |
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
721 domainRight.setDate(domainRight.getDate() + 1); |
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
722 |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
723 let lineChunked = d3 |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
724 .lineChunked() |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
725 // render only data points that are visible in the current scale |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
726 .defined(d => d.date > domainLeft && d.date < domainRight) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
727 .x(d => scale.x(d.date)) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
728 .y(d => scale.y(d.waterlevel)) |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
729 .curve(d3.curveLinear) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
730 .isNext(this.isNext(scale)) |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
731 .pointAttrs({ r: 1.7 }); |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
732 // to avoid creating empty clip-path element |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
733 if (this.hasPredictions) { |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
734 lineChunked |
3253
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
735 .chunk(d => (d.predicted ? "predicted" : "line")) |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
736 .chunkDefinitions({ predicted: {} }); |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
737 } |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
738 return lineChunked; |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
739 }; |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
740 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
741 diagram |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
742 .append("g") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
743 .attr("class", "line") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
744 .datum(this.waterlevels) |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
745 .call(waterlevelChartDrawer()); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
746 |
3253
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
747 return () => { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
748 diagram.select(".line").call(waterlevelChartDrawer()); |
3253
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
749 }; |
3a7b6eb162db
client: waterlevel diagram: separated main chart and navigation drawers
Markus Kottlaender <markus@intevation.de>
parents:
3252
diff
changeset
|
750 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
751 drawNavigationChart({ scale, navigation }) { |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
752 let lineChunked = d3 |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
753 .lineChunked() |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
754 .x(d => scale.x2(d.date)) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
755 .y(d => scale.y2(d.waterlevel)) |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
756 .curve(d3.curveLinear) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
757 .isNext(this.isNext(scale)) |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
758 .pointAttrs({ r: 1.7 }); |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
759 // to avoid creating empty clip-path element |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
760 if (this.hasPredictions) { |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
761 lineChunked |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
762 .chunk(d => (d.predicted ? "predicted" : "line")) |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
763 .chunkDefinitions({ predicted: {} }); |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
764 } |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
765 navigation |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
766 .append("g") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
767 .attr("class", "line") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
768 .datum(this.waterlevels) |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
769 .call(lineChunked); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
770 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
771 drawNowLines({ scale, extent, diagram, navigation }) { |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
772 const nowLine = d3 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
773 .line() |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
774 .x(d => scale.x(d.x)) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
775 .y(d => scale.y(d.y)); |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
776 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
777 const nowLabel = selection => { |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
778 selection.attr( |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
779 "transform", |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
780 `translate(${scale.x(new Date())}, ${scale.y( |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
781 extent.waterlevel[1] - 16 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
782 )})` |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
783 ); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
784 }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
785 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
786 // draw in main |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
787 diagram |
2604
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
788 .append("path") |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
789 .datum([ |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
790 { x: new Date(), y: extent.waterlevel[0] }, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
791 { x: new Date(), y: extent.waterlevel[1] - 20 } |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
792 ]) |
2775
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
793 .attr("class", "now-line") |
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
794 .attr("d", nowLine); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
795 diagram // label |
2775
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
796 .append("text") |
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
797 .text(this.$gettext("Now")) |
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
798 .attr("class", "now-line-label") |
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
799 .attr("text-anchor", "middle") |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
800 .call(nowLabel); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
801 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
802 // draw in nav |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
803 navigation |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
804 .append("path") |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
805 .datum([ |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
806 { x: new Date(), y: extent.waterlevel[0] }, |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
807 { x: new Date(), y: extent.waterlevel[1] - 20 } |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
808 ]) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
809 .attr("class", "now-line") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
810 .attr( |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
811 "d", |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
812 d3 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
813 .line() |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
814 .x(d => scale.x2(d.x)) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
815 .y(d => scale.y2(d.y)) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
816 ); |
2775
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
817 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
818 return () => { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
819 diagram.select(".now-line").attr("d", nowLine); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
820 diagram.select(".now-line-label").call(nowLabel); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
821 }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
822 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
823 drawPredictionAreas({ scale, diagram, navigation }) { |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
824 const predictionArea = isNav => |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
825 d3 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
826 .area() |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
827 .defined(d => d.predicted && d.min && d.max) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
828 .x(d => scale[isNav ? "x2" : "x"](d.date)) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
829 .y0(d => scale[isNav ? "y2" : "y"](d.min)) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
830 .y1(d => scale[isNav ? "y2" : "y"](d.max)); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
831 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
832 diagram |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
833 .append("path") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
834 .datum(this.waterlevels) |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
835 .attr("class", "prediction-area") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
836 .attr("d", predictionArea()); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
837 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
838 navigation |
2775
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
839 .append("path") |
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
840 .datum(this.waterlevels) |
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
841 .attr("class", "prediction-area") |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
842 .attr("d", predictionArea(true)); |
2610
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
843 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
844 return () => { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
845 diagram.select(".prediction-area").attr("d", predictionArea()); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
846 }; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
847 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
848 drawRefLines({ refWaterLevels, diagram, scale, dimensions, extent }) { |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
849 // filling area between HDC and LDC |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
850 diagram |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
851 .append("rect") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
852 .attr("class", "hdc-ldc-area") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
853 .attr("x", 0) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
854 .attr("y", scale.y(refWaterLevels.HDC)) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
855 .attr("width", dimensions.width) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
856 .attr( |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
857 "height", |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
858 scale.y(refWaterLevels.LDC) - scale.y(refWaterLevels.HDC) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
859 ); |
2610
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
860 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
861 const refWaterlevelLine = d3 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
862 .line() |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
863 .x(d => scale.x(d.x)) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
864 .y(d => scale.y(d.y)); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
865 |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
866 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
|
867 if (refWaterLevels[ref]) { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
868 diagram |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
869 .append("path") |
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
870 .datum([ |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
871 { x: 0, y: refWaterLevels[ref] }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
872 { 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
|
873 ]) |
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
874 .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
|
875 .attr("d", refWaterlevelLine); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
876 diagram // label |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
877 .append("rect") |
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
878 .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
|
879 .attr("x", 1) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
880 .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
|
881 .attr("width", 55) |
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
882 .attr("height", 12); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
883 diagram |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
884 .append("text") |
3576
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
885 .text( |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
886 `${ref} (${this.$options.filters.waterlevel( |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
887 refWaterLevels[ref] |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
888 )})` |
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
889 ) |
3211
f76927849ef8
client: waterlevel diagrams: moved reference waterlevel labels and lines to foreground
Markus Kottlaender <markus@intevation.de>
parents:
3209
diff
changeset
|
890 .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
|
891 .attr("x", 5) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
892 .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
|
893 } |
3209
5b8916b78cea
client: waterlevel diagrams: check which reference waterlevels are available and added RN as possible option
Markus Kottlaender <markus@intevation.de>
parents:
3179
diff
changeset
|
894 } |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
895 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
896 drawNashSutcliffe({ hours, diagram, scale, dimensions }) { |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
897 const coeff = this.nashSutcliffe.coeffs.find(c => c.hours === hours); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
898 const dateNow = new Date(this.nashSutcliffe.when); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
899 const dateStart = new Date(dateNow.getTime() - hours * 60 * 60 * 1000); |
2751
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
900 |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
901 const nashSutcliffeBox = hours => { |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
902 // show/hide boxes depending on scale of chart (hide if > 90 days) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
903 diagram |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
904 .selectAll("path.nash-sutcliffe") |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
905 .attr( |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
906 "stroke-opacity", |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
907 scale.x.domain()[1] - scale.x.domain()[0] > 90 * 86400000 ? 0 : 1 |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
908 ); |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
909 |
2751
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
910 return d3 |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
911 .area() |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
912 .x(d => scale.x(d)) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
913 .y0(() => dimensions.mainHeight + 0.5) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
914 .y1(() => dimensions.mainHeight - 15 * (hours / 24)); |
2751
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
915 }; |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
916 |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
917 const nashSutcliffeLabel = (label, date, hours) => { |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
918 let days = hours / 24; |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
919 label |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
920 .attr("x", Math.min(scale.x(date), dimensions.width) - 4) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
921 .attr("y", dimensions.mainHeight - (15 * days + 0.5) + 12); |
2751
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
922 }; |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2728
diff
changeset
|
923 |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
924 if (coeff.samples) { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
925 diagram |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
926 .append("path") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
927 .datum([dateStart, dateNow]) |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
928 .attr("class", "nash-sutcliffe ns" + hours) |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
929 .attr("d", nashSutcliffeBox(hours)); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
930 diagram |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
931 .append("text") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
932 .attr("class", "nash-sutcliffe ns" + hours) |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
933 .attr("text-anchor", "end") |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
934 .call(nashSutcliffeLabel, dateNow, hours) |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
935 .append("tspan") |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
936 .text(hours + "h: ") |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
937 .select(function() { |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
938 return this.parentNode; |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
939 }) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
940 .append("tspan") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
941 .text(coeff.value.toFixed(2)) |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
942 .select(function() { |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
943 return this.parentNode; |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
944 }) |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
945 .append("tspan") |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
946 .text(` (${coeff.samples})`); |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
947 } |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
948 |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
949 return () => { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
950 diagram |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
951 .select("path.nash-sutcliffe.ns" + hours) |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
952 .attr("d", nashSutcliffeBox(hours)); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
953 diagram |
3348
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
954 .select("text.nash-sutcliffe.ns" + hours) |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
955 .call(nashSutcliffeLabel, dateNow, hours); |
7bb6c921cf91
client: waterlevel diagram: improved nash sutcliffe display
Markus Kottlaender <markus@intevation.de>
parents:
3346
diff
changeset
|
956 }; |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
957 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
958 createZoom({ updaters, eventRect, dimensions, scale, navigation, svg }) { |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
959 const brush = d3 |
2610
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
960 .brushX() |
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
961 .handleSize(4) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
962 .extent([[0, 0], [dimensions.width, dimensions.navHeight]]); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
963 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
964 const zoom = d3 |
2610
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
965 .zoom() |
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
966 .scaleExtent([1, Infinity]) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
967 .translateExtent([[0, 0], [dimensions.width, dimensions.mainHeight]]) |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
968 .extent([[0, 0], [dimensions.width, dimensions.mainHeight]]); |
2610
5ce1b4b29869
client: waterlevel diagram: refactored code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2607
diff
changeset
|
969 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
970 brush.on("brush end", () => { |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
971 if (d3.event.sourceEvent && d3.event.sourceEvent.type === "zoom") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
972 return; // ignore brush-by-zoom |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
973 let s = d3.event.selection || scale.x2.range(); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
974 scale.x.domain(s.map(scale.x2.invert, scale.x2)); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
975 updaters.forEach(u => u && u()); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
976 this.setInlineStyles(svg); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
977 svg |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
978 .select(".zoom") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
979 .call( |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
980 zoom.transform, |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
981 d3.zoomIdentity |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
982 .scale(dimensions.width / (s[1] - s[0])) |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
983 .translate(-s[0], 0) |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
984 ); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
985 }); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
986 |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
987 zoom.on("zoom", () => { |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
988 if (d3.event.sourceEvent && d3.event.sourceEvent.type === "brush") |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
989 return; // ignore zoom-by-brush |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
990 let t = d3.event.transform; |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
991 scale.x.domain(t.rescaleX(scale.x2).domain()); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
992 updaters.forEach(u => u && u()); |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
993 this.setInlineStyles(svg); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
994 navigation |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
995 .select(".brush") |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
996 .call(brush.move, scale.x.range().map(t.invertX, t)); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
997 }); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
998 zoom.on("start", () => { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
999 svg.select(".chart-dot").style("opacity", 0); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1000 svg.select(".chart-tooltip").style("opacity", 0); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
1001 }); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
1002 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1003 navigation |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1004 .append("g") |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1005 .attr("class", "brush") |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1006 .call(brush) |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1007 .call(brush.move, scale.x.range()); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1008 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
1009 eventRect.call(zoom); |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
1010 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1011 createTooltips({ eventRect, diagram, scale, dimensions }) { |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1012 // create clippable container for the dot |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1013 diagram |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1014 .append("g") |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1015 .attr("class", "chart-dots") |
2689
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1016 .append("circle") |
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1017 .attr("class", "chart-dot") |
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1018 .attr("r", 4); |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1019 |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1020 // create container for the tooltip |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1021 const tooltip = diagram.append("g").attr("class", "chart-tooltip"); |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1022 tooltip |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1023 .append("rect") |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1024 .attr("rx", "0.25em") |
3782
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
1025 .attr("ry", "0.25em") |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
1026 .attr("width", "0px") |
d36ccff8de5f
pdf: waterlevel diagram with svg2pdf
Thomas Junk <thomas.junk@intevation.de>
parents:
3780
diff
changeset
|
1027 .attr("height", "0px"); |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1028 |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1029 // create container for multiple text rows |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1030 const tooltipText = tooltip.append("text").attr("text-anchor", "middle"); |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1031 |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1032 // padding inside the tooltip box and diagram padding to determine left |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1033 // and right offset from the diagram boundaries for the tooltip position. |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1034 const tooltipPadding = 10; |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1035 const diagramPadding = 5; |
2689
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1036 |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
1037 eventRect |
2689
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1038 .on("mouseover", () => { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1039 diagram.select(".chart-dot").style("opacity", 1); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1040 diagram.select(".chart-tooltip").style("opacity", 1); |
2689
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1041 }) |
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1042 .on("mouseout", () => { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1043 diagram.select(".chart-dot").style("opacity", 0); |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1044 diagram.select(".chart-tooltip").style("opacity", 0); |
2689
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1045 }) |
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1046 .on("mousemove", () => { |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1047 // find data point closest to mouse |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1048 const x0 = scale.x.invert( |
3212
f87fd173f750
client: waterlevel diagrams: fixed tooltip bug
Markus Kottlaender <markus@intevation.de>
parents:
3211
diff
changeset
|
1049 d3.mouse(document.getElementById("zoom-waterlevels"))[0] |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
1050 ), |
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
1051 i = d3.bisector(d => d.date).left(this.waterlevels, x0, 1), |
2689
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1052 d0 = this.waterlevels[i - 1], |
2715
8d96b9254465
client: waterlevel diagram: fixed console error when hovering the chart where no data is available
Markus Kottlaender <markus@intevation.de>
parents:
2710
diff
changeset
|
1053 d1 = this.waterlevels[i] || d0, |
2689
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1054 d = x0 - d0.date > d1.date - x0 ? d1 : d0; |
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1055 |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1056 const coords = { |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1057 x: scale.x(d.date), |
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1058 y: scale.y(d.waterlevel) |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1059 }; |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1060 |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1061 // position the dot |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1062 diagram |
2689
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1063 .select(".chart-dot") |
2691
023a607c4bcc
client: waterlevel diagram: fixed tooltip display while moving/zooming the chart
Markus Kottlaender <markus@intevation.de>
parents:
2689
diff
changeset
|
1064 .style("opacity", 1) |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1065 .attr("transform", `translate(${coords.x}, ${coords.y})`); |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1066 |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1067 // remove current texts |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1068 tooltipText.selectAll("tspan").remove(); |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1069 |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1070 // write date |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1071 tooltipText |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1072 .append("tspan") |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1073 .attr("dominant-baseline", "hanging") |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1074 .attr("text-anchor", "middle") |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1075 .text( |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1076 d.date.toLocaleString([], { |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1077 year: "2-digit", |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1078 month: "2-digit", |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1079 day: "2-digit", |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1080 hour: "2-digit", |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1081 minute: "2-digit" |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1082 }) |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1083 ); |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1084 |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1085 if (d.predicted) { |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1086 tooltipText |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1087 .append("tspan") |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1088 .attr("x", 0) |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1089 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1090 .attr("dy", "1.4em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1091 .attr("dominant-baseline", "hanging") |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1092 .attr("text-anchor", "middle") |
3576
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
1093 .text(this.$options.filters.waterlevel(d.max) + " m"); |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1094 tooltipText |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1095 .append("tspan") |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1096 .attr("x", 0) |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1097 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1098 .attr("dy", "2.6em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1099 .attr("dominant-baseline", "hanging") |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1100 .attr("text-anchor", "middle") |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1101 .attr("class", "font-weight-bold") |
3576
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
1102 .text(this.$options.filters.waterlevel(d.waterlevel) + " m"); |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1103 tooltipText |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1104 .append("tspan") |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1105 .attr("x", 0) |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1106 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1107 .attr("dy", "3.8em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1108 .attr("dominant-baseline", "hanging") |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1109 .attr("text-anchor", "middle") |
3576
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
1110 .text(this.$options.filters.waterlevel(d.min) + " m"); |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1111 } else { |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1112 tooltipText |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1113 .append("tspan") |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1114 .attr("x", 0) |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1115 .attr("y", 0) |
2842
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1116 .attr("dy", "1.4em") |
37c2a73ed001
client: diagrams: fixed tooltips in firefox
Markus Kottlaender <markus@intevation.de>
parents:
2839
diff
changeset
|
1117 .attr("dominant-baseline", "hanging") |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1118 .attr("text-anchor", "middle") |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1119 .attr("class", "font-weight-bold") |
3576
1109a38f7ff1
client: waterlevel format in diagrams changed from cm to m and localized
Markus Kottlaender <markus@intevation.de>
parents:
3565
diff
changeset
|
1120 .text(this.$options.filters.waterlevel(d.waterlevel) + " m"); |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1121 } |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1122 |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1123 // get text dimensions |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1124 const textBBox = tooltipText.node().getBBox(); |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1125 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1126 diagram |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1127 .selectAll(".chart-tooltip text tspan") |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1128 .attr("x", textBBox.width / 2 + tooltipPadding) |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1129 .attr("y", tooltipPadding); |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1130 |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1131 // position and scale tooltip box |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1132 const xMax = |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1133 dimensions.width - |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1134 (textBBox.width + diagramPadding + tooltipPadding * 2); |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1135 const tooltipX = Math.max( |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1136 diagramPadding, |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1137 Math.min(coords.x - (textBBox.width + tooltipPadding * 2) / 2, xMax) |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1138 ); |
2824
d7c4169516fa
client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents:
2821
diff
changeset
|
1139 let tooltipY = coords.y - (textBBox.height + tooltipPadding * 2) - 10; |
d7c4169516fa
client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents:
2821
diff
changeset
|
1140 if (coords.y < textBBox.height + tooltipPadding * 2) { |
d7c4169516fa
client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents:
2821
diff
changeset
|
1141 tooltipY = coords.y + 10; |
d7c4169516fa
client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents:
2821
diff
changeset
|
1142 } |
d7c4169516fa
client: spuc7/8: further improved tooltip positioning
Markus Kottlaender <markus@intevation.de>
parents:
2821
diff
changeset
|
1143 |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1144 diagram |
2816
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1145 .select(".chart-tooltip") |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1146 .style("opacity", 1) |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1147 .attr("transform", `translate(${tooltipX}, ${tooltipY})`) |
c02cebff3f16
client: SPUC7/8: fix tooltip size and positioning
Markus Kottlaender <markus@intevation.de>
parents:
2810
diff
changeset
|
1148 .select("rect") |
2819
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1149 .attr("width", textBBox.width + tooltipPadding * 2) |
53c2bd009c68
client: diagrams: further improved tooltip positioning/sizing
Markus Kottlaender <markus@intevation.de>
parents:
2816
diff
changeset
|
1150 .attr("height", textBBox.height + tooltipPadding * 2); |
2689
8f919fe629f9
client: waterlevel diagram: added tooltips showing date and waterlevel on the chart
Markus Kottlaender <markus@intevation.de>
parents:
2684
diff
changeset
|
1151 }); |
2805
eb91ad1d7a93
client: waterlevel diagram: optimized code for better readability
Markus Kottlaender <markus@intevation.de>
parents:
2794
diff
changeset
|
1152 }, |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1153 isNext(scale) { |
3252
fccb28813159
client: wterlevel diagram: improved performance
Markus Kottlaender <markus@intevation.de>
parents:
3249
diff
changeset
|
1154 // Check whether points in the chart can be considered "next to each other". |
fccb28813159
client: wterlevel diagram: improved performance
Markus Kottlaender <markus@intevation.de>
parents:
3249
diff
changeset
|
1155 // For that they need to be exactly 15 minutes apart (for automatically |
fccb28813159
client: wterlevel diagram: improved performance
Markus Kottlaender <markus@intevation.de>
parents:
3249
diff
changeset
|
1156 // imported gauge measurements). If the chart shows more than 15 days then |
fccb28813159
client: wterlevel diagram: improved performance
Markus Kottlaender <markus@intevation.de>
parents:
3249
diff
changeset
|
1157 // 1 hour is also valid (for approved gauge measurements). |
fccb28813159
client: wterlevel diagram: improved performance
Markus Kottlaender <markus@intevation.de>
parents:
3249
diff
changeset
|
1158 return (prev, current) => { |
fccb28813159
client: wterlevel diagram: improved performance
Markus Kottlaender <markus@intevation.de>
parents:
3249
diff
changeset
|
1159 let difference = (current.date - prev.date) / 1000; |
3885
d42158f77841
waterlevel: factor out side-effects from diagram rendering
Thomas Junk <thomas.junk@intevation.de>
parents:
3853
diff
changeset
|
1160 if ((scale.x.domain()[1] - scale.x.domain()[0]) / 86400000 > 15) |
3252
fccb28813159
client: wterlevel diagram: improved performance
Markus Kottlaender <markus@intevation.de>
parents:
3249
diff
changeset
|
1161 return [900, 3600].includes(difference); |
fccb28813159
client: wterlevel diagram: improved performance
Markus Kottlaender <markus@intevation.de>
parents:
3249
diff
changeset
|
1162 return difference === 900; |
fccb28813159
client: wterlevel diagram: improved performance
Markus Kottlaender <markus@intevation.de>
parents:
3249
diff
changeset
|
1163 }; |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1164 } |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1165 }, |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1166 created() { |
3924
2efda3391fa8
client: waterlevel diagram: fixed handing of resize listener
Markus Kottlaender <markus@intevation.de>
parents:
3910
diff
changeset
|
1167 this.resizeListenerFunction = debounce(this.drawDiagram, 100); |
2efda3391fa8
client: waterlevel diagram: fixed handing of resize listener
Markus Kottlaender <markus@intevation.de>
parents:
3910
diff
changeset
|
1168 window.addEventListener("resize", this.resizeListenerFunction); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1169 }, |
2810
97cf32cf2562
client: waterlevel diagram: draw diagram when component is mounted
Markus Kottlaender <markus@intevation.de>
parents:
2805
diff
changeset
|
1170 mounted() { |
3303
d6405c6769a3
client: waterlevel diagram: wait for child component before rendering diagram
Markus Kottlaender <markus@intevation.de>
parents:
3295
diff
changeset
|
1171 // Nasty but necessary if we don't want to use the updated hook to re-draw |
d6405c6769a3
client: waterlevel diagram: wait for child component before rendering diagram
Markus Kottlaender <markus@intevation.de>
parents:
3295
diff
changeset
|
1172 // the diagram because this would re-draw it also for irrelevant reasons. |
d6405c6769a3
client: waterlevel diagram: wait for child component before rendering diagram
Markus Kottlaender <markus@intevation.de>
parents:
3295
diff
changeset
|
1173 // In this case we need to wait for the child component (DiagramLegend) to |
d6405c6769a3
client: waterlevel diagram: wait for child component before rendering diagram
Markus Kottlaender <markus@intevation.de>
parents:
3295
diff
changeset
|
1174 // render. According to the docs (https://vuejs.org/v2/api/#mounted) this |
d6405c6769a3
client: waterlevel diagram: wait for child component before rendering diagram
Markus Kottlaender <markus@intevation.de>
parents:
3295
diff
changeset
|
1175 // should be possible with $nextTick() but it doesn't work because it does |
d6405c6769a3
client: waterlevel diagram: wait for child component before rendering diagram
Markus Kottlaender <markus@intevation.de>
parents:
3295
diff
changeset
|
1176 // not guarantee that the DOM is not only updated but also re-painted on the |
d6405c6769a3
client: waterlevel diagram: wait for child component before rendering diagram
Markus Kottlaender <markus@intevation.de>
parents:
3295
diff
changeset
|
1177 // screen. |
3924
2efda3391fa8
client: waterlevel diagram: fixed handing of resize listener
Markus Kottlaender <markus@intevation.de>
parents:
3910
diff
changeset
|
1178 setTimeout(this.drawDiagram, 150); |
3303
d6405c6769a3
client: waterlevel diagram: wait for child component before rendering diagram
Markus Kottlaender <markus@intevation.de>
parents:
3295
diff
changeset
|
1179 |
3143
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
1180 this.templates[0] = this.defaultTemplate; |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
1181 this.form.template = this.templates[0]; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3132
diff
changeset
|
1182 this.templateData = this.form.template; |
3229
5e773e0c05be
client: diagram-template: adjust the routes for waterlevels and hydrologicalconditions diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3222
diff
changeset
|
1183 HTTP.get("/templates/diagram", { |
3140
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1184 headers: { |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1185 "X-Gemma-Auth": localStorage.getItem("token"), |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1186 "Content-type": "text/xml; charset=UTF-8" |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1187 } |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1188 }) |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1189 .then(response => { |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1190 if (response.data.length) { |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1191 this.templates = response.data; |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1192 this.form.template = this.templates[0]; |
3143
8fdbc524e7b5
client: make the default template available to use even if backend provided templates
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3142
diff
changeset
|
1193 this.templates[this.templates.length] = this.defaultTemplate; |
3140
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1194 this.applyChange(); |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1195 } |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1196 }) |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1197 .catch(e => { |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1198 const { status, data } = e.response; |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1199 displayError({ |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1200 title: this.$gettext("Backend Error"), |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1201 message: `${status}: ${data.message || data}` |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1202 }); |
91556825d95c
client: implement geting templates from backend for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3139
diff
changeset
|
1203 }); |
2810
97cf32cf2562
client: waterlevel diagram: draw diagram when component is mounted
Markus Kottlaender <markus@intevation.de>
parents:
2805
diff
changeset
|
1204 }, |
2986
7ee9a3ef90d4
client: remove resize event listener from diagrams after they are closed
Markus Kottlaender <markus@intevation.de>
parents:
2843
diff
changeset
|
1205 destroyed() { |
3924
2efda3391fa8
client: waterlevel diagram: fixed handing of resize listener
Markus Kottlaender <markus@intevation.de>
parents:
3910
diff
changeset
|
1206 window.removeEventListener("resize", this.resizeListenerFunction); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1207 } |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1208 }; |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1209 </script> |