summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/monitoring/mixins/monitoring_mixins.js
blob: 4f23814ff3e07a760f5d5aae7e2966a11500d4b3 (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
77
78
79
80
81
import { bisectDate } from '../utils/date_time_formatters';

const mixins = {
  methods: {
    mouseOverDeployInfo(mouseXPos) {
      if (!this.reducedDeploymentData) return false;

      let dataFound = false;
      this.reducedDeploymentData = this.reducedDeploymentData.map((d) => {
        const deployment = d;
        if (d.xPos >= mouseXPos - 10 && d.xPos <= mouseXPos + 10 && !dataFound) {
          dataFound = d.xPos + 1;

          deployment.showDeploymentFlag = true;
        } else {
          deployment.showDeploymentFlag = false;
        }
        return deployment;
      });

      return dataFound;
    },

    formatDeployments() {
      this.reducedDeploymentData = this.deploymentData.reduce((deploymentDataArray, deployment) => {
        const time = new Date(deployment.created_at);
        const xPos = Math.floor(this.timeSeries[0].timeSeriesScaleX(time));

        time.setSeconds(this.timeSeries[0].values[0].time.getSeconds());

        if (xPos >= 0) {
          const seriesIndex = bisectDate(this.timeSeries[0].values, time, 1);

          deploymentDataArray.push({
            id: deployment.id,
            time,
            sha: deployment.sha,
            commitUrl: `${this.projectPath}/commit/${deployment.sha}`,
            tag: deployment.tag,
            tagUrl: deployment.tag ? `${this.tagsPath}/${deployment.ref.name}` : null,
            ref: deployment.ref.name,
            xPos,
            seriesIndex,
            showDeploymentFlag: false,
          });
        }

        return deploymentDataArray;
      }, []);
    },

    positionFlag() {
      const timeSeries = this.timeSeries[0];
      const hoveredDataIndex = bisectDate(timeSeries.values, this.hoverData.hoveredDate, 1);

      this.currentData = timeSeries.values[hoveredDataIndex];
      this.currentXCoordinate = Math.floor(timeSeries.timeSeriesScaleX(this.currentData.time));

      this.currentCoordinates = this.timeSeries.map((series) => {
        const currentDataIndex = bisectDate(series.values, this.hoverData.hoveredDate, 1);
        const currentData = series.values[currentDataIndex];
        const currentX = Math.floor(series.timeSeriesScaleX(currentData.time));
        const currentY = Math.floor(series.timeSeriesScaleY(currentData.value));

        return {
          currentX,
          currentY,
          currentDataIndex,
        };
      });

      if (this.hoverData.currentDeployXPos) {
        this.showFlag = false;
      } else {
        this.showFlag = true;
      }
    },
  },
};

export default mixins;