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

How to fix missing hover tooltip #320

Open
SamOutlan opened this issue Feb 7, 2023 · 1 comment
Open

How to fix missing hover tooltip #320

SamOutlan opened this issue Feb 7, 2023 · 1 comment

Comments

@SamOutlan
Copy link

SamOutlan commented Feb 7, 2023

I am using neovis.js on my Angular (currently v13.1.4) web app. I am not able to get the hover functionality to work (ex. when hovering over a node or edge no tooltip appears).

  const config = {
      containerId: 'viz',
      interaction: {
        click:true,
        hover: true,
       },
      visConfig: {
        nodes: {
          borderWidth: 2,
          borderWidthSelected: 5,
        },
        edges: {
          color: 'gray',
          arrows: {
            to: {enabled: true}
          }
        },
      },
      labels: {
              	Donor: {
              		value: "donorID",
                        label: "name"
              		group: "donorCategory"
              	},
                SuperPac: {
              		value: "id",
                        label: "name"
              	}
              },
      relationships: {
              	CONTRIBUTED_TO_2014: {
                  label: "amountYearDisplay",
                }
      },

      initialCypher: `MATCH p=(d:Donor)-[r:CONTRIBUTED_TO_2014]->(s:SuperPac) RETURN p ORDER BY r.amountYear DESC`
    };
    
    const viz = new NeoVis(config);
    console.log(viz);
    viz.render();
@FStriewski
Copy link

FStriewski commented Jul 5, 2023

I had a similar issue with React and with a lot of trial and error I figured it out.

You can set the default tooltip on specific nodes like this.

 labels: {
          Person: {
            label: "name",
            [Neovis.NEOVIS_ADVANCED_CONFIG]: {
              static: {
                color: "blue",
                border: "#ffffff",
              },
              function: {
                title: Neovis.objectToTitleHtml,     // <---------------------
              },
            },
          },
          Abstract: { label: "title" },
          Organisation: { label: "name" },
          Partner: { label: "name", title: "type" },
        },

If you want to register a handler for DIY stuff, onClick works out of the box with Neovis:

    let vis;
      const config = {    
        containerId: "viz",
        neo4j: {
          serverUrl: "...",
          serverUser: "...",
          serverPassword: "...",
        },
        visConfig: {
          nodes: {...},
         edges: {...},
      };
      vis = new Neovis(config);

      vis.registerOnEvent("clickNode", (e) => {  // <-------------------
        console.info(e.node.raw.properties);
        setNode(e.node.raw.properties);
      });

For hovering however, vis needs you to change the options. See the documentation here: https://visjs.github.io/vis-network/docs/network/interaction.html . So the handler looks like this:

      vis.registerOnEvent("completed", (e) => {
        vis.network.interactionHandler.options.hover = true;   // <-----------IMPORTANT
        console.log(vis.network.interactionHandler.options);
        vis.network.on("hoverNode", (event) => {
          console.log(event);
        });
      });

Note that you can only access the network property after the rendering is complete

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

No branches or pull requests

2 participants