Skip to content

Instantly share code, notes, and snippets.

@sverweij
Last active June 5, 2022 09:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sverweij/93e324f67310f66a8f5da5c2abe94682 to your computer and use it in GitHub Desktop.
Save sverweij/93e324f67310f66a8f5da5c2abe94682 to your computer and use it in GitHub Desktop.
Highlight an edge in a graphviz generated svg
<!-- slap this somewhere at the top -->
<style>
/* the lines within the edges */
.edge:active path,
.edge:hover path {
stroke: fuchsia;
stroke-width: 3;
stroke-opacity: 1;
}
/* arrows are typically drawn with a polygon */
.edge:active polygon,
.edge:hover polygon {
stroke: fuchsia;
stroke-width: 3;
fill: fuchsia;
stroke-opacity: 1;
fill-opacity: 1;
}
/* If you happen to have text and want to color that as well... */
.edge:active text,
.edge:hover text {
fill: fuchsia;
}
</style>
@yijunwu
Copy link

yijunwu commented Jun 25, 2020

Thank you for providing this. It really helped. Just one comment, do you happen to know any way to bring edge to front when hovered on? Thanks.

@yijunwu
Copy link

yijunwu commented Jun 25, 2020

and that code snippet makes the lines highlighted, not the arrows, is there any way to highlight arrows as well? Thanks.

@sverweij
Copy link
Author

sverweij commented Jun 25, 2020

@yijunwu Currently I use a different variant of this which also highlights arrows (and text attached to the edge if so desired) I'll update the snippet

<style>
      /* the lines within the edges */
      .edge:active path,
      .edge:hover path {
        stroke: fuchsia;
        stroke-width: 3;
        stroke-opacity: 1;
      }
      /* arrows are typically drawn with a polygon */
      .edge:active polygon,
      .edge:hover polygon {
        stroke: fuchsia;
        stroke-width: 3;
        fill: fuchsia;
        stroke-opacity: 1;
        fill-opacity: 1;
      }
      /* If you happen to have text and want to color that as well... */
      .edge:active text,
      .edge:hover text {
        fill: fuchsia;
      }
</style>

An edge within an svg generated by graphviz typically looks like this (taken from this graph of yarn v2)

<g id="edge27" class="edge">
<title>packages/plugin-node-modules-&gt;packages/yarnpkg-libzip</title>

<!-- this would be the line -->
<path fill="none" stroke="#007700" stroke-width="2" stroke-opacity="0.466667" d="M120.3,-726.1C224.56,-726.1 454.65,-726.1 454.65,-726.1 454.65,-726.1 454.65,-523.51 454.65,-523.51"></path>

<!-- this is typically the arrow/ endpoint --> 
<polygon fill="#007700" fill-opacity="0.466667" stroke="#007700" stroke-width="2" stroke-opacity="0.466667" points="456.75,-523.51 454.65,-517.51 452.55,-523.51 456.75,-523.51"></polygon>
</g>

@yijunwu
Copy link

yijunwu commented Jul 5, 2020

@sverweij It works, thank you for sharing that!

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