Trrack / trrackjs

A library for history/provenance tracking in web-based visualizations.
https://apps.vdl.sci.utah.edu/trrack
BSD 3-Clause "New" or "Revised" License
18 stars 7 forks source link

Add flag to to determine if currentChange is triggered by node traversal or node addition. #25

Closed Dev-Lan closed 1 year ago

Dev-Lan commented 1 year ago

What It would be useful to be able to conveniently determine if currentChange was triggered by node traversal (undo/redo/click on trrackViz) vs a user action causing a new node to be added to the track tree. This could be added as an argument in the currentChange callback, or property on the trrack object returned by initializeTrrack.

Why My current approach to handling provenance with vue/pinia is to subscribe to changes on the pinia store then call the relevant prov.apply(...) function to update the trrack state. Then of prov.currentChange is triggered. Now we get to the branching logic.

Workaround Right now, I have a working solution:

const prov = initializeTrrack(...);
const nodeIds = new Set<string>([prov.root.id]);
prov.currentChange(() => {
    const provNodeId = prov.current.id;
    if (nodeIds.has(prov.current.id)) {
        // update pinia state based on trrack state
    } else {
        // do nothing
    }
    nodeIds.add(provNodeId);
});

So far, this appears to be working. I'm not sure how this will work with URL state sharing — it may require some updates, i.e. adding all of the state node ids on initial load probably.