Skip to content

Pie-chart hover events #150

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

Merged
merged 11 commits into from
Jan 6, 2016
Merged

Pie-chart hover events #150

merged 11 commits into from
Jan 6, 2016

Conversation

mdtusz
Copy link
Contributor

@mdtusz mdtusz commented Dec 29, 2015

The fx.hover method needed a bit of a tweak because pie gd's don't seem to have a _fullLayout.plots.

@mdtusz mdtusz closed this Dec 29, 2015
@mdtusz mdtusz reopened this Dec 29, 2015
@mdtusz mdtusz changed the title Hover pie Pie-chart hover events Dec 29, 2015
@@ -309,6 +309,13 @@ fx.unhover = function (gd, evt, subplot) {
// The actual implementation is here:

function hover(gd, evt, subplot){
if(gd._fullLayout._hasPie){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdtusz you're right.

The concept of (sub)plots doesn't extend to pies. Pies are considered traces that have thier own domain and no corresponding axes.

What does evt contain here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evt contains the data from the hover event - in this case, information on the slice that was hovered over. The plotly_hover event fires and gets passed data in the same format as the click events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but Fx.hover for pie traces should emit that same data as for non-pie traces minus the info about the axes of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contents of [evt] mimic the same "format" as other traces hover events points value (as much as we can with a pie chart) but xvals/yvals and xaxes/yaxes are out of context here. The xvals/yvals are the mouse hover position relative to the axes scaling and values, so without any axes, these are meaningless.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks for the clarification. 🍻

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdtusz On second thought, a check on _hasPie is too coerced.

Say we have a pie and bar trace on the same graph:

var gd = Tabs.fresh();

Plotly.plot(gd, 
    [
        {
            type: 'pie',
            labels: ['a', 'b', 'c'],
            values: [1, 2, 3],
            domain: {
                x: [0, 0.45]
            }
        },
        {
            type: 'bar',
            x: ['A', 'B', 'C'],
            y: [1, 2, 3],
        }

    ],
    {
        title: 'Pie vs bar',
        xaxis: { domain: [0.55, 1] },
        showlegend: false
    }
);

gd.on('plotly_hover', function(data) {
    var pt = data.points[0]
    console.log(pt);
});

then hovering over the bars will result in an un-formatted hover data.

So, we should use the subplot argument and make the if-clause: if(subplot === 'pie').

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@etpinard
Copy link
Contributor

etpinard commented Jan 4, 2016

@mdtusz

Looks good.

If you're up for it, it'd be nice to add a test in https://github.com/plotly/plotly.js/blob/master/test/jasmine/tests/hover_label_test.js for pie hover labels.

@mdtusz
Copy link
Contributor Author

mdtusz commented Jan 4, 2016

Not sure why tests are failing... they all pass locally. Can you try pulling the branch down and testing it locally @etpinard?

var el = document.elementFromPoint(x,y);
var options = opts || { bubbles: true };
var ev = new window.MouseEvent(type, options);
el.dispatchEvent(ev);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great. 🍻

@etpinard
Copy link
Contributor

etpinard commented Jan 4, 2016

@mdtusz here's why:

image

The local tests run on Chrome by default whereas the CircleCi tests run on FF.

Looks like FF is more precise than Chrome here.

@mdtusz
Copy link
Contributor Author

mdtusz commented Jan 4, 2016

Ahh lovely. Ok. I'll have to make the test expectations a lil bit more/less specific then. Good catch though. I scanned the values but my eyes must have swapped the 5 and 6!

@etpinard
Copy link
Contributor

etpinard commented Jan 4, 2016

@mdtusz maybe use Jasmine's toBeCloseTo (ref http://jsfiddle.net/lucassus/4DrrW/light/)

expect(count).toEqual(2);
expect(futureData[0]).not.toEqual(futureData[1])
done();
}, 100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Great test!

@mdtusz
Copy link
Contributor Author

mdtusz commented Jan 6, 2016

@etpinard anything else we want to add to this pr?

@etpinard
Copy link
Contributor

etpinard commented Jan 6, 2016

💃

mdtusz added a commit that referenced this pull request Jan 6, 2016
@mdtusz mdtusz merged commit 6e128e8 into master Jan 6, 2016
@mdtusz mdtusz deleted the hover-pie branch January 6, 2016 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants