@@ -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 ) ;
@@ -25,9 +25,10 @@ const Bubblechart = (aData) => {
25
25
. attr ( 'class' , 'chart-svg' ) ;
26
26
27
27
28
+
28
29
let root = d3 . hierarchy ( jsonToDisplay )
29
30
. sum ( function ( d ) { return d . id } )
30
- . sort ( function ( a , b ) { return b . id - a . id } ) ;
31
+ // .sort(function (a, b) { return b.id - a.id });
31
32
32
33
33
34
bubble ( root ) ;
@@ -36,30 +37,47 @@ const Bubblechart = (aData) => {
36
37
. data ( root . children )
37
38
. enter ( )
38
39
. append ( 'g' ) . attr ( 'class' , 'node' )
39
- . attr ( 'transform' , function ( d ) { return 'translate(' + d . x + ' ' + d . y + ')' ; } )
40
+ . attr ( 'transform' , function ( d ) { return 'translate(' + d . x + ' ' + d . y + ')' ; } )
41
+
42
+ let defs = node . append ( 'defs' ) ;
40
43
44
+ defs . append ( "pattern" )
45
+ . attr ( "id" , function ( d ) { return d . data . id } )
46
+
47
+ . attr ( "width" , 10 )
48
+ . attr ( "height" , 10 )
49
+ . append ( "image" )
50
+ . attr ( "xlink:href" , function ( d ) {
51
+ return d . data . avatar_url
52
+ } )
53
+ . attr ( 'height' , function ( d ) { return d . r * 2 } )
54
+ . attr ( 'width' , function ( d ) { return d . r * 2 * 1.02 } )
55
+ . attr ( "x" , 0 )
56
+ . attr ( "y" , 0 ) ;
41
57
42
58
node . append ( "circle" )
43
59
. attr ( 'r' , function ( d ) {
44
- return d . r ;
60
+ return d . r / ( Math . sqrt ( 1.5 ) ) ;
45
61
} )
46
- . style ( "fill" , function ( d ) {
47
- return color ( d ) ;
48
- } ) ;
62
+ . style ( "fill" , "#fff" )
63
+ . style ( "fill" , function ( d ) { return "url(#" + d . data . id + ")" } )
64
+ . style ( "stroke" , "black" )
65
+
49
66
50
67
node . append ( "text" )
51
68
. attr ( "dy" , ".3em" )
52
69
. style ( "text-anchor" , "middle" )
53
- . text ( function ( d ) { return d . data . login } )
70
+ . text ( function ( d ) { return d . data . login } )
54
71
. style ( "fill" , "#ffffff" ) ;
55
72
56
73
node . append ( "text" )
57
74
. attr ( "dy" , "2em" )
58
75
. style ( "text-anchor" , "middle" )
59
- . text ( function ( d ) { return d . data . contributions } )
76
+ . text ( function ( d ) { return d . data . contributions } )
60
77
. style ( "fill" , "#EEEfff" ) ;
61
78
62
79
80
+
63
81
return (
64
82
< div >
65
83
< svg id = "chart" className = "chart" > </ svg >
0 commit comments