debian-mirror-gitlab/app/assets/javascripts/monitoring/components/graph/flag.vue

181 lines
4.4 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2018-05-09 12:01:36 +05:30
import { dateFormat, timeFormat } from '../../utils/date_time_formatters';
import { formatRelevantDigits } from '../../../lib/utils/number_utils';
import Icon from '../../../vue_shared/components/icon.vue';
import TrackLine from './track_line.vue';
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
export default {
components: {
Icon,
TrackLine,
},
props: {
currentXCoordinate: {
type: Number,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
currentData: {
type: Object,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
deploymentFlagData: {
type: Object,
required: false,
default: null,
},
graphHeight: {
type: Number,
required: true,
},
graphHeightOffset: {
type: Number,
required: true,
},
realPixelRatio: {
type: Number,
required: true,
},
showFlagContent: {
type: Boolean,
required: true,
},
timeSeries: {
type: Array,
required: true,
},
unitOfDisplay: {
type: String,
required: true,
},
legendTitle: {
type: String,
required: true,
},
2018-10-15 14:42:47 +05:30
currentCoordinates: {
2018-11-20 20:47:30 +05:30
type: Object,
2018-10-15 14:42:47 +05:30
required: true,
},
2018-05-09 12:01:36 +05:30
},
computed: {
formatTime() {
return this.deploymentFlagData
? timeFormat(this.deploymentFlagData.time)
: timeFormat(this.currentData.time);
},
formatDate() {
return this.deploymentFlagData
? dateFormat(this.deploymentFlagData.time)
: dateFormat(this.currentData.time);
},
cursorStyle() {
const xCoordinate = this.deploymentFlagData
? this.deploymentFlagData.xPos
: this.currentXCoordinate;
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
const offsetTop = 20 * this.realPixelRatio;
const offsetLeft = (70 + xCoordinate) * this.realPixelRatio;
const height = (this.graphHeight - this.graphHeightOffset) * this.realPixelRatio;
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
return {
top: `${offsetTop}px`,
left: `${offsetLeft}px`,
height: `${height}px`,
};
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
flagOrientation() {
if (this.currentXCoordinate * this.realPixelRatio > 120) {
return 'left';
}
return 'right';
},
},
methods: {
2018-10-15 14:42:47 +05:30
seriesMetricValue(seriesIndex, series) {
2018-11-20 20:47:30 +05:30
const indexFromCoordinates = this.currentCoordinates[series.metricTag]
? this.currentCoordinates[series.metricTag].currentDataIndex : 0;
2018-05-09 12:01:36 +05:30
const index = this.deploymentFlagData
? this.deploymentFlagData.seriesIndex
2018-10-15 14:42:47 +05:30
: indexFromCoordinates;
2018-05-09 12:01:36 +05:30
const value = series.values[index] && series.values[index].value;
2018-11-08 19:23:39 +05:30
if (Number.isNaN(value)) {
2018-05-09 12:01:36 +05:30
return '-';
}
return `${formatRelevantDigits(value)}${this.unitOfDisplay}`;
},
seriesMetricLabel(index, series) {
if (this.timeSeries.length < 2) {
return this.legendTitle;
}
if (series.metricTag) {
return series.metricTag;
}
return `series ${index + 1}`;
},
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
<div
:style="cursorStyle"
2018-11-08 19:23:39 +05:30
class="prometheus-graph-cursor"
2018-03-17 18:26:18 +05:30
>
<div
v-if="showFlagContent"
:class="flagOrientation"
2018-11-08 19:23:39 +05:30
class="prometheus-graph-flag popover"
2018-03-17 18:26:18 +05:30
>
2018-11-18 11:00:15 +05:30
<div class="arrow-shadow"></div>
2018-03-17 18:26:18 +05:30
<div class="arrow"></div>
<div class="popover-title">
<h5 v-if="deploymentFlagData">
Deployed
</h5>
2018-10-15 14:42:47 +05:30
{{ formatDate }}
2018-03-17 18:26:18 +05:30
<strong>{{ formatTime }}</strong>
</div>
<div
v-if="deploymentFlagData"
class="popover-content deploy-meta-content"
>
<div>
<icon
:size="12"
2018-11-08 19:23:39 +05:30
name="commit"
2018-03-17 18:26:18 +05:30
/>
<a :href="deploymentFlagData.commitUrl">
{{ deploymentFlagData.sha.slice(0, 8) }}
</a>
</div>
<div
v-if="deploymentFlagData.tag"
>
<icon
:size="12"
2018-11-08 19:23:39 +05:30
name="label"
2018-03-17 18:26:18 +05:30
/>
<a :href="deploymentFlagData.tagUrl">
{{ deploymentFlagData.ref }}
</a>
</div>
</div>
<div class="popover-content">
2018-05-09 12:01:36 +05:30
<table class="prometheus-table">
2018-03-17 18:26:18 +05:30
<tr
v-for="(series, index) in timeSeries"
:key="index"
>
2018-05-09 12:01:36 +05:30
<track-line :track="series"/>
2018-03-17 18:26:18 +05:30
<td>
2018-10-15 14:42:47 +05:30
{{ series.track }} {{ seriesMetricLabel(index, series) }}
</td>
<td>
<strong>{{ seriesMetricValue(index, series) }}</strong>
2018-03-17 18:26:18 +05:30
</td>
</tr>
</table>
</div>
</div>
</div>
</template>