@sedoo/unidoo 0.1.71 → 0.1.73

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.
@@ -4,86 +4,92 @@
4
4
  </template>
5
5
 
6
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'
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
18
 
19
- export default {
20
- name: 'MapContainer',
21
- components: {},
22
- props: {
19
+ export default {
20
+ name: "MapContainer",
21
+ components: {},
22
+ props: {
23
23
  color: {
24
24
  type: String,
25
- default: 'red',
25
+ default: "red"
26
26
  },
27
27
  json: {
28
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
- })
29
+ default: ""
30
+ }
31
+ },
32
+ mounted() {
33
+ this.axios
34
+ .get(this.json)
35
+ .then((res) => {
36
+ const geoJsonObject = res.data;
37
+ geoJsonObject.crs = {
38
+ type: "name",
39
+ properties: {
40
+ name: "EPSG:3857"
41
+ }
42
+ };
43
+ const styles = {
44
+ LineString: new Style({
45
+ stroke: new Stroke({
46
+ color: this.color,
47
+ width: 2
58
48
  })
49
+ })
50
+ };
51
+ const styleFunction = function (feature) {
52
+ return styles[feature.getGeometry().getType()];
53
+ };
54
+ const vectorSource = new VectorSource({
55
+ features: new GeoJSON().readFeatures(geoJsonObject, {
56
+ dataProjection: "EPSG:4326",
57
+ featureProjection: "EPSG:3857"
58
+ })
59
+ });
59
60
 
60
- const vectorLayer = new VectorLayer({
61
- source: vectorSource,
62
- style: styleFunction,
63
- });
61
+ const vectorLayer = new VectorLayer({
62
+ source: vectorSource,
63
+ style: styleFunction
64
+ });
64
65
 
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
- ],
66
+ // this is where we create the OpenLayers map
67
+ // eslint-disable-next-line no-new
68
+ new Map({
69
+ // the map will be created using the 'map-root' ref
70
+ target: this.$refs["map-root"],
71
+ layers: [
72
+ // adding a background tiled layer
73
+ new TileLayer({
74
+ source: new OSM() // tiles are served by OpenStreetMap
75
+ }),
76
+ vectorLayer
77
+ ],
77
78
 
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());
79
+ // the map view will initially show the whole world
80
+ view: new View({
81
+ zoom: 0,
82
+ center: [0, 0],
83
+ constrainResolution: true,
84
+ projection: "EPSG:3857"
85
+ })
86
86
  })
87
- },
87
+ .getView()
88
+ .fit(vectorSource.getExtent());
89
+ })
90
+ .catch((e) => {
91
+ console.error(e);
92
+ });
88
93
  }
94
+ };
89
95
  </script>
@@ -1,74 +1,80 @@
1
-
2
1
  export default class CalendarHeatmap {
3
- constructor (year, values, max) {
4
- this.year = this._parseDate(year)
5
- if (typeof max === 'number' && max >= 0) {
6
- this.max = max
2
+ constructor(year, values, max) {
3
+ if (typeof window === "undefined") return;
4
+ this.year = this._parseDate(year);
5
+ if (typeof max === "number" && max >= 0) {
6
+ this.max = max;
7
7
  } else {
8
- this.max = Math.ceil((Math.max(...values.map(day => day.count)) / 5) * 4)
8
+ this.max = Math.ceil(
9
+ (Math.max(...values.map((day) => day.count)) / 5) * 4
10
+ );
9
11
  }
10
- this.values = values.map(v => { return { date: this._valuesDateFormat(v.date), count: v.count } })
11
- this.times = this._getTimes(this.year.getFullYear())
12
- this.times.sort()
12
+ this.values = values.map((v) => {
13
+ return { date: this._valuesDateFormat(v.date), count: v.count };
14
+ });
15
+ this.times = this._getTimes(this.year.getFullYear());
16
+ this.times.sort();
13
17
  }
14
18
 
15
- get activities () {
19
+ get activities() {
16
20
  return this.values.reduce((newValues, day) => {
17
21
  newValues[this._keyDayParser(day.date)] = {
18
22
  count: day.count,
19
23
  colorIndex: this.getColorIndex(day.count)
20
- }
21
- return newValues
22
- }, {})
24
+ };
25
+ return newValues;
26
+ }, {});
23
27
  }
24
28
 
25
- get monthCalendar () {
26
- const year = this.year.getFullYear()
27
- const date = new Date(year, 0, 1).toUnidooUTC()
28
- let i = 0
29
- return Array.from({ length: 12 },
30
- () => Array.from({ length: this.daysInMonth(year, i++) },
31
- () => {
32
- const dDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()).toUnidooUTC()
33
- const dayValues = this.activities[this._keyDayParser(dDate)]
34
- date.setDate(date.getDate() + 1)
35
- return {
36
- date: dDate,
37
- count: dayValues ? dayValues.count : null,
38
- colorIndex: dayValues ? dayValues.colorIndex : 0
39
- }
40
- }
41
- )
42
- )
29
+ get monthCalendar() {
30
+ const year = this.year.getFullYear();
31
+ const date = new Date(year, 0, 1).toUnidooUTC();
32
+ let i = 0;
33
+ return Array.from({ length: 12 }, () =>
34
+ Array.from({ length: this.daysInMonth(year, i++) }, () => {
35
+ const dDate = new Date(
36
+ date.getFullYear(),
37
+ date.getMonth(),
38
+ date.getDate()
39
+ ).toUnidooUTC();
40
+ const dayValues = this.activities[this._keyDayParser(dDate)];
41
+ date.setDate(date.getDate() + 1);
42
+ return {
43
+ date: dDate,
44
+ count: dayValues ? dayValues.count : null,
45
+ colorIndex: dayValues ? dayValues.colorIndex : 0
46
+ };
47
+ })
48
+ );
43
49
  }
44
50
 
45
- daysInMonth (year, month) {
46
- return new Date(year, month + 1, 0).toUnidooUTC().getDate()
51
+ daysInMonth(year, month) {
52
+ return new Date(year, month + 1, 0).toUnidooUTC().getDate();
47
53
  }
48
54
 
49
55
  daysInYear(year) {
50
- const start = new Date(year, 0, 0).toUnidooUTC()
51
- const end = new Date(year, 11, 31).toUnidooUTC()
52
- const diff = end - start
53
- return Math.floor(diff / (1000 * 60 * 60 * 24))
56
+ const start = new Date(year, 0, 0).toUnidooUTC();
57
+ const end = new Date(year, 11, 31).toUnidooUTC();
58
+ const diff = end - start;
59
+ return Math.floor(diff / (1000 * 60 * 60 * 24));
54
60
  }
55
61
 
56
- getColorIndex (value) {
62
+ getColorIndex(value) {
57
63
  if (value == null || value === undefined) {
58
- return 0
64
+ return 0;
59
65
  } else if (value >= this.max) {
60
- return 5
66
+ return 5;
61
67
  } else if (value <= 0) {
62
- return 1
68
+ return 1;
63
69
  } else {
64
- return (Math.ceil(((value * 100) / this.max) * (0.03))) + 1
70
+ return Math.ceil(((value * 100) / this.max) * 0.03) + 1;
65
71
  }
66
72
  }
67
73
 
68
74
  getDayFromDate(entry) {
69
- if (entry) {
75
+ if (entry) {
70
76
  const sdate = this._valuesDateFormat(entry);
71
- const day = this.values.filter(d => d.date === sdate)[0];
77
+ const day = this.values.filter((d) => d.date === sdate)[0];
72
78
  if (day) {
73
79
  return {
74
80
  date: new Date(day.date).toUnidooUTC(),
@@ -76,108 +82,119 @@ export default class CalendarHeatmap {
76
82
  colorIndex: this.getColorIndex(day.count)
77
83
  };
78
84
  } else {
79
- return { date: new Date(entry).toUnidooUTC(), count: NaN, colorIndex: 0 };
85
+ return {
86
+ date: new Date(entry).toUnidooUTC(),
87
+ count: NaN,
88
+ colorIndex: 0
89
+ };
80
90
  }
81
91
  }
82
92
  }
83
93
 
84
94
  getNextAvailableDate(date, countGreaterThanZero) {
85
95
  if (date) {
86
- date.setHours(0, 0, 0)
96
+ date.setHours(0, 0, 0);
87
97
  if (this.times && this.times.length) {
88
- let index = this.times.indexOf(this._encodeDate(date, null))
89
- if (index < 0) index = this.times.indexOf(this._encodeDate(date, 1))
90
- if (index < 0) index = this.times.indexOf(this._encodeDate(date, 0))
98
+ let index = this.times.indexOf(this._encodeDate(date, null));
99
+ if (index < 0) index = this.times.indexOf(this._encodeDate(date, 1));
100
+ if (index < 0) index = this.times.indexOf(this._encodeDate(date, 0));
91
101
  if (index >= 0) {
92
- const maxIndex = this.times.length - 1
93
- let n = index + 1
102
+ const maxIndex = this.times.length - 1;
103
+ let n = index + 1;
94
104
  if (countGreaterThanZero) {
95
105
  while (n <= maxIndex) {
96
- const curr = this.times[n]
97
- if (curr.endsWith('i')) return this._decodeDate(curr)
98
- n++
106
+ const curr = this.times[n];
107
+ if (curr.endsWith("i")) return this._decodeDate(curr);
108
+ n++;
99
109
  }
100
110
  } else {
101
111
  while (n <= maxIndex) {
102
- const curr = this.times[n]
103
- if (!curr.endsWith('n')) return this._decodeDate(curr)
104
- n++
112
+ const curr = this.times[n];
113
+ if (!curr.endsWith("n")) return this._decodeDate(curr);
114
+ n++;
105
115
  }
106
116
  }
107
- }
117
+ }
108
118
  }
109
119
  }
110
- return null
120
+ return null;
111
121
  }
112
122
 
113
123
  getPreviousAvailableDate(date, countGreaterThanZero) {
114
- if (date) {
115
- date.setHours(0, 0, 0)
124
+ if (date) {
125
+ date.setHours(0, 0, 0);
116
126
  if (this.times && this.times.length) {
117
- let index = this.times.indexOf(this._encodeDate(date, null))
118
- if (index < 0) index = this.times.indexOf(this._encodeDate(date, 1))
119
- if (index < 0) index = this.times.indexOf(this._encodeDate(date, 0))
127
+ let index = this.times.indexOf(this._encodeDate(date, null));
128
+ if (index < 0) index = this.times.indexOf(this._encodeDate(date, 1));
129
+ if (index < 0) index = this.times.indexOf(this._encodeDate(date, 0));
120
130
  if (index >= 0) {
121
- let n = index - 1
131
+ let n = index - 1;
122
132
  if (countGreaterThanZero) {
123
133
  while (n >= 0) {
124
- const curr = this.times[n]
125
- if (curr.endsWith('i')) return this._decodeDate(curr)
126
- n--
134
+ const curr = this.times[n];
135
+ if (curr.endsWith("i")) return this._decodeDate(curr);
136
+ n--;
127
137
  }
128
138
  } else {
129
139
  while (n >= 0) {
130
- const curr = this.times[n]
131
- if (!curr.endsWith('n')) return this._decodeDate(curr)
132
- n--
140
+ const curr = this.times[n];
141
+ if (!curr.endsWith("n")) return this._decodeDate(curr);
142
+ n--;
133
143
  }
134
144
  }
135
145
  }
136
146
  }
137
147
  }
138
- return null
148
+ return null;
139
149
  }
140
150
 
141
- _getTimes (year) {
142
- const date = new Date(year, 0, 1).toUnidooUTC()
143
- return Array.from({ length: this.daysInYear(year) },
144
- () => {
145
- const dDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()).toUnidooUTC()
146
- dDate.setHours(0, 0, 0)
147
- const dayValues = this.activities[this._keyDayParser(dDate)]
148
- date.setDate(date.getDate() + 1)
149
- return this._encodeDate(dDate, (dayValues) ? dayValues.count : null)
150
- }
151
- )
151
+ _getTimes(year) {
152
+ const date = new Date(year, 0, 1).toUnidooUTC();
153
+ return Array.from({ length: this.daysInYear(year) }, () => {
154
+ const dDate = new Date(
155
+ date.getFullYear(),
156
+ date.getMonth(),
157
+ date.getDate()
158
+ ).toUnidooUTC();
159
+ dDate.setHours(0, 0, 0);
160
+ const dayValues = this.activities[this._keyDayParser(dDate)];
161
+ date.setDate(date.getDate() + 1);
162
+ return this._encodeDate(dDate, dayValues ? dayValues.count : null);
163
+ });
152
164
  }
153
-
154
- _valuesDateFormat (d) {
155
- if (!d) return ''
156
- const date = this._parseDate(d)
157
- return `${date.getFullYear()}-${this._paddNumber(date.getMonth() + 1)}-${this._paddNumber(date.getDate())}`
165
+
166
+ _valuesDateFormat(d) {
167
+ if (!d) return "";
168
+ const date = this._parseDate(d);
169
+ return `${date.getFullYear()}-${this._paddNumber(
170
+ date.getMonth() + 1
171
+ )}-${this._paddNumber(date.getDate())}`;
158
172
  }
159
173
 
160
- _paddNumber (n) {
161
- return ('' + n).padStart(2, '0')
174
+ _paddNumber(n) {
175
+ return ("" + n).padStart(2, "0");
162
176
  }
163
177
 
164
- _encodeDate (d, count) {
165
- const date = this._parseDate(d)
166
- return this._valuesDateFormat(date) + ((Number.isFinite(count)) ? ((count > 0) ? 'i' : 'o') : 'n')
178
+ _encodeDate(d, count) {
179
+ const date = this._parseDate(d);
180
+ return (
181
+ this._valuesDateFormat(date) +
182
+ (Number.isFinite(count) ? (count > 0 ? "i" : "o") : "n")
183
+ );
167
184
  }
168
185
 
169
- _decodeDate (d) {
170
- if (!d) return null
171
- const sdate = d.slice(0, -1)
172
- return new Date(sdate).toUnidooUTC()
186
+ _decodeDate(d) {
187
+ if (!d) return null;
188
+ const sdate = d.slice(0, -1);
189
+ return new Date(sdate).toUnidooUTC();
173
190
  }
174
191
 
175
- _parseDate (entry) {
176
- return (entry instanceof Date) ? entry : (new Date(entry).toUnidooUTC())
192
+ _parseDate(entry) {
193
+ return entry instanceof Date ? entry : new Date(entry).toUnidooUTC();
177
194
  }
178
195
 
179
- _keyDayParser (date) {
180
- const day = this._parseDate(date)
181
- return `${day.getFullYear()}-${day.getMonth()}-${day.getDate()}`
196
+ _keyDayParser(date) {
197
+ const day = this._parseDate(date);
198
+ return `${day.getFullYear()}-${day.getMonth()}-${day.getDate()}`;
182
199
  }
183
- }
200
+ }