HomeLanguagesJavascriptD3.js log.invert() Function

D3.js log.invert() Function

The log.invert() function returns a value from the domain when a value from the range is given. This inversion is useful for interaction such as determining the data value that corresponds to the position of the mouse.

Syntax:

log.invert(value);

Parameters: This function accepts only one parameter as given above and described below.

  • value: A number that belongs to any value in the given range.

Return Value: This function returns a number value that lies in the corresponding domain.

Example 1:

html




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" path1tent="width=device-width, 
                   initial-scale=1.0" />
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
        var log = d3.scaleLog()
            .domain([10, 130])
            .range([0, 960]);
        console.log("log(130):", log(130));
        console.log("log.invert(960): ", 
                    log.invert(960))
  
        console.log("log(log.invert(15)):", 
                    log(log.invert(960)));
    </script>
</body>
  
</html>


Output:

Example 2:

html




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" path1tent=
    "width=device-width, initial-scale=1.0"/>
  
    <script src="https://d3js.org/d3.v4.min.js">
    </script>
</head>
  
<body>
    <script>
        var log = d3.scaleLog()
            .domain([10, 130, 140])
            .range([0, 96, 500]);
        console.log("log(140):", log(140));
          
        console.log("log.invert(500): ", 
                        log.invert(500))
  
        console.log("log(log.invert(500)):", 
                        log(log.invert(500)));
    </script>
</body>
  
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32533 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6913 POSTS0 COMMENTS
Nicole Veronica
12028 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12132 POSTS0 COMMENTS
Shaida Kate Naidoo
7043 POSTS0 COMMENTS
Ted Musemwa
7280 POSTS0 COMMENTS
Thapelo Manthata
6999 POSTS0 COMMENTS
Umr Jansen
6986 POSTS0 COMMENTS