diff --git a/docs/income.md b/docs/income.md index 47f8fe2..24ff324 100644 --- a/docs/income.md +++ b/docs/income.md @@ -15,14 +15,6 @@ const selectedYear = Generators.input(yearInput); yearInput.querySelector("input[type=number]").remove(); ``` -```js -const mostRecentYear = uniqueYears[uniqueYears.length - 1]; -const income = await db.query(` - SELECT income, count, sector FROM data - WHERE year = ${mostRecentYear} -`); -``` - ```js // Order the sectors by mean income const mostRecentYear = uniqueYears[uniqueYears.length - 1]; @@ -36,20 +28,20 @@ const orderSectors = await db.query(` ``` ```js -async function incomeChart(db, selectedYear, width) { - const income = await db.query(` +const income = db.query(` SELECT income, count, sector FROM data WHERE year = ${selectedYear} - `); - - console.log(income); // Should show the resolved array of data, not a promise - console.log(orderSectors); // Should show an array of sector names +`); +``` +```js +function incomeChart(income, width) { // Create a histogram with a logarithmic base. return Plot.plot({ width, marginLeft: 60, x: { type: "log" }, + y: { axis: null }, // Hide the y-axis color: { legend: "swatches", columns: 6, domain: orderSectors }, marks: [ Plot.rectY( @@ -73,36 +65,6 @@ async function incomeChart(db, selectedYear, width) { } ``` -```js -// Assuming yearInput is already defined and set up as shown in your code. - -// Listen for changes on the yearInput to update the chart accordingly. -yearInput.addEventListener('change', () => { - // Retrieve the current selected year from the input. - const selectedYear = yearInput.value; - - // Call renderChart with the selected year. - renderChart(selectedYear); -}); - -// Call renderChart initially to render the chart for the first time with the most recent year or a default year. -renderChart(yearInput.value); - -function renderChart(selectedYear) { - incomeChart(db, selectedYear, window.innerWidth * 0.9) // Adjust width as needed - .then(chart => { - const chartContainer = document.querySelector("#chartContainer"); - if (chartContainer) { - chartContainer.innerHTML = ''; // Clear the container before appending new content - chartContainer.appendChild(chart); // Append the chart - } else { - console.error("Chart container not found"); - } - }) - .catch(error => console.error("Failed to render chart:", error)); -} -``` -