@sedoo/unidoo 0.0.49 → 0.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sedoo/unidoo",
3
- "version": "0.0.49",
3
+ "version": "0.0.53",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "build": "vue-cli-service build --target lib --name unidoo src/plugin.js",
@@ -16,6 +16,7 @@
16
16
  "src/**/*"
17
17
  ],
18
18
  "dependencies": {
19
+ "ol": "^6.8.1",
19
20
  "v-tooltip": "^2.1.3",
20
21
  "vue-axios": "3.2.4"
21
22
  },
@@ -6,7 +6,7 @@
6
6
  <v-card-actions>
7
7
  <v-spacer></v-spacer>
8
8
  <v-btn @click="confirmDialog=false">{{ cancelButtonLabel }}</v-btn>
9
- <v-btn color="info" @click="confirm">{{ confirmButtonLabel }}</v-btn>
9
+ <v-btn color="info" @click="confirm" :loading="loading">{{ confirmButtonLabel }}</v-btn>
10
10
  </v-card-actions>
11
11
  </v-card>
12
12
  </v-dialog>
@@ -27,13 +27,16 @@ export default {
27
27
  width: '500px',
28
28
  cancelButtonLabel: "Cancel",
29
29
  confirmButtonLabel: "Confirm",
30
- callback: {}
30
+ callback: {},
31
+ loading: false
31
32
  }
32
33
  },
33
34
  methods: {
34
- confirm: function() {
35
+ async confirm () {
36
+ this.loading = true
37
+ await this.callback()
35
38
  this.confirmDialog = false
36
- this.callback()
39
+ this.loading = false
37
40
  },
38
41
 
39
42
  show (params) {
@@ -0,0 +1,89 @@
1
+ /* eslint-disable no-new */
2
+ <template>
3
+ <div ref="map-root" style="width: 100%; height: 100%"></div>
4
+ </template>
5
+
6
+ <script>
7
+ import View from 'ol/View'
8
+ import Map from 'ol/Map'
9
+ import TileLayer from 'ol/layer/Tile'
10
+ import OSM from 'ol/source/OSM'
11
+ import GeoJSON from 'ol/format/GeoJSON';
12
+ import VectorLayer from 'ol/layer/Vector'
13
+ import VectorSource from 'ol/source/Vector'
14
+ import { Stroke, Style } from 'ol/style';
15
+ // importing the OpenLayers stylesheet is required for having
16
+ // good looking buttons!
17
+ import 'ol/ol.css'
18
+
19
+ export default {
20
+ name: 'MapContainer',
21
+ components: {},
22
+ props: {
23
+ color: {
24
+ type: String,
25
+ default: 'red',
26
+ },
27
+ json: {
28
+ type: String,
29
+ default: '',
30
+ },
31
+ },
32
+ mounted() {
33
+ this.axios.get(this.json)
34
+ .then(res => {
35
+ const geoJsonObject = res.data
36
+ geoJsonObject.crs = {
37
+ type: 'name',
38
+ properties: {
39
+ name: 'EPSG:3857',
40
+ },
41
+ }
42
+ const styles = {
43
+ LineString: new Style({
44
+ stroke: new Stroke({
45
+ color: this.color,
46
+ width: 2,
47
+ }),
48
+ }),
49
+ }
50
+ const styleFunction = function (feature) {
51
+ return styles[feature.getGeometry().getType()];
52
+ };
53
+ const vectorSource = new VectorSource({
54
+ features: new GeoJSON().readFeatures(geoJsonObject, {
55
+ dataProjection: 'EPSG:4326',
56
+ featureProjection: 'EPSG:3857'
57
+ })
58
+ })
59
+
60
+ const vectorLayer = new VectorLayer({
61
+ source: vectorSource,
62
+ style: styleFunction,
63
+ });
64
+
65
+ // this is where we create the OpenLayers map
66
+ // eslint-disable-next-line no-new
67
+ new Map({
68
+ // the map will be created using the 'map-root' ref
69
+ target: this.$refs['map-root'],
70
+ layers: [
71
+ // adding a background tiled layer
72
+ new TileLayer({
73
+ source: new OSM() // tiles are served by OpenStreetMap
74
+ }),
75
+ vectorLayer
76
+ ],
77
+
78
+ // the map view will initially show the whole world
79
+ view: new View({
80
+ zoom: 0,
81
+ center: [0, 0],
82
+ constrainResolution: true,
83
+ projection: 'EPSG:3857'
84
+ }),
85
+ }).getView().fit(vectorSource.getExtent());
86
+ })
87
+ },
88
+ }
89
+ </script>
@@ -46,7 +46,7 @@
46
46
  :id="id"
47
47
  :max="max"
48
48
  :min="min"
49
- :tick-labels="graduation"
49
+ :tick-labels="filteredGraduation"
50
50
  hide-details
51
51
  ticks="always"
52
52
  tick-size="4"
@@ -75,7 +75,7 @@
75
75
 
76
76
  </template>
77
77
  </v-slider>
78
-
78
+ <iframe ref="sizeHandlerIframe" src="about:blank" style="width:100%; height:0; border:0;"></iframe>
79
79
  </v-col>
80
80
  </v-list-item>
81
81
 
@@ -127,7 +127,9 @@ export default {
127
127
  isPlaying: false,
128
128
  clickedValue: null,
129
129
  id: null,
130
- isZoomed: false
130
+ isZoomed: false,
131
+ filteredGraduation: [],
132
+ sliderSize: null
131
133
  }),
132
134
 
133
135
  computed: {
@@ -143,6 +145,7 @@ export default {
143
145
  const vh = (this.isZoomed) ? '60vh' : '40vh';
144
146
  return { gridTemplateRows: ((this.playerBarTop) ? '10px 140px 10px ' + vh + ' 10px' : '10px ' + vh + ' 10px 140px 10px')};
145
147
  }
148
+
146
149
  },
147
150
 
148
151
  watch: {
@@ -172,7 +175,17 @@ export default {
172
175
  self.focusSlider();
173
176
  })
174
177
  }
178
+ },
179
+
180
+ graduation(){
181
+ this.initGraduation();
182
+ },
183
+
184
+ sliderSize(){
185
+ this.initGraduation();
175
186
  }
187
+
188
+
176
189
  },
177
190
 
178
191
  created() {
@@ -189,10 +202,12 @@ export default {
189
202
  this.play();
190
203
  }
191
204
  document.dispatchEvent(new CustomEvent('show-play'));
205
+ this.initIframe();
192
206
  },
193
207
 
194
208
  beforeDestroy() {
195
209
  this.stop();
210
+ this.clearIframe();
196
211
  },
197
212
 
198
213
  destroyed() {
@@ -204,7 +219,6 @@ export default {
204
219
  },
205
220
 
206
221
  methods: {
207
-
208
222
  play() {
209
223
  if (this.max === 0 || !this.canPlay) {
210
224
  return;
@@ -321,6 +335,75 @@ export default {
321
335
  this.$emit('reload-frames');
322
336
  },
323
337
 
338
+ initGraduation(){
339
+ let result = [];
340
+ if(this.graduation){
341
+ const gradsLength = this.graduation.length;
342
+ let delta = 1;
343
+ if(this.sliderSize && gradsLength && this.graduation[0]){
344
+ const firstGrad = this.graduation[0].length * 9; // nb chars * number of pixels for 1 character
345
+ let exceed = Math.ceil(this.sliderSize - (gradsLength * firstGrad) - 30); // add 30px of margin
346
+ exceed = (exceed < 0) ? - exceed : 0;
347
+ const gradsExceed = exceed / firstGrad;
348
+ if(gradsLength - gradsExceed){
349
+ delta = Math.ceil(gradsLength / (gradsLength - gradsExceed));
350
+ } else {
351
+ delta = Math.ceil(gradsLength);
352
+ }
353
+ }
354
+
355
+ let n = 0;
356
+ this.graduation.forEach(element => {
357
+ if (n % delta) {
358
+ result.push(null);
359
+ } else {
360
+ result.push(element);
361
+ }
362
+ n++;
363
+ });
364
+ }
365
+
366
+ this.filteredGraduation = result;
367
+ },
368
+
369
+ initIframe(){
370
+ const iframe = this.$refs.sizeHandlerIframe;
371
+ if(iframe){
372
+ const box = iframe.getBoundingClientRect();
373
+ this.sliderSize = box.width - 114 -9 -32 -10; // - padding and margin
374
+ const iframeWin = iframe.contentWindow;
375
+ this.resizeListener = this.handleResize.bind(this);
376
+ iframeWin.addEventListener('resize', this.resizeListener);
377
+ }
378
+ },
379
+
380
+ clearIframe(){
381
+ const iframe = this.$refs.sizeHandlerIframe;
382
+ if(iframe){
383
+ const iframeWin = iframe.contentWindow;
384
+ if(iframeWin){
385
+ iframeWin.removeEventListener('resize', this.resizeListener);
386
+ }
387
+ this.resizeListener = null;
388
+ }
389
+ },
390
+
391
+ handleResize(){
392
+ // add a delay of 500ms to handle slider width resize
393
+ if(this.timer !== null){
394
+ clearTimeout(this.timer);
395
+ }
396
+ const self = this;
397
+ this.timer = setTimeout(() => {
398
+ const box = self.$refs.sizeHandlerIframe.getBoundingClientRect();
399
+ const sliderWidth = box.width - 114 -9 -32 -10;
400
+ if(self.sliderSize != sliderWidth){
401
+ self.sliderSize = sliderWidth;
402
+ }
403
+ self.time = null;
404
+ }, 200);
405
+ },
406
+
324
407
  create_UUID() {
325
408
  var dt = new Date().getTime();
326
409
  var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
@@ -144,27 +144,10 @@ export default {
144
144
 
145
145
  initGraduation() {
146
146
  if (this.entries && this.entries.length) {
147
- const entriesLength = this.entries.length;
148
- if (entriesLength <= 8) {
149
147
  this.graduation = []
150
148
  this.entries.forEach(element => {
151
149
  this.graduation.push(element.type);
152
150
  });
153
- } else {
154
- const firstType = this.entries[0].type;
155
- const typeLengthFactor = (firstType.length < 5) ? 1 : (firstType.length / 6);
156
- const delta = (entriesLength <= 30) ? 2 : Math.round((entriesLength * typeLengthFactor) / 10);
157
- this.graduation = []
158
- let n = 0;
159
- this.entries.forEach(element => {
160
- if (n % delta) {
161
- this.graduation.push(null);
162
- } else {
163
- this.graduation.push(element.type);
164
- }
165
- n++;
166
- });
167
- }
168
151
  }
169
152
  },
170
153
 
package/src/plugin.js CHANGED
@@ -149,7 +149,7 @@ function install(Vue) {
149
149
  plugin.EventBus.$emit("unidoo-crud-show", params)
150
150
  },
151
151
  }
152
-
152
+
153
153
  Vue.prototype.$unidooHeatmap = {
154
154
  setDate(date, key) {
155
155
  plugin.EventBus.$emit("unidoo-heatmap-set-date", { date: date, key: key })