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

Tool Tips remain after GeoMap page is unloaded and browser displays another 'page'. #36

Open
strafton opened this issue Nov 30, 2020 · 2 comments
Assignees
Labels

Comments

@strafton
Copy link

First off , thank you for creating this for react. It's working great except for the tooltips which once they are opened remain open even when the page unloads for another screen.

I am using the GeoMap with points defined. When you hover over the point it displays some information and when you click on the point the user is navigated away from the page. The issue is the information displayed in the tool tip never disappears until you go back to the map and hover over another point.

Any ideas on how to fix this issue would be greatly appreciated since there doesn't not appear to be a handle to the svg objects anywhere.

const methods = {
//status: 0 good, 50 -out of range 100- critical
data: data
,
pointSizeMax: 5,
pointSizeMin: 1,

            // hides ColorScale, but still allows coloring shapes
            colorScalePosition: false,
            colorScale:"status",
            colorScaleConfig:{
                color: ["blue",  "green",  "red"],
            },
            groupBy:["label"],
            color:{
                value: "status"
            },

            label:(d)=> {
                return d.label  ;
            },

            legend: false,
            point:(d)=> {
                return [d.lon, d.lat];
            },on: {
                "click.shape": (d) => this.poolSelectHandler(d),
            },

        };

        geoGraph = <Geomap config={methods} /> ;

////
poolSelectHandler = (d) => {
this.props.onSetCompanyId(d.cId);
this.props.history.push( '/info/');
};

This is happening in all browsers, Chrome, Firefox and Safari on a Mac Desktop.
Screen Shot 2020-11-30 at 11 33 05 AM
Screen Shot 2020-11-30 at 11 33 22 AM

@davelandry davelandry added the bug label Dec 7, 2020
@davelandry davelandry self-assigned this Dec 7, 2020
@davelandry
Copy link
Member

davelandry commented Dec 7, 2020

@strafton thanks reporting this, and for the kind words! 🍻

This is a really good point, and I think d3plus-react could handle this with something like a componentDidUnmount event. In the meantime, since I'm the only dev here and this isn't at the top of my todo... here's a hack that we've used in other projects:

You can manually target the d3plus tooltip and remove it from the page. Depending on your project, this code could live in something like a react-router middleware where you able to detect the page change, or maybe even directly in your on click event:

d3.selectAll(".d3plus-tooltip").remove();

(I'm using d3-selection here, but this could be written in any library with query selection, or just raw vanilla JS)

@strafton
Copy link
Author

strafton commented Dec 8, 2020

@davelandry thank you for this tip. I was able to get it working using raw vanilla JS since react didn't seem to have a handle to the d3 object itself. Much appreciated!

// inside the onClick handler
let toolTips = document.getElementsByClassName("d3plus-tooltip");
Array.from(toolTips).forEach(function (element) {
         element.remove();
 });

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

No branches or pull requests

2 participants