Skip to content
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
31 changes: 28 additions & 3 deletions src/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ let lineChart = new AppendingLineChart(d3.select("#linechart"),
["#777", "black"]);

function makeGUI() {
// Close a pinned hovercard when the user presses the mouse outside of it.
document.addEventListener("mousedown", (event: MouseEvent) => {
let card = document.getElementById("hovercard");
if (hovercardPinned && !card.contains(event.target as Node)) {
closeHoverCard();
}
});

d3.select("#reset-button").on("click", () => {
reset();
userHasInteracted();
Expand Down Expand Up @@ -702,15 +710,31 @@ function addPlusMinusControl(x: number, layerIdx: number) {
);
}

/**
* While a weight or bias is being edited, the hovercard is pinned: moving the
* mouse off the link (or onto another one) no longer closes or replaces it.
* It closes on Enter, Escape or a mouse press outside of the card.
*/
let hovercardPinned = false;

function closeHoverCard() {
hovercardPinned = false;
updateHoverCard(null);
}

function updateHoverCard(type: HoverType, nodeOrLink?: nn.Node | nn.Link,
coordinates?: [number, number]) {
if (hovercardPinned) {
return;
}
let hovercard = d3.select("#hovercard");
if (type == null) {
hovercard.style("display", "none");
d3.select("#svg").on("click", null);
return;
}
d3.select("#svg").on("click", () => {
hovercardPinned = true;
hovercard.select(".value").style("display", "none");
let input = hovercard.select("input");
input.style("display", null);
Expand All @@ -724,9 +748,10 @@ function updateHoverCard(type: HoverType, nodeOrLink?: nn.Node | nn.Link,
updateUI();
}
});
input.on("keypress", () => {
if ((d3.event as any).keyCode === 13) {
updateHoverCard(type, nodeOrLink, coordinates);
input.on("keydown", () => {
let keyCode = (d3.event as any).keyCode;
if (keyCode === 13 || keyCode === 27) {
closeHoverCard();
}
});
(input.node() as HTMLInputElement).focus();
Expand Down
2 changes: 1 addition & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ g.column rect {

/** Invisible thick links used for showing weight values on mouse hover. */
#network .core .link-hover {
stroke-width: 8;
stroke-width: 14;
stroke: black;
fill: none;
opacity: 0;
Expand Down
Loading