annotate client/src/components/TimeSlider.vue @ 5157:673f2a00c767

add missing Author in Timeslider
author Fadi Abbud <fadi.abbud@intevation.de>
date Thu, 02 Apr 2020 13:17:13 +0200
parents 6a6eaa536787
children c86ce16937fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
1 <template>
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
2 <div
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
3 id="slider"
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
4 :class="[
5037
9d288d9b851b client: move selectedTime to store
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5036
diff changeset
5 'd-flex box ui-element rounded bg-white flex-row',
5094
f59ba73ff692 client: better positioning for time-slider during window resizing and opened diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5090
diff changeset
6 { expanded: showTimeSlider },
f59ba73ff692 client: better positioning for time-slider during window resizing and opened diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5090
diff changeset
7 {
f59ba73ff692 client: better positioning for time-slider during window resizing and opened diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5090
diff changeset
8 reposition: ['DEFAULT', 'COMPARESURVEYS'].indexOf(this.paneSetup) === -1
f59ba73ff692 client: better positioning for time-slider during window resizing and opened diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5090
diff changeset
9 }
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
10 ]"
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
11 >
5071
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
12 <div id="timeselection" class="d-flex mt-1 mr-1">
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
13 <input
5046
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
14 class="form-control-sm mr-1"
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
15 type="date"
5046
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
16 v-model="dateSelection"
5039
aec0923f9c52 icon shows now date and time
Thomas Junk <thomas.junk@intevation.de>
parents: 5038
diff changeset
17 min="2015-01-01"
5048
700758d22737 client: (minor) adjust max value for input field
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5046
diff changeset
18 :max="new Date().toISOString().split('T')[0]"
5074
8ec4f1a0db86 client: remove clear button on date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5072
diff changeset
19 required
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
20 />
5046
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
21 <input
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
22 type="time"
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
23 min="00:00"
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
24 max="23:59"
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
25 v-model="timeSelection"
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
26 class="form-control-sm"
5074
8ec4f1a0db86 client: remove clear button on date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5072
diff changeset
27 required
5046
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
28 />
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
29 </div>
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
30 <div
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
31 id="sliderContainer"
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
32 class="d-flex sliderContainer"
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
33 style="width: 98%;"
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
34 ></div>
5071
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
35 <div
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
36 id="closebutton"
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
37 @click="close"
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
38 class="d-flex box-control mr-0"
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
39 style="width: 2%;"
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
40 >
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
41 <font-awesome-icon icon="times"></font-awesome-icon>
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
42 </div>
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
43 </div>
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
44 </template>
5071
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
45 <style lang="scss" scoped>
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
46 #slider {
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
47 position: absolute;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
48 bottom: 0;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
49 min-width: 100vw;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
50 }
5094
f59ba73ff692 client: better positioning for time-slider during window resizing and opened diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5090
diff changeset
51 // reposition time slider in case of opened diagram
f59ba73ff692 client: better positioning for time-slider during window resizing and opened diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5090
diff changeset
52 #slider.reposition {
f59ba73ff692 client: better positioning for time-slider during window resizing and opened diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5090
diff changeset
53 bottom: 50%;
f59ba73ff692 client: better positioning for time-slider during window resizing and opened diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5090
diff changeset
54 }
5071
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
55 #slider.expanded {
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
56 max-height: 100%;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
57 max-width: 100%;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
58 margin: 0;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
59 }
5074
8ec4f1a0db86 client: remove clear button on date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5072
diff changeset
60 input::-webkit-clear-button {
8ec4f1a0db86 client: remove clear button on date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5072
diff changeset
61 display: none;
8ec4f1a0db86 client: remove clear button on date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5072
diff changeset
62 }
8ec4f1a0db86 client: remove clear button on date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5072
diff changeset
63 // hide clear button on IE
8ec4f1a0db86 client: remove clear button on date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5072
diff changeset
64 input::-ms-clear {
8ec4f1a0db86 client: remove clear button on date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5072
diff changeset
65 display: none;
8ec4f1a0db86 client: remove clear button on date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5072
diff changeset
66 }
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
67 </style>
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
68 <script>
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
69 /* This is Free Software under GNU Affero General Public License v >= 3.0
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
70 * without warranty, see README.md and license for details.
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
71 *
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
72 * SPDX-License-Identifier: AGPL-3.0-or-later
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
73 * License-Filename: LICENSES/AGPL-3.0.txt
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
74 *
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
75 * Copyright (C) 2020 by via donau
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
76 * – Österreichische Wasserstraßen-Gesellschaft mbH
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
77 * Software engineering by Intevation GmbH
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
78 *
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
79 * Author(s):
5157
673f2a00c767 add missing Author in Timeslider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5150
diff changeset
80 * Fadi Abbud <fadi.abbud@intevation.de>
673f2a00c767 add missing Author in Timeslider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5150
diff changeset
81 * Thomas Junk <thomas.junk@intevation.de>
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
82 */
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
83 import { mapState } from "vuex";
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
84 import * as d3 from "d3";
5043
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
85 import app from "@/main";
5044
ca5b1b5a553a client: date localization for time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5043
diff changeset
86 import { localeDateString } from "@/lib/datelocalization";
5082
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
87 import { format, setHours, setMinutes, compareAsc } from "date-fns";
5067
99ac62a56dd2 client: add window resize event listener
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5066
diff changeset
88 import debounce from "debounce";
5043
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
89
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
90 let zoom = null;
5061
37371727f704 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5060
diff changeset
91 let xScale = null;
37371727f704 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5060
diff changeset
92 let xAxis = null;
5072
51b30f7c64a2 Timeslider proper rescale
Thomas Junk <thomas.junk@intevation.de>
parents: 5071
diff changeset
93 let currentScaleFactor = 1;
5061
37371727f704 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5060
diff changeset
94
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
95 export default {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
96 name: "timeslider",
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
97 data() {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
98 return {
5067
99ac62a56dd2 client: add window resize event listener
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5066
diff changeset
99 isSelectedTimeHourly: false,
99ac62a56dd2 client: add window resize event listener
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5066
diff changeset
100 resizeListenerFunction: null
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
101 };
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
102 },
5040
066b76ef5e6a selected time is refreshed after reloads
Thomas Junk <thomas.junk@intevation.de>
parents: 5039
diff changeset
103 watch: {
066b76ef5e6a selected time is refreshed after reloads
Thomas Junk <thomas.junk@intevation.de>
parents: 5039
diff changeset
104 ongoingRefresh() {
066b76ef5e6a selected time is refreshed after reloads
Thomas Junk <thomas.junk@intevation.de>
parents: 5039
diff changeset
105 if (this.ongoingRefresh) return;
066b76ef5e6a selected time is refreshed after reloads
Thomas Junk <thomas.junk@intevation.de>
parents: 5039
diff changeset
106 this.$store.commit("application/setSelectedTime", new Date());
5065
385cb52d32ee client: enhanced time-slider behavior on updating selected time after reloads
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5064
diff changeset
107 this.$nextTick(this.rescaleSlider(1));
5075
aeb100b4c41b timeslider: prerequisites for time travel
Thomas Junk <thomas.junk@intevation.de>
parents: 5074
diff changeset
108 },
aeb100b4c41b timeslider: prerequisites for time travel
Thomas Junk <thomas.junk@intevation.de>
parents: 5074
diff changeset
109 ongoingTimeSlide() {
aeb100b4c41b timeslider: prerequisites for time travel
Thomas Junk <thomas.junk@intevation.de>
parents: 5074
diff changeset
110 if (this.ongoingTimeSlide) return;
aeb100b4c41b timeslider: prerequisites for time travel
Thomas Junk <thomas.junk@intevation.de>
parents: 5074
diff changeset
111 this.$store.commit(
aeb100b4c41b timeslider: prerequisites for time travel
Thomas Junk <thomas.junk@intevation.de>
parents: 5074
diff changeset
112 "application/setCurrentVisibleTime",
5085
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
113 this.refreshLayersTime
5075
aeb100b4c41b timeslider: prerequisites for time travel
Thomas Junk <thomas.junk@intevation.de>
parents: 5074
diff changeset
114 );
5080
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
115 },
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
116 selectedTime() {
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
117 this.triggerMapReload();
5082
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
118 },
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
119 sourcesLoading() {
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
120 // initiate refresh layers request if the time for the finished request
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
121 // differs from the selected time on time slider
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
122 if (this.sourcesLoading !== 0) return;
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
123 if (compareAsc(this.selectedTime, this.currentVisibleTime) === 0) return;
5085
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
124 this.triggerMapReload();
5040
066b76ef5e6a selected time is refreshed after reloads
Thomas Junk <thomas.junk@intevation.de>
parents: 5039
diff changeset
125 }
066b76ef5e6a selected time is refreshed after reloads
Thomas Junk <thomas.junk@intevation.de>
parents: 5039
diff changeset
126 },
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
127 computed: {
5080
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
128 ...mapState("application", [
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
129 "showTimeSlider",
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
130 "paneSetup",
5085
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
131 "currentVisibleTime",
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
132 "refreshLayersTime"
5080
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
133 ]),
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
134 ...mapState("map", [
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
135 "ongoingRefresh",
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
136 "ongoingTimeSlide",
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
137 "openLayersMaps"
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
138 ]),
5046
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
139 dateSelection: {
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
140 get() {
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
141 const date = this.$store.state.application.selectedTime;
5045
a7cda81bf96f client: better formatting of time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5044
diff changeset
142 return format(date, "YYYY-MM-DD");
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
143 },
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
144 set(value) {
5057
abe3a70526a6 fix accidental deletion of current input
Thomas Junk <thomas.junk@intevation.de>
parents: 5056
diff changeset
145 if (!value) return;
5063
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
146 let date = new Date(value);
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
147 const [hours, minutes] = this.timeSelection.split(":");
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
148 date = setHours(date, hours);
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
149 date = setMinutes(date, minutes);
5149
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
150 if (date > new Date()) return;
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
151 this.$store.commit("application/setSelectedTime", date);
5060
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
152 this.rescaleSlider(50);
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
153 }
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
154 },
5046
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
155 timeSelection: {
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
156 get() {
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
157 const time = this.$store.state.application.selectedTime;
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
158 return format(time, "HH:mm");
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
159 },
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
160 set(value) {
5057
abe3a70526a6 fix accidental deletion of current input
Thomas Junk <thomas.junk@intevation.de>
parents: 5056
diff changeset
161 if (!value) return;
5046
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
162 let date = this.selectedTime;
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
163 date = setHours(date, value.split(":")[0]);
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
164 date = setMinutes(date, value.split(":")[1]);
5149
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
165 if (date > new Date()) return;
5046
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
166 this.$store.commit("application/setSelectedTime", date);
5060
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
167 this.rescaleSlider(800);
5046
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
168 }
b5e77c43fb8b client: add Time picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5045
diff changeset
169 },
5037
9d288d9b851b client: move selectedTime to store
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5036
diff changeset
170 selectedTime: {
9d288d9b851b client: move selectedTime to store
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5036
diff changeset
171 get() {
9d288d9b851b client: move selectedTime to store
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5036
diff changeset
172 return this.$store.state.application.selectedTime;
9d288d9b851b client: move selectedTime to store
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5036
diff changeset
173 },
9d288d9b851b client: move selectedTime to store
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5036
diff changeset
174 set(value) {
5063
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
175 if (!this.isSelectedTimeHourly) {
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
176 value = setHours(value, 12);
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
177 value = setMinutes(value, 0);
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
178 }
5037
9d288d9b851b client: move selectedTime to store
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5036
diff changeset
179 this.$store.commit("application/setSelectedTime", value);
9d288d9b851b client: move selectedTime to store
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5036
diff changeset
180 }
5080
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
181 },
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
182 sourcesLoading() {
5084
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
183 const layers = [
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
184 "BOTTLENECKS",
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
185 "GAUGES",
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
186 "FAIRWAYDIMENSIONSLOS1",
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
187 "FAIRWAYDIMENSIONSLOS2",
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
188 "FAIRWAYDIMENSIONSLOS3",
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
189 "WATERWAYAXIS",
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
190 "FAIRWAYMARKS"
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
191 ];
5080
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
192 let counter = 0;
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
193 this.openLayersMaps.forEach(map => {
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
194 for (let i = 0; i < layers.length; i++) {
5084
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
195 let layer = map.getLayer(layers[i]);
2c3108152497 timeslider: only watch timebased layers
Thomas Junk <thomas.junk@intevation.de>
parents: 5083
diff changeset
196 if (layer.getSource().loading) counter++;
5080
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
197 }
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
198 });
faa1521e597b client: Reload layers with value from time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5075
diff changeset
199 return counter;
5082
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
200 }
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
201 },
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
202 methods: {
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
203 close() {
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
204 this.$store.commit("application/showTimeSlider", false);
5090
70bd5c824639 client: distinguish time in refreshLayers requests during Time-slider enable/disable
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5085
diff changeset
205 this.$store.commit("application/setStoredTime", this.currentVisibleTime);
70bd5c824639 client: distinguish time in refreshLayers requests during Time-slider enable/disable
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5085
diff changeset
206 this.$store.commit("application/setSelectedTime", new Date());
5082
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
207 },
5085
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
208 triggerMapReload() {
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
209 // trigger refresh layers only when last loading of layers was ended
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
210 if (this.sourcesLoading) {
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
211 return;
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
212 }
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
213 this.$store.commit(
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
214 "application/setLayerRefreshedTime",
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
215 this.selectedTime
fe63733750d7 client: correct refresh layers request time
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5084
diff changeset
216 );
5082
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
217 this.$store.commit("map/startTimeSlide");
5083
5ec30f63fd58 client: reload only the relevant layers with changed value on time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5082
diff changeset
218 this.$store.dispatch("map/refreshTimebasedLayers");
5082
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
219 this.$nextTick(() => {
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
220 this.$store.commit("map/finishTimeSlide");
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
221 });
c4ebb6ccc588 client: start a request for the last changed time on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5080
diff changeset
222 },
5060
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
223 rescaleSlider(scaleFactor) {
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
224 const tx =
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
225 -scaleFactor *
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
226 this.getScale()(d3.isoParse(this.selectedTime.toISOString())) +
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
227 document.getElementById("sliderContainer").clientWidth / 2;
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
228 var t = d3.zoomIdentity.translate(tx, 0).scale(scaleFactor);
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
229 this.getScale().domain(t.rescaleX(this.getScale()));
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
230 d3.select(".zoom").call(zoom.transform, t);
ed1d963017e7 client: improve behavior of time-slider during the use of date/time picker
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5058
diff changeset
231 },
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
232 createSlider() {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
233 const element = document.getElementById("sliderContainer");
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
234 const svgWidth = element ? element.clientWidth : 0,
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
235 svgHeight = 40,
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
236 marginTop = 20,
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
237 marginLeft = 0;
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
238
5044
ca5b1b5a553a client: date localization for time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5043
diff changeset
239 d3.timeFormatDefaultLocale(localeDateString);
5061
37371727f704 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5060
diff changeset
240 xScale = this.getScale();
37371727f704 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5060
diff changeset
241 xAxis = this.getAxes();
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
242 let svg = d3
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
243 .select(".sliderContainer")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
244 .append("svg")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
245 .attr("width", svgWidth)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
246 .attr("height", svgHeight);
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
247
5038
9d26f67dd916 client: add date picker to the time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5037
diff changeset
248 zoom = d3
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
249 .zoom()
5041
abe9b75686ba client: set wheeldelta to facilitate quick changes of zoomlevel
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5040
diff changeset
250 .scaleExtent([0.8, 102000])
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
251 .translateExtent([[0, 0], [svgWidth, svgHeight]])
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
252 .extent([[0, 0], [(svgWidth, svgHeight)]])
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
253 .on("zoom", this.zoomed);
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
254
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
255 svg
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
256 .append("g")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
257 .attr("class", "axis--x")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
258 .attr("transform", `translate(${marginLeft}, ${marginTop})`)
5061
37371727f704 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5060
diff changeset
259 .call(xAxis);
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
260
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
261 // create rectanlge on the slider area to capture mouse events
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
262 const eventRect = svg
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
263 .append("rect")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
264 .attr("id", "zoom")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
265 .attr("class", "zoom")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
266 .attr("width", svgWidth)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
267 .attr("height", svgHeight)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
268 .attr("fill", "white")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
269 .attr("opacity", 0.2)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
270 .on("mouseover", () => {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
271 svg.select(".zoom").attr("cursor", "move");
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
272 });
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
273 eventRect.call(zoom).on("click", this.onClick);
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
274
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
275 const toIsoDate = d => {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
276 return d.toISOString();
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
277 };
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
278
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
279 let drag = d3
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
280 .drag()
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
281 .on("start", () => {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
282 d3.select(".line")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
283 .raise()
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
284 .classed("active", true);
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
285 })
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
286 .on("drag", this.onDrag)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
287 .on("end", () => {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
288 d3.select(".line").classed("active", false);
5149
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
289 const now = new Date();
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
290 if (this.selectedTime > now) this.selectedTime = now;
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
291 d3.select(".line").attr(
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
292 "x",
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
293 xAxis.scale()(d3.isoParse(this.selectedTime))
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
294 );
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
295 });
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
296
5149
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
297 svg
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
298 .append("rect")
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
299 .attr("class", "future")
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
300 .attr("x", xAxis.scale()(d3.isoParse(toIsoDate(new Date()))))
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
301 .attr("y", 0)
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
302 .attr("width", svgWidth)
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
303 .attr("height", svgHeight)
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
304 .attr("fill", "#333333")
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
305 .attr("opacity", 0.3);
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
306
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
307 // Create cursor to indicate to the selected time
5126
ee559cd0731f Backed out changeset 67efc7e4df4b
Thomas Junk <thomas.junk@intevation.de>
parents: 5125
diff changeset
308 svg
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
309 .append("rect")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
310 .attr("class", "line")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
311 .attr("id", "scrubber")
5064
d87438a8c891 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5063
diff changeset
312 .attr("x", xAxis.scale()(d3.isoParse(toIsoDate(this.selectedTime))))
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
313 .attr("y", 0)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
314 .attr("width", 2)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
315 .attr("height", svgHeight)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
316 .attr("stroke", "#17a2b8")
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
317 .attr("stroke-width", 2)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
318 .attr("opacity", 0.6)
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
319 .on("mouseover", () => {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
320 svg.select(".line").attr("cursor", "e-resize");
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
321 })
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
322 .call(drag);
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
323 },
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
324 getScale() {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
325 return d3
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
326 .scaleTime()
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
327 .range([0, document.getElementById("sliderContainer").clientWidth || 0])
5039
aec0923f9c52 icon shows now date and time
Thomas Junk <thomas.junk@intevation.de>
parents: 5038
diff changeset
328 .domain([d3.isoParse(new Date("2015-01-01")), d3.isoParse(new Date())]);
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
329 },
5043
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
330 getAxes() {
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
331 const axesFormat = date => {
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
332 return (d3.timeSecond(date) < date
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
333 ? d3.timeFormat(".%L")
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
334 : d3.timeMinute(date) < date
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
335 ? d3.timeFormat(":%S")
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
336 : d3.timeHour(date) < date
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
337 ? d3.timeFormat("%H:%M")
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
338 : d3.timeDay(date) < date
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
339 ? d3.timeFormat("%H:%M")
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
340 : d3.timeMonth(date) < date
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
341 ? d3.timeWeek(date) < date
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
342 ? d3.timeFormat(app.$gettext("%a %d"))
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
343 : d3.timeFormat(app.$gettext("%b %d"))
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
344 : d3.timeYear(date) < date
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
345 ? d3.timeFormat("%B")
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
346 : d3.timeFormat("%Y"))(date);
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
347 };
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
348 return d3
5064
d87438a8c891 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5063
diff changeset
349 .axisBottom(xScale)
5043
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
350 .ticks(12)
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
351 .tickFormat(axesFormat);
bae2548dc484 client: improve the axes labeling for time-slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5041
diff changeset
352 },
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
353 zoomed() {
5064
d87438a8c891 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5063
diff changeset
354 let newX = d3.event.transform.rescaleX(xScale);
5072
51b30f7c64a2 Timeslider proper rescale
Thomas Junk <thomas.junk@intevation.de>
parents: 5071
diff changeset
355 currentScaleFactor = d3.event.transform.k;
5062
da28a58eb10d client: correct showing of time in toolbar according to zoom level(selected time)
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5061
diff changeset
356 const isHourly = currentScaleFactor > 400;
5063
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
357 if (this.isSelectedTimeHourly != isHourly)
43bebcc8961f client: set time according to zoom level.
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5062
diff changeset
358 this.isSelectedTimeHourly = isHourly;
5064
d87438a8c891 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5063
diff changeset
359 xAxis.scale(newX);
5061
37371727f704 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5060
diff changeset
360 d3.select(".axis--x").call(xAxis);
5064
d87438a8c891 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5063
diff changeset
361 d3.select(".line").attr("x", newX(d3.isoParse(this.selectedTime)));
5149
21fe34ac7498 timelider: greyout future
Thomas Junk <thomas.junk@intevation.de>
parents: 5126
diff changeset
362 d3.select(".future").attr("x", newX(d3.isoParse(new Date())));
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
363 },
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
364 onClick() {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
365 // Extract the click location
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
366 let point = d3.mouse(document.getElementById("zoom")),
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
367 p = { x: point[0], y: point[1] };
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
368 d3.select(".line").attr("x", p.x);
5150
6a6eaa536787 client: fix cursor placement on time slider
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5149
diff changeset
369 this.selectedTime = d3.isoParse(xAxis.scale().invert(p.x + 2));
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
370 },
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
371 onDrag() {
5064
d87438a8c891 client: improve time-slider code
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5063
diff changeset
372 this.selectedTime = d3.isoParse(xAxis.scale().invert(d3.event.x + 2));
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
373 d3.select(".line").attr("x", d3.event.x);
5071
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
374 },
5072
51b30f7c64a2 Timeslider proper rescale
Thomas Junk <thomas.junk@intevation.de>
parents: 5071
diff changeset
375 redrawTimeSlider() {
5071
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
376 const bodyWidth = document.querySelector("body").clientWidth;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
377 const timeSelectionWidth = document.querySelector("#timeselection")
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
378 .clientWidth;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
379 const closeButton = document.querySelector("#closebutton").clientWidth;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
380 const svgWidth = bodyWidth - timeSelectionWidth - closeButton;
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
381 document
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
382 .querySelector(".sliderContainer svg")
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
383 .setAttribute("width", svgWidth);
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
384 xScale.range([0, svgWidth]);
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
385 xAxis.scale(xScale);
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
386 d3.select(".axis--x").call(xAxis);
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
387 d3.select(".line").attr(
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
388 "x",
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
389 xAxis.scale()(d3.isoParse(this.selectedTime))
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
390 );
5072
51b30f7c64a2 Timeslider proper rescale
Thomas Junk <thomas.junk@intevation.de>
parents: 5071
diff changeset
391 this.rescaleSlider(currentScaleFactor);
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
392 }
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
393 },
5067
99ac62a56dd2 client: add window resize event listener
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5066
diff changeset
394 created() {
5072
51b30f7c64a2 Timeslider proper rescale
Thomas Junk <thomas.junk@intevation.de>
parents: 5071
diff changeset
395 this.resizeListenerFunction = debounce(this.redrawTimeSlider, 100);
5067
99ac62a56dd2 client: add window resize event listener
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5066
diff changeset
396 window.addEventListener("resize", this.resizeListenerFunction);
99ac62a56dd2 client: add window resize event listener
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5066
diff changeset
397 },
5071
45d868476dea timeslider: resizable
Thomas Junk <thomas.junk@intevation.de>
parents: 5070
diff changeset
398 destroyed() {
5067
99ac62a56dd2 client: add window resize event listener
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5066
diff changeset
399 window.removeEventListener("resize", this.resizeListenerFunction);
99ac62a56dd2 client: add window resize event listener
Fadi Abbud <fadi.abbud@intevation.de>
parents: 5066
diff changeset
400 },
5036
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
401 mounted() {
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
402 setTimeout(this.createSlider, 150);
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
403 }
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
404 };
8f421cd3c746 client: Implemented first version of time-sliding
Fadi Abbud <fadi.abbud@intevation.de>
parents:
diff changeset
405 </script>