naver / billboard.js

📊 Re-usable, easy interface JavaScript chart library based on D3.js
https://naver.github.io/billboard.js/
MIT License
5.84k stars 353 forks source link

Set cursor to pointer only when hovering over onclick target box #3084

Open nickgirardo opened 1 year ago

nickgirardo commented 1 year ago

Description

I have a chart with points which have onclick events attached. I'd like to change the cursor to a pointer only when a point is hovered.

I have seen #220, however this doesn't quite get me where I want to be. The .bb_event_rect seems to cover the entire body of the chart, whereas the hitboxes for the onclick events only cover a small radius around my points. I wouldn't want my users to expect there to be something happening when they click on the body of a chart when in fact my onclick events will not be fired

There are a few other options I've considered which do not seem to work for me either: Css attached to the point itself. I've attemted to add styles along the lines of

.bb-chart .bb-shapes.bb.circles .bb-circle {
    cursor: pointer;
}

This has a few issues

Another approach I briefly considered was changing the cursor to a pointer whenever a point is expanded with css along the lines of

.bb-chart:has(.bb-circle._expanded_) {
    cursor: pointer;
}

Unfortunately, this approach also seems like a non-starter

Is it possible to set the cursor to a pointer when a user hovers over the exact area where an onclick event would be triggered?

Steps to check or reproduce

nickgirardo commented 1 year ago

As a quick update, it looks like the has() approach does work quite well if tooltip.grouped is set to false. I've enabled this flag for other reasons and it seems to work fairly well for this case, however this is still far from ideal as only 80% of users browsers support this feature.

netil commented 1 year ago

@nickgirardo, you can add cursor style attribute setting via data.onover and data.onout option.

checkout the online working demo:

data: {
   ...
    onover: function() {
        this.$.main.select("rect").style("cursor", "pointer");
    },
    onout: function() {
        this.$.main.select("rect").style("cursor", null);
    }
}

Feb-13-2023 12-05-06