Skip to content

Commit

Permalink
Merge pull request #201 from episphere/tidy-code
Browse files Browse the repository at this point in the history
Add table bug fix to code-refactor
  • Loading branch information
LKMason authored Dec 5, 2023
2 parents 0c468c9 + 45a19fd commit 4e893d4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
2 changes: 0 additions & 2 deletions src/utils/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const SEARCH_SELECT_INPUT_QUERIES = [

export async function start() {
toggleLoading(true);

state = new State();
state.defineDynamicProperty("data", []);
state.defineDynamicProperty("mapZoom", 1);
Expand Down Expand Up @@ -221,7 +220,6 @@ function update() {
} else {
state.deferPlotFunction = plotFunction
}

plotTable()

// let valuesPrimary = null;
Expand Down
26 changes: 16 additions & 10 deletions src/utils/mapPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,22 @@ function plotConfigUpdated(plotConfig) {
elements.colorLegend.innerHTML = ""
elements.groupDownloadButton.setAttribute("disabled", "")
} else {
plotMortalityMapGrid(elements.mapGrid, legendContainer, plotConfig.mortalityData, primaryGeoJSON, {
overlayFeatureCollection: overlayGeoJSON,
rowField: plotConfig.query.compareRow,
columnField: plotConfig.query.compareColumn,
level: plotConfig.query.spatialLevel,
measureField: plotConfig.measure,
measureLabel: staticData.nameMappings["measures"][plotConfig.measure],
scheme: plotConfig.scheme,
featureNameFormat,
})
const isActiveTable = elements.tableNavLink.classList.contains('active')
if (isActiveTable) {
plotTable()
} else {
plotMortalityMapGrid(elements.mapGrid, legendContainer, plotConfig.mortalityData, primaryGeoJSON, {
overlayFeatureCollection: overlayGeoJSON,
rowField: plotConfig.query.compareRow,
columnField: plotConfig.query.compareColumn,
level: plotConfig.query.spatialLevel,
measureField: plotConfig.measure,
measureLabel: staticData.nameMappings["measures"][plotConfig.measure],
scheme: plotConfig.scheme,
featureNameFormat,
})
}

elements.groupDownloadButton.removeAttribute("disabled")
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/mapPlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export function createChoroplethPlot(spatialData, featureCollection, options={})

export function plotMortalityMapGrid(container, legendContainer, mortalityData, mainFeatureCollection, options={}) {
const mapsContainer = container
console.log('plotMortalityMapGrid', {mortalityData});

options = {
overlayFeatureCollection: null,
Expand Down
43 changes: 25 additions & 18 deletions src/utils/quantilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ async function queryUpdated(query) {
}

function plotConfigUpdated(plotConfig) {

console.log('plotConfigUpdated', {plotConfig: plotConfig, state});
const year = plotConfig.query.year.split("-").at(-1)

const measureDetails = names.quantile_fields[plotConfig.query.quantileField]
Expand All @@ -258,23 +258,29 @@ function plotConfigUpdated(plotConfig) {
const formatRace = d => names.races[d]?.formatted
const facetTickFormat = plotConfig.query.compareFacet == "race" ? formatRace : d => d
const colorTickFormat = plotConfig.query.compareColor == "race" ? formatRace : d => d

plotQuantileScatter(elements.plotContainer, data, {
valueField: plotConfig.measure,
facet: plotConfig.query.compareFacet != "none" ? plotConfig.query.compareFacet : null,
intervalFields: [plotConfig.measure+"_low", plotConfig.measure+"_high"],
color: colorFunction,
drawLines: state.showLines,
yStartZero: state.startZero,
xLabel: `${measureDetails.measure} (${measureDetails.unit})`,
yLabel: names.measures[plotConfig.measure],
facetLabel: names.fields[state.compareFacet],
xTickFormat: xTickFormat,
tooltipFields: [plotConfig.query.compareFacet, plotConfig.query.compareColor].filter(d => d != "none"),
colorDomain: colorDomainValues,
facetTickFormat,
colorTickFormat
})

const isActiveTable = elements.tableNavLink.classList.contains('active')

if (isActiveTable) {
plotTable()
} else {
plotQuantileScatter(elements.plotContainer, data, {
valueField: plotConfig.measure,
facet: plotConfig.query.compareFacet != "none" ? plotConfig.query.compareFacet : null,
intervalFields: [plotConfig.measure+"_low", plotConfig.measure+"_high"],
color: colorFunction,
drawLines: state.showLines,
yStartZero: state.startZero,
xLabel: `${measureDetails.measure} (${measureDetails.unit})`,
yLabel: names.measures[plotConfig.measure],
facetLabel: names.fields[state.compareFacet],
xTickFormat: xTickFormat,
tooltipFields: [plotConfig.query.compareFacet, plotConfig.query.compareColor].filter(d => d != "none"),
colorDomain: colorDomainValues,
facetTickFormat,
colorTickFormat
})
}

updateGraphTitle()
toggleLoading(false)
Expand Down Expand Up @@ -427,6 +433,7 @@ function setInputsEnabled(enabled) {

function plotTable() {
elements.tableContainer.innerHTML = ``
console.log('plotTable', {mortalityData: state.mortalityData});

new DataTable(elements.tableContainer, {
data: dataToTableData(state.mortalityData),
Expand Down

0 comments on commit 4e893d4

Please sign in to comment.