tree.rb 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rjson.rb +9 -0
- data/bin/rtree +0 -0
- data/bin/tree_rb +0 -0
- data/examples/d3_treemap/d3.js +4149 -0
- data/examples/d3_treemap/d3.layout.js +1890 -0
- data/examples/d3_treemap/d3_tree_rb_output.json +380 -0
- data/examples/d3_treemap/d3_treemap.html +177 -0
- data/examples/d3_treemap/prova.html +84 -0
- data/examples/d3_treemap/style.css +89 -0
- data/examples/prova/flare.js +381 -0
- data/examples/prova/prova.html +99 -0
- data/lib/tree_rb/cli/cli_json.rb +320 -0
- data/lib/tree_rb/cli/cli_tree.rb +72 -49
- data/lib/tree_rb/directory_walker.rb +9 -4
- data/lib/tree_rb/version.rb +1 -1
- data/lib/tree_rb/visitors/directory_to_hash2_visitor.rb +414 -0
- data/lib/tree_rb_cli.rb +1 -0
- data/spec/fixtures/test_json/1.json +1 -0
- data/spec/tree_rb/cli/cli_json_spec.rb +40 -0
- data/spec/tree_rb/tree_dsl_with_derived_class_spec.rb +1 -1
- data/spec/tree_rb/util/dir_processor_spec.rb +1 -1
- data/tasks/tree_rb.rake +22 -0
- metadata +25 -2
@@ -0,0 +1,380 @@
|
|
1
|
+
{
|
2
|
+
"name": "flare",
|
3
|
+
"children": [
|
4
|
+
{
|
5
|
+
"name": "analytics1",
|
6
|
+
"children": [
|
7
|
+
{
|
8
|
+
"name": "cluster",
|
9
|
+
"children": [
|
10
|
+
{"name": "AgglomerativeCluster", "size": 3938},
|
11
|
+
{"name": "CommunityStructure", "size": 3812},
|
12
|
+
{"name": "HierarchicalCluster", "size": 6714},
|
13
|
+
{"name": "MergeEdge", "size": 743}
|
14
|
+
]
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"name": "graph",
|
18
|
+
"children": [
|
19
|
+
{"name": "BetweennessCentrality", "size": 3534},
|
20
|
+
{"name": "LinkDistance", "size": 5731},
|
21
|
+
{"name": "MaxFlowMinCut", "size": 7840},
|
22
|
+
{"name": "ShortestPaths", "size": 5914},
|
23
|
+
{"name": "SpanningTree", "size": 3416}
|
24
|
+
]
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"name": "optimization",
|
28
|
+
"children": [
|
29
|
+
{"name": "AspectRatioBanker", "size": 7074}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
]
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"name": "animate",
|
36
|
+
"children": [
|
37
|
+
{"name": "Easing", "size": 17010},
|
38
|
+
{"name": "FunctionSequence", "size": 5842},
|
39
|
+
{
|
40
|
+
"name": "interpolate",
|
41
|
+
"children": [
|
42
|
+
{"name": "ArrayInterpolator", "size": 1983},
|
43
|
+
{"name": "ColorInterpolator", "size": 2047},
|
44
|
+
{"name": "DateInterpolator", "size": 1375},
|
45
|
+
{"name": "Interpolator", "size": 8746},
|
46
|
+
{"name": "MatrixInterpolator", "size": 2202},
|
47
|
+
{"name": "NumberInterpolator", "size": 1382},
|
48
|
+
{"name": "ObjectInterpolator", "size": 1629},
|
49
|
+
{"name": "PointInterpolator", "size": 1675},
|
50
|
+
{"name": "RectangleInterpolator", "size": 2042}
|
51
|
+
]
|
52
|
+
},
|
53
|
+
{"name": "ISchedulable", "size": 1041},
|
54
|
+
{"name": "Parallel", "size": 5176},
|
55
|
+
{"name": "Pause", "size": 449},
|
56
|
+
{"name": "Scheduler", "size": 5593},
|
57
|
+
{"name": "Sequence", "size": 5534},
|
58
|
+
{"name": "Transition", "size": 9201},
|
59
|
+
{"name": "Transitioner", "size": 19975},
|
60
|
+
{"name": "TransitionEvent", "size": 1116},
|
61
|
+
{"name": "Tween", "size": 6006}
|
62
|
+
]
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"name": "data",
|
66
|
+
"children": [
|
67
|
+
{
|
68
|
+
"name": "converters",
|
69
|
+
"children": [
|
70
|
+
{"name": "Converters", "size": 721},
|
71
|
+
{"name": "DelimitedTextConverter", "size": 4294},
|
72
|
+
{"name": "GraphMLConverter", "size": 9800},
|
73
|
+
{"name": "IDataConverter", "size": 1314},
|
74
|
+
{"name": "JSONConverter", "size": 2220}
|
75
|
+
]
|
76
|
+
},
|
77
|
+
{"name": "DataField", "size": 1759},
|
78
|
+
{"name": "DataSchema", "size": 2165},
|
79
|
+
{"name": "DataSet", "size": 586},
|
80
|
+
{"name": "DataSource", "size": 3331},
|
81
|
+
{"name": "DataTable", "size": 772},
|
82
|
+
{"name": "DataUtil", "size": 3322}
|
83
|
+
]
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"name": "display",
|
87
|
+
"children": [
|
88
|
+
{"name": "DirtySprite", "size": 8833},
|
89
|
+
{"name": "LineSprite", "size": 1732},
|
90
|
+
{"name": "RectSprite", "size": 3623},
|
91
|
+
{"name": "TextSprite", "size": 10066}
|
92
|
+
]
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"name": "flex",
|
96
|
+
"children": [
|
97
|
+
{"name": "FlareVis1111", "size": 4116}
|
98
|
+
]
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"name": "physics",
|
102
|
+
"children": [
|
103
|
+
{"name": "DragForce", "size": 1082},
|
104
|
+
{"name": "GravityForce", "size": 1336},
|
105
|
+
{"name": "IForce", "size": 319},
|
106
|
+
{"name": "NBodyForce", "size": 10498},
|
107
|
+
{"name": "Particle", "size": 2822},
|
108
|
+
{"name": "Simulation", "size": 9983},
|
109
|
+
{"name": "Spring", "size": 2213},
|
110
|
+
{"name": "SpringForce", "size": 1681}
|
111
|
+
]
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"name": "query",
|
115
|
+
"children": [
|
116
|
+
{"name": "AggregateExpression", "size": 1616},
|
117
|
+
{"name": "And", "size": 1027},
|
118
|
+
{"name": "Arithmetic", "size": 3891},
|
119
|
+
{"name": "Average", "size": 891},
|
120
|
+
{"name": "BinaryExpression", "size": 2893},
|
121
|
+
{"name": "Comparison", "size": 5103},
|
122
|
+
{"name": "CompositeExpression", "size": 3677},
|
123
|
+
{"name": "Count", "size": 781},
|
124
|
+
{"name": "DateUtil", "size": 4141},
|
125
|
+
{"name": "Distinct", "size": 933},
|
126
|
+
{"name": "Expression", "size": 5130},
|
127
|
+
{"name": "ExpressionIterator", "size": 3617},
|
128
|
+
{"name": "Fn", "size": 3240},
|
129
|
+
{"name": "If", "size": 2732},
|
130
|
+
{"name": "IsA", "size": 2039},
|
131
|
+
{"name": "Literal", "size": 1214},
|
132
|
+
{"name": "Match", "size": 3748},
|
133
|
+
{"name": "Maximum", "size": 843},
|
134
|
+
{
|
135
|
+
"name": "methods",
|
136
|
+
"children": [
|
137
|
+
{"name": "add", "size": 593},
|
138
|
+
{"name": "and", "size": 330},
|
139
|
+
{"name": "average", "size": 287},
|
140
|
+
{"name": "count", "size": 277},
|
141
|
+
{"name": "distinct", "size": 292},
|
142
|
+
{"name": "div", "size": 595},
|
143
|
+
{"name": "eq", "size": 594},
|
144
|
+
{"name": "fn", "size": 460},
|
145
|
+
{"name": "gt", "size": 603},
|
146
|
+
{"name": "gte", "size": 625},
|
147
|
+
{"name": "iff", "size": 748},
|
148
|
+
{"name": "isa", "size": 461},
|
149
|
+
{"name": "lt", "size": 597},
|
150
|
+
{"name": "lte", "size": 619},
|
151
|
+
{"name": "max", "size": 283},
|
152
|
+
{"name": "min", "size": 283},
|
153
|
+
{"name": "mod", "size": 591},
|
154
|
+
{"name": "mul", "size": 603},
|
155
|
+
{"name": "neq", "size": 599},
|
156
|
+
{"name": "not", "size": 386},
|
157
|
+
{"name": "or", "size": 323},
|
158
|
+
{"name": "orderby", "size": 307},
|
159
|
+
{"name": "range", "size": 772},
|
160
|
+
{"name": "select", "size": 296},
|
161
|
+
{"name": "stddev", "size": 363},
|
162
|
+
{"name": "sub", "size": 600},
|
163
|
+
{"name": "sum", "size": 280},
|
164
|
+
{"name": "update", "size": 307},
|
165
|
+
{"name": "variance", "size": 335},
|
166
|
+
{"name": "where", "size": 299},
|
167
|
+
{"name": "xor", "size": 354},
|
168
|
+
{"name": "_", "size": 264}
|
169
|
+
]
|
170
|
+
},
|
171
|
+
{"name": "Minimum", "size": 843},
|
172
|
+
{"name": "Not", "size": 1554},
|
173
|
+
{"name": "Or", "size": 970},
|
174
|
+
{"name": "Query", "size": 13896},
|
175
|
+
{"name": "Range", "size": 1594},
|
176
|
+
{"name": "StringUtil", "size": 4130},
|
177
|
+
{"name": "Sum", "size": 791},
|
178
|
+
{"name": "Variable", "size": 1124},
|
179
|
+
{"name": "Variance", "size": 1876},
|
180
|
+
{"name": "Xor", "size": 1101}
|
181
|
+
]
|
182
|
+
},
|
183
|
+
{
|
184
|
+
"name": "scale",
|
185
|
+
"children": [
|
186
|
+
{"name": "IScaleMap", "size": 2105},
|
187
|
+
{"name": "LinearScale", "size": 1316},
|
188
|
+
{"name": "LogScale", "size": 3151},
|
189
|
+
{"name": "OrdinalScale", "size": 3770},
|
190
|
+
{"name": "QuantileScale", "size": 2435},
|
191
|
+
{"name": "QuantitativeScale", "size": 4839},
|
192
|
+
{"name": "RootScale", "size": 1756},
|
193
|
+
{"name": "Scale", "size": 4268},
|
194
|
+
{"name": "ScaleType", "size": 1821},
|
195
|
+
{"name": "TimeScale", "size": 5833}
|
196
|
+
]
|
197
|
+
},
|
198
|
+
{
|
199
|
+
"name": "util",
|
200
|
+
"children": [
|
201
|
+
{"name": "Arrays", "size": 8258},
|
202
|
+
{"name": "Colors", "size": 10001},
|
203
|
+
{"name": "Dates", "size": 8217},
|
204
|
+
{"name": "Displays", "size": 12555},
|
205
|
+
{"name": "Filter", "size": 2324},
|
206
|
+
{"name": "Geometry", "size": 10993},
|
207
|
+
{
|
208
|
+
"name": "heap",
|
209
|
+
"children": [
|
210
|
+
{"name": "FibonacciHeap", "size": 9354},
|
211
|
+
{"name": "HeapNode", "size": 1233}
|
212
|
+
]
|
213
|
+
},
|
214
|
+
{"name": "IEvaluable", "size": 335},
|
215
|
+
{"name": "IPredicate", "size": 383},
|
216
|
+
{"name": "IValueProxy", "size": 874},
|
217
|
+
{
|
218
|
+
"name": "math",
|
219
|
+
"children": [
|
220
|
+
{"name": "DenseMatrix", "size": 3165},
|
221
|
+
{"name": "IMatrix", "size": 2815},
|
222
|
+
{"name": "SparseMatrix", "size": 3366}
|
223
|
+
]
|
224
|
+
},
|
225
|
+
{"name": "Maths", "size": 17705},
|
226
|
+
{"name": "Orientation", "size": 1486},
|
227
|
+
{
|
228
|
+
"name": "palette",
|
229
|
+
"children": [
|
230
|
+
{"name": "ColorPalette", "size": 6367},
|
231
|
+
{"name": "Palette", "size": 1229},
|
232
|
+
{"name": "ShapePalette", "size": 2059},
|
233
|
+
{"name": "SizePalette", "size": 2291}
|
234
|
+
]
|
235
|
+
},
|
236
|
+
{"name": "Property", "size": 5559},
|
237
|
+
{"name": "Shapes", "size": 19118},
|
238
|
+
{"name": "Sort", "size": 6887},
|
239
|
+
{"name": "Stats", "size": 6557},
|
240
|
+
{"name": "Strings", "size": 22026}
|
241
|
+
]
|
242
|
+
},
|
243
|
+
{
|
244
|
+
"name": "vis",
|
245
|
+
"children": [
|
246
|
+
{
|
247
|
+
"name": "axis",
|
248
|
+
"children": [
|
249
|
+
{"name": "Axes", "size": 1302},
|
250
|
+
{"name": "Axis", "size": 24593},
|
251
|
+
{"name": "AxisGridLine", "size": 652},
|
252
|
+
{"name": "AxisLabel", "size": 636},
|
253
|
+
{"name": "CartesianAxes", "size": 6703}
|
254
|
+
]
|
255
|
+
},
|
256
|
+
{
|
257
|
+
"name": "controls",
|
258
|
+
"children": [
|
259
|
+
{"name": "AnchorControl", "size": 2138},
|
260
|
+
{"name": "ClickControl", "size": 3824},
|
261
|
+
{"name": "Control", "size": 1353},
|
262
|
+
{"name": "ControlList", "size": 4665},
|
263
|
+
{"name": "DragControl", "size": 2649},
|
264
|
+
{"name": "ExpandControl", "size": 2832},
|
265
|
+
{"name": "HoverControl", "size": 4896},
|
266
|
+
{"name": "IControl", "size": 763},
|
267
|
+
{"name": "PanZoomControl", "size": 5222},
|
268
|
+
{"name": "SelectionControl", "size": 7862},
|
269
|
+
{"name": "TooltipControl", "size": 8435}
|
270
|
+
]
|
271
|
+
},
|
272
|
+
{
|
273
|
+
"name": "data",
|
274
|
+
"children": [
|
275
|
+
{"name": "Data", "size": 20544},
|
276
|
+
{"name": "DataList", "size": 19788},
|
277
|
+
{"name": "DataSprite", "size": 10349},
|
278
|
+
{"name": "EdgeSprite", "size": 3301},
|
279
|
+
{"name": "NodeSprite", "size": 19382},
|
280
|
+
{
|
281
|
+
"name": "render",
|
282
|
+
"children": [
|
283
|
+
{"name": "ArrowType", "size": 698},
|
284
|
+
{"name": "EdgeRenderer", "size": 5569},
|
285
|
+
{"name": "IRenderer", "size": 353},
|
286
|
+
{"name": "ShapeRenderer", "size": 2247}
|
287
|
+
]
|
288
|
+
},
|
289
|
+
{"name": "ScaleBinding", "size": 11275},
|
290
|
+
{"name": "Tree", "size": 7147},
|
291
|
+
{"name": "TreeBuilder", "size": 9930}
|
292
|
+
]
|
293
|
+
},
|
294
|
+
{
|
295
|
+
"name": "events",
|
296
|
+
"children": [
|
297
|
+
{"name": "DataEvent", "size": 2313},
|
298
|
+
{"name": "SelectionEvent", "size": 1880},
|
299
|
+
{"name": "TooltipEvent", "size": 1701},
|
300
|
+
{"name": "VisualizationEvent", "size": 1117}
|
301
|
+
]
|
302
|
+
},
|
303
|
+
{
|
304
|
+
"name": "legend",
|
305
|
+
"children": [
|
306
|
+
{"name": "Legend", "size": 20859},
|
307
|
+
{"name": "LegendItem", "size": 4614},
|
308
|
+
{"name": "LegendRange", "size": 10530}
|
309
|
+
]
|
310
|
+
},
|
311
|
+
{
|
312
|
+
"name": "operator",
|
313
|
+
"children": [
|
314
|
+
{
|
315
|
+
"name": "distortion",
|
316
|
+
"children": [
|
317
|
+
{"name": "BifocalDistortion", "size": 4461},
|
318
|
+
{"name": "Distortion", "size": 6314},
|
319
|
+
{"name": "FisheyeDistortion", "size": 3444}
|
320
|
+
]
|
321
|
+
},
|
322
|
+
{
|
323
|
+
"name": "encoder",
|
324
|
+
"children": [
|
325
|
+
{"name": "ColorEncoder", "size": 3179},
|
326
|
+
{"name": "Encoder", "size": 4060},
|
327
|
+
{"name": "PropertyEncoder", "size": 4138},
|
328
|
+
{"name": "ShapeEncoder", "size": 1690},
|
329
|
+
{"name": "SizeEncoder", "size": 1830}
|
330
|
+
]
|
331
|
+
},
|
332
|
+
{
|
333
|
+
"name": "filter",
|
334
|
+
"children": [
|
335
|
+
{"name": "FisheyeTreeFilter", "size": 5219},
|
336
|
+
{"name": "GraphDistanceFilter", "size": 3165},
|
337
|
+
{"name": "VisibilityFilter", "size": 3509}
|
338
|
+
]
|
339
|
+
},
|
340
|
+
{"name": "IOperator", "size": 1286},
|
341
|
+
{
|
342
|
+
"name": "label",
|
343
|
+
"children": [
|
344
|
+
{"name": "Labeler", "size": 9956},
|
345
|
+
{"name": "RadialLabeler", "size": 3899},
|
346
|
+
{"name": "StackedAreaLabeler", "size": 3202}
|
347
|
+
]
|
348
|
+
},
|
349
|
+
{
|
350
|
+
"name": "layout",
|
351
|
+
"children": [
|
352
|
+
{"name": "AxisLayout", "size": 6725},
|
353
|
+
{"name": "BundledEdgeRouter", "size": 3727},
|
354
|
+
{"name": "CircleLayout", "size": 9317},
|
355
|
+
{"name": "CirclePackingLayout", "size": 12003},
|
356
|
+
{"name": "DendrogramLayout", "size": 4853},
|
357
|
+
{"name": "ForceDirectedLayout", "size": 8411},
|
358
|
+
{"name": "IcicleTreeLayout", "size": 4864},
|
359
|
+
{"name": "IndentedTreeLayout", "size": 3174},
|
360
|
+
{"name": "Layout", "size": 7881},
|
361
|
+
{"name": "NodeLinkTreeLayout", "size": 12870},
|
362
|
+
{"name": "PieLayout", "size": 2728},
|
363
|
+
{"name": "RadialTreeLayout", "size": 12348},
|
364
|
+
{"name": "RandomLayout", "size": 870},
|
365
|
+
{"name": "StackedAreaLayout", "size": 9121},
|
366
|
+
{"name": "TreeMapLayout", "size": 9191}
|
367
|
+
]
|
368
|
+
},
|
369
|
+
{"name": "Operator", "size": 2490},
|
370
|
+
{"name": "OperatorList", "size": 5248},
|
371
|
+
{"name": "OperatorSequence", "size": 4190},
|
372
|
+
{"name": "OperatorSwitch", "size": 2581},
|
373
|
+
{"name": "SortOperator", "size": 2023}
|
374
|
+
]
|
375
|
+
},
|
376
|
+
{"name": "Visualization", "size": 16540}
|
377
|
+
]
|
378
|
+
}
|
379
|
+
]
|
380
|
+
}
|
@@ -0,0 +1,177 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
5
|
+
|
6
|
+
<link type="text/css" rel="stylesheet" href="style.css">
|
7
|
+
<script type="text/javascript" src="d3.js"></script>
|
8
|
+
<script type="text/javascript" src="d3.layout.js"></script>
|
9
|
+
<style type="text/css">
|
10
|
+
|
11
|
+
.chart {
|
12
|
+
display: block;
|
13
|
+
margin: auto;
|
14
|
+
margin-top: 40px;
|
15
|
+
}
|
16
|
+
|
17
|
+
text {
|
18
|
+
font-size: 11px;
|
19
|
+
}
|
20
|
+
|
21
|
+
rect {
|
22
|
+
fill: none;
|
23
|
+
}
|
24
|
+
|
25
|
+
</style>
|
26
|
+
</head>
|
27
|
+
|
28
|
+
<body>
|
29
|
+
<div id="body">
|
30
|
+
<div id="footer">
|
31
|
+
d3.layout.treemap
|
32
|
+
<div class="hint">click or option-click to descend or ascend</div>
|
33
|
+
<div><select>
|
34
|
+
<option value="size">Size</option>
|
35
|
+
<option value="count">Count</option>
|
36
|
+
</select></div>
|
37
|
+
</div>
|
38
|
+
<div class="chart" style="width: 1200px; height: 620px; ">
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<script type="text/javascript">
|
43
|
+
|
44
|
+
console.log("ciao");
|
45
|
+
|
46
|
+
var w = 1280 - 80,
|
47
|
+
h = 800 - 180,
|
48
|
+
x = d3.scale.linear().range([0, w]),
|
49
|
+
y = d3.scale.linear().range([0, h]),
|
50
|
+
color = d3.scale.category20c(),
|
51
|
+
root,
|
52
|
+
node;
|
53
|
+
|
54
|
+
var treemap = d3.layout.treemap()
|
55
|
+
.round(false)
|
56
|
+
.size([w, h])
|
57
|
+
.sticky(true)
|
58
|
+
.value(function (d) {
|
59
|
+
return d.size;
|
60
|
+
});
|
61
|
+
|
62
|
+
var svg = d3
|
63
|
+
.select("#body")
|
64
|
+
.append("div")
|
65
|
+
.attr("class", "chart")
|
66
|
+
.style("width", w + "px")
|
67
|
+
.style("height", h + "px")
|
68
|
+
.append("svg:svg")
|
69
|
+
.attr("width", w)
|
70
|
+
.attr("height", h)
|
71
|
+
.append("svg:g")
|
72
|
+
.attr("transform", "translate(.5,.5)");
|
73
|
+
|
74
|
+
d3.json("d3_tree_rb_output.json", function (data) {
|
75
|
+
node = root = data;
|
76
|
+
|
77
|
+
var nodes = treemap.nodes(root)
|
78
|
+
.filter(function (d) {
|
79
|
+
return !d.children;
|
80
|
+
});
|
81
|
+
|
82
|
+
var cell = svg.selectAll("g")
|
83
|
+
.data(nodes)
|
84
|
+
.enter().append("svg:g")
|
85
|
+
.attr("class", "cell")
|
86
|
+
.attr("transform", function (d) {
|
87
|
+
return "translate(" + d.x + "," + d.y + ")";
|
88
|
+
})
|
89
|
+
.on("click", function (d) {
|
90
|
+
return zoom(node == d.parent ? root : d.parent);
|
91
|
+
});
|
92
|
+
|
93
|
+
cell.append("svg:rect")
|
94
|
+
.attr("width", function (d) {
|
95
|
+
return d.dx - 1;
|
96
|
+
})
|
97
|
+
.attr("height", function (d) {
|
98
|
+
return d.dy - 1;
|
99
|
+
})
|
100
|
+
.style("fill", function (d) {
|
101
|
+
return color(d.parent.name);
|
102
|
+
});
|
103
|
+
|
104
|
+
cell.append("svg:text")
|
105
|
+
.attr("x", function (d) {
|
106
|
+
return d.dx / 2;
|
107
|
+
})
|
108
|
+
.attr("y", function (d) {
|
109
|
+
return d.dy / 2;
|
110
|
+
})
|
111
|
+
.attr("dy", ".35em")
|
112
|
+
.attr("text-anchor", "middle")
|
113
|
+
.text(function (d) {
|
114
|
+
return d.name;
|
115
|
+
})
|
116
|
+
.style("opacity", function (d) {
|
117
|
+
d.w = this.getComputedTextLength();
|
118
|
+
return d.dx > d.w ? 1 : 0;
|
119
|
+
});
|
120
|
+
|
121
|
+
d3.select(window).on("click", function () {
|
122
|
+
zoom(root);
|
123
|
+
});
|
124
|
+
|
125
|
+
d3.select("select").on("change", function () {
|
126
|
+
d3_treemap.value(this.value == "size" ? size : count).nodes(root);
|
127
|
+
zoom(node);
|
128
|
+
});
|
129
|
+
});
|
130
|
+
|
131
|
+
function size(d) {
|
132
|
+
return d.size;
|
133
|
+
}
|
134
|
+
|
135
|
+
function count(d) {
|
136
|
+
return 1;
|
137
|
+
}
|
138
|
+
|
139
|
+
function zoom(d) {
|
140
|
+
var kx = w / d.dx, ky = h / d.dy;
|
141
|
+
x.domain([d.x, d.x + d.dx]);
|
142
|
+
y.domain([d.y, d.y + d.dy]);
|
143
|
+
|
144
|
+
var t = svg.selectAll("g.cell").transition()
|
145
|
+
.duration(d3.event.altKey ? 7500 : 750)
|
146
|
+
.attr("transform", function (d) {
|
147
|
+
return "translate(" + x(d.x) + "," + y(d.y) + ")";
|
148
|
+
});
|
149
|
+
|
150
|
+
t.select("rect")
|
151
|
+
.attr("width", function (d) {
|
152
|
+
return kx * d.dx - 1;
|
153
|
+
})
|
154
|
+
.attr("height", function (d) {
|
155
|
+
return ky * d.dy - 1;
|
156
|
+
})
|
157
|
+
|
158
|
+
t.select("text")
|
159
|
+
.attr("x", function (d) {
|
160
|
+
return kx * d.dx / 2;
|
161
|
+
})
|
162
|
+
.attr("y", function (d) {
|
163
|
+
return ky * d.dy / 2;
|
164
|
+
})
|
165
|
+
.style("opacity", function (d) {
|
166
|
+
return kx * d.dx > d.w ? 1 : 0;
|
167
|
+
});
|
168
|
+
|
169
|
+
node = d;
|
170
|
+
d3.event.stopPropagation();
|
171
|
+
}
|
172
|
+
|
173
|
+
</script>
|
174
|
+
|
175
|
+
|
176
|
+
</body>
|
177
|
+
</html>
|