1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<script>
import { formatRelevantDigits } from '~/lib/utils/number_utils';
export default {
props: {
legendTitle: {
type: String,
required: true,
},
timeSeries: {
type: Array,
required: true,
},
currentDataIndex: {
type: Number,
required: true,
},
unitOfDisplay: {
type: String,
required: true,
},
},
methods: {
formatMetricUsage(series) {
const value =
series.values[this.currentDataIndex] && series.values[this.currentDataIndex].value;
if (isNaN(value)) {
return '-';
}
return `${formatRelevantDigits(value)} ${this.unitOfDisplay}`;
},
summaryMetrics(series) {
return `Avg: ${formatRelevantDigits(series.average)} · Max: ${formatRelevantDigits(series.max)}`;
},
strokeDashArray(type) {
if (type === 'dashed') return '6, 3';
if (type === 'dotted') return '3, 3';
return null;
},
},
};
</script>
<template>
<div class="prometheus-graph-legends prepend-left-10">
<table class="prometheus-table">
<tr
v-for="(series, index) in timeSeries"
:key="index"
>
<td>
<svg
width="15"
height="6"
>
<line
:stroke-dasharray="strokeDashArray(series.lineStyle)"
:stroke="series.lineColor"
stroke-width="4"
:x1="0"
:x2="15"
:y1="2"
:y2="2"
/>
</svg>
</td>
<td
class="legend-metric-title"
v-if="timeSeries.length > 1"
>
<template v-if="series.metricTag">
<strong>{{ series.metricTag }}</strong>
{{ formatMetricUsage(series) }} {{ summaryMetrics(series) }}
</template>
<template v-else>
<strong>{{ legendTitle }}</strong>
series {{ index + 1 }} {{ formatMetricUsage(series) }} {{ summaryMetrics(series) }}
</template>
</td>
<td v-else>
<strong>{{ legendTitle }}</strong>
{{ formatMetricUsage(series) }} {{ summaryMetrics(series) }}
</td>
</tr>
</table>
</div>
</template>
|