Skip to content

How to get the index of the clicked point? #221

@mjperez-usgs

Description

@mjperez-usgs

I am trying to make this plugin perform an action when the user clicks on a point in the boxplot. I set some extra metadata on the dataset that I am trying to retrieve in the onclick handler. I do this in a scatter plot in a different chart, which works for me but I also want it to work on my boxplot version.

An example that I've been working on, but haven't yet got to work:

       this.chart.options.onClick = (event, elements, chart) => {
            if (this.monitoringMap != null && this.lastHoveredPoint != null)  {
          
                const activePoints = chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, true);
                if (activePoints.length > 0) {
                    const firstClickedPoint = activePoints[0];
                    if (firstClickedPoint.datasetIndex === 0 || firstClickedPoint.datasetIndex === 1) {
                        let dataset = chart.data.datasets[firstClickedPoint.datasetIndex].data[firstClickedPoint.index];
                        // How do I access the index of items/outliers here?

                        
                        this.monitoringMap.zoomToPoint(this.lastHoveredPoint.objectid, this.lastHoveredPoint.type, true, true);
                    }
                }
            }
        };
    }

Currently I am trying to track the last hovered index from when the tooltip pops up (which is demonstrated #17). This information doesn't appear to be surfaced in the onclick handler though which I imagine will lead to issues where the last hovered item might not actually be what you click on, so I'm trying to figure out how to do that. I only get the dataset index and the data index, but I need to know one further index into items/outliers, but I don't see any way to do that.

I have item and outlier radius turned on - it works just fine right now in my tooltips.

Context

  • Version: 4.4.5
  • Browser: MS Edge 146

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions