How to trigger selection event

Hi,

I want to trigger selection event by mouse click and, even if the mouse pointer is on an item or a group. Is this even possible?

Currently the selection is only triggered out side on my graph, and it’s not good enough for us.

The default behavior is that when the user clicks on a GraphObject, that object’s GraphObject.part will be selected. That’s the simple case, and it’s all controlled by ClickSelectingTool. Here’s how it handles the mouse-up of a click:

ClickSelectingTool.prototype.doMouseUp = function() {
  if (this.isActive) {
    this.standardMouseSelect();
    var handled = this.standardMouseClick();
    if (!handled) {
      if (this.diagram !== null && this.diagram.lastInput.isTouchEvent) {
        this.diagram.toolManager.doToolTip();
      }
    }
  }
  this.stopTool();
};

So you might want to either override this method or ClickSelectingTool.standardMouseSelect. FYI, that is defined as:

Tool.prototype.standardMouseSelect = function() {
  var diagram = this.diagram;
  if (diagram === null || !diagram.allowSelect) return;
  var e = diagram.lastInput;
  var curobj = diagram.findPartAt(e.documentPoint, false);  // to select containing Group if Part.canSelect() is false
  if (curobj !== null) {
    if (e.meta || e.control) {  // toggle the part's selection
      diagram.raiseDiagramEvent('ChangingSelection');
      var part = curobj;
      while (part !== null && !part.canSelect()) part = part.containingGroup;
      if (part !== null) part.isSelected = !part.isSelected;
      diagram.raiseDiagramEvent('ChangedSelection');
    } else if (e.shift) {  // add the part to the selection
      if (!curobj.isSelected) {
        diagram.raiseDiagramEvent('ChangingSelection');
        var part = curobj;
        while (part !== null && !part.canSelect()) part = part.containingGroup;
        if (part !== null) part.isSelected = true;
        diagram.raiseDiagramEvent('ChangedSelection');
      }
    } else {
      if (!curobj.isSelected) {
        var part = curobj;
        while (part !== null && !part.canSelect()) part = part.containingGroup;
        if (part !== null) diagram.select(part);  // also raises ChangingSelection/Finished
      }
    }
  } else if (e.left && !(e.meta || e.control) && !e.shift) {
    // left click on background with no modifier: clear selection
    diagram.clearSelection();  // also raises ChangingSelection/Finished
  }
};