There was an error while loading. Please reload this page.
1 parent 5bae5f4 commit 149d174Copy full SHA for 149d174
4 files changed
d3.js
@@ -2578,11 +2578,11 @@ function d3_scale_log(linear, log) {
2578
var d3_scale_logFormat = d3.format(".0e");
2579
2580
function d3_scale_logp(x) {
2581
- return Math.log(x) / Math.LN10;
+ return Math.log(x < 0 ? 0 : x) / Math.LN10;
2582
}
2583
2584
function d3_scale_logn(x) {
2585
- return -Math.log(-x) / Math.LN10;
+ return -Math.log(x > 0 ? 0 : -x) / Math.LN10;
2586
2587
2588
d3_scale_logp.pow = function(x) {
d3.min.js
src/scale/log.js
@@ -69,11 +69,11 @@ function d3_scale_log(linear, log) {
69
70
71
72
73
74
75
76
77
78
79
test/scale/log-test.js
@@ -106,13 +106,23 @@ suite.addBatch({
106
},
107
"can clamp to the domain": function(log) {
108
var x = log().clamp(true);
109
- assert.inDelta(x(.5), 0, 1e-6);
+ assert.inDelta(x(-1), 0, 1e-6);
110
assert.inDelta(x(5), 0.69897, 1e-6);
111
assert.inDelta(x(15), 1, 1e-6);
112
var x = log().domain([10, 1]).clamp(true);
113
- assert.inDelta(x(.5), 1, 1e-6);
+ assert.inDelta(x(-1), 1, 1e-6);
114
assert.inDelta(x(5), 0.30103, 1e-6);
115
assert.inDelta(x(15), 0, 1e-6);
116
+ },
117
+ "can clamp to the range": function(log) {
118
+ var x = log().clamp(true);
119
+ assert.inDelta(x.invert(-.1), 1, 1e-6);
120
+ assert.inDelta(x.invert(0.69897), 5, 1e-6);
121
+ assert.inDelta(x.invert(1.5), 10, 1e-6);
122
+ var x = log().domain([10, 1]).clamp(true);
123
+ assert.inDelta(x.invert(-.1), 10, 1e-6);
124
+ assert.inDelta(x.invert(0.30103), 5, 1e-6);
125
+ assert.inDelta(x.invert(1.5), 1, 1e-6);
126
127
128
0 commit comments