File size: 1,223 Bytes
63858e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import * as d3 from 'd3'

d3.selection.prototype.clear = function() {  
    this.selectAll('*').remove();
    return this;
}

d3.selection.prototype.toggleClass = function(className) {  
    this.classed(className, !this.classed(className));
    return this;
}

d3.selection.prototype.show = function() {  
    this.style('display', 'initial');
    return this;
}

d3.selection.prototype.hide = function() {  
    this.style('display', 'none');
    return this;
}

d3.selection.prototype.toggle = function() {  
    var isHidden = this.style('display') == 'none';
    return this.style('display', isHidden ? 'inherit' : 'none');
}

d3.selection.prototype.after = function(tagName) {  
    var elements = [];
  
    this.each(function() {
      var element = document.createElement(tagName);
      this.parentNode.insertBefore(element, this.nextSibling);
      elements.push(element);
    });
  
    return d3.selectAll(elements);
  }

d3.selection.prototype.before = function(tagName) {  
    var elements = [];
  
    this.each(function() {
      var element = document.createElement(tagName);
      this.parentNode.insertBefore(element, this);
      elements.push(element);
    });
  
    return d3.selectAll(elements);
}