Transform the color of links in a Sankey diagram on Google upon clicking a node

Currently, I am in the process of creating a Sankey diagram using Google charts.

As of now, I have implemented the following CSS:

svg path:hover {
fill: red;
}

However, I have noticed that this code only changes the color of the links when hovering over them. If you hover over a node, the links highlight but not in the specified red color. My aim is to have the links connected to the node change to a more contrasting color when the node is hovered over.

I also tried adding the following code:

sankey: {
        node: { interactivity:true,}
        }

While this did provide some improvement, I still feel the need for greater contrast.


                google.charts.load('current', {'packages':['sankey']});
                google.charts.setOnLoadCallback(drawChart);

                function drawChart() {
                    var data = new google.visualization.DataTable();
                    data.addColumn('string', 'From');
                    data.addColumn('string', 'To');
                    data.addColumn('number', 'Weight');
                    data.addRows([
                        [ 'A', 'X', 5 ],
                        [ 'A', 'Y', 7 ],
                        [ 'A', 'Z', 6 ],
                        [ 'B', 'X', 2 ],
                        [ 'B', 'Y', 9 ],
                        [ 'B', 'Z', 4 ]
                    ]);

                    var options = {
                        width: 600,
                        sankey: {
                            node: { interactivity:true,}
                        }
                    };

                    var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
                    chart.draw(data, options);
                }
            

                svg path:hover {
                    fill:red;
                }
            

                <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
                <div id="sankey_basic" style="width: 900px; height: 300px;"></div>
            

Answer №1

It's worth noting the use of path[fill-opacity="0.8"] in CSS selectors to target the svg fill-opacity attribute. This idea was inspired by one of my previous responses. To avoid unintended effects on other parts of the page, consider refining this rule with a class or id restriction.

      google.charts.load('current', {'packages':['sankey']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'From');
        data.addColumn('string', 'To');
        data.addColumn('number', 'Weight');
        data.addRows([
          [ 'A', 'X', 5 ],
          [ 'A', 'Y', 7 ],
          [ 'A', 'Z', 6 ],
          [ 'B', 'X', 2 ],
          [ 'B', 'Y', 9 ],
          [ 'B', 'Z', 4 ]
        ]);

        // Sets chart options.
        var options = {
          width: 600,
          sankey: {
node: { interactivity:true,}
}
        };

        // Instantiates and draws our chart, passing in some options.
        var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
        chart.draw(data, options);
      }
svg path[fill-opacity="0.8"] {
fill:red;
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
       <div id="sankey_basic" style="width: 900px; height: 300px;"></div>
   

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to make a select tag read-only before the Ajax request is successful

Is there a way to make a select tag read-only before an Ajax success? I tried using this code, but it didn't work: $("#tower").prop('readonly', true); Then I tried this alternative, but I couldn't get the value from the select tag: ...

The regular expression for validating credit card numbers is invalid due to a repetition error

Here is the regular expression I've been using to validate credit card numbers in JavaScript: var match = /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|?(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])?[0-9]{11})|((?:2131|1800 ...

Cropped portion of the captcha image located on the left side

edit: I manually adjusted cnv.width = this.width to 120 and it seems to be working. Upon closer inspection, I discovered that the image has both a rendered size and an intrinsic size. The width is 35 for rendered size and 40 for intrinsic size, which may e ...

Ways to add values to a database through modal window

There are two buttons on the interface: login and register. Clicking the login button opens the login modal, while clicking the register button should open the register modal. My objective is to validate the form and insert the values into a database aft ...

Tips on validating if a form has already been submitted using JavaScript and AJAX to prevent duplicate submissions

Exploring the world of web development, I stumbled upon a fascinating component - forms in JavaScript or jQuery. However, here lies my dilemma: In JS: const themeFolder = object_name.templateUrl; const urlAjax = themeFolder + '/FormHandler.php&apos ...

The media query fails to start in the browser's mobile display

Instead of just adjusting the browser window size, I utilized Chrome's developer tools to make adjustments. I double-checked that the appropriate meta tags were included in the code: <meta name="viewport" content="width=device-width, initial-scal ...

What is the best approach to slowly transition a value to a different one over a set period of time?

if(!isWalking) { isWalking = true; var animation = setInterval(function () {$player.css({'left': "+="+boxSize/25})}, 10); setTimeout(function(){clearInterval(animation)},250); setTimeout(function(){isWalking = false},250); ...

Loading JS scripts in MVC 4: A Guide

As a newcomer to MVC, I have encountered various challenges when it comes to loading my JavaScript files properly. Initially, here is the structure of my website: _Layout.cshtml (main page) Index.cshtml _MainMenu.cshtml (partial view) I include my M ...

Disabling the final grid cell(s)

I am currently working on a 4 column grid in ReactJS. The grid includes various elements with images and text. I want to ensure that if there are five elements filled, the last three should be inactive so that each row always has four columns without any e ...

Guide for implementing pagination on a lengthy list with React MaterialUI

I'm currently working on a project using react and MaterialUI to create a list with filter functionality. The list will be populated with data from an Http request and may contain a large number of items. I was researching pagination in the MaterialUI ...

Enhance Your Search Input: Adding an Icon Before Placeholder Text in Material Design

I am currently facing an issue where the placeholder text is overlapping the icon in the code below. I need to have the placeholder text indented to the right of the icon. Is there a more efficient way to include both an icon and a placeholder text in a ...

Content retrieved from Ajax response

When making an ajax call and receiving JSON data (Data Attached), the data appears as follows after being converted to a String: { "shipments":[ { "companyName":"TriStar Inc.", "shipmentDate":null, "transMode":"NDAY" ...

How come an absolutely positioned element does not disregard its sibling's position and appears after it?

<div> is styled flexibly, while <section> is inserted within it and formatted statically. However, <section> shows up underneath the lower right corner of the image, rather than at the upper left corner of its flexible parent. I am strugg ...

What could be the reason for the gtag event not showing up in Google Analytics?

Here is an example of my script: <html> <head> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxx-1"></script> <script> wi ...

The endpoint /api/user does not allow POST requests

I'm currently testing a user registration route and encountering a "Cannot POST /api/user" error. Although I can successfully make a GET request using Postman, the issue arises when trying to make a POST request. Any help or guidance on pinpointing t ...

Attempting to display a brief description when hovering over a particular project image

My goal on is to display a description when hovering over a portfolio image by setting the opacity to 1. However, this functionality seems to not be working. .description { display: block; opacity: 0; text-align: left; height: 130px; padding- ...

Generate a random word using Typed.js

Can Typed.js generate a random word for output? $(function(){ $(".element").typed({ strings: ["Lorem", "Ipsum", "Dolor"], typeSpeed: 0 }); }); The output should be one of the following words. (Lorem / Ipsum / Dolor) ...

Firebase Database: Unidentified node kind with separate Firebase initialization process

In order to replicate this issue, a minimal repository can be found at: https://github.com/ljrahn/firebase-unknown-node-type The problem arises when the firebase initialization logic is separated into a distinct package and then imported. This leads to an ...

Trouble with executing AJAX for API call

My current project is built on CI3 and I have created an API that belongs to a different domain than the application itself. $.ajax({ url: "http://www.example.com/restapi/index.php/api/user", type: "GET", data: {"user_id": user_id} ...

Tips for marking a p-checkbox as selected and saving the chosen item to a list

Here is a sample list: rows: any[] = [ {"id":"1721079361", "type":"0002", "number":"2100074912","checked":true}, {"id":"1721079365", "type":"0003", "number":"2100074913","checked":false}, {"id":"1721079364", "type":"0004", "number":"2100074914"," ...