Preview a chart while editing its value
This GistPad example puts editing next to a D3 preview. Explore a shorter feedback loop between the input and the chart.
Jonathan Carter · GistPad · Source post
Visualize edited numbers in place
An independent web example inspired by the original reference.
Change the number to 75, then to 101, and observe the difference in display.
Implementation steps
- Place the numeric input and preview in the same spot. The sample uses 0–100 progress.
- Validate the value on input events. If valid, update the gauge and displayed value from the same state.
- If out of range or empty, show the reason and keep the last valid preview.
Acceptance check
Valid values apply immediately; invalid values keep the last correct display.
View sample code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Visualize edited numbers in place</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 16px;
background: #23232a;
color: #f4f0ea;
font: 16px/1.6 system-ui, sans-serif;
}
label, output, strong, audio, progress { display: block; margin: 6px 0; }
input, select, button { max-width: 100%; font: inherit; }
input, select { padding: 4px 7px; }
button {
margin: 4px 0;
padding: 5px 12px;
cursor: pointer;
border: 1px solid #b5a399;
border-radius: 6px;
}
:focus-visible { outline: 3px solid #ffad73; outline-offset: 2px; }
audio { width: 100%; }
[hidden] { display: none !important; }
</style>
</head>
<body>
<label>Progress (%) <input type="number" id="value" min="0" max="100" value="40" required></label>
<progress id="bar" max="100" value="40" aria-label="Progress"></progress>
<output id="percent">40%</output>
<p id="error" role="status"></p>
<script>
const input = document.querySelector('#value');
input.oninput = () => {
const valid = input.checkValidity();
document.querySelector('#error').textContent = valid ? '' : 'Enter a whole number from 0 to 100';
if (!valid) return;
document.querySelector('#bar').value = input.valueAsNumber;
document.querySelector('#percent').textContent = input.value + '%';
};
</script>
</body>
</html>Save as index.html and open in a browser to run it locally.