From 409e4a355f8e1648956f872da17a5db543ea0d5c Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Fri, 29 Sep 2017 20:40:25 +0200 Subject: [PATCH] Network detect clicks on labels (#3410) * Small refactoring in Label._drawBackground() * Added size calculation to Label, basic framework for detecting click on label. * First fully working version of label click. * Put in extra checks, refactored visibility of labels for more general usage. * Final fixes to code; added to example and in docs * Adressed review comments * Add next attempt to fix Travis unit test bug * Addressed review issues --- docs/network/index.html | 20 +++- examples/network/labels/labelAlignment.html | 13 ++- lib/network/modules/Canvas.js | 11 +-- lib/network/modules/InteractionHandler.js | 5 +- lib/network/modules/SelectionHandler.js | 58 ++++++++++++ lib/network/modules/components/Edge.js | 93 +++++++++++++++--- lib/network/modules/components/Node.js | 36 +++++++ .../modules/components/edges/util/EdgeBase.js | 19 ++-- .../components/shared/ComponentUtil.js | 73 ++++++++++++++ .../modules/components/shared/Label.js | 94 +++++++++++++------ 10 files changed, 353 insertions(+), 69 deletions(-) diff --git a/docs/network/index.html b/docs/network/index.html index 01af8ad0..2ade8795 100644 --- a/docs/network/index.html +++ b/docs/network/index.html @@ -1313,7 +1313,7 @@ var options = { Fired when the user clicks the mouse or taps on a touchscreen device. Passes an object with properties structured as: -
{
+
{
   nodes: [Array of selected nodeIds],
   edges: [Array of selected edgeIds],
   event: [Object] original click event,
@@ -1323,6 +1323,24 @@ var options = {
   }
 }
 
+ +This is the structure common to all events. Specifically for the click event, the following property is added: + +
{
+...
+  items: [Array of click items],
+}
+ +Where the click items can be: +
+  {nodeId:NodeId}            // node with given id clicked on
+  {nodeId:NodeId labelId:0}  // label of node with given id clicked on
+  {edgeId:EdgeId}            // edge with given id clicked on
+  {edge:EdgeId, labelId:0}   // label of edge with given id clicked on
+
+ +The order of the items array is descending in z-order. +Thus, to get the topmost item, get the value at index 0. doubleClick diff --git a/examples/network/labels/labelAlignment.html b/examples/network/labels/labelAlignment.html index dd837ca7..78b47717 100644 --- a/examples/network/labels/labelAlignment.html +++ b/examples/network/labels/labelAlignment.html @@ -9,7 +9,7 @@