Simplify code
This commit is contained in:
30
app.qmd
30
app.qmd
@@ -46,24 +46,22 @@ chart = {
|
|||||||
{ label: 'Noncentrality', get: () => selectedNonc, set: v => selectedNonc = v, min: -4, max: 4, step: 2 },
|
{ label: 'Noncentrality', get: () => selectedNonc, set: v => selectedNonc = v, min: -4, max: 4, step: 2 },
|
||||||
{ label: 'Tailweight', get: () => Math.log2(selectedTailw), set: v => selectedTailw = 2 ** v, min: -2, max: 2, step: 1 }
|
{ label: 'Tailweight', get: () => Math.log2(selectedTailw), set: v => selectedTailw = 2 ** v, min: -2, max: 2, step: 1 }
|
||||||
];
|
];
|
||||||
sliders.forEach(s => {
|
// Build slider controls with D3 data join
|
||||||
const ctrl = controlsContainer.append('div').style('display','flex').style('align-items','center').style('gap','10px');
|
const sliderCont = controlsContainer.selectAll('div').data(sliders).join('div')
|
||||||
ctrl.append('label').text(`${s.label}:`).style('font-size','20px');
|
.style('display','flex').style('align-items','center').style('gap','10px')
|
||||||
ctrl.append('input')
|
.style('flex','1').style('min-width','0px');
|
||||||
.attr('type','range')
|
sliderCont.append('label').text(d => d.label + ':').style('font-size','20px');
|
||||||
.attr('min', s.min)
|
sliderCont.append('input')
|
||||||
.attr('max', s.max)
|
.attr('type','range').attr('min', d => d.min).attr('max', d => d.max).attr('step', d => d.step)
|
||||||
.attr('step', s.step)
|
.property('value', d => d.get())
|
||||||
.property('value', s.get())
|
.on('input', function(event, d) {
|
||||||
.on('input', function() {
|
const val = +this.value; d.set(val);
|
||||||
const val = +this.value;
|
d3.select(this.parentNode).select('span').text(d.label.match(/Sigma|Tailweight/) ? 2**val : val);
|
||||||
s.set(val);
|
|
||||||
ctrl.select('span').text(s.label === 'Sigma' || s.label === 'Tailweight' ? (2 ** val) : val);
|
|
||||||
updateChart(filteredData());
|
updateChart(filteredData());
|
||||||
})
|
})
|
||||||
.style('width', '100%').style('box-sizing', 'border-box');
|
.style('width', '100%');
|
||||||
ctrl.append('span').text(s.label === 'Sigma' || s.label === 'Tailweight' ? selectedSig : s.get()).style('font-size','20px');
|
sliderCont.append('span').text(d => (d.label.match(/Sigma|Tailweight/) ? d.get() : d.get()))
|
||||||
});
|
.style('font-size','20px');
|
||||||
// Build SVG
|
// Build SVG
|
||||||
const width = 800;
|
const width = 800;
|
||||||
const height = 400;
|
const height = 400;
|
||||||
|
|||||||
Reference in New Issue
Block a user