Skip to content

Commit 11805a5

Browse files
committed
More graceful display when insufficient data available. Closes #8
1 parent 500c384 commit 11805a5

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/widgets/chart.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export default {
128128
return config
129129
}
130130
},
131-
watch: {
131+
watch: {
132132
currentPeriod: {
133133
immediate: true,
134134
handler(newVal, oldVal) {
@@ -212,7 +212,8 @@ export default {
212212
if(this.currentPeriod == 'day') {
213213
let labels = Object.keys(response)
214214
formatedLabels = labels.map(key => {
215-
return parseInt(key) + 1 + 'h'
215+
let label = parseInt(key) + 1 + 'h'
216+
return isFinite(label) ? label : ''
216217
})
217218
tooltipLabels = formatedLabels
218219
dataset = labels.map(key => {
@@ -240,4 +241,4 @@ export default {
240241
},
241242
}
242243
}
243-
</script>
244+
</script>

src/components/widgets/overview.vue

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</div>
1515
<div class="details">{{ $t('matomo.visits').toLowerCase() }} {{ $t('matomo.period.'+currentPeriod) }}.</div>
1616
</div>
17-
<div :class="['difference', visitsDiff.status, {grey: loading}]">
17+
<div v-if="isFinite(visitsDiff.diff)" :class="['difference', visitsDiff.status, {grey: loading}]">
1818
<span v-if="loading"><span class="loader"></span></span>
1919
<span v-else>{{visitsDiff.string}}%</span>
2020
<div v-if="!loading" class="icon"><svg><use href="#icon-matomo-arrow-up" /></svg></div>
@@ -28,7 +28,7 @@
2828
<span v-else>{{durationString}}</span></div>
2929
<div class="details">{{ $t('matomo.duration.caption') }}.</div>
3030
</div>
31-
<div :class="['difference', durationDiff.status, {grey: loading}]">
31+
<div v-if="isFinite(durationDiff.diff)" :class="['difference', durationDiff.status, {grey: loading}]">
3232
<span v-if="loading"><span class="loader"></span></span>
3333
<span v-else>{{durationDiff.string}}%</span>
3434
<div v-if="!loading" class="icon"><svg><use href="#icon-matomo-arrow-up" /></svg></div>
@@ -39,11 +39,11 @@
3939
<h5>{{ $t('matomo.bounce') }}</h5>
4040
<div class="big-number">
4141
<span v-if="loading"><span class="loader"></span></span>
42-
<span v-else>{{current.bounce}}%</span>
42+
<span v-else>{{bounceString}}</span>
4343
</div>
4444
<div class="details">{{ $t('matomo.bounce.caption') }}.</div>
4545
</div>
46-
<div :class="['difference', bounceDiff.status, {grey: loading}]">
46+
<div v-if="isFinite(bounceDiff.diff)" :class="['difference', bounceDiff.status, {grey: loading}]">
4747
<span v-if="loading"><span class="loader"></span></span>
4848
<span v-else>{{bounceDiff.string}}%</span>
4949
<div v-if="!loading" class="icon"><svg><use href="#icon-matomo-arrow-up" /></svg></div>
@@ -54,11 +54,11 @@
5454
<h5>{{ $t('matomo.actions') }}</h5>
5555
<div class="big-number">
5656
<span v-if="loading"><span class="loader"></span></span>
57-
<span v-else>{{current.actions}}</span>
57+
<span v-else>{{actionsString}}</span>
5858
</div>
5959
<div class="details">{{ $t('matomo.actions.caption') }}.</div>
6060
</div>
61-
<div :class="['difference', actionsDiff.status, {grey: loading}]">
61+
<div v-if="isFinite(actionsDiff.diff)" :class="['difference', actionsDiff.status, {grey: loading}]">
6262
<span v-if="loading"><span class="loader"></span></span>
6363
<span v-else>{{actionsDiff.string}}%</span>
6464
<div v-if="!loading" class="icon"><svg><use href="#icon-matomo-arrow-up" /></svg></div>
@@ -107,7 +107,8 @@ export default {
107107
let string = prefix + Math.abs(diff)
108108
return {
109109
string: string,
110-
status: status
110+
status: status,
111+
diff: diff
111112
}
112113
},
113114
durationDiff() {
@@ -117,7 +118,8 @@ export default {
117118
let string = prefix + Math.abs(diff)
118119
return {
119120
string: string,
120-
status: status
121+
status: status,
122+
diff: diff
121123
}
122124
},
123125
bounceDiff() {
@@ -127,7 +129,8 @@ export default {
127129
let string = prefix + Math.abs(diff)
128130
return {
129131
string: string,
130-
status: status
132+
status: status,
133+
diff: diff
131134
}
132135
},
133136
actionsDiff() {
@@ -137,12 +140,19 @@ export default {
137140
let string = prefix + Math.abs(diff)
138141
return {
139142
string: string,
140-
status: status
143+
status: status,
144+
diff: diff
141145
}
142146
},
143147
durationString() {
144148
return this.formatTime(this.current.duration)
145149
},
150+
bounceString() {
151+
return !isFinite(this.current.bounce) ? '' : this.current.bounce + '%'
152+
},
153+
actionsString() {
154+
return !isFinite(this.current.actions) ? '' : this.current.actions + '%'
155+
},
146156
isPositive() {
147157
return !this.loading
148158
},
@@ -254,7 +264,7 @@ export default {
254264
},
255265
formatTime(time) {
256266
let t = Math.floor(time)
257-
return (t - (t%=60)) / 60 + (9 < t ? 'mn ' : 'mn 0') + t + 's'
267+
return isFinite(t) ? (t - (t%=60)) / 60 + (9 < t ? 'mn ' : 'mn 0') + t + 's' : ''
258268
},
259269
firstN(obj, n) {
260270
return Object.keys(obj).slice(0, n).reduce(function(el, index) {
@@ -327,7 +337,7 @@ export default {
327337
},
328338
diff(current, prev) {
329339
let diff = (current - prev) / prev * 100
330-
return diff.toFixed(2)
340+
return diff.toFixed(2)
331341
}
332342
},
333343
}

0 commit comments

Comments
 (0)