-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3525fed
commit e48c6b5
Showing
13 changed files
with
132 additions
and
1,883 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
// filter.js | ||
export function filterData(originalData) { | ||
return originalData.filter((item) => { | ||
if (!document.querySelector(`input[value="${item.dayOfWeek}"]`).checked) { | ||
return false; | ||
} | ||
if (!document.querySelector(`input[value="${item.monthOfYear}"]`).checked) { | ||
return false; | ||
} | ||
if (!document.querySelector(`input[value="${item.productCategory}"]`).checked) { | ||
return false; | ||
} | ||
if (!document.querySelector(`input[value="${item.storeLocation}"]`).checked) { | ||
return false; | ||
} | ||
return true; | ||
return originalData.filter((item) => { | ||
const dayOfWeekChecked = document.querySelector(`input[value="${item.dayOfWeek}"]`).checked; | ||
const monthOfYearChecked = document.querySelector(`input[value="${item.monthOfYear}"]`).checked; | ||
const productCategoryChecked = document.querySelector(`input[value="${item.productCategory}"]`).checked; | ||
const storeLocationChecked = document.querySelector(`input[value="${item.storeLocation}"]`).checked; | ||
|
||
return dayOfWeekChecked && monthOfYearChecked && productCategoryChecked && storeLocationChecked; | ||
}); | ||
} | ||
|
||
export function addCheckboxEventListeners(updateDataDisplay, originalData) { | ||
document | ||
.querySelectorAll('input[type="checkbox"]') | ||
.forEach((checkbox) => { | ||
checkbox.addEventListener("change", () => { | ||
const filteredData = filterData(originalData); | ||
updateDataDisplay(filteredData); | ||
}); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { filterData, addCheckboxEventListeners } from './filter.js'; | ||
|
||
window.addEventListener('load', initialize); | ||
|
||
function initialize() { | ||
fetchData("data/trend_data.json") | ||
.then((originalData) => { | ||
const updateDataDisplay = createDataDisplayUpdater(originalData); | ||
updateDataDisplay(originalData); | ||
addCheckboxEventListeners(updateDataDisplay, originalData); | ||
}) | ||
.catch((error) => console.error("Error:", error)); | ||
} | ||
|
||
function fetchData(url) { | ||
return fetch(url).then((response) => response.json()); | ||
} | ||
|
||
function createDataDisplayUpdater(originalData) { | ||
return function updateDataDisplay(data) { | ||
const filteredData = filterData(data); | ||
processAndDisplayData(filteredData); | ||
}; | ||
} | ||
|
||
function processAndDisplayData(data) { | ||
const table = document.getElementById("storeTable"); | ||
table.innerHTML = ''; // Clear existing table rows | ||
|
||
const groupedData = data.reduce((acc, curr) => { | ||
const key = `${curr.productCategory}-${curr.productType}-${curr.storeLocation}`; | ||
if (!acc[key]) { | ||
acc[key] = { | ||
productCategory: curr.productCategory, | ||
productType: curr.productType, | ||
storeLocation: curr.storeLocation, | ||
totalQty: 0, | ||
totalRevenue: 0, | ||
}; | ||
} | ||
acc[key].totalQty += curr.totalQty; | ||
acc[key].totalRevenue += curr.totalRevenue; | ||
return acc; | ||
}, {}); | ||
|
||
const sortedData = Object.values(groupedData).sort((a, b) => { | ||
if (a.productCategory < b.productCategory) return -1; | ||
if (a.productCategory > b.productCategory) return 1; | ||
if (a.productType < b.productType) return -1; | ||
if (a.productType > b.productType) return 1; | ||
return b.totalRevenue - a.totalRevenue; | ||
}); | ||
|
||
sortedData.forEach((item) => { | ||
const row = `<tr> | ||
<td>${item.productType}</td> | ||
<td>${item.storeLocation}</td> | ||
<td>${item.totalQty}</td> | ||
<td>${item.totalRevenue}</td> | ||
</tr>`; | ||
table.innerHTML += row; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.