areeb ahmed
areeb ahmed

Reputation: 51

link analysis with visjs on the basis of timestamp

I want to create link analysis and I'm using visjs for that for now I'm displaying the nodes and edges one by one after one second on the basis of index and it works fine, but now I want to show nodes and edges on the basis of timestamp I have timestamp var in my json data but I'm unable to do it. how can I do it?

const nodes = [
     { id: 1, label: jsonData.author.name, hidden:false,startTimestamp: mainNodeStartTime,image:jsonData.author.image ,likes: parseInt(jsonData.impressions.no_of_reactions_c), color: "yellow", size: 100 , title: jsonData.author.username},
    ...jsonData.comments.map((comment, index) => ({
        id: uuidv4(), // Use username as node ID
        label: comment.commenter.username, // Use username as node label
        likes: getRandomLikes(), // TODO: Random number but less than 100
        title: comment.commenter.username,
        size: getRandomLikes(),
        image: comment.commenter.image,
        startTimestamp:commentStartTimes[index],
        hidden:false
      })),

];
const edges = [
    
    // Edges between main author node and commenter nodes
    ...jsonData.comments.map((comment, index) => ({
        from: 1,
        to: nodes[index + 1].id,
      id: uuidv4(), // Generate a unique ID for the edge
      source: jsonData.author.username, // Source node is the main author
      target: comment.commenter.username, // Target node is the commenter
      color: 'gray', // You can specify edge color here
    })),
  ];
  var currentNodes = [];
  var currentEdges = [];
  var currentIndex = 0;

  function addNodeWithDelay() {
    if (currentIndex < nodes.length) {
        currentNodes.push(nodes[currentIndex]);
        currentEdges.push(edges[currentIndex]);
        currentIndex++;
        console.log('new edges are . . ',currentEdges)
    }
}
setInterval(addNodeWithDelay, 1000);
  

Upvotes: 0

Views: 26

Answers (0)

Related Questions