lighthouse_garden/templates/assets/js/graph.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.25

Size

Lines of Code 64
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 51
dl 0
loc 64
rs 10
c 0
b 0
f 0
mnd 1
bc 1
fnc 4
bpm 0.25
cpm 1.25
noi 1
1
document.addEventListener('DOMContentLoaded', function() {
2
    var classes = document.getElementsByClassName('graph');
3
4
    var layout = {
5
      showlegend: false,
6
      height: 80,
7
      width: 300,
8
      xaxis: {
9
        showline: false,
10
        showgrid: false,
11
        showticklabels: false,
12
        linecolor: 'rgb(204,204,204)',
13
        linewidth: 2,
14
        autotick: false,
15
        ticks: 'outside',
16
        tickcolor: 'rgb(204,204,204)',
17
        tickwidth: 0,
18
        ticklen: 0,
19
      },
20
      yaxis: {
21
        showgrid: false,
22
        zeroline: false,
23
        showline: false,
24
        showticklabels: false
25
      },
26
      autosize: false,
27
      margin: {
28
        autoexpand: false,
29
        l: 0,
30
        r: 0,
31
        t: 0,
32
        b: 30
33
      },
34
    };
35
36
    var i;
37
    for (i = 0; i < classes.length; i++) {
38
      var values_y = classes[i].getAttribute('data-values-y').split(',');
39
      var values_x = classes[i].getAttribute('data-values-x').split(',');
40
      var values_text = classes[i].getAttribute('data-values-text').split(',');
41
      var id = classes[i].getAttribute('id');
42
      var trace1 = {
43
          y: values_y,
44
          x: values_x,
45
          z: values_text,
46
          type: 'lines'
47
      };
48
      var data = [trace1];
49
      var myPlot = document.getElementById(id);
50
51
      Plotly.newPlot(id, data, layout, {displayModeBar: false});
0 ignored issues
show
Bug introduced by
The variable Plotly seems to be never declared. If this is a global, consider adding a /** global: Plotly */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
52
53
        myPlot.on('plotly_click', function(data){
54
            data.points.map(function(d){
55
              var key = Object.keys(d.data.x).find(key => d.data.x[key] === d.x);
56
              var modal = $('#frameModal');
57
              modal.find('.modal-title').text('Report ' + d.data.x[key]);
58
              modal.find('.modal-body').html('<iframe src="' + d.data.z[key] + '">');
59
              modal.find('.modal-body iframe').height(0.8 * $(document).height());
60
              modal.modal('show');
61
            });
62
        });
63
    }
64
});
65
66