Skip to content

Commit 9c5840c

Browse files
committed
Update county_od.js
1 parent b07867b commit 9c5840c

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/county_od.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@
145145
return Math.round(num || 0).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
146146
}
147147

148+
function roundToThousands(num) {
149+
if (num === null || num === undefined || isNaN(num)) return 0;
150+
return Math.round(num / 1000) * 1000;
151+
}
152+
148153
function loadWithFallback(loader, mainPath, fallbackPath, callback) {
149154
loader(mainPath, function(err, data) {
150155
if (!err && data) {
@@ -283,7 +288,7 @@
283288
.style('font-size', '12px')
284289
.style('font-weight', 'bold')
285290
.text(function(d, i) {
286-
return formatNumber(breaks[i]) + ' - ' + formatNumber(breaks[i + 1]);
291+
return formatNumber(roundToThousands(breaks[i])) + ' - ' + formatNumber(roundToThousands(breaks[i + 1]));
287292
});
288293
}
289294

@@ -408,17 +413,16 @@
408413
if (!o || !d || o === d) return;
409414

410415
if (!odData[o]) odData[o] = {};
411-
odData[o][d] = {};
412416

417+
var rowValues = {};
413418
numericColumns.forEach(function(col) {
414-
odData[o][d][col] = +row[col] || 0;
419+
rowValues[col] = Math.round(+row[col] || 0);
415420
});
416421

417-
// NOW countyNameByFips is defined
418-
odData[o][d].origin_county = countyNameByFips[o] || firstDefined(row, ['origin_county', 'oName', 'Origin_County']) || o;
419-
odData[o][d].destination_county = countyNameByFips[d] || firstDefined(row, ['destination_county', 'dName', 'Destination_County']) || d;
420-
421-
console.log('OD Record:', o, '→', d, 'Value:', odData[o][d][selectedAttribute]);
422+
rowValues.origin_county = countyNameByFips[o] || firstDefined(row, ['origin_county', 'oName', 'Origin_County']) || o;
423+
rowValues.destination_county = countyNameByFips[d] || firstDefined(row, ['destination_county', 'dName', 'Destination_County']) || d;
424+
425+
odData[o][d] = rowValues;
422426
});
423427

424428
var desireFeatures = getTopoFeatures(desirelinesTopo);

0 commit comments

Comments
 (0)