Thursday, September 18, 2025
HomeLanguagesJavascriptD3.js pow.invert() Function

D3.js pow.invert() Function

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

Syntax:

pow.invert( value )

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

  • value: It is a number that belongs to any value in the given range.

Return Values: This function returns a number from the domain.

The program below illustrates the pow.invert() function in D3.js:

Example 1: Taking all elements of range to be positive.

HTML




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" 
        content="width=device-width,
                 initial-scale=1.0" />
  <title>neveropen</title>
  <script src=
  </script>
  <script src=
  </script>
  <script src=
  </script>
  <script src=
  </script>
</head>
<body>
  <h2 style="color: green">neveropen</h2>
    
<p>pow.invert() Function </p>
  
  <script>
    var pow = d3.scalePow()
      .domain([0, 1])
      .range([1, 2, 3, 4, 5, 6]);
  
    document.write("<h3> pow.invert(1): " + 
                   pow.invert(1) + "</h3>");
    document.write("<h3>pow.invert(2): " +
                   pow.invert(2) + "</h3>");
    document.write("<h3>pow.invert(3): " + 
                   pow.invert(3) + "</h3>");
    document.write("<h3> pow(pow.invert(1)): " + 
                   pow(pow.invert(1)) + "</h3>");
    document.write("<h3>pow(pow.invert(2)): " +
                   pow(pow.invert(2)) + "</h3>");
    document.write("<h3>pow(pow.invert(3)): " +
                   pow(pow.invert(3)) + "</h3>");
  </script>
</body>
</html>


Output:

Example 2: Taking a range array such that it contains positive and negative numbers both.

HTML




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" 
        content="width=device-width,
                 initial-scale=1.0" />
  <title>neveropen</title>
  <script src=
  </script>
  <script src=
  </script>
  <script src=
  </script>
  <script src=
  </script>
</head>
<body>
  <h2 style="color: green">neveropen</h2>
    
<p>pow.invert() Function </p>
  
  <script>
    var pow = d3.scalePow()
      .domain([-1, 1])
      .rangeRound([10, 20, 30, 40, 50, 60])
      .exponent(2);
  
    document.write("<h3> pow.invert(1): " +
                   pow.invert(1) + "</h3>");
    document.write("<h3>pow.invert(2): " +
                   pow.invert(2) + "</h3>");
    document.write("<h3>pow.invert(3): " + 
                   pow.invert(3) + "</h3>");
    document.write("<h3> pow(pow.invert(-1)): " +
                   pow(pow.invert(-1)) + "</h3>");
    document.write("<h3>pow(pow.invert(-2)): " +
                   pow(pow.invert(-2)) + "</h3>");
    document.write("<h3>pow(pow.invert(-1)): " + 
                   pow(pow.invert(-3)) + "</h3>");
  </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

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6660 POSTS0 COMMENTS
Nicole Veronica
11835 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7053 POSTS0 COMMENTS
Thapelo Manthata
6735 POSTS0 COMMENTS
Umr Jansen
6741 POSTS0 COMMENTS