Skip to content

Commit 9e0d374

Browse files
committed
Fix timezone of displayed dates PoonLab#106
1 parent ec0c26a commit 9e0d374

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ <h3>Near real-time visualization of SARS-CoV-2 genomic variation</h3>
8989
<script src="js/jquery.js"></script>
9090
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
9191
<script src="js/d3.js"></script>
92+
<script src="js/utils.js"></script>
9293
<script src="js/beadplot.js"></script>
9394
<script src="js/phylo.js"></script>
9495
<script src="js/drawtree.js"></script>

js/beadplot.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ function beadplot(cid) {
337337

338338
tooltipText += region_to_string(table(d.region));
339339
tooltipText += `<br><b>Unique collection dates:</b> ${d.numBeads}<br>`;
340-
let formatDate = d3.timeFormat("%Y-%m-%d");
341-
tooltipText += `<br><b>Collection dates:</b><br>${formatDate(new Date(d.x1))} / ${formatDate(new Date(d.x2))}<br>`;
340+
tooltipText += `<br><b>Collection dates:</b><br>${formatDate(d.x1)} / ${formatDate(d.x2)}<br>`;
342341

343342
// Tooltip appears 10 pixels left of the cursor
344343
bTooltip.html(tooltipText)
@@ -400,8 +399,7 @@ function beadplot(cid) {
400399
let tooltipText = `<b>Parent:</b> ${d.parent}<br><b>Child:</b> ${d.child}<br>`;
401400
tooltipText += `<b>Genomic distance:</b> ${d.dist}<br><br>`;
402401

403-
let formatDate = d3.timeFormat("%Y-%m-%d");
404-
tooltipText += `<b>Collection date:</b> ${formatDate(new Date(d.x2))}`;
402+
tooltipText += `<b>Collection date:</b> ${formatDate(d.x2)}`;
405403

406404
// Tooltip appears 10 pixels left of the cursor
407405
bTooltip.html(tooltipText)
@@ -448,8 +446,7 @@ function beadplot(cid) {
448446
}
449447

450448
tooltipText += region_to_string(table(d.region));
451-
let formatDate = d3.timeFormat("%Y-%m-%d");
452-
tooltipText += `<br><b>Collection date:</b> ${formatDate(new Date(d.x))}<br>`;
449+
tooltipText += `<br><b>Collection date:</b> ${formatDate(d.x)}<br>`;
453450

454451
// Tooltip appears 10 pixels left of the cursor
455452
bTooltip.html(tooltipText)
@@ -517,7 +514,6 @@ function region_to_string(my_regions) {
517514
*/
518515
function gen_details_table(obj) {
519516
var details = [];
520-
let formatDate = d3.timeFormat("%Y-%m-%d");
521517

522518
// Check for a list of samples
523519
if (Array.isArray(obj)) {
@@ -527,7 +523,7 @@ function gen_details_table(obj) {
527523

528524
// "zip" the sequence details of each sample
529525
for (let i = 0; i < obj[j].accessions.length; i++) {
530-
let sample_details = [obj[j].accessions[i], obj[j].labels[i], formatDate(new Date(obj[j].x))];
526+
let sample_details = [obj[j].accessions[i], obj[j].labels[i], formatDate(obj[j].x)];
531527
details.push(sample_details);
532528
}
533529
}
@@ -536,7 +532,7 @@ function gen_details_table(obj) {
536532
else {
537533
// "zip" the sequence details of each sample
538534
for (let i = 0; i < obj.accessions.length; i++) {
539-
let sample_details = [obj.accessions[i], obj.labels[i], formatDate(new Date(obj.x))];
535+
let sample_details = [obj.accessions[i], obj.labels[i], formatDate(obj.x)];
540536
details.push(sample_details);
541537
}
542538
}

js/drawtree.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ function create_clusterH(obj, obj_2) {
5252
.raise();
5353
}
5454

55-
/**
56-
* Returns true if the string is an accession number
57-
*/
58-
function is_accn(string) {
59-
const accn_pat = /^EPI_ISL_[0-9]+$/i; // case-insensitive
60-
return accn_pat.test(string);
61-
}
62-
6355
/**
6456
* Rectangular layout of tree, update nodes in place with x,y coordinates
6557
* @param {object} root
@@ -255,8 +247,7 @@ function draw_clusters(tips) {
255247
let ctooltipText = `<b>Mean pairwise distance:</b> ${d.pdist}<br><b>Mean root distance:</b> ${d.rdist}<br><br>`;
256248
ctooltipText += region_to_string(d.allregions);
257249
ctooltipText += `<br><b>Number of variants:</b> ${d.varcount}<br>`;
258-
const formatDate = d3.timeFormat("%Y-%m-%d");
259-
ctooltipText += `<br><b>Collection dates:</b><br>${formatDate(new Date(d.first_date))} / ${formatDate(new Date(d.last_date))}<br>`;
250+
ctooltipText += `<br><b>Collection dates:</b><br>${formatDate(d.first_date)} / ${formatDate(d.last_date)}<br>`;
260251

261252
cTooltip.html(ctooltipText)
262253
.style("left", (d3.event.pageX + 10) + "px") // Tooltip appears 10 pixels left of the cursor
@@ -284,7 +275,7 @@ function draw_clusters(tips) {
284275

285276
beadplot(d.cluster_idx);
286277

287-
if (is_accn($('#search-input').val())) {
278+
if (isAccn($('#search-input').val())) {
288279
$('#search-input').val('');
289280
}
290281

js/search.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function search(beaddata) {
242242
const points = find_beads_points(beaddata)
243243
.filter(point => point.labels.some(label => label.includes(query)));
244244
// TODO: Make select_bead_by_* use find_beads_points result
245-
is_accn(query) ? select_bead_by_accession(query) : select_beads_by_substring(query);
245+
isAccn(query) ? select_bead_by_accession(query) : select_beads_by_substring(query);
246246
const stats = search_stats.update({
247247
query,
248248
current_point: 1,

js/utils.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Utility functions accesible to all scripts
2+
3+
/**
4+
* Returns true if the string is an accession number
5+
*/
6+
function isAccn(string) {
7+
const accn_pat = /^EPI_ISL_[0-9]+$/i; // case-insensitive
8+
return accn_pat.test(string);
9+
}
10+
11+
/**
12+
* Returns a string in an ISO8601 format
13+
*
14+
* @param {Date} date: The date to be formated
15+
*/
16+
function formatDate(date) {
17+
return d3.utcFormat("%Y-%m-%d")(date);
18+
}

0 commit comments

Comments
 (0)