Welcome to mirror list, hosted at ThFree Co, Russian Federation.

graph_bar.vue « components « branches « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 21cbcac820a65f88017def1ccc729e3bb84215cd (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
<script>
import { SIDES, MAX_COMMIT_COUNT } from '../constants';

export default {
  props: {
    position: {
      type: String,
      required: true,
    },
    count: {
      type: Number,
      required: true,
    },
    maxCommits: {
      type: Number,
      required: true,
    },
  },
  computed: {
    label() {
      if (this.count >= MAX_COMMIT_COUNT) {
        return `${MAX_COMMIT_COUNT - 1}+`;
      }

      return this.count;
    },
    barGraphWidthFactor() {
      return this.maxCommits > 0 ? 100 / this.maxCommits : 0;
    },
    style() {
      return {
        width: `${this.count * this.barGraphWidthFactor}%`,
      };
    },
    isFullWidth() {
      return this.position === SIDES.full;
    },
    isLeftSide() {
      return this.position === SIDES.left;
    },
    roundedClass() {
      if (this.isFullWidth) return 'rounded';

      return `rounded-${this.position}`;
    },
    textAlignmentClass() {
      if (this.isFullWidth) return 'text-center';

      return `text-${this.isLeftSide ? SIDES.right : SIDES.left}`;
    },
    positionSideClass() {
      return `position-${this.isLeftSide ? SIDES.right : SIDES.left}-0`;
    },
  },
};
</script>

<template>
  <div :class="{ full: isFullWidth }" class="position-relative float-left pt-1 graph-side h-100">
    <div
      :style="style"
      :class="[roundedClass, positionSideClass]"
      class="position-absolute bar js-graph-bar"
    ></div>
    <span :class="textAlignmentClass" class="d-block pt-1 pr-1 count js-graph-count">
      {{ label }}
    </span>
  </div>
</template>