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

Beginning to build a tour feature #79 #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions network-app/core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{ function: transformToWindow, settings: settings },
{ function: saveToStorage },
{ function: setupJLouvain },
{ function: tour },
]); // transformToWindow, saveToStorage, and setupJLouvain is called as a callback

});
Expand Down
10 changes: 9 additions & 1 deletion network-app/core/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ const setupInteractivity = (settings = undefined) => {
nodeElements.on("click", (event, node) => {
// console.log('event', event);
// console.log('node', node);
if (window.tour)
return false;

event.stopPropagation();
if (event.metaKey === true) {
if (nodeIsSelected(node)) {
Expand All @@ -352,16 +355,21 @@ const setupInteractivity = (settings = undefined) => {
});

textElements.on("click", (event, node) => {
console.log(node);
if (window.tour)
return false;
toggleNode(node);
return true;
});

edgeElements.on("mouseover", (event, edge) => {
if (window.tour)
return false;
if (!window.nodeSelected && !window.edgeSelected) quickEdgeInfo(edge);
});

edgeElements.on("click", (event, edge) => {
if (window.tour)
return false;
event.stopPropagation();
quickEdgeInfo(edge);
if (window.toggledCommentedElements) {
Expand Down
54 changes: 47 additions & 7 deletions network-app/core/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,51 @@ const tour1 = [
},
];

const tour = () => {
// don't forget to run resetLocalStorage() before this function!
tour1.forEach((step) => {
step.settings.forEach((settings) => changeSetting(settings));
console.log(step.text);
function until(conditionFunction) {
const poll = (resolve) => {
if (conditionFunction()) resolve();
else setTimeout((_) => poll(resolve), 400);
};

return new Promise(poll);
}

async function tour(steps = []) {
window.tour = true;

// hide settings
hide("#settings");

changeSetting("#minDegree", 0, true, 'slider');
changeSetting("#minWeight", 0, true, 'slider');
changeSetting("#startYear", 1930, true, 'dropdown');
changeSetting("#endYear", 1940, true, 'dropdown');

await until((_) => window.simulationDone == true);

steps = [
{
node_id: "jackie_maye",
zoom: 1,
wait: 4000,
html: "Jackie Maye",
textX: 200,
textY: 200,
},
];

goTo(0,0);

steps.forEach((step) => {
let nodeObject = findNode(step.node_id);
if (nodeObject) {
d3.select('#quickEdgeInfo').style('top', `${step.textY}px`)
d3.select('#quickEdgeInfo').style('left', `${step.textX}px`)
d3.select('#quickEdgeInfo').html(step.html)
zoomToNode(step.node_id, step.zoom);
} else {
console.error(`Could not find node with id ${step.node_id}`)
}
});
return true;
};

}
5 changes: 5 additions & 0 deletions network-app/core/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ const modifySimulation = (settings) => {
graph.simulation.force("link").strength(settings.force.linkStrength);

graph.simulation.on("tick", function () {
window.simulationDone = false;
nodeElements.attr("cx", (n) => n.x);
nodeElements.attr("cy", (n) => n.y);

Expand All @@ -575,6 +576,10 @@ const modifySimulation = (settings) => {
textElements.attr("y", (n) => n.y + 4);
});

graph.simulation.on("end", function () {
window.simulationDone = true;
})

// restart the simulation now that everything is set
graph.simulation.restart();

Expand Down
6 changes: 3 additions & 3 deletions network-app/core/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if (_)
d3.zoomIdentity.translate(_.x, _.y).scale(_.k)
);

function zoomToNode(node = undefined, z=4) {
function zoomToNode(node = undefined, z=4, blink=3) {
if (node === undefined)
node = graph.nodes[Math.floor(Math.random() * graph.nodes.length - 1)];

Expand All @@ -70,9 +70,9 @@ function zoomToNode(node = undefined, z=4) {
graph.svg
.transition()
.duration(1000)
.call(zoom.transform, d3.zoomIdentity.scale(4).translate(-node.x, -node.y));
.call(zoom.transform, d3.zoomIdentity.scale(z).translate(-node.x, -node.y));

highlightNode(node.node_id, 3);
highlightNode(node.node_id, blink);

return node;
}
Expand Down