-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_kmeans.html
executable file
·239 lines (202 loc) · 22.1 KB
/
test_kmeans.html
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body {
background-color: #222
}
svg {
background-color: #202020;
/*border: 1px solid #111*/
}
label {
color: white;
}
</style>
</head>
<body>
<script src="dist/druid.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.9.2/d3.js"></script>
<script>
const width = 600;
const height = width;
const margin = 10;
let svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
const c = d3.scaleOrdinal(d3.schemeDark2);
//let rand = new druid.Randomizer(19870307);
let rand_c = d3.randomNormal(0, 4);
const clusters = 10;
const N = 1000;
const cluster_offsets = [];
for (let i = 0; i < clusters; ++i) {
cluster_offsets.push([rand_c() * 2, rand_c() * 2])
}
let rand = d3.randomNormal(0, 1);
A = d3.range(N).map((d, i) => {
return [
rand() + cluster_offsets[Math.floor(i / (N / clusters))][0],
rand() + cluster_offsets[Math.floor(i / (N / clusters))][1]]
})
A = druid.Matrix.from(A)
/*A = druid.Matrix.from([[-2.1817925404159126,5.825593854666946],[-2.6485126847002,6.007972208547478],[-2.558594085023488,5.3872666568670535],[-3.307488637762188,5.545054281019839],[-2.6209957844562224,5.822426045234735],[-4.559515970036826,5.158245040971013],[-2.0601852317576506,5.428585728745974],[-1.486258597041385,5.566210277460359],[-3.4799755367608016,4.795236710460628],[-1.5402218230185272,5.197281389527364],[-3.2165331500292558,6.054310867790884],[-1.9850711260047276,3.9698811622454313],[-2.6265778270095095,4.680931495946124],[-2.5776927881185605,6.592692126916661],[-2.7843293252347627,4.718536126238221],[-2.893990092279279,4.245260948139656],[-3.328825626352915,4.391750483503824],[-3.0958931869275736,5.882439139943832],[-4.053678718164845,5.606059899129981],[-2.8013073697374864,4.283873348705959],[-1.9873562806727296,4.184374975520446],[-2.0264689060901944,4.198723485647515],[-5.1492497238079515,4.808626877189784],[-4.0681989837156705,5.793631508520054],[-4.082342661362059,4.369182642262513],[-2.8931272984814025,4.5330658815125995],[-4.680099215669067,5.631804406008673],[-1.4347343291539911,3.9954942089427012],[-1.0391825605111407,4.642019826791715],[-2.2074987977056573,6.48502206177015],[-2.5369234637901132,3.912556093885175],[-2.4929682237006285,5.136738883484122],[-1.1540345084427563,3.0361416758659483],[-4.272860760207145,4.72258153873922],[-2.599601506357316,4.601658684883629],[-3.116276899790375,5.920328235828983],[-4.747882224061517,3.5889716994922614],[-1.8114007820554132,4.7867143869375886],[-1.7684064452723376,6.961212457258618],[-2.6181514269043342,4.007033499579363],[-3.9482685087842535,6.122540040761051],[-2.4624839899122084,2.7185155401056056],[-3.399832453944814,4.411841719777226],[-3.6862269279695403,4.906359943012942],[-3.5271516802088305,3.2845128511790174],[-2.9017630172259405,3.2134919091129173],[-3.5410935028966586,4.746824095262538],[-2.7331253564319664,4.9141402302855814],[-3.7412317889463647,4.203903344405415],[-2.1330817621010247,5.054563366790872],[-1.1292369742300936,3.5644451479435033],[-1.3608026520212335,2.721966990472266],[-1.49979845152717,3.9796185152469494],[-0.31720179749770816,4.323903588540554],[-1.6161724824873203,4.937954813637135],[-2.4391209934522378,3.7232384994109875],[-3.8065727694672877,4.24311886450466],[-2.3869441167874,5.687627337662093],[-4.757894843137022,4.204940534464426],[-4.23905444695459,3.4788788984209775],[-1.0339440589640454,5.213971050177782],[-2.9399105511701626,3.6979137704721565],[-3.703135511172118,3.0894013967332157],[-2.329369493036333,4.204367123639573],[-3.216558751627515,5.5851530182280715],[-2.3853241076779574,5.959081649203628],[-2.8695206078100273,3.747103464463877],[-3.1586753689967897,5.604889058632674],[-3.9369653339725525,5.351351822102899],[-3.1552309239766725,4.3914866708251115],[-1.6337392344288213,6.389100029620018],[-2.1376325451017846,4.683500782736571],[-3.6241374820391665,5.25574982886861],[-3.8938585599008197,3.5314184717638812],[-2.2638178645996585,3.452447646192938],[-4.165364981188143,3.960861907554074],[-4.231833626799521,5.627540826180842],[-2.1723647955468075,5.356093777054457],[-3.4306263973819924,5.292232448761585],[-4.3136016083747,3.3477413947607686],[-2.050823365732135,5.529241801757883],[-3.0120362885303518,4.623006331634861],[-0.5761697242286781,5.546307609987798],[-3.5635112041321797,2.7095303627193186],[-3.2019658185797235,4.520440793299666],[-2.7318874161141444,4.69430818418889],[-3.1003919327601173,5.910912460767555],[-1.8606006150089545,3.4729402182242826],[-2.5077867742759787,4.146656672749185],[-3.6247138624159523,5.573655331199032],[-3.255759753063364,3.9769511896733665],[-3.484434073068787,3.2782128315098844],[-2.838302905832063,6.421871179506127],[-3.9467471522284496,4.173565628250303],[-2.980503710714339,5.862337012246723],[-1.6056575015263879,5.385414598562951],[-3.0068915669275205,4.619919811115225],[-1.3492224892688847,3.140438689329933],[-2.316932465625063,5.139424226019749],[-1.680793100520947,5.7077124785099205],[1.2626075666010124,-1.6802825852392282],[3.0347873374119114,-1.7926545273185228],[0.7109604438003583,-0.19353502370136927],[1.456591200644231,-1.3227073301605663],[1.8440740388897607,-0.30963620924916974],[1.01511977809423,1.1443451804421791],[3.185098138839395,0.27002521618549846],[1.8765122082705847,0.44476414785170926],[3.7253953323140077,-0.7475558526891519],[0.7718289905778117,-0.2272525447615547],[3.2767866224002713,-0.7193498459705044],[0.7213874559143196,-2.8049152787530045],[1.8571609088451169,-1.0078296377596005],[2.734669382758418,-1.4583344087031131],[3.859346229140873,-0.7122695587867615],[2.231049981601954,-1.4180327021924513],[0.8371126691615627,1.339022838161968],[0.7764012391828368,0.14742635274665994],[1.7097618233606258,-1.8630100087268624],[2.2367096538882856,-2.768527788721138],[2.0308009834891716,-1.52533136107892],[1.2952547133401136,-0.6696066144064918],[2.039970149691901,-0.6072192086251349],[3.5598640223356877,-0.2866691508250326],[3.27111842585792,-1.203884119511887],[3.2618155718306574,0.006411783665186466],[2.167170511714691,-0.22574032163285535],[1.946535398186214,-1.3824649179877586],[1.246510075606774,-0.16571485460837054],[2.9979621749001204,-0.8283231814576683],[1.0086092195832763,0.08036894351340207],[2.6222756014532225,0.7416202435841821],[2.6581199340888237,-0.7545164159967201],[1.108541460882259,-0.6155886852419455],[2.2944542643763297,1.6381339855124595],[0.910479383662149,-1.0251017908470827],[3.1567660786401444,-0.042936137024987],[2.998222970045651,-1.665217650038709],[2.7606219620433565,-0.9689243213393521],[4.0272675350858025,-1.0342677632249426],[1.6033178054042638,-0.6545187468286534],[1.4082758502086983,-0.4404967574674755],[4.301291499837806,-0.34376055343350265],[0.44636006936827344,-0.6010831059180517],[2.8095673912109898,-0.23229923229195337],[3.793449524990743,0.8511609449271635],[3.8376987697037297,0.84289157749815],[2.3405373429454848,-1.637907153781067],[2.592660712708146,1.7191604731440004],[3.3276094789838027,0.7713737052881446],[2.5701279086237454,-1.629882901049686],[0.28734701031999177,-1.083319138672659],[1.6802153738931753,-0.6901830694222651],[3.5607288572125384,-0.7750417922293833],[2.7070884216483795,1.1903955688118097],[2.675287317116158,-0.229365762399736],[1.4939334744345105,0.20614655466939047],[1.5253764743274392,-1.664254838125334],[2.719232257730017,-0.7151544441299151],[1.2214197702968121,-1.48175170696274],[1.2040151235528769,-0.7483050849054848],[2.641165335013296,0.5144714889415314],[1.2613631563476084,-1.9882023800160349],[0.8550348070790208,-2.4791646628871313],[0.5683156435880858,-0.9940123193926806],[2.040577894367741,-0.05139591478564898],[1.8888682515207589,-0.0953722871528001],[0.9118263778563993,-0.0898119085088277],[3.4906414393783542,-1.6406616305186703],[1.833645748477554,-1.6410085003505501],[2.9996193143214644,-0.2706402197409577],[2.8995029624960096,-1.0308765028786708],[0.9107145415058966,0.7623872135424716],[2.9440307557998806,1.304207731243828],[1.9242343171831529,-1.6938449184809634],[1.3651000282952062,-1.3733642229751328],[0.8945215356337017,0.7088573903337692],[1.8846107554252391,0.2605166913928223],[2.3713835299385186,-0.569641943742247],[2.773593920007226,-1.0381382751918296],[0.11837469936466594,0.7869233794043564],[3.1910898379769845,-0.5496649763348334],[3.4858637009085807,-2.7359688303066685],[2.989195334060052,1.4622795984759893],[1.6594517847194235,1.0213861389825136],[2.4865934705521835,-0.8659725979231729],[3.652333205332899,-1.1251245969834318],[2.647818359322477,-1.1299905459101536],[1.2676675610831158,-0.14962979984073815],[2.4444559385968656,-1.7691866608239084],[3.12282857147348,-0.28172663605507253],[1.9328322809799143,0.7651860611278161],[1.5421389253273718,-0.24807746308049267],[1.6036407307675888,-0.5666647920010277],[3.9467260055996514,0.8324192192043491],[2.969302850601248,-1.7191656400431812],[2.703101981228574,-0.13433475103928738],[3.6805189314810125,-1.1589765363824727],[3.204941140195232,-1.1314055393095148],[3.1222002906681996,-0.28557018987005056],[6.2073716108226495,8.858740205837897],[7.27345216559597,11.323684881097675],[7.546850591307437,10.98368485716879],[6.896587743374444,10.458313123895397],[6.412911694900288,10.12042343610099],[7.238653412857717,8.351814769576897],[6.193818424901991,9.813243535845864],[6.705245353877654,9.467777675332444],[6.202500895469873,9.629946145942972],[5.879675594742893,10.069691243421357],[5.568744874019053,9.439396259433865],[6.214499802664113,8.988780169387455],[7.820795278697905,8.911252954118089],[7.084733507780544,9.827878017933237],[6.917857744929477,8.711375489787283],[6.766395216621707,8.386763307133926],[6.35441162703063,9.975087825947565],[6.961543113861912,9.771160056430888],[8.717013878547984,10.620116841096703],[5.092649371290753,9.840573609178339],[5.101593643117582,9.899469425436736],[7.96850466319338,9.728415652617967],[6.613575529173971,9.940676905653604],[5.827532666035846,10.26615432398275],[5.872249945235403,8.76950044305104],[6.512992457335668,10.69576438983088],[3.8634124004178503,9.95430470997252],[5.464508493159647,9.215853647785663],[6.981095686033238,10.80841152275488],[6.986017121485765,9.536487821546125],[7.430981475000248,8.122934392634772],[6.917162783289074,10.269373694326648],[8.238693214571024,9.221050637762952],[5.939412363379822,8.636166231820978],[7.457656391230647,10.932979848882821],[6.938255860608141,10.53253058104941],[5.489001048164922,9.809216163148983],[6.412619069555679,10.077972373631868],[7.4044672385889205,10.109065555538757],[7.024317746240662,9.1921840203069],[5.534746179358389,10.8621168251996],[4.632128735590788,9.541578589241828],[6.0343822755432095,9.679214206473915],[6.949248085710569,10.645720589678401],[6.346920241319923,9.660570453789852],[7.808236740209843,10.518850326939447],[8.03905468809096,9.532827751060415],[5.9603453053921385,11.046447806544633],[6.79961407838924,8.450422189414406],[5.107893865074237,8.61287544484333],[6.412090095169792,10.88605106775373],[5.154738217370399,8.586120074641835],[5.054062732460032,9.9787806506516],[5.4572330252891685,8.687824068876058],[5.935394793313902,8.890383630458425],[8.447075255896896,8.639141510373047],[6.695033537024857,11.547854072113946],[8.311083871972551,9.417963760833052],[5.719421130635991,10.150502744498409],[6.5492255280952065,9.346206166348837],[5.333625509754558,8.399337532023994],[6.7242428082441,11.443617957230412],[7.108856268782695,8.565871719315771],[8.317984973808878,11.992105354961112],[5.411688297954436,9.593818797711224],[6.031326486341285,10.64491543562232],[6.348413323411411,9.47662367054148],[7.816928371781802,10.893371695077596],[8.975176789414867,10.2213015283758],[7.278925092927388,9.296565931063807],[5.597077408101901,8.93600666984686],[6.976881492302263,8.19238372921271],[8.241284153997073,10.206945629605341],[7.809753097507436,9.61826674026256],[8.592837919367815,10.952589803991856],[5.381547523813488,8.864000997409956],[5.639224853532939,9.623046499676377],[6.712763764071509,11.872143229648534],[6.844405322500786,9.384511984130391],[6.933224866369902,10.500682639059733],[6.034856914714432,10.90148519241433],[4.775647717438177,11.775543216631315],[5.554163335489775,11.141836957494386],[6.8638359778936255,9.558727273525841],[7.820443004299326,9.29698461928863],[5.2837128077950375,12.234615180786319],[5.816769665637683,9.080637153634585],[7.140357440042546,9.402953140559234],[6.665516384354978,11.011444041418969],[5.592577896645976,10.055545616037515],[6.5415648430327895,9.818793917010739],[5.519945632179889,9.02766373668973],[6.368634154570206,10.276419861282633],[7.027933550726458,9.939947888056432],[8.414314246793058,8.37229672213441],[4.410572758400427,8.978750288868094],[8.552862999366075,10.766834911664784],[6.0854478414591995,10.53534733425499],[6.205544059664119,11.022031938084849],[6.479099292039024,10.451068811439944],[-5.382260566426023,1.54380015569135],[-5.858895028486605,-0.44378452424162174],[-5.119878494914355,-1.155290431842559],[-5.8732044484781065,0.97461602556516],[-7.946974618714668,0.4816418385761408],[-7.2591078569829275,-1.246501072034877],[-5.125594847176017,0.8033273289296234],[-6.373375892692571,-0.7317653161977713],[-6.926890971035933,0.869229930020902],[-6.067647179170281,-0.26962014215279734],[-4.953274625468043,0.7827882935687828],[-5.45939525264509,-0.6858688204186253],[-4.28271078347519,0.9856666897616391],[-4.410624073209559,0.7138711653903401],[-5.949014475518975,1.4093969574812761],[-5.8428672241849275,0.4795369853038818],[-6.83600588606641,-0.43169667984283666],[-5.276024671316134,0.39649566511327183],[-5.0765401395656475,0.4036152535843905],[-6.876460328595954,1.4426241815993195],[-6.526499860145627,0.7206188109482832],[-5.542513060716647,0.14599086113785315],[-5.864595752571791,-0.7405042874882625],[-5.094180652813674,-0.6240905846980278],[-6.2612654409353725,0.6633294829408364],[-5.881167668164653,2.2811151003122028],[-7.390516476317942,1.7540167295233258],[-3.9956252359536233,-0.5043392455684926],[-5.608749343515587,-0.007511912986062094],[-6.624774235824031,0.36231744128340343],[-6.649462832465082,-0.6226329923358824],[-6.120989136701669,-1.4022247543600201],[-7.449392350459391,-0.666753899526794],[-6.317571246498761,-0.7880488011401341],[-7.234968750038828,-1.8821871314570608],[-7.333616478591004,-1.2895834389173642],[-5.195309874095974,-1.6595344064290383],[-7.104639266779171,1.8886568901151048],[-5.417059139358234,-0.9978968448514643],[-6.307184778088419,-1.1297910249107685],[-6.021738362591232,-1.021204585285239],[-5.9134848449026585,0.14215329211363548],[-7.722131564279021,1.07661606524122],[-7.347887587016742,-1.0893924749100954],[-7.301095424892937,-0.09800702815529685],[-6.559139394481456,-0.6876436396540306],[-6.0988212799949,0.6095531153473063],[-7.492454041222247,0.5111305662996721],[-5.920589210991992,-0.4166576200203645],[-6.144001390548154,-0.29895957409119117],[-4.451035383851394,-0.23845113848626945],[-5.819560010576873,-0.2989016742801416],[-4.058305197466785,0.19903654347426633],[-3.5149922105803673,-1.5997138158622617],[-6.016677018087455,0.4014375713462562],[-6.955180236051704,-0.3063490981455747],[-8.8336307742054,-0.36746459318683494],[-6.188725877847488,-0.026000568587290468],[-6.622889973314741,0.8159667466087253],[-5.7915752489162005,-0.07299305903736035],[-5.269265859137284,-0.8328008431883889],[-5.054900637719741,-0.2523890414788773],[-6.620999687163674,1.6816641573102253],[-5.092204547355657,-0.5054889919534826],[-6.185613217621365,-0.38719555930901034],[-6.804825193332951,-1.7337811885226664],[-5.4770656291102675,-0.20428097686126023],[-5.533843855967146,0.7943750624859062],[-5.6422791812499025,-2.1640142163347633],[-4.777633944028727,1.4681336085819745],[-7.60225600845152,-0.6824642452817473],[-4.016794181373243,-0.19563606120029173],[-5.4630394312351775,-2.595206979888569],[-6.625763705681877,0.3301105547797557],[-5.836323546807829,-0.39569748816188566],[-5.958476080872936,-1.4301955834757858],[-4.491279150611599,1.8273116670817742],[-6.287631967614887,-0.13079396213361996],[-6.496818902765126,0.12063690611508843],[-5.8751054884511005,-1.0305942146079392],[-7.686009773225401,-1.2113895587902594],[-5.86482951474393,-0.2281945590089429],[-6.302369570717418,0.24083600499888907],[-5.907013638215465,-0.28750260046930737],[-4.758299519175782,0.8088362699232291],[-7.691728114844647,1.2275445631229136],[-6.778126856316154,-0.4115940500733559],[-7.625917593361881,-0.022326593269139147],[-4.99762507555956,-0.637363821424804],[-6.8311123122921416,-1.0802343864078723],[-3.6809649808460163,-0.04858345496193935],[-7.020040035269961,1.598738361080021],[-6.778287939223563,-0.2888811076600735],[-4.965270580293918,0.5863696612092529],[-6.6658341189762975,-0.4063635225887007],[-8.27044308059774,1.5227573910939922],[-3.925572846608703,0.44935814443495925],[-4.6875670041036965,1.6502046123298735],[-6.137283216283425,1.5057984242836118],[-6.808528755618382,-0.7649842292855052]])*/
let clust = new druid.KMeans(A, clusters, druid.manhattan)
let ci = A.to2dArray.map((d,i) => i %10)
const root = clust.root
let res = clust.get_clusters()
res.forEach((arr, i) => {
arr.forEach(index => ci[index] = i);
})
console.log(res)
let cluster_areas = res.map(arr => {
let centroid = arr
.reduce((a, b) => [A.entry(b, 0) + a[0], A.entry(b, 1) + a[1]], [0, 0])
.map(d => d / arr.length)
let radius = arr.reduce((a,b) => Math.max(a, druid.euclidean(centroid, A.row(b))), -Infinity)
return {
centroid: centroid,
radius: radius,
}
})
draw(A)
//re = new druid.Reorder(A), console.log(re.reorder())
/*let div = d3.select("body").append("div")
let input = div.append("input")
.attr("type", "range")
.attr("min", 1)
.attr("max", clust.root.depth)
.on("input", function() {
label.text(+this.value)
let res = clust.get_clusters(+this.value, "depth")
res.forEach((arr, i) => {
arr.forEach(index => ci[index] = i);
})
draw(A)
});
let label = div.append("label")
.text(root.depth);
let div2 = d3.select("body").append("div")
let input2 = div2.append("input")
.attr("type", "range")
.attr("min", 0)
.attr("max", clust.root.dist + .1)
.attr("step", .1)
.on("input", function() {
let d = +this.value;
label2.text(d)
let res = clust.get_clusters(+this.value, "distance")
res.forEach((arr, i) => {
arr.forEach(index => ci[index] = i);
})
draw(A)
});
let label2 = div2.append("label")
.text(clust.root.dist + .1)
let svg2 = d3.select("body").append("svg")
.attr("width", width)
.attr("height", 300)
let hd = druid.linspace(1, root.dist + .1, 100)
let hc = new Array(hd.length)
let x = d3.scaleLinear()
.domain([0, 99])
.range([margin, width-margin])
hd.forEach((d, i) => hc[i] = clust.get_clusters(d).length)
let y = d3.scaleLinear()
.domain([1, clust.get_clusters(1).length])
.range([0, 200])
let w = x(1) - x(0)
svg2.selectAll("rect")
.data(hc)
.enter()
.append("rect")
.attr("x", (d,i) => x(i))
.attr("y", d => 250 - y(d))
.attr("width", w)
.attr("height", d => y(d))
.attr("fill", "steelblue")
let svg3 = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", width * 2);
*/
function get_ranges(data) {
let x_extent = d3.extent(data, d => d[0])
let y_extent = d3.extent(data, d => d[1])
let x_span = x_extent[1] - x_extent[0]
let y_span = y_extent[1] - y_extent[0]
let offset = Math.abs(x_span - y_span) / 2
if (x_span > y_span) {
y_extent[0] -= offset
y_extent[1] += offset
} else {
x_extent[0] -= offset
x_extent[1] += offset
}
let x = d3.scaleLinear()
.domain(x_extent)
.range([margin, width - margin])
let y = d3.scaleLinear()
.domain(y_extent)
.range([margin, height - margin])
return [x, y];
}
function draw(A) {
let data = A.to2dArray;
/* let x = d3.scaleLinear()
.domain(d3.extent(data, d => d[0]))
.range([margin, width - margin])
let y = d3.scaleLinear()
.domain(d3.extent(data, d => d[1]))
.range([margin, height - margin]) */
const [x, y] = get_ranges(data)
svg.selectAll("circle")
.data(data)
.enter()
.append("circle")
.merge(svg.selectAll("circle"))
.attr("cx", d => x(d[0]))
.attr("cy", d => y(d[1]))
.attr("r", 2)
.attr("fill", "transparent")
.attr("stroke", (d,i) => c(ci[i]))
svg.selectAll(".r")
.data(cluster_areas)
.enter()
.append("circle")
.attr("cx", d => x(d.centroid[0]))
.attr("cy", d => y(d.centroid[1]))
.attr("r", d => x(d.radius) - x(0))
.attr("fill", "transparent")
.attr("stroke", (d,i) => c(i));
/*let node = root;
let parent_id = 0;
t = (node, parent) => {
if (node.isLeaf) {
node.parent = parent;
} else {
node.parent = parent;
t(node.left, node)
t(node.right, node)
}
}
t(root.left, root)
t(root.right, root)
let x0 = 0
t = (node) => {
//if (!(node.depth in x3)) x3[node.depth] = 0
x3[node.depth]++
if (node.isLeaf) return
t(node.left)
t(node.right)
}
t(root)
console.log(x3)*/
}
</script>
</body>
</html>