Skip to content

Commit

Permalink
made first and last date automatic from the node dataA
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarvey committed Nov 11, 2024
1 parent 51c4c06 commit febc2f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 0 additions & 2 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"data": "data/people.json",
"filter": "",
"startDate": "2024-10-17 00:00:00",
"firstDate": "1900-01-01 00:00:00",
"lastDate": "2024-10-17 00:00:00",
"speed": 50,
"debug": false,
"menuDefaultOpen": true,
Expand Down
19 changes: 15 additions & 4 deletions js/lineage.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ function Lineage() {
config = conf;

config.startDate = new Date(config.startDate);
config.lastDate = new Date(config.lastDate);
config.firstDate = new Date(config.firstDate);

currentTime = config.startDate;
initShowDead(config.showDead);
Expand Down Expand Up @@ -115,6 +113,8 @@ function Lineage() {

users = d3.group(nodes, (d) => d.id);
data = prepareData(data, filters);
config.firstDate = new Date(findFirstDate(config.nodes));
config.lastDate = new Date(findLastDate(config.nodes));
console.log(`${data.nodes.length} nodes`);
console.log(`${data.links.length} links`);
simulation = d3.forceSimulation(nodes);
Expand Down Expand Up @@ -328,6 +328,17 @@ function Lineage() {
}, new Date());
}

function findLastDate(someNodes) {
if (!someNodes || someNodes.length === 0) {
return new Date();
}

return nodes.reduce((latest, node) => {
const createdAt = new Date(node.createdAt);
return createdAt > latest ? createdAt : latest;
}, new Date());
}

function updateFilter() {
if (filters !== $('#search').val()) {
filters = $('#search').val();
Expand Down Expand Up @@ -496,8 +507,8 @@ function Lineage() {
context.scale(transform.k, transform.k);
context.translate(width / 2, height / 2);

const startDate = findFirstDate(config.nodes);
const endDate = new Date(config.lastDate);
const startDate = config.firstDate
const endDate = config.lastDate;
const totalDays = (endDate - startDate) / (1000 * 60 * 60 * 24);

users.forEach((user) => {
Expand Down

0 comments on commit febc2f7

Please sign in to comment.