summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/monitoring/components/graph/legend.vue
blob: 140190d34a95a6994077daf954fcaa06f2701638 (plain)
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
<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,
    },
  },
  methods: {
    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>
          <strong>{{ series.track }}</strong>
        </td>
        <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> {{ summaryMetrics(series) }}
          </template>
          <template v-else>
            <strong>{{ legendTitle }}</strong>
            series {{ index + 1 }} {{ summaryMetrics(series) }}
          </template>
        </td>
        <td v-else>
          <strong>{{ legendTitle }}</strong> {{ summaryMetrics(series) }}
        </td>
      </tr>
    </table>
  </div>
</template>