Passed
Push — develop ( 9a1b4b...96b452 )
by Xaver
03:40
created

lib/gui.js   A

Complexity

Total Complexity 11
Complexity/F 1.38

Size

Lines of Code 143
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 100
mnd 3
bc 3
fnc 8
dl 0
loc 143
rs 10
bpm 0.375
cpm 1.375
noi 0
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A gui.js ➔ onclick 0 9 2
A gui.js ➔ mkView 0 5 2
A gui.js ➔ removeContent 0 12 4
A gui.js ➔ addContent 0 9 1
1
define(['d3-interpolate', 'map', 'sidebar', 'tabs', 'container', 'legend',
2
  'linklist', 'nodelist', 'simplenodelist', 'infobox/main',
3
  'proportions', 'forcegraph', 'title', 'about', 'datadistributor',
4
  'filters/filtergui', 'filters/hostname', 'helper'],
5
function (d3Interpolate, Map, Sidebar, Tabs, Container, Legend, Linklist,
6
  Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
7
  Title, About, DataDistributor, FilterGUI, HostnameFilter, helper) {
8
  'use strict';
9
10
  return function (language) {
11
    var self = this;
12
    var content;
13
    var contentDiv;
14
15
    var linkScale = d3Interpolate.interpolate(config.map.tqFrom, config.map.tqTo);
16
    var sidebar;
17
18
    var buttons = document.createElement('div');
19
    buttons.classList.add('buttons');
20
21
    var fanout = new DataDistributor();
22
    var fanoutUnfiltered = new DataDistributor();
23
    fanoutUnfiltered.add(fanout);
24
25
    function removeContent() {
26
      if (!content) {
27
        return;
28
      }
29
30
      router.removeTarget(content);
31
      fanout.remove(content);
32
33
      content.destroy();
34
35
      content = null;
36
    }
37
38
    function addContent(K) {
39
      removeContent();
40
41
      content = new K(linkScale, sidebar, buttons);
42
      content.render(contentDiv);
43
44
      fanout.add(content);
45
      router.addTarget(content);
46
    }
47
48
    function mkView(K) {
49
      return function () {
50
        addContent(K);
51
      };
52
    }
53
54
    var loader = document.getElementsByClassName('loader')[0];
55
    loader.classList.add('hide');
56
57
    contentDiv = document.createElement('div');
58
    contentDiv.classList.add('content');
59
    document.body.appendChild(contentDiv);
60
61
    sidebar = new Sidebar(document.body);
62
63
    contentDiv.appendChild(buttons);
64
65
    var buttonToggle = document.createElement('button');
66
    buttonToggle.classList.add('ion-eye');
67
    buttonToggle.setAttribute('aria-label', _.t('button.switchView'));
68
    buttonToggle.onclick = function onclick() {
69
      var data;
70
      if (content.constructor === Map) {
71
        data = { view: 'graph', lat: undefined, lng: undefined, zoom: undefined };
72
      } else {
73
        data = { view: 'map' };
74
      }
75
      router.fullUrl(data, false, true);
76
    };
77
78
    buttons.appendChild(buttonToggle);
79
80
    if (config.fullscreen || config.fullscreenFrame && window.frameElement) {
81
      var buttonFullscreen = document.createElement('button');
82
      buttonFullscreen.classList.add('ion-full-enter');
83
      buttonFullscreen.setAttribute('aria-label', _.t('button.fullscreen'));
84
      buttonFullscreen.onclick = function onclick() {
85
        helper.fullscreen(buttonFullscreen);
86
      };
87
88
      buttons.appendChild(buttonFullscreen);
89
    }
90
91
    var title = new Title();
92
93
    var header = new Container('header');
94
    var infobox = new Infobox(sidebar, linkScale);
95
    var tabs = new Tabs();
96
    var overview = new Container();
97
    var legend = new Legend(language);
98
    var newnodeslist = new SimpleNodelist('new', 'firstseen', _.t('node.new'));
99
    var lostnodeslist = new SimpleNodelist('lost', 'lastseen',  _.t('node.missing'));
100
    var nodelist = new Nodelist();
101
    var linklist = new Linklist(linkScale);
102
    var statistics = new Proportions(fanout);
103
    var about = new About();
104
105
    fanoutUnfiltered.add(legend);
106
    fanoutUnfiltered.add(newnodeslist);
107
    fanoutUnfiltered.add(lostnodeslist);
108
    fanoutUnfiltered.add(infobox);
109
    fanout.add(nodelist);
110
    fanout.add(linklist);
111
    fanout.add(statistics);
112
113
    sidebar.add(header);
114
    header.add(legend);
115
116
    overview.add(newnodeslist);
117
    overview.add(lostnodeslist);
118
119
    var filterGUI = new FilterGUI(fanout);
120
    fanout.watchFilters(filterGUI);
121
    header.add(filterGUI);
122
123
    var hostnameFilter = new HostnameFilter();
124
    fanout.addFilter(hostnameFilter);
125
126
    sidebar.add(tabs);
127
    tabs.add('sidebar.actual', overview);
128
    tabs.add('node.nodes', nodelist);
129
    tabs.add('node.links', linklist);
130
    tabs.add('sidebar.stats', statistics);
131
    tabs.add('sidebar.about', about);
132
133
    router.addTarget(title);
134
    router.addTarget(infobox);
135
136
    router.addView('map', mkView(Map));
137
    router.addView('graph', mkView(ForceGraph));
138
139
    self.setData = fanoutUnfiltered.setData;
140
141
    return self;
142
  };
143
});
144