Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make calendarToNumeric parse negative dates #627

Merged
merged 2 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/info/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ const pluralise = (word, n) => {
};

const styliseDateRange = (dateStr) => {
// 2012-01-22
const fields = dateStr.split('-');
return `${months[fields[1]]} ${fields[0]}`;
// 2012-01-22
if (fields.length==3){
return `${months[fields[1]]} ${fields[0]}`;
}else{ // other cases like negative numbers
return dateStr;
}
};

const getNumSelectedTips = (nodes, visibility) => {
Expand Down
14 changes: 11 additions & 3 deletions src/util/dateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ const dateScale = scaleTime()
.range([2000, 2100]);

export const numericToCalendar = (numDate) => {
if (numDate<0){
return Math.round(numDate).toString();
}
const d3Date = dateScale.invert(numDate);
const calDate = dateFormatter(d3Date);
return calDate;
};

export const calendarToNumeric = (calDate) => {
const d3Date = dateParser(calDate);
const numDate = dateScale(d3Date);
return numDate;
if (calDate[0]==='-'){
const pieces = calDate.substring(1).split('-');
return -parseFloat(pieces[0]);
}else{
const d3Date = dateParser(calDate);
const numDate = dateScale(d3Date);
return numDate;
}
};

export const currentNumDate = () => {
Expand Down