Layer Properties required to allow click events

In my diagram, I’m using a node on a specific layer to act as “past time”. I set the layer as isTemporary so that changes to this aren’t managed by the UndoManager and I would expect any click events to work fine.

However, I’m seeing issues where clicking on where this node is doesn’t unselect other nodes and right clicking doesn’t display the diagram’s context menu.

Are there different properties I should be setting for this layer?

Yes, a lot of functionality depends on ignoring objects that are in temporary layers.

I suppose you could implement work-arounds for some of those cases, such as ContextMenuTool.findObjectWithContextMenu. There are other uses for temporary layers, such as such Parts not invalidating any Layout nor being included in the document bounds.

So I think it’s going to be very hard to implement what you want in that manner.

Is your goal just to avoid recording ChangedEvents in the UndoManager, but otherwise have the node act completely normally? That is most easily implemented by overriding UndoManager.skipsEvent.

  function CustomUndoManager() {
    go.UndoManager.call(this);
    this.isEnabled = true;
  }
  go.Diagram.inherit(CustomUndoManager, go.UndoManager);

  CustomUndoManager.prototype.skipsEvent = function(e) {
    if (go.UndoManager.prototype.skipsEvent.call(this, e)) return true;
    var obj = e.object;
    if (obj instanceof go.GraphObject) {
      var lay = obj.layer;
      if (lay !== null && lay.name === "test") return true;  // SUBSTITUTE YOUR SPECIAL LAYER NAME
    }
    return false;
  }

Now whenever you create a Model you’ll need to set Model.undoManager to a new instance of CustomUndoManager.

Or more generally, you don’t even need a new Layer to hold such Parts. Just have some way for UndoManager.skipsEvent to recognize that it is or is an element of that special kind of Part.

Sorry, I was unclear in my description. I don’t want the node to be interactable at all - its intended use is just to provide a visual indication for time on a Gantt chart that is in the past - it’s basically part of the background.

However, I want to ensure its z-index in accordance with other layers we’re using, which is why I didn’t directly add it to the Grid layer or something similar.

I created a calendar_layer to hold items like this, but I’m seeing click and context-click events be swallowed where ever there are nodes in this layer.

Artboard%20%E2%80%93%201

Maybe you want to set Layer | GoJS API to false?

Nope. :-(

I’ve set isTemporary = true; pickable = false; allowSelect = false;, but none of these are giving me the functionality I want. I’ll keep digging to see if our custom tools behaving poorly as well.

Huh? If a GraphObject is not pickable, either via GraphObject.pickable or Panel or Layer being not pickable, then there’s no way for mouse/touch events to get to that object. In your case all events would simply ignore that layer.

Maybe you have some large transparent objects lying around in other layers?

I don’t think so - if I don’t add this shadow node to the model, my events pass through just fine. However, since I’ve set the layerName on the shadow to be this pickable = false layer, I don’t see why having the node in the model would change anything.

Oh, interesting.

Upon investigating this shadow node, I see that its layerName is actually "", where I would expect it to be "$CalendarL", even though I’ve set layerName: "$CalendarL" in its definition.

This is why my layer changes aren’t working properly - now just to find where the layer name is being changed. I’m not sure how this would occur, since the template doesn’t have a binding to layerName, though.

If the node got added to the diagram before that layer (named “$CalendarL”) existed, I think it would be added to the default layer.

I don’t see that happening - the layer is added well before the node is added to the model. We actually don’t even generate or assign a model to the diagram until after all of that bootstrapping is completed.

OK, I was just guessing about ways that your situation might occur.

Another might be the removal of that Layer.

I checked the list of layers in the diagram and its there for sure - it even has a few nodes.

However, I would expect one more item in its list of nodes that has a category of PastTimeShadow.

image

So, I set a binding for layerName on my PastTimeShadow template and that seems to have fixed the issue. I’m not sure why I need this binding since I initialize the layerName in the template itself, but I will continue investigation.

Also, setting pickable = false allows my events to flow through this layer as expected. Thank you!

FYI, I just played with adding a Part to a new non-pickable Layer, via a model and an additional node template but without a binding on Part.layerName. I didn’t encounter any problems with that part ending up in any layer other than that special new layer.