doc_range = docWidget({
linePadding: 5,
inputs: {
r: slider({title: `ratio`, min:0.01, max:1, step:'any', value:.25}),
c: slider({title: `count`, min:1, max:10, step:1, value:6}),
i: slider({title: `i`, min:0, max:99, step:1, value:1}),
},
outputLabel: 'range(ratio,count,i)',
output: ({r, c, i}) => range(+r.value, +c.value, +i.value),
onInput: ({c, i}) => {
i[0].max = c[0].valueAsNumber-1;
i.dispatchEvent(new CustomEvent('input', {bubble: false}));
},
onDraw: (api, {c, r, i}) => {
const count = +c.value, ratio = +r.value, index = +i.value;
const height = 1/count, offsets = Array.from({length: count}, (_, i) => {
const [min, max] = range(ratio, count, i);
return {i, x: min, y: i/count, width: (max - min)};
});
api.secondary().lineWidth(1).lineDash([3]);
for(const {x, width} of offsets) api.verticalLine(x + width/2);
for(const {i, x, y, width} of offsets) {
i === index ? api.secondary() : api.primary();
api.box(x, y, width, height, 1);
}
},
})