When selecting a different county (e.g., Brooks) from the county dropdown, the system was:
- Correctly filtering the year and voting method dropdowns
- BUT still showing Hidalgo County data on the map
- NOT zooming to the selected county
- NOT updating the stats to show the selected county's data
When selecting Brooks County (which only has 2026 data), the year dropdown was showing 2026, 2024, 2022, and 2018. This was because Brooks County appears in statewide datasets for those years, but with only 1-9 voters (stragglers in the statewide data), not meaningful county-specific data.
The DatasetSelectorV2 was not properly:
- Updating the global
selectedCountyFiltervariable thatloadDataset()and_fetchAndDisplayStats()rely on - Modifying the dataset's
selectedCountiesproperty to only include the selected county - Triggering a zoom to the selected county
The getCountyDatasets() method was including ALL datasets where the county appeared in the counties array, even if that county only had 1-9 voters in a statewide dataset. For example:
- 2026 statewide combined: Brooks has 889 voters (REAL Brooks data)
- 2024 statewide combined: Brooks has 9 voters (just stragglers)
- 2022 statewide combined: Brooks has 1 voter (just stragglers)
- 2018 statewide combined: Brooks has 1 voter (just stragglers)
File: WhoVoted/public/dataset-selector-v2.js (onCountyChange method)
onCountyChange() {
this.currentCounty = this.countySelect.value;
console.log('DatasetSelectorV2: County changed to', this.currentCounty);
// CRITICAL: Update global county filter variable FIRST
// This is used by loadDataset() and _fetchAndDisplayStats()
if (typeof window.selectedCountyFilter !== 'undefined') {
window.selectedCountyFilter = this.currentCounty;
} else {
window.selectedCountyFilter = this.currentCounty;
}
this.populateYearDropdown();
}This ensures that when loadDataset() is called, it uses the correct county filter.
File: WhoVoted/public/dataset-selector-v2.js (loadCurrentDataset method)
loadCurrentDataset() {
const datasets = this.getCountyDatasets();
const dataset = datasets.find(ds =>
ds.year === this.currentYear &&
ds.votingMethod === this.currentMethod
);
if (dataset && this.onDatasetChange) {
// Create a modified dataset with only the selected county
const modifiedDataset = {
...dataset,
// Override selectedCounties to only include the current county
selectedCounties: this.currentCounty === 'all'
? (dataset.counties || [dataset.county])
: [this.currentCounty],
// Update county field to reflect the selected county
county: this.currentCounty === 'all'
? dataset.county
: this.currentCounty
};
// ... rest of the code
// Zoom to the selected county if not "all"
if (this.currentCounty !== 'all' && typeof zoomToCounty === 'function') {
zoomToCounty(this.currentCounty);
}
this.onDatasetChange(modifiedDataset);
}
}This ensures:
- The dataset passed to
loadDataset()has the correctselectedCountiesproperty - The map zooms to the selected county
- The county field is updated to reflect the selection
File: WhoVoted/public/dataset-selector-v2.js (getCountyDatasets method)
getCountyDatasets() {
if (!this.currentCounty || this.currentCounty === 'all') {
return this.allDatasets;
}
return this.allDatasets.filter(ds => {
const counties = ds.counties || [ds.county];
// Check if this county is in the dataset
if (!counties.includes(this.currentCounty)) {
return false;
}
// If there's a countyBreakdown, check if this county has meaningful data
if (ds.countyBreakdown && ds.countyBreakdown[this.currentCounty]) {
const countyData = ds.countyBreakdown[this.currentCounty];
// Only include if county has >50 voters (filters out statewide datasets with just a few voters)
return countyData.totalVoters > 50;
}
// If no breakdown, include it (single-county dataset)
return true;
});
}This filters out datasets where the selected county has fewer than 50 voters, which are typically just stragglers in statewide datasets rather than meaningful county-specific data.
- User selects "Brooks" from county dropdown
onCountyChange()fires:- Sets
this.currentCounty = 'Brooks' - Updates
window.selectedCountyFilter = 'Brooks' - Calls
populateYearDropdown()
- Sets
getCountyDatasets()filters datasets:- Finds all datasets with Brooks in counties array
- Checks countyBreakdown for Brooks
- Only includes datasets where Brooks has >50 voters
- Result: Only 2026 datasets (889 voters) are included
- Excludes: 2024 (9 voters), 2022 (1 voter), 2018 (1 voter)
populateYearDropdown()shows only "2026"populateMethodDropdown()shows methods available for Brooks 2026loadCurrentDataset()is called:- Finds the Brooks County dataset for 2026
- Creates a modified dataset with
selectedCounties: ['Brooks'] - Calls
zoomToCounty('Brooks')to zoom the map - Calls
onDatasetChange(modifiedDataset)
loadDataset()in data.js receives the modified dataset:- Checks
selectedCountyFilter(now 'Brooks') - Fetches heatmap data for Brooks County only
- Fetches stats for Brooks County only
- Updates the map and stats box
- Checks
When Brooks County is selected, the system makes these API calls:
GET /api/voters/heatmap?county=Brooks&election_date=2026-03-03&voting_method=combined
GET /api/election-stats?county=Brooks&election_date=2026-03-03&voting_method=combined
These return ONLY Brooks County data (889 voters), not the statewide data.
- Hard refresh (Ctrl+Shift+R)
- Open Data Options panel
- Select "Brooks" from county dropdown
- Expected results:
- Map zooms to Brooks County
- Year dropdown shows ONLY "2026" (not 2024, 2022, 2018)
- Voting Method dropdown shows methods available for Brooks 2026
- Stats box shows "Brooks County 2026 Primary (Complete Election)"
- Map displays ~889 Brooks County voters only
- Select "Hidalgo" from dropdown
- Expected results:
- Map zooms to Hidalgo County
- Year dropdown shows 2026, 2024, 2022 (years with >50 Hidalgo voters)
- Stats show Hidalgo data (~80,000 voters for 2026)
- Select "All Counties" from dropdown
- Expected results:
- Map shows all counties (statewide view)
- Stats show combined totals for all counties
- No automatic zoom
- Select "Hidalgo" → should show Hidalgo data
- Select "Cameron" → should show Cameron data
- Select "Brooks" → should show Brooks data (only 2026)
- Each selection should zoom to that county and update all data
WhoVoted/public/dataset-selector-v2.js- Fixed county selection logic and filtering
- Commits:
a7906a5,9ec516f - Deployed to:
/opt/whovoted - No backend restart needed (frontend-only changes)
- Users need hard refresh to see changes
THREE_DROPDOWN_FIX_COMPLETE.md- Previous fix for dropdown populationTHREE_DROPDOWN_IMPLEMENTATION.md- Original implementation planCOMBINED_DATASETS_STATUS.md- Combined datasets feature status