@@ -19,65 +19,29 @@ const Bubblechart = (aData) => {
19
19
}
20
20
21
21
let svg = d3 . select ( '#chart' ) . append ( 'svg' )
22
-
22
+
23
23
. attr ( 'viewBox' , '0 0 ' + ( diameter + margin . right ) + ' ' + diameter )
24
24
. attr ( 'width' , ( diameter + margin . right ) )
25
25
. attr ( 'height' , diameter )
26
26
. attr ( 'class' , 'chart-svg' ) ;
27
27
28
-
29
-
28
+
29
+
30
30
31
31
let root = d3 . hierarchy ( jsonToDisplay )
32
32
. sum ( function ( d ) { console . log ( d . id ) ; return d . id ; } )
33
-
33
+
34
34
. sort ( function ( a , b ) { return b . id - a . id } ) ;
35
-
36
-
35
+
36
+
37
37
bubble ( root ) ;
38
38
39
39
let node = svg . selectAll ( 'node' )
40
40
. data ( root . children )
41
- . enter ( ) . append ( 'g' )
41
+ . enter ( ) . append ( 'g' )
42
42
. attr ( 'class' , 'node' )
43
43
. attr ( 'transform' , function ( d ) { return 'translate(' + d . x + ' ' + d . y + ')' ; } )
44
44
45
-
46
-
47
- /*let tooltip = node.append('tooltip')
48
- .append("div")
49
- .style("opacity", 0)
50
- .attr("class", "tooltip")
51
- .style("z-index", "10")
52
- .style("background-color", "black")
53
- .style("border-radius", "5px")
54
- .style("padding", "10px")
55
- .style("color", "white")
56
-
57
- let showTooltip = function(d) {
58
- tooltip
59
- .transition()
60
- .duration(200)
61
- .style("opacity", 1)
62
- .style("stroke", "black")
63
- .text(function (d) {
64
- console.log("contribution" + d.data.contributions);
65
- return "Name : " + d.data.login + "<br/>Contribution: " + d.contributions })
66
- .style("left", (d.x + (d3.pointer(this)[0] + 90)) + "px")
67
- .style("top", (d.y + (d3.pointer(this)[1])) + "px");
68
- }
69
- let moveTooltip = function(d) {
70
- tooltip
71
- .style("left", (d.x + (d3.pointer(this)[0] + 30)) + "px")
72
- .style("top", (d.y + (d3.pointer(this)[1] + 30)) + "px");
73
- }
74
- let hideTooltip = function(d) {
75
- tooltip
76
- .transition()
77
- .duration(200)
78
- .style("opacity", 0)
79
- .style("visibility", "hidden");
80
- }*/
81
45
82
46
let defs = node . append ( 'defs' ) ;
83
47
@@ -94,13 +58,13 @@ const Bubblechart = (aData) => {
94
58
. attr ( 'width' , function ( d ) { return d . r * 2 * 1.02 } )
95
59
. attr ( "x" , 0 )
96
60
. attr ( "y" , 0 ) ;
97
-
98
-
99
-
100
-
61
+
62
+
63
+
64
+
101
65
node . append ( "circle" )
102
66
. attr ( 'r' , function ( d ) {
103
- return d . r / ( Math . sqrt ( 1.5 ) ) ;
67
+ return d . r / ( Math . sqrt ( 1.5 ) ) ;
104
68
} )
105
69
. style ( "fill" , "#fff" )
106
70
. style ( "fill" , function ( d ) { return "url(#" + d . data . id + ")" } )
@@ -109,27 +73,27 @@ const Bubblechart = (aData) => {
109
73
. on ( "mousemove" , mousemove )
110
74
. on ( "mouseout" , mouseout ) ;
111
75
112
-
113
- let div = d3 . select ( "#bubble" ) . append ( "div" )
76
+
77
+ let div = d3 . select ( "#bubble" ) . append ( "div" )
114
78
. attr ( "class" , "tooltip" )
115
79
. style ( "display" , "none" ) ;
116
80
117
- function mouseover ( ) {
118
- div . style ( "display" , "inline" ) ;
119
- }
81
+ function mouseover ( ) {
82
+ div . style ( "display" , "inline" ) ;
83
+ }
120
84
121
- function mousemove ( event , d ) {
122
- const [ x , y ] = d3 . pointer ( event ) ;
123
- div
85
+ function mousemove ( event , d ) {
86
+ const [ x , y ] = d3 . pointer ( event ) ;
87
+ div
124
88
. text ( x + ", " + y )
125
89
. style ( "left" , ( x ) + "px" )
126
90
. style ( "top" , ( y ) + "px" ) ;
127
- }
91
+ }
92
+
93
+ function mouseout ( ) {
94
+ div . style ( "display" , "none" ) ;
95
+ }
128
96
129
- function mouseout ( ) {
130
- div . style ( "display" , "none" ) ;
131
- }
132
-
133
97
134
98
node . append ( "text" )
135
99
. attr ( "dy" , ".3em" )
@@ -146,7 +110,7 @@ function mouseout() {
146
110
147
111
148
112
return (
149
- < div id = "bubble" className = "bubble" >
113
+ < div id = "bubble" className = "bubble" >
150
114
< svg id = "chart" className = "chart" > </ svg >
151
115
</ div >
152
116
) ;
0 commit comments