Public
Edited
Nov 20, 2022
Importers
1 star
Insert cell
md`# Non-Linear Sliders`
Insert cell
Insert cell
arr
Insert cell
function nonlinear_factor_sliders(config = {}) {
let {
values = [],
size = 10,
magnitude = 1,
base = 10,
step = 0.02,
labels = [],
value = 0,
show_percentages = 1,
title
} = typeof config === "number" ? { value: config } : config;
let formTemplate = `<form>`;
if (title) {
formTemplate += `<h2>${title}</h2>`;
}
for (let i = 0; i < size; i++) {
let n = "f" + i;
formTemplate += `<input type=range name=${n} min=${-magnitude} max=${magnitude} step=${step} value=${
values[i] == undefined ? 0 : values[i]
}><label id="${n}" for=${n}></label> ${labels[i] || ""}<br/>`;
}
formTemplate += `</form>`;
return (function() {
const form = html`${formTemplate}`;
form.oninput = () => {
let a = [];
for (let i = 0; i < size; i++) {
let n = "f" + i;
let linear_input = form[n].valueAsNumber;
let nonlinear = base ** linear_input;
if (show_percentages) {
form.children.namedItem(n).innerText = `${(100 * nonlinear).toFixed(
1
)} %`;
}
a.push(nonlinear);
}
form.value = a;
return form.value;
};
form.oninput();
return form;
})();
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more