You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
848 B
35 lines
848 B
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);
|
|
}
|
|
|