Trigger mouse events only within the geometry definition

I’ve created a custom Shape, whose shape is actually defined by a geometry definition, such as the following:

var shape = $$(go.Shape, {
    stroke: colours.white,
    strokeWidth: 2,
    geometryStretch: go.GraphObject.None,
    stretch: go.GraphObject.None,
    fill: colours.light_gray,
    alignment: go.Spot.TopLeft,
    alignmentFocus: go.Spot.TopLeft,
    geometry: new go.Geometry()
        .add(new go.PathFigure(0, 40)  // start point
            .add(new go.PathSegment(go.PathSegment.Arc,
                start, perSegment,  // angles
                0, 40,  // center
                40, 40)  // radius

When I set a click listener to this shape, it works as expected. However, the click listener is called even when the the click occurs outside the arc. I understand that this is because the shape is represented as a bounding rectangle, and that any clicks within that bounding rectangle will trigger the click event.

How do I create a shape such that mouse events are triggered only from within the closed path of the geometry defined?

EDIT: Sorry, I had a typo in my code - I was setting the click listener over the containing panel. However, after setting it to the shape that I created, the click events don’t seem to be triggered at all. What could be the problem here?

I just tried your code, substituting reasonable constants for your expressions that I didn’t know, and added a event handler to the Shape.

Everything worked as I think both of us would expect – the click happened in the lightgray painted area, and no click happened elsewhere, even within the bounds of the shape.

Could you provide a more specific example which fails? I do notice that when the sweep angle is zero, there’s no click event because there’s no area to the arc. That might be considered a bug – we’ll have to evaluate whether or not that really is a bug or not.

hey Walter,
Seems like I had to set isActionable to true to my shape. My shape is part of an adornment.

Now it seems to work well :)