@@ -4,9 +4,9 @@ import "./Bubblechart.css";
4
4
5
5
6
6
const Bubblechart = ( aData ) => {
7
- let jsonToDisplay = { "children" :[ ...aData . data ] } ;
8
- let diameter = 1000 ,
9
- color = d3 . scaleOrdinal ( [ "#1f77b4" , "#ff7f0e" , "#2ca02c" , "#d62728" , "#9467bd" , "#8c564b" , "#e377c2" , "#7f7f7f" , "#bcbd22" , "#17becf" ] ) ;
7
+ let jsonToDisplay = { "children" : [ ...aData . data ] } ;
8
+ let diameter = 1000 ;
9
+ // color = d3.scaleOrdinal(["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"]);
10
10
let bubble = d3 . pack ( )
11
11
. size ( [ diameter , diameter ] )
12
12
. padding ( 2 ) ;
@@ -19,49 +19,84 @@ const Bubblechart = (aData) => {
19
19
}
20
20
21
21
let svg = d3 . select ( '#chart' ) . append ( 'svg' )
22
+
22
23
. attr ( 'viewBox' , '0 0 ' + ( diameter + margin . right ) + ' ' + diameter )
23
24
. attr ( 'width' , ( diameter + margin . right ) )
24
25
. attr ( 'height' , diameter )
25
26
. attr ( 'class' , 'chart-svg' ) ;
26
27
27
28
29
+
30
+
28
31
let root = d3 . hierarchy ( jsonToDisplay )
29
- . sum ( function ( d ) { return d . id } )
32
+ . sum ( function ( d ) { console . log ( d . id ) ; return d . id ; } )
33
+
30
34
. sort ( function ( a , b ) { return b . id - a . id } ) ;
31
35
32
36
33
37
bubble ( root ) ;
34
38
35
39
let node = svg . selectAll ( 'node' )
36
40
. data ( root . children )
37
- . enter ( )
38
- . append ( 'g' ) . attr ( 'class' , 'node' )
39
- . attr ( 'transform' , function ( d ) { return 'translate(' + d . x + ' ' + d . y + ')' ; } )
41
+ . enter ( ) . append ( 'g' )
42
+ . attr ( 'class' , 'node' )
43
+ . attr ( 'transform' , function ( d ) { return 'translate(' + d . x + ' ' + d . y + ')' ; } )
44
+
45
+
46
+ let defs = node . append ( 'defs' ) ;
47
+
48
+ defs . append ( "pattern" )
49
+ . attr ( "id" , function ( d ) { console . log ( d . data . id ) ; return d . data . id } )
50
+
51
+ . attr ( "width" , 10 )
52
+ . attr ( "height" , 10 )
53
+ . append ( "image" )
54
+ . attr ( "xlink:href" , function ( d ) {
55
+ return d . data . avatar_url
56
+ } )
57
+ . attr ( 'height' , function ( d ) { return d . r * 2 } )
58
+ . attr ( 'width' , function ( d ) { return d . r * 2 * 1.02 } )
59
+ . attr ( "x" , 0 )
60
+ . attr ( "y" , 0 ) ;
40
61
41
62
42
63
node . append ( "circle" )
43
64
. attr ( 'r' , function ( d ) {
44
- return d . r ;
65
+ return d . r / ( Math . sqrt ( 1.5 ) ) ;
45
66
} )
46
- . style ( "fill" , function ( d ) {
47
- return color ( d ) ;
48
- } ) ;
67
+ . style ( "fill" , "#fff" )
68
+ . style ( "fill" , function ( d ) { return "url(#" + d . data . id + ")" } )
69
+ . style ( "stroke" , "black" )
70
+ . on ( "mouseover" , mouseover )
71
+ . on ( "mousemove" , mousemove )
72
+ . on ( "mouseout" , mouseout ) ;
73
+
74
+
75
+ let div = d3 . select ( "#bubble" ) . append ( "div" )
76
+ . attr ( "class" , "tooltip" )
77
+ . style ( "display" , "none" ) ;
78
+
79
+ function mouseover ( ) {
80
+ div . style ( "display" , "inline" ) ;
81
+ }
82
+
83
+ function mousemove ( event , d ) {
84
+
85
+ div
86
+ . text ( d . data . login + ", " + d . data . contributions )
87
+ . style ( "left" , ( d . x + 150 ) + "px" )
88
+ . style ( "top" , ( d . y ) + "px" )
89
+
90
+ }
49
91
50
- node . append ( "text" )
51
- . attr ( "dy" , ".3em" )
52
- . style ( "text-anchor" , "middle" )
53
- . text ( function ( d ) { return d . data . login } )
54
- . style ( "fill" , "#ffffff" ) ;
92
+ function mouseout ( d ) {
93
+ div . style ( "display" , "none" ) ;
94
+ }
55
95
56
- node . append ( "text" )
57
- . attr ( "dy" , "2em" )
58
- . style ( "text-anchor" , "middle" )
59
- . text ( function ( d ) { return d . data . contributions } )
60
- . style ( "fill" , "#EEEfff" ) ;
61
96
62
97
63
98
return (
64
- < div >
99
+ < div id = "bubble" className = "bubble" >
65
100
< svg id = "chart" className = "chart" > </ svg >
66
101
</ div >
67
102
) ;
0 commit comments