Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MUR Drupal
d3-library
Commits
ea7b43e8
Commit
ea7b43e8
authored
May 18, 2014
by
Mike Bostock
Browse files
Abbreviate internal variables.
parent
b567b5d1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
116 deletions
+119
-116
d3.js
d3.js
+54
-54
d3.min.js
d3.min.js
+5
-5
src/layout/hierarchy.js
src/layout/hierarchy.js
+2
-0
src/layout/tree.js
src/layout/tree.js
+58
-57
No files found.
d3.js
View file @
ea7b43e8
...
...
@@ -6882,98 +6882,98 @@
}
}
d3
.
layout
.
tree
=
function
()
{
var
hierarchy
=
d3
.
layout
.
hierarchy
().
sort
(
null
).
value
(
null
),
separation
=
d3_layout_treeSeparation
,
size
=
[
1
,
1
],
nodeSize
=
false
;
var
hierarchy
=
d3
.
layout
.
hierarchy
().
sort
(
null
).
value
(
null
),
separation
=
d3_layout_treeSeparation
,
size
=
[
1
,
1
],
nodeSize
=
null
;
function
tree
(
d
,
i
)
{
var
nodes
=
hierarchy
.
call
(
this
,
d
,
i
),
root0
=
nodes
[
0
],
root1
=
wrapTree
(
root0
);
d3_layout_hierarchyVisitAfter
(
root1
,
firstWalk
),
root1
.
parent
.
m
od
=
-
root1
.
prelim
;
d3_layout_hierarchyVisitAfter
(
root1
,
firstWalk
),
root1
.
parent
.
m
=
-
root1
.
z
;
d3_layout_hierarchyVisitBefore
(
root1
,
secondWalk
);
if
(
nodeSize
)
{
d3_layout_hierarchyVisitBefore
(
root1
,
function
(
node
)
{
node
.
node
.
x
*=
size
[
0
];
node
.
node
.
y
=
node
.
node
.
depth
*
size
[
1
];
});
}
else
{
if
(
nodeSize
)
d3_layout_hierarchyVisitBefore
(
root1
,
sizeNode
);
else
{
var
left
=
d3_layout_treeSearch
(
root0
,
d3_layout_treeLeftmost
),
right
=
d3_layout_treeSearch
(
root0
,
d3_layout_treeRightmost
),
x0
=
left
.
x
-
separation
(
left
,
right
)
/
2
,
x1
=
right
.
x
+
separation
(
right
,
left
)
/
2
,
y1
=
d3_layout_treeSearch
(
root0
,
d3_layout_treeDeepest
).
depth
||
1
;
d3_layout_hierarchyVisitBefore
(
root1
,
function
(
node
)
{
node
.
node
.
x
=
(
node
.
node
.
x
-
x0
)
/
(
x1
-
x0
)
*
size
[
0
];
node
.
node
.
y
=
node
.
node
.
depth
/
y1
*
size
[
1
];
node
.
_
.
x
=
(
node
.
_
.
x
-
x0
)
/
(
x1
-
x0
)
*
size
[
0
];
node
.
_
.
y
=
node
.
_
.
depth
/
y1
*
size
[
1
];
});
}
return
nodes
;
}
function
wrapTree
(
root0
)
{
var
root1
=
{
defaultAncestor
:
null
,
A
:
null
,
children
:
[
root0
]
},
queue
=
[
root1
],
node1
;
while
((
node1
=
queue
.
pop
())
!=
null
)
{
for
(
var
children
=
node1
.
children
,
child
,
i
=
0
,
n
=
children
.
length
;
i
<
n
;
++
i
)
{
queue
.
push
((
children
[
i
]
=
child
=
{
node
:
children
[
i
],
_
:
children
[
i
],
parent
:
node1
,
children
:
(
child
=
children
[
i
].
children
)
&&
child
.
slice
()
||
[],
defaultAncestor
:
null
,
ancestor
:
null
,
prelim
:
0
,
mod
:
0
,
change
:
0
,
shift
:
0
,
number
:
i
}).
ancestor
=
child
);
A
:
null
,
a
:
null
,
z
:
0
,
m
:
0
,
c
:
0
,
s
:
0
,
t
:
null
,
i
:
i
}).
a
=
child
);
}
}
return
root1
.
children
[
0
];
}
function
firstWalk
(
v
)
{
var
children
=
v
.
children
,
siblings
=
v
.
parent
.
children
,
w
=
v
.
number
?
siblings
[
v
.
number
-
1
]
:
null
;
var
children
=
v
.
children
,
siblings
=
v
.
parent
.
children
,
w
=
v
.
i
?
siblings
[
v
.
i
-
1
]
:
null
;
if
(
children
.
length
)
{
d3_layout_treeShift
(
v
);
var
midpoint
=
(
children
[
0
].
prelim
+
children
[
children
.
length
-
1
].
prelim
)
/
2
;
var
midpoint
=
(
children
[
0
].
z
+
children
[
children
.
length
-
1
].
z
)
/
2
;
if
(
w
)
{
v
.
prelim
=
w
.
prelim
+
separation
(
v
.
node
,
w
.
node
);
v
.
m
od
=
v
.
prelim
-
midpoint
;
v
.
z
=
w
.
z
+
separation
(
v
.
_
,
w
.
_
);
v
.
m
=
v
.
z
-
midpoint
;
}
else
{
v
.
prelim
=
midpoint
;
v
.
z
=
midpoint
;
}
}
else
if
(
w
)
{
v
.
prelim
=
w
.
prelim
+
separation
(
v
.
node
,
w
.
node
);
v
.
z
=
w
.
z
+
separation
(
v
.
_
,
w
.
_
);
}
v
.
parent
.
defaultAncestor
=
apportion
(
v
,
w
,
v
.
parent
.
defaultAncestor
||
siblings
[
0
]);
v
.
parent
.
A
=
apportion
(
v
,
w
,
v
.
parent
.
A
||
siblings
[
0
]);
}
function
secondWalk
(
v
)
{
v
.
node
.
x
=
v
.
prelim
+
v
.
parent
.
m
od
;
v
.
m
od
+=
v
.
parent
.
m
od
;
v
.
_
.
x
=
v
.
z
+
v
.
parent
.
m
;
v
.
m
+=
v
.
parent
.
m
;
}
function
apportion
(
v
,
w
,
ancestor
)
{
if
(
w
)
{
var
vip
=
v
,
vop
=
v
,
vim
=
w
,
vom
=
vip
.
parent
.
children
[
0
],
sip
=
vip
.
m
od
,
sop
=
vop
.
m
od
,
sim
=
vim
.
m
od
,
som
=
vom
.
m
od
,
shift
;
var
vip
=
v
,
vop
=
v
,
vim
=
w
,
vom
=
vip
.
parent
.
children
[
0
],
sip
=
vip
.
m
,
sop
=
vop
.
m
,
sim
=
vim
.
m
,
som
=
vom
.
m
,
shift
;
while
(
vim
=
d3_layout_treeRight
(
vim
),
vip
=
d3_layout_treeLeft
(
vip
),
vim
&&
vip
)
{
vom
=
d3_layout_treeLeft
(
vom
);
vop
=
d3_layout_treeRight
(
vop
);
vop
.
a
ncestor
=
v
;
shift
=
vim
.
prelim
+
sim
-
vip
.
prelim
-
sip
+
separation
(
vim
.
node
,
vip
.
node
);
vop
.
a
=
v
;
shift
=
vim
.
z
+
sim
-
vip
.
z
-
sip
+
separation
(
vim
.
_
,
vip
.
_
);
if
(
shift
>
0
)
{
d3_layout_treeMove
(
d3_layout_treeAncestor
(
vim
,
v
,
ancestor
),
v
,
shift
);
sip
+=
shift
;
sop
+=
shift
;
}
sim
+=
vim
.
m
od
;
sip
+=
vip
.
m
od
;
som
+=
vom
.
m
od
;
sop
+=
vop
.
m
od
;
sim
+=
vim
.
m
;
sip
+=
vip
.
m
;
som
+=
vom
.
m
;
sop
+=
vop
.
m
;
}
if
(
vim
&&
!
d3_layout_treeRight
(
vop
))
{
vop
.
t
hread
=
vim
;
vop
.
m
od
+=
sim
-
sop
;
vop
.
t
=
vim
;
vop
.
m
+=
sim
-
sop
;
}
if
(
vip
&&
!
d3_layout_treeLeft
(
vom
))
{
vom
.
t
hread
=
vip
;
vom
.
m
od
+=
sip
-
som
;
vom
.
t
=
vip
;
vom
.
m
+=
sip
-
som
;
ancestor
=
v
;
}
}
return
ancestor
;
}
function
sizeNode
(
node
)
{
node
.
_
.
x
*=
size
[
0
];
node
.
_
.
y
=
node
.
_
.
depth
*
size
[
1
];
}
tree
.
separation
=
function
(
x
)
{
if
(
!
arguments
.
length
)
return
separation
;
separation
=
x
;
...
...
@@ -6981,12 +6981,12 @@
};
tree
.
size
=
function
(
x
)
{
if
(
!
arguments
.
length
)
return
nodeSize
?
null
:
size
;
nodeSize
=
(
size
=
x
)
==
null
;
nodeSize
=
(
size
=
x
)
==
null
?
sizeNode
:
null
;
return
tree
;
};
tree
.
nodeSize
=
function
(
x
)
{
if
(
!
arguments
.
length
)
return
nodeSize
?
size
:
null
;
nodeSize
=
(
size
=
x
)
!
=
null
;
nodeSize
=
(
size
=
x
)
=
=
null
?
null
:
sizeNode
;
return
tree
;
};
return
d3_layout_hierarchyRebind
(
tree
,
hierarchy
);
...
...
@@ -7017,31 +7017,31 @@
}
function
d3_layout_treeLeft
(
v
)
{
var
children
=
v
.
children
;
return
children
.
length
?
children
[
0
]
:
v
.
t
hread
;
return
children
.
length
?
children
[
0
]
:
v
.
t
;
}
function
d3_layout_treeRight
(
v
)
{
var
children
=
v
.
children
,
n
;
return
(
n
=
children
.
length
)
?
children
[
n
-
1
]
:
v
.
t
hread
;
return
(
n
=
children
.
length
)
?
children
[
n
-
1
]
:
v
.
t
;
}
function
d3_layout_treeMove
(
wm
,
wp
,
shift
)
{
var
change
=
shift
/
(
wp
.
number
-
wm
.
number
);
wp
.
c
hange
-=
change
;
wp
.
s
hift
+=
shift
;
wm
.
c
hange
+=
change
;
wp
.
prelim
+=
shift
;
wp
.
m
od
+=
shift
;
var
change
=
shift
/
(
wp
.
i
-
wm
.
i
);
wp
.
c
-=
change
;
wp
.
s
+=
shift
;
wm
.
c
+=
change
;
wp
.
z
+=
shift
;
wp
.
m
+=
shift
;
}
function
d3_layout_treeShift
(
v
)
{
var
shift
=
0
,
change
=
0
,
children
=
v
.
children
,
i
=
children
.
length
,
w
;
while
(
--
i
>=
0
)
{
w
=
children
[
i
];
w
.
prelim
+=
shift
;
w
.
m
od
+=
shift
;
shift
+=
w
.
s
hift
+
(
change
+=
w
.
c
hange
);
w
.
z
+=
shift
;
w
.
m
+=
shift
;
shift
+=
w
.
s
+
(
change
+=
w
.
c
);
}
}
function
d3_layout_treeAncestor
(
vim
,
v
,
ancestor
)
{
return
vim
.
a
ncestor
.
parent
===
v
.
parent
?
vim
.
a
ncestor
:
ancestor
;
return
vim
.
a
.
parent
===
v
.
parent
?
vim
.
a
:
ancestor
;
}
d3
.
layout
.
cluster
=
function
()
{
var
hierarchy
=
d3
.
layout
.
hierarchy
().
sort
(
null
).
value
(
null
),
separation
=
d3_layout_treeSeparation
,
size
=
[
1
,
1
],
nodeSize
=
false
;
...
...
d3.min.js
View file @
ea7b43e8
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/layout/hierarchy.js
View file @
ea7b43e8
...
...
@@ -82,6 +82,7 @@ function d3_layout_hierarchyRebind(object, hierarchy) {
return
object
;
}
// Pre-order traversal.
function
d3_layout_hierarchyVisitBefore
(
node
,
callback
)
{
var
nodes
=
[
node
];
while
((
node
=
nodes
.
pop
())
!=
null
)
{
...
...
@@ -93,6 +94,7 @@ function d3_layout_hierarchyVisitBefore(node, callback) {
}
}
// Post-order traversal.
function
d3_layout_hierarchyVisitAfter
(
node
,
callback
)
{
var
nodes
=
[
node
],
nodes2
=
[];
while
((
node
=
nodes
.
pop
())
!=
null
)
{
...
...
src/layout/tree.js
View file @
ea7b43e8
...
...
@@ -6,7 +6,7 @@ d3.layout.tree = function() {
var
hierarchy
=
d3
.
layout
.
hierarchy
().
sort
(
null
).
value
(
null
),
separation
=
d3_layout_treeSeparation
,
size
=
[
1
,
1
],
// width, height
nodeSize
=
false
;
nodeSize
=
null
;
function
tree
(
d
,
i
)
{
var
nodes
=
hierarchy
.
call
(
this
,
d
,
i
),
...
...
@@ -14,16 +14,11 @@ d3.layout.tree = function() {
root1
=
wrapTree
(
root0
);
// Compute the layout using Buchheim et al.'s algorithm.
d3_layout_hierarchyVisitAfter
(
root1
,
firstWalk
),
root1
.
parent
.
m
od
=
-
root1
.
prelim
;
d3_layout_hierarchyVisitAfter
(
root1
,
firstWalk
),
root1
.
parent
.
m
=
-
root1
.
z
;
d3_layout_hierarchyVisitBefore
(
root1
,
secondWalk
);
// If a fixed node size is specified, scale x and y.
if
(
nodeSize
)
{
d3_layout_hierarchyVisitBefore
(
root1
,
function
(
node
)
{
node
.
node
.
x
*=
size
[
0
];
node
.
node
.
y
=
node
.
node
.
depth
*
size
[
1
];
});
}
if
(
nodeSize
)
d3_layout_hierarchyVisitBefore
(
root1
,
sizeNode
);
// If a fixed tree size is specified, scale x and y based on the extent.
// Compute the left-most, right-most, and depth-most nodes for extents.
...
...
@@ -34,8 +29,8 @@ d3.layout.tree = function() {
x1
=
right
.
x
+
separation
(
right
,
left
)
/
2
,
y1
=
d3_layout_treeSearch
(
root0
,
d3_layout_treeDeepest
).
depth
||
1
;
d3_layout_hierarchyVisitBefore
(
root1
,
function
(
node
)
{
node
.
node
.
x
=
(
node
.
node
.
x
-
x0
)
/
(
x1
-
x0
)
*
size
[
0
];
node
.
node
.
y
=
node
.
node
.
depth
/
y1
*
size
[
1
];
node
.
_
.
x
=
(
node
.
_
.
x
-
x0
)
/
(
x1
-
x0
)
*
size
[
0
];
node
.
_
.
y
=
node
.
_
.
depth
/
y1
*
size
[
1
];
});
}
...
...
@@ -43,24 +38,25 @@ d3.layout.tree = function() {
}
function
wrapTree
(
root0
)
{
var
root1
=
{
defaultAncestor
:
null
,
children
:
[
root0
]},
var
root1
=
{
A
:
null
,
children
:
[
root0
]},
queue
=
[
root1
],
node1
;
while
((
node1
=
queue
.
pop
())
!=
null
)
{
for
(
var
children
=
node1
.
children
,
child
,
i
=
0
,
n
=
children
.
length
;
i
<
n
;
++
i
)
{
queue
.
push
((
children
[
i
]
=
child
=
{
node
:
children
[
i
],
_
:
children
[
i
],
// source node
parent
:
node1
,
children
:
(
child
=
children
[
i
].
children
)
&&
child
.
slice
()
||
[],
defaultAncestor
:
null
,
ancestor
:
null
,
prelim
:
0
,
mod
:
0
,
change
:
0
,
shift
:
0
,
number
:
i
}).
ancestor
=
child
);
A
:
null
,
// default ancestor
a
:
null
,
// ancestor
z
:
0
,
// prelim
m
:
0
,
// mod
c
:
0
,
// change
s
:
0
,
// shift
t
:
null
,
// thread
i
:
i
// number
}).
a
=
child
);
}
}
...
...
@@ -75,27 +71,27 @@ d3.layout.tree = function() {
function
firstWalk
(
v
)
{
var
children
=
v
.
children
,
siblings
=
v
.
parent
.
children
,
w
=
v
.
number
?
siblings
[
v
.
number
-
1
]
:
null
;
w
=
v
.
i
?
siblings
[
v
.
i
-
1
]
:
null
;
if
(
children
.
length
)
{
d3_layout_treeShift
(
v
);
var
midpoint
=
(
children
[
0
].
prelim
+
children
[
children
.
length
-
1
].
prelim
)
/
2
;
var
midpoint
=
(
children
[
0
].
z
+
children
[
children
.
length
-
1
].
z
)
/
2
;
if
(
w
)
{
v
.
prelim
=
w
.
prelim
+
separation
(
v
.
node
,
w
.
node
);
v
.
m
od
=
v
.
prelim
-
midpoint
;
v
.
z
=
w
.
z
+
separation
(
v
.
_
,
w
.
_
);
v
.
m
=
v
.
z
-
midpoint
;
}
else
{
v
.
prelim
=
midpoint
;
v
.
z
=
midpoint
;
}
}
else
if
(
w
)
{
v
.
prelim
=
w
.
prelim
+
separation
(
v
.
node
,
w
.
node
);
v
.
z
=
w
.
z
+
separation
(
v
.
_
,
w
.
_
);
}
v
.
parent
.
defaultAncestor
=
apportion
(
v
,
w
,
v
.
parent
.
defaultAncestor
||
siblings
[
0
]);
v
.
parent
.
A
=
apportion
(
v
,
w
,
v
.
parent
.
A
||
siblings
[
0
]);
}
// SECOND WALK
// Computes all real x-coordinates by summing up the modifiers recursively.
function
secondWalk
(
v
)
{
v
.
node
.
x
=
v
.
prelim
+
v
.
parent
.
m
od
;
v
.
m
od
+=
v
.
parent
.
m
od
;
v
.
_
.
x
=
v
.
z
+
v
.
parent
.
m
;
v
.
m
+=
v
.
parent
.
m
;
}
// APPORTION
...
...
@@ -116,39 +112,44 @@ d3.layout.tree = function() {
vop
=
v
,
vim
=
w
,
vom
=
vip
.
parent
.
children
[
0
],
sip
=
vip
.
m
od
,
sop
=
vop
.
m
od
,
sim
=
vim
.
m
od
,
som
=
vom
.
m
od
,
sip
=
vip
.
m
,
sop
=
vop
.
m
,
sim
=
vim
.
m
,
som
=
vom
.
m
,
shift
;
while
(
vim
=
d3_layout_treeRight
(
vim
),
vip
=
d3_layout_treeLeft
(
vip
),
vim
&&
vip
)
{
vom
=
d3_layout_treeLeft
(
vom
);
vop
=
d3_layout_treeRight
(
vop
);
vop
.
a
ncestor
=
v
;
shift
=
vim
.
prelim
+
sim
-
vip
.
prelim
-
sip
+
separation
(
vim
.
node
,
vip
.
node
);
vop
.
a
=
v
;
shift
=
vim
.
z
+
sim
-
vip
.
z
-
sip
+
separation
(
vim
.
_
,
vip
.
_
);
if
(
shift
>
0
)
{
d3_layout_treeMove
(
d3_layout_treeAncestor
(
vim
,
v
,
ancestor
),
v
,
shift
);
sip
+=
shift
;
sop
+=
shift
;
}
sim
+=
vim
.
m
od
;
sip
+=
vip
.
m
od
;
som
+=
vom
.
m
od
;
sop
+=
vop
.
m
od
;
sim
+=
vim
.
m
;
sip
+=
vip
.
m
;
som
+=
vom
.
m
;
sop
+=
vop
.
m
;
}
if
(
vim
&&
!
d3_layout_treeRight
(
vop
))
{
vop
.
t
hread
=
vim
;
vop
.
m
od
+=
sim
-
sop
;
vop
.
t
=
vim
;
vop
.
m
+=
sim
-
sop
;
}
if
(
vip
&&
!
d3_layout_treeLeft
(
vom
))
{
vom
.
t
hread
=
vip
;
vom
.
m
od
+=
sip
-
som
;
vom
.
t
=
vip
;
vom
.
m
+=
sip
-
som
;
ancestor
=
v
;
}
}
return
ancestor
;
}
function
sizeNode
(
node
)
{
node
.
_
.
x
*=
size
[
0
];
node
.
_
.
y
=
node
.
_
.
depth
*
size
[
1
];
}
tree
.
separation
=
function
(
x
)
{
if
(
!
arguments
.
length
)
return
separation
;
separation
=
x
;
...
...
@@ -157,13 +158,13 @@ d3.layout.tree = function() {
tree
.
size
=
function
(
x
)
{
if
(
!
arguments
.
length
)
return
nodeSize
?
null
:
size
;
nodeSize
=
(
size
=
x
)
==
null
;
nodeSize
=
(
size
=
x
)
==
null
?
sizeNode
:
null
;
return
tree
;
};
tree
.
nodeSize
=
function
(
x
)
{
if
(
!
arguments
.
length
)
return
nodeSize
?
size
:
null
;
nodeSize
=
(
size
=
x
)
!
=
null
;
nodeSize
=
(
size
=
x
)
=
=
null
?
null
:
sizeNode
;
return
tree
;
};
...
...
@@ -212,26 +213,26 @@ function d3_layout_treeDeepest(a, b) {
// returns null if and only if v is on the highest level of its subtree.
function
d3_layout_treeLeft
(
v
)
{
var
children
=
v
.
children
;
return
children
.
length
?
children
[
0
]
:
v
.
t
hread
;
return
children
.
length
?
children
[
0
]
:
v
.
t
;
}
// NEXT RIGHT
// This function works analogously to NEXT LEFT.
function
d3_layout_treeRight
(
v
)
{
var
children
=
v
.
children
,
n
;
return
(
n
=
children
.
length
)
?
children
[
n
-
1
]
:
v
.
t
hread
;
return
(
n
=
children
.
length
)
?
children
[
n
-
1
]
:
v
.
t
;
}
// MOVE SUBTREE
// Shifts the current subtree rooted at w+. This is done by increasing
// prelim(w+) and mod(w+) by shift.
function
d3_layout_treeMove
(
wm
,
wp
,
shift
)
{
var
change
=
shift
/
(
wp
.
number
-
wm
.
number
);
wp
.
c
hange
-=
change
;
wp
.
s
hift
+=
shift
;
wm
.
c
hange
+=
change
;
wp
.
prelim
+=
shift
;
wp
.
m
od
+=
shift
;
var
change
=
shift
/
(
wp
.
i
-
wm
.
i
);
wp
.
c
-=
change
;
wp
.
s
+=
shift
;
wm
.
c
+=
change
;
wp
.
z
+=
shift
;
wp
.
m
+=
shift
;
}
// EXECUTE SHIFTS
...
...
@@ -246,9 +247,9 @@ function d3_layout_treeShift(v) {
w
;
while
(
--
i
>=
0
)
{
w
=
children
[
i
];
w
.
prelim
+=
shift
;
w
.
m
od
+=
shift
;
shift
+=
w
.
s
hift
+
(
change
+=
w
.
c
hange
);
w
.
z
+=
shift
;
w
.
m
+=
shift
;
shift
+=
w
.
s
+
(
change
+=
w
.
c
);
}
}
...
...
@@ -256,5 +257,5 @@ function d3_layout_treeShift(v) {
// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
// returns the specified (default) ancestor.
function
d3_layout_treeAncestor
(
vim
,
v
,
ancestor
)
{
return
vim
.
a
ncestor
.
parent
===
v
.
parent
?
vim
.
a
ncestor
:
ancestor
;
return
vim
.
a
.
parent
===
v
.
parent
?
vim
.
a
:
ancestor
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment