1
1
import * as d3Scale from 'd3-scale' ;
2
2
import * as d3Shape from "d3-shape" ;
3
+ import * as d3Array from "d3-array" ;
3
4
import * as d3Hierarchy from "d3-hierarchy" ;
4
5
5
6
export default function ( ) {
@@ -54,7 +55,7 @@ export default function() {
54
55
55
56
function identity ( nodes ) {
56
57
57
- nodes . forEach ( function ( n , i ) {
58
+ nodes . forEach ( function ( n ) {
58
59
n . x = n . x || 0 ;
59
60
n . y = n . y || 0 ;
60
61
n . width = n . width || size [ 0 ] ;
@@ -104,7 +105,7 @@ export default function() {
104
105
105
106
cols = rows = 1 ;
106
107
107
- nodes . forEach ( function ( n , i ) {
108
+ nodes . forEach ( function ( n ) {
108
109
n . x = 0 + offset [ 0 ] ;
109
110
n . y = 0 + offset [ 1 ] ;
110
111
n . width = size [ 0 ] ;
@@ -158,17 +159,17 @@ export default function() {
158
159
valueX = function ( ) { return Math . random ( ) ; }
159
160
x . domain ( [ 0 , 1 ] ) . range ( [ 0 , size [ 0 ] ] ) ;
160
161
} else {
161
- x . domain ( d3 . extent ( nodes , valueX ) ) . range ( [ 0 , size [ 0 ] ] ) ;
162
+ x . domain ( d3Array . extent ( nodes , valueX ) ) . range ( [ 0 , size [ 0 ] ] ) ;
162
163
}
163
164
164
165
if ( ! valueY ) {
165
166
valueY = function ( ) { return Math . random ( ) ; }
166
167
y . domain ( [ 0 , 1 ] ) . range ( [ 0 , size [ 1 ] ] ) ;
167
168
} else {
168
- y . domain ( d3 . extent ( nodes , valueY ) ) . range ( [ 0 , size [ 1 ] ] ) ;
169
+ y . domain ( d3Array . extent ( nodes , valueY ) ) . range ( [ 0 , size [ 1 ] ] ) ;
169
170
}
170
171
171
- nodes . forEach ( function ( n , i ) {
172
+ nodes . forEach ( function ( n ) {
172
173
n . x = x ( valueX ( n ) ) + offset [ 0 ] ;
173
174
n . y = y ( valueY ( n ) ) + offset [ 1 ] ;
174
175
n . width = cellSize ? cellSize [ 0 ] : size [ 0 ] / nodes . length ;
@@ -192,7 +193,7 @@ export default function() {
192
193
193
194
var pie = d3Shape . pie ( )
194
195
. sort ( sort )
195
- . value ( function ( d ) { return 1 ; } ) ;
196
+ . value ( function ( ) { return 1 ; } ) ;
196
197
197
198
var arcs = pie ( nodes ) ;
198
199
@@ -210,17 +211,16 @@ export default function() {
210
211
211
212
function treemap ( nodes ) {
212
213
213
- var treemap = d3 . treemap ( )
214
+ var treemap = d3Hierarchy . treemap ( )
214
215
. size ( [ size [ 0 ] , size [ 1 ] ] )
215
216
. padding ( padding ) ;
216
217
217
- var tree = treemap ( d3 . stratify ( )
218
+ var tree = treemap ( d3Hierarchy . stratify ( )
218
219
. id ( function ( d , i ) { return i ; } )
219
220
. parentId ( function ( d , i ) {
220
221
return i === 0 ? "" : 0 ;
221
- } )
222
- ( [ { } ] . concat ( nodes ) )
223
- . sum ( function ( d , i ) { return 1 ; } )
222
+ } ) ( [ { } ] . concat ( nodes ) )
223
+ . sum ( function ( ) { return 1 ; } )
224
224
) ;
225
225
226
226
nodes . forEach ( function ( n , i ) {
@@ -237,17 +237,16 @@ export default function() {
237
237
238
238
function pack ( nodes ) {
239
239
240
- var pack = d3 . pack ( )
240
+ var pack = d3Hierarchy . pack ( )
241
241
. size ( [ size [ 0 ] , size [ 1 ] ] )
242
242
. padding ( padding ) ;
243
243
244
- var packed = pack ( d3 . stratify ( )
244
+ var packed = pack ( d3Hierarchy . stratify ( )
245
245
. id ( function ( d , i ) { return i ; } )
246
246
. parentId ( function ( d , i ) {
247
247
return i === 0 ? "" : 0 ;
248
- } )
249
- ( [ { } ] . concat ( nodes ) )
250
- . sum ( function ( d , i ) { return 1 ; } )
248
+ } ) ( [ { } ] . concat ( nodes ) )
249
+ . sum ( function ( ) { return 1 ; } )
251
250
) ;
252
251
253
252
nodes . forEach ( function ( n , i ) {
@@ -264,11 +263,11 @@ export default function() {
264
263
265
264
function stack ( nodes ) {
266
265
267
- var stack = d3 . stack ( )
266
+ var stack = d3Hierarchy . stack ( )
268
267
. keys ( nodes . map ( function ( d , i ) { return i + "_" ; } ) ) // Creates unique ids for nodes
269
268
. value ( function ( d , key ) { return nodes . indexOf ( d [ key ] ) ; } ) ;
270
269
271
- y . domain ( [ 0 , d3 . sum ( d3 . range ( nodes . length ) ) + nodes . length ] ) . range ( [ 0 , size [ 1 ] ] ) ;
270
+ y . domain ( [ 0 , d3Array . sum ( d3Array . range ( nodes . length ) ) + nodes . length ] ) . range ( [ 0 , size [ 1 ] ] ) ;
272
271
273
272
var new_data = { } ;
274
273
@@ -300,7 +299,7 @@ export default function() {
300
299
301
300
if ( orient == "up" ) {
302
301
n . x = x ( i ) + offset [ 0 ] ;
303
- n . y = height - ( y ( i ) + offset [ 1 ] ) - size [ 1 ] / nodes . length ;
302
+ n . y = size [ 1 ] - ( y ( i ) + offset [ 1 ] ) - size [ 1 ] / nodes . length ;
304
303
} else {
305
304
n . x = x ( i ) + offset [ 0 ] ;
306
305
n . y = y ( i ) + offset [ 1 ] ;
@@ -338,8 +337,6 @@ export default function() {
338
337
339
338
function pyramid ( nodes ) {
340
339
341
- var spacing = size [ 0 ] * 2 ;
342
-
343
340
var shiftX = size [ 0 ] / ( 2 * nodes . length ) ;
344
341
var shiftY = size [ 1 ] / ( 2 * nodes . length ) ;
345
342
@@ -485,4 +482,4 @@ export default function() {
485
482
}
486
483
487
484
return gridding ;
488
- } ;
485
+ }
0 commit comments