Skip to content

Commit

Permalink
change behavior of select node, add button to reset. Relates to #73
Browse files Browse the repository at this point in the history
  • Loading branch information
boludo00 committed Apr 30, 2021
1 parent 1a90dc0 commit a81c755
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
4 changes: 3 additions & 1 deletion pyvis/lib/bindings/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function neighbourhoodHighlight(params) {
console.log("in nieghborhoodhighlight");
console.log(params);
allNodes = nodes.get({ returnType: "Object" });
// originalNodes = JSON.parse(JSON.stringify(allNodes));
// if something is selected:
Expand Down Expand Up @@ -98,6 +100,6 @@ function neighbourhoodHighlight(params) {

function selectNode(node) {
network.selectNodes([node]);
network.focus(node, { scale: 2 });
neighbourhoodHighlight({ nodes: [node] });
return node;
}
39 changes: 25 additions & 14 deletions pyvis/templates/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,27 @@ <h1>{{heading}}</h1>
<div class="card" style="width: 100%">
{% if select_menu %}
<div class="card-header">
<select
class="form-select"
aria-label="Default select example"
onchange="selectNode(value);"
searchable="Search here"
>
<option selected>Select a Node by ID</option>
{% for node in nodes %}
<option value="{{ node.id }}">{{node.id}}</option>
{% endfor %} {#
<option value="2">Two</option>
<option value="3">Three</option>
#}
</select>
<div class="row no-gutters">
<div class="col-10 pb-2">
<select
class="form-select"
aria-label="Default select example"
onchange="selectNode(value);"
searchable="Search here"
>
<option selected>Select a Node by ID</option>
{% for node in nodes %}
<option value="{{ node.id }}">{{node.id}}</option>
{% endfor %} {#
<option value="2">Two</option>
<option value="3">Three</option>
#}
</select>
</div>
<div class="col-2 pb-2">
<button type="button" class="btn btn-primary btn-block" onclick="neighbourhoodHighlight({nodes: []});">Reset Selection</button>
<div>
</div>
</div>
{% endif %}
<div id="mynetwork" class="card-body"></div>
Expand Down Expand Up @@ -248,6 +255,10 @@ <h1>{{heading}}</h1>
network.on("click", neighbourhoodHighlight);
{% endif %}

{% if select_menu %}
network.on("selectNode", neighbourhoodHighlight);
{% endif %}

{% if tooltip_link %}
// make a custom popup
var popup = document.createElement("div");
Expand Down

0 comments on commit a81c755

Please sign in to comment.