Published
Edited
Oct 13, 2021
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
scale = scaleExponent() // Work the "same" way as in scaleLinear
.number(2) // the number to raise to the power of ..., 2 by default if no arguments return the number, if null resets to 2
.domain([0, values]) // by default domains is [0, 1], if no arguments, return the current domain, if null resets to default
.range([7, 25]) // by default range is [0, 1], if no arguments, return the current domain, if null resets to default
Insert cell
Insert cell
Insert cell
Insert cell
tex`${scale.number()}^{${scale.exponent(value)}} = ${scale(value)}`
Insert cell
scale.invert(scale(value))
Insert cell
scale.invert2(scale(value))
Insert cell
scale.ticks().map(scale)
Insert cell
Insert cell
Insert cell
scaleExponent = (domain = [0, 1], range = [0, 1]) => {
let m,
b,
n = 2;

function up() {
m = (range[1] - range[0]) / (domain[1] - domain[0]);
}
up();

const exp = (x) => Math.pow(n, m * (x - domain[0]) + range[0]);
exp.exponent = (x) => m * (x - domain[0]) + range[0];
exp.number = (_) => (_ === undefined ? n : ((n = _ ?? 2), exp));
exp.domain = (_) =>
_ === undefined ? domain : ((domain = _ ?? [0, 1]), up(), exp);
exp.range = (_) =>
_ === undefined ? range : ((range = _ ?? [0, 1]), up(), exp);
exp.invert = (x) => (Math.log(x) / Math.log(n) - range[0]) / m + domain[0];
exp.invert2 = (x) =>
((domain[1] - domain[0]) / (range[1] - range[0])) *
(Math.log(x) / Math.log(n) - range[0]) +
domain[0];
exp.ticks = function (count) {
var d = exp.domain();
return d3.ticks(d[0], d[d.length - 1], count == null ? 10 : count);
};

return exp;
}
Insert cell
import { funplot } from "@mbostock/funplot"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more