Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getElementAtEvent() returns array of single element, not single element #3237

Closed
jeffzap opened this issue Aug 31, 2016 · 3 comments
Closed

Comments

@jeffzap
Copy link

jeffzap commented Aug 31, 2016

Contrary to the docs, getElementAtEvent() returns an array containing a single ChartElement. Observed while implementing custom click behavior on a pie chart.

@Pikamander2
Copy link
Contributor

Here are the relevant lines.

        // Get the single element that was clicked on
        // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
        getElementAtEvent: function(e) {
            var me = this;
            var eventPosition = helpers.getRelativePosition(e, me.chart);
            var elementsArray = [];

            helpers.each(me.data.datasets, function(dataset, datasetIndex) {
                if (me.isDatasetVisible(datasetIndex)) {
                    var meta = me.getDatasetMeta(datasetIndex);
                    helpers.each(meta.data, function(element) {
                        if (element.inRange(eventPosition.x, eventPosition.y)) {
                            elementsArray.push(element);
                            return elementsArray;
                        }
                    });
                }
            });

            return elementsArray.slice(0, 1);
        },

return elementsArray.slice(0, 1) could be replaced with something like return elementsArray[0], but at this point that would probably cause backwards compatibility problems. It might be better just to change the documentation.

Thoughts, @etimberg?

@etimberg
Copy link
Member

etimberg commented Sep 5, 2016

@Pikamander2 it might cause other problems in the code that runs these functions. I would support changing the docs in this case

@etimberg
Copy link
Member

Fixed in #3751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants