ACE-IoT-Solutions / ace-svg-react

Grafana SVG Rendering Panel using the 7+ Plugin Framework
https://grafana.com/grafana/plugins/aceiot-svg-panel/
MIT License
41 stars 14 forks source link

an "Onclick" link #8

Closed SamuelJoly closed 3 years ago

SamuelJoly commented 3 years ago

Is there a way to program an "onclick" link. Like for example, if I the user would click on my SVG circle, it would send him to another page. Can we do that?

I tried this without sucess: https://medium.com/@gianpaul.r/adding-clickable-links-to-an-svg-image-file-f254e0f6b71a

MarcusCalidus commented 3 years ago

The easiest solution would be (for static links) to use something like this:

<?xml version="1.0"?>
<svg viewBox="0 0 120 120" version="1.1"
  xmlns="http://www.w3.org/2000/svg">
  <circle id="circle" cx="60" cy="60" r="50" onclick="window.location.href = 'https://google.com';"/>
</svg>

to do more sophisticated on click events you can try the svg.js event handling: https://svgjs.com/docs/3.0/events/

acedrew commented 3 years ago

Hey @SamuelJoly the SVG.js library allows attachement of arbitrary events to elements with the on('event', handler) method on each element in your svgmap.

smartcuc commented 3 years ago

svgmap.YourCycle.click(function() { open("http://www.cnn.com/", "CNN_WindowName"); });