From e7a113c4eea1f9ba1450577dd5da28d52a037150 Mon Sep 17 00:00:00 2001 From: James Graham Date: Wed, 12 May 2021 19:56:18 +0100 Subject: [PATCH] feat: add buttons to anonymise nodes on graph --- people/static/js/network.js | 28 +++++++++++++++++++++++++++- people/templates/people/network.html | 5 +++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/people/static/js/network.js b/people/static/js/network.js index 4da4d68..06849a1 100644 --- a/people/static/js/network.js +++ b/people/static/js/network.js @@ -6,11 +6,21 @@ var hide_organisations = false; var organisation_nodes; var organisation_edges; +var anonymise_people = false; +var anonymise_organisations = false; + var network_style = [ { selector: 'node[name]', style: { - label: 'data(name)', + label: function (ele) { + var anonymise = anonymise_people; + if (ele.data('kind') == 'organisation') { + anonymise = anonymise_organisations; + } + + return anonymise ? ele.data('id') : ele.data('name') + }, width: '100px', height: '100px', 'text-halign': 'center', @@ -63,6 +73,22 @@ function toggle_organisations() { } } +/** + * Toggle person node labels between names and ids. + */ +function toggle_anonymise_people() { + anonymise_people = !anonymise_people + cy.elements().remove().restore(); +} + +/** + * Toggle organisation node labels between names and ids. + */ +function toggle_anonymise_organisations() { + anonymise_organisations = !anonymise_organisations + cy.elements().remove().restore(); +} + /** * Populate a Cytoscape network from :class:`Person` and :class:`Relationship` JSON embedded in page. */ diff --git a/people/templates/people/network.html b/people/templates/people/network.html index a70f9e2..12cbb08 100644 --- a/people/templates/people/network.html +++ b/people/templates/people/network.html @@ -73,6 +73,11 @@
+ +
+ + +