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
d6ca25e8
Commit
d6ca25e8
authored
Mar 23, 2014
by
Mike Bostock
Browse files
Fix ordinal scales with singleton domains.
Fixes #1717. Turns out, -1 % 1 is 0!
parent
f9e00b1d
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
3 deletions
+5
-3
d3.js
d3.js
+1
-1
d3.min.js
d3.min.js
+1
-1
src/scale/ordinal.js
src/scale/ordinal.js
+1
-1
test/scale/ordinal-test.js
test/scale/ordinal-test.js
+2
-0
No files found.
d3.js
View file @
d6ca25e8
...
...
@@ -7615,7 +7615,7 @@
function
d3_scale_ordinal
(
domain
,
ranger
)
{
var
index
,
range
,
rangeBand
;
function
scale
(
x
)
{
return
range
[((
index
.
get
(
x
)
||
ranger
.
t
===
"
range
"
&&
index
.
set
(
x
,
domain
.
push
(
x
)))
-
1
)
%
range
.
length
];
return
range
[((
index
.
get
(
x
)
||
(
ranger
.
t
===
"
range
"
?
index
.
set
(
x
,
domain
.
push
(
x
))
:
NaN
)
)
-
1
)
%
range
.
length
];
}
function
steps
(
start
,
step
)
{
return
d3
.
range
(
domain
.
length
).
map
(
function
(
i
)
{
...
...
d3.min.js
View file @
d6ca25e8
This diff is collapsed.
Click to expand it.
src/scale/ordinal.js
View file @
d6ca25e8
...
...
@@ -12,7 +12,7 @@ function d3_scale_ordinal(domain, ranger) {
rangeBand
;
function
scale
(
x
)
{
return
range
[((
index
.
get
(
x
)
||
ranger
.
t
===
"
range
"
&&
index
.
set
(
x
,
domain
.
push
(
x
)))
-
1
)
%
range
.
length
];
return
range
[((
index
.
get
(
x
)
||
(
ranger
.
t
===
"
range
"
?
index
.
set
(
x
,
domain
.
push
(
x
))
:
NaN
)
)
-
1
)
%
range
.
length
];
}
function
steps
(
start
,
step
)
{
...
...
test/scale/ordinal-test.js
View file @
d6ca25e8
...
...
@@ -117,6 +117,8 @@ suite.addBatch({
"
correctly handles singleton domains
"
:
function
(
ordinal
)
{
var
x
=
ordinal
().
domain
([
"
a
"
]).
rangePoints
([
0
,
120
]);
assert
.
deepEqual
(
x
.
range
(),
[
60
]);
assert
.
isUndefined
(
x
(
"
b
"
));
assert
.
deepEqual
(
x
.
domain
(),
[
"
a
"
]);
},
"
can be set to a descending range
"
:
function
(
ordinal
)
{
var
x
=
ordinal
().
domain
([
"
a
"
,
"
b
"
,
"
c
"
]).
rangePoints
([
120
,
0
]);
...
...
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