File size: 1,307 Bytes
fe66731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Contains the logic for the reset button.
 *
 * @param graph the associated webvowl graph
 * @returns {{}}
 */
module.exports = function ( graph ){
  
  var resetMenu = {},
    options = graph.graphOptions(),
    resettableModules,
    untouchedOptions = webvowl.options();
  
  
  /**
   * Adds the reset button to the website.
   * @param _resettableModules modules that can be resetted
   */
  resetMenu.setup = function ( _resettableModules ){
    resettableModules = _resettableModules;
    d3.select("#reset-button").on("click", resetGraph);
    var menuEntry = d3.select("#resetOption");
    menuEntry.on("mouseover", function (){
      var searchMenu = graph.options().searchMenu();
      searchMenu.hideSearchEntries();
    });
  };
  
  function resetGraph(){
    graph.resetSearchHighlight();
    graph.options().searchMenu().clearText();
    options.classDistance(untouchedOptions.classDistance());
    options.datatypeDistance(untouchedOptions.datatypeDistance());
    options.charge(untouchedOptions.charge());
    options.gravity(untouchedOptions.gravity());
    options.linkStrength(untouchedOptions.linkStrength());
    graph.reset();
    
    resettableModules.forEach(function ( module ){
      module.reset();
    });
    
    graph.updateStyle();
  }
  
  
  return resetMenu;
};