File size: 848 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import {linearish} from "./linear.js";
import {copy, transformer} from "./continuous.js";
import {initRange} from "./init.js";
function transformSymlog(c) {
return function(x) {
return Math.sign(x) * Math.log1p(Math.abs(x / c));
};
}
function transformSymexp(c) {
return function(x) {
return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
};
}
export function symlogish(transform) {
var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
scale.constant = function(_) {
return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
};
return linearish(scale);
}
export default function symlog() {
var scale = symlogish(transformer());
scale.copy = function() {
return copy(scale, symlog()).constant(scale.constant());
};
return initRange.apply(scale, arguments);
}
|