Skip to content

Commit fed0cb6

Browse files
author
Dmytro Trotsko
committed
Aligned geography unit ids
1 parent 9d64746 commit fed0cb6

File tree

12 files changed

+1513
-1540
lines changed

12 files changed

+1513
-1540
lines changed

src/assets/js/alter_dashboard.js

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,41 @@ class AlterDashboard {
188188
}
189189
};
190190

191+
// Plugin to draw vertical tick marks on X axis
192+
const xAxisTickMarksPlugin = {
193+
id: 'xAxisTickMarks',
194+
afterDraw(chart) {
195+
if (chart.animating) return;
196+
197+
const ctx = chart.ctx;
198+
const xAxis = chart.scales.x;
199+
const chartArea = chart.chartArea;
200+
201+
if (!xAxis || !chartArea || !xAxis.ticks || xAxis.ticks.length === 0) {
202+
return;
203+
}
204+
205+
ctx.save();
206+
ctx.strokeStyle = '#64748b';
207+
ctx.lineWidth = 1;
208+
209+
// Draw small vertical lines at each tick position
210+
const tickLength = 4; // Length of tick marks in pixels
211+
const tickY = chartArea.bottom; // Bottom of chart area
212+
213+
xAxis.ticks.forEach((tick) => {
214+
if (tick.label !== '') { // Only draw ticks that have labels
215+
ctx.beginPath();
216+
ctx.moveTo(tick.x, tickY);
217+
ctx.lineTo(tick.x, tickY + tickLength);
218+
ctx.stroke();
219+
}
220+
});
221+
222+
ctx.restore();
223+
}
224+
};
225+
191226
// Dual-level X-axis plugin (weeks on top, days below)
192227
// Optimized to reduce redraws during pan/zoom
193228
const dualAxisPlugin = {
@@ -375,22 +410,40 @@ class AlterDashboard {
375410
autoSkip: true, // Automatically skip ticks when crowded
376411
autoSkipPadding: 5,
377412
callback: function(value, index) {
378-
// Show day labels, but only for selected ticks
379-
const label = dayLabels[index];
413+
// Use value (data index) instead of index for correct alignment
414+
const dataIndex = Math.round(value);
415+
if (dataIndex < 0 || dataIndex >= dayLabels.length) return '';
416+
const label = dayLabels[dataIndex];
380417
if (!label) return '';
381-
// Format date to be more compact
418+
// Format date with month abbreviation and year in January
382419
try {
383-
const date = new Date(label);
384-
const month = date.getMonth() + 1;
385-
const day = date.getDate();
386-
return month + '/' + day;
420+
// Parse YYYY-MM-DD format explicitly to avoid timezone issues
421+
const parts = String(label).match(/^(\d{4})-(\d{2})-(\d{2})$/);
422+
if (!parts) return label;
423+
424+
const year = parseInt(parts[1], 10);
425+
const month = parseInt(parts[2], 10) - 1; // 0-indexed
426+
const day = parseInt(parts[3], 10);
427+
428+
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
429+
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
430+
const monthName = monthNames[month];
431+
432+
// Show year every January
433+
if (month === 0) {
434+
return monthName + ' ' + day + ' ' + year;
435+
}
436+
return monthName + ' ' + day;
387437
} catch (e) {
388438
return label;
389439
}
390440
},
391441
maxRotation: 45,
392442
minRotation: 45
393-
}
443+
},
444+
// Add vertical tick marks on the X axis
445+
drawOnChartArea: true,
446+
drawTicks: true
394447
},
395448
y: {
396449
display: true,
@@ -465,7 +518,7 @@ class AlterDashboard {
465518
}
466519
}
467520
},
468-
plugins: [htmlLegendPlugin, dualAxisPlugin]
521+
plugins: [htmlLegendPlugin, dualAxisPlugin, xAxisTickMarksPlugin]
469522
});
470523

471524
// Set initial zoom to last 12 months after chart is created

src/epiportal/management/commands/reset_ids.py

Lines changed: 0 additions & 89 deletions
This file was deleted.

src/fixtures/counties.json

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10575,8 +10575,8 @@
1057510575
"pk": 962,
1057610576
"fields": {
1057710577
"geo_id": "72021",
10578-
"name": "Bayam\u00f3n",
10579-
"display_name": "Bayam\u00f3n County, PR",
10578+
"name": "Bayamón",
10579+
"display_name": "Bayamón County, PR",
1058010580
"level": 6,
1058110581
"geo_level": 6
1058210582
}
@@ -10740,8 +10740,8 @@
1074010740
"pk": 977,
1074110741
"fields": {
1074210742
"geo_id": "72117",
10743-
"name": "Rinc\u00f3n",
10744-
"display_name": "Rinc\u00f3n County, PR",
10743+
"name": "Rincón",
10744+
"display_name": "Rincón County, PR",
1074510745
"level": 6,
1074610746
"geo_level": 6
1074710747
}
@@ -29957,8 +29957,8 @@
2995729957
"pk": 2724,
2995829958
"fields": {
2995929959
"geo_id": "35013",
29960-
"name": "Do\u00f1a Ana",
29961-
"display_name": "Do\u00f1a Ana County, NM",
29960+
"name": "Doña Ana",
29961+
"display_name": "Doña Ana County, NM",
2996229962
"level": 6,
2996329963
"geo_level": 6
2996429964
}
@@ -33114,8 +33114,8 @@
3311433114
"pk": 3011,
3311533115
"fields": {
3311633116
"geo_id": "72029",
33117-
"name": "Can\u00f3vanas",
33118-
"display_name": "Can\u00f3vanas County, PR",
33117+
"name": "Canóvanas",
33118+
"display_name": "Canóvanas County, PR",
3311933119
"level": 6,
3312033120
"geo_level": 6
3312133121
}
@@ -33136,8 +33136,8 @@
3313633136
"pk": 3013,
3313733137
"fields": {
3313833138
"geo_id": "72033",
33139-
"name": "Cata\u00f1o",
33140-
"display_name": "Cata\u00f1o County, PR",
33139+
"name": "Cataño",
33140+
"display_name": "Cataño County, PR",
3314133141
"level": 6,
3314233142
"geo_level": 6
3314333143
}
@@ -33180,8 +33180,8 @@
3318033180
"pk": 3017,
3318133181
"fields": {
3318233182
"geo_id": "72045",
33183-
"name": "Comer\u00edo",
33184-
"display_name": "Comer\u00edo County, PR",
33183+
"name": "Comerío",
33184+
"display_name": "Comerío County, PR",
3318533185
"level": 6,
3318633186
"geo_level": 6
3318733187
}
@@ -33466,8 +33466,8 @@
3346633466
"pk": 3043,
3346733467
"fields": {
3346833468
"geo_id": "72055",
33469-
"name": "Gu\u00e1nica",
33470-
"display_name": "Gu\u00e1nica County, PR",
33469+
"name": "Guánica",
33470+
"display_name": "Guánica County, PR",
3347133471
"level": 6,
3347233472
"geo_level": 6
3347333473
}
@@ -33554,8 +33554,8 @@
3355433554
"pk": 3051,
3355533555
"fields": {
3355633556
"geo_id": "72075",
33557-
"name": "Juana D\u00edaz",
33558-
"display_name": "Juana D\u00edaz County, PR",
33557+
"name": "Juana Díaz",
33558+
"display_name": "Juana Díaz County, PR",
3355933559
"level": 6,
3356033560
"geo_level": 6
3356133561
}
@@ -33587,8 +33587,8 @@
3358733587
"pk": 3054,
3358833588
"fields": {
3358933589
"geo_id": "72083",
33590-
"name": "Las Mar\u00edas",
33591-
"display_name": "Las Mar\u00edas County, PR",
33590+
"name": "Las Marías",
33591+
"display_name": "Las Marías County, PR",
3359233592
"level": 6,
3359333593
"geo_level": 6
3359433594
}
@@ -33598,8 +33598,8 @@
3359833598
"pk": 3055,
3359933599
"fields": {
3360033600
"geo_id": "72087",
33601-
"name": "Lo\u00edza",
33602-
"display_name": "Lo\u00edza County, PR",
33601+
"name": "Loíza",
33602+
"display_name": "Loíza County, PR",
3360333603
"level": 6,
3360433604
"geo_level": 6
3360533605
}
@@ -33609,8 +33609,8 @@
3360933609
"pk": 3056,
3361033610
"fields": {
3361133611
"geo_id": "72091",
33612-
"name": "Manat\u00ed",
33613-
"display_name": "Manat\u00ed County, PR",
33612+
"name": "Manatí",
33613+
"display_name": "Manatí County, PR",
3361433614
"level": 6,
3361533615
"geo_level": 6
3361633616
}
@@ -33631,8 +33631,8 @@
3363133631
"pk": 3058,
3363233632
"fields": {
3363333633
"geo_id": "72097",
33634-
"name": "Mayag\u00fcez",
33635-
"display_name": "Mayag\u00fcez County, PR",
33634+
"name": "Mayagüez",
33635+
"display_name": "Mayagüez County, PR",
3363633636
"level": 6,
3363733637
"geo_level": 6
3363833638
}
@@ -33961,8 +33961,8 @@
3396133961
"pk": 3088,
3396233962
"fields": {
3396333963
"geo_id": "72111",
33964-
"name": "Pe\u00f1uelas",
33965-
"display_name": "Pe\u00f1uelas County, PR",
33964+
"name": "Peñuelas",
33965+
"display_name": "Peñuelas County, PR",
3396633966
"level": 6,
3396733967
"geo_level": 6
3396833968
}
@@ -33994,8 +33994,8 @@
3399433994
"pk": 3091,
3399533995
"fields": {
3399633996
"geo_id": "72119",
33997-
"name": "R\u00edo Grande",
33998-
"display_name": "R\u00edo Grande County, PR",
33997+
"name": "Río Grande",
33998+
"display_name": "Río Grande County, PR",
3399933999
"level": 6,
3400034000
"geo_level": 6
3400134001
}
@@ -34016,8 +34016,8 @@
3401634016
"pk": 3093,
3401734017
"fields": {
3401834018
"geo_id": "72125",
34019-
"name": "San Germ\u00e1n",
34020-
"display_name": "San Germ\u00e1n County, PR",
34019+
"name": "San Germán",
34020+
"display_name": "San Germán County, PR",
3402134021
"level": 6,
3402234022
"geo_level": 6
3402334023
}
@@ -34038,8 +34038,8 @@
3403834038
"pk": 3095,
3403934039
"fields": {
3404034040
"geo_id": "72131",
34041-
"name": "San Sebasti\u00e1n",
34042-
"display_name": "San Sebasti\u00e1n County, PR",
34041+
"name": "San Sebastián",
34042+
"display_name": "San Sebastián County, PR",
3404334043
"level": 6,
3404434044
"geo_level": 6
3404534045
}
@@ -34434,8 +34434,8 @@
3443434434
"pk": 3131,
3443534435
"fields": {
3443634436
"geo_id": "72011",
34437-
"name": "A\u00f1asco",
34438-
"display_name": "A\u00f1asco County, PR",
34437+
"name": "Añasco",
34438+
"display_name": "Añasco County, PR",
3443934439
"level": 6,
3444034440
"geo_level": 6
3444134441
}
@@ -35463,4 +35463,4 @@
3546335463
"geo_level": 6
3546435464
}
3546535465
}
35466-
]
35466+
]

src/fixtures/hhs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@
109109
"geo_level": 2
110110
}
111111
}
112-
]
112+
]

src/fixtures/hrr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3365,4 +3365,4 @@
33653365
"geo_level": 8
33663366
}
33673367
}
3368-
]
3368+
]

0 commit comments

Comments
 (0)