Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
MUR Drupal
d3-library
Commits
0e0ba089
Commit
0e0ba089
authored
Oct 07, 2011
by
Mike Bostock
Browse files
Fix a centroid bug with CCW polygons.
parent
9edd4bc0
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
d3.geo.js
View file @
0e0ba089
...
...
@@ -542,18 +542,20 @@ d3.geo.path = function() {
function
polygonCentroid
(
coordinates
)
{
var
polygon
=
d3
.
geom
.
polygon
(
coordinates
[
0
].
map
(
projection
)),
// exterior ring
centroid
=
polygon
.
centroid
(
1
),
area
=
polygon
.
area
(),
centroid
=
polygon
.
centroid
(
area
<
0
?
(
area
*=
-
1
,
1
)
:
-
1
),
x
=
centroid
[
0
],
y
=
centroid
[
1
],
z
=
Math
.
abs
(
polygon
.
area
())
,
z
=
area
,
i
=
0
,
// coordinates index
n
=
coordinates
.
length
;
while
(
++
i
<
n
)
{
polygon
=
d3
.
geom
.
polygon
(
coordinates
[
i
].
map
(
projection
));
// holes
centroid
=
polygon
.
centroid
(
1
);
area
=
polygon
.
area
();
centroid
=
polygon
.
centroid
(
area
<
0
?
(
area
*=
-
1
,
1
)
:
-
1
);
x
-=
centroid
[
0
];
y
-=
centroid
[
1
];
z
-=
Math
.
abs
(
polygon
.
area
())
;
z
-=
area
;
}
return
[
x
,
y
,
6
*
z
];
// weighted centroid
}
...
...
d3.geo.min.js
View file @
0e0ba089
This diff is collapsed.
Click to expand it.
d3.js
View file @
0e0ba089
...
...
@@ -10,7 +10,7 @@ try {
d3_style_setProperty
.
call
(
this
,
name
,
value
+
""
,
priority
);
};
}
d3
=
{
version
:
"
2.3.
3
"
};
// semver
d3
=
{
version
:
"
2.3.
4
"
};
// semver
var
d3_array
=
d3_arraySlice
;
// conversion for NodeLists
function
d3_arrayCopy
(
pseudoarray
)
{
...
...
d3.min.js
View file @
0e0ba089
This diff is collapsed.
Click to expand it.
package.json
View file @
0e0ba089
{
"name"
:
"d3"
,
"version"
:
"2.3.
3
"
,
"version"
:
"2.3.
4
"
,
"description"
:
"A small, free JavaScript library for manipulating documents based on data."
,
"keywords"
:
[
"dom"
,
...
...
src/core/core.js
View file @
0e0ba089
d3
=
{
version
:
"
2.3.
3
"
};
// semver
d3
=
{
version
:
"
2.3.
4
"
};
// semver
src/geo/path.js
View file @
0e0ba089
...
...
@@ -186,18 +186,20 @@ d3.geo.path = function() {
function
polygonCentroid
(
coordinates
)
{
var
polygon
=
d3
.
geom
.
polygon
(
coordinates
[
0
].
map
(
projection
)),
// exterior ring
centroid
=
polygon
.
centroid
(
1
),
area
=
polygon
.
area
(),
centroid
=
polygon
.
centroid
(
area
<
0
?
(
area
*=
-
1
,
1
)
:
-
1
),
x
=
centroid
[
0
],
y
=
centroid
[
1
],
z
=
Math
.
abs
(
polygon
.
area
())
,
z
=
area
,
i
=
0
,
// coordinates index
n
=
coordinates
.
length
;
while
(
++
i
<
n
)
{
polygon
=
d3
.
geom
.
polygon
(
coordinates
[
i
].
map
(
projection
));
// holes
centroid
=
polygon
.
centroid
(
1
);
area
=
polygon
.
area
();
centroid
=
polygon
.
centroid
(
area
<
0
?
(
area
*=
-
1
,
1
)
:
-
1
);
x
-=
centroid
[
0
];
y
-=
centroid
[
1
];
z
-=
Math
.
abs
(
polygon
.
area
())
;
z
-=
area
;
}
return
[
x
,
y
,
6
*
z
];
// weighted centroid
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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