Open In App

D3.js geoGinzburg8() Function

Last Updated : 23 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

D3.js is a JavaScript library for producing dynamic, interactive data visualizations in web browsers. It makes use of Scalable Vector Graphics, HTML5, and Cascading Style Sheets standards.

The geoGinzburg8() function in d3.js is used to draw the Ginzburg VIII projection.

Syntax: 

d3.geoGinzburg8()

Parameters: This method does not accept any parameters.

Return Value: This method creates and returns Ginzburg8 projection from given JSON data.

Example 1: The following example draws the Ginzburg8 projection of the world with the center at (0,0) and 0 rotation.

HTML




<!DOCTYPE html> 
<html lang="en"
  
<head
    <meta charset="UTF-8" /> 
    <meta name="viewport"
        content="width=device-width, 
                initial-scale=1.0"/> 
    
    <script src="https://d3js.org/d3.v4.js"></script>
    
    <script src=
    </script>
</head
  
<body
    <div style="width:700px; height:500px;"
        <svg width="600" height="450"
        </svg
    </div
      
    <script>
        var svg = d3.select("svg"),
            width = +svg.attr("width"),
            height = +svg.attr("height");
  
        // Ginzburg8 projection
        // Center(0,0) with 0 rotation
        var gfg = d3.geoGinzburg8()
            .scale(width / 1.5 / Math.PI)
            .rotate([0,0])
            .center([0,0])
            .translate([width / 2, height / 2])
  
        // Loading the json data
        d3.json(
            "https://raw.githubusercontent.com/"
            +"janasayantan/datageojson/master/world.json",
            function(data){
                // Drawing the map
                svg.append("g")
                    .selectAll("path")
                    .data(data.features)
                    .enter().append("path")
                    .attr("fill", "DarkSlateGrey")
                    .attr("d", d3.geoPath()
                        .projection(gfg)
                    )
                    .style("stroke", "#ffff")
        })
    </script>
</body
  
</html>


Output:

Ginzburg8 projection of World with no rotation and centered at (0,0)

Example 2: The following example draws the Ginzburg8 projection of the world after customizing the center and rotation.

HTML




<!DOCTYPE html> 
<html lang="en"
  
<head
    <meta charset="UTF-8" /> 
    <meta name="viewport"
        content="width=device-width, 
                initial-scale=1.0"/> 
                  
    <script src="https://d3js.org/d3.v4.js"></script>
  
    <script src=
    </script>
</head
  
<body
    <div style="width:700px; height:600px;"
        <svg width="500" height="450"
        </svg
    </div
  
    <script>
        var svg = d3.select("svg"),
            width = +svg.attr("width"),
            height = +svg.attr("height");
  
        // Ginzburg8  projection
        // Center(0,0) and 90 degree
        // rotation w.r.t Y-axis
        var gfg = d3.geoGinzburg8()
            .scale(width / 1.3 / Math.PI)
            .rotate([90,0])
            .center([0,0])
            .translate([width / 2, height / 2])
  
        // Loading the json data
        d3.json(
            "https://raw.githubusercontent.com/"
            +"janasayantan/datageojson/master/world.json", 
            function(data){
                // Draw the map
                svg.append("g")
                    .selectAll("path")
                    .data(data.features)
                    .enter().append("path")
                    .attr("fill", "grey")
                    .attr("d", d3.geoPath()
                        .projection(gfg)
                    )
                    .style("stroke", "#ffff")
        })
    </script>
</body
  
</html>


Output:

Ginzburg8 projection with 90 degree rotation w.r.t  Y axis  and centered at (0,0)



Similar Reads

How to get the function name from within that function using JavaScript ?
Given a function and the task is to get the name of the function from inside the function using JavaScript. There are basically two methods to get the function name from within that function in JavaScript. These are: Using String substr() MethodUsing Function prototype name propertyGet the Function name using String substr() MethodThis method gets
2 min read
How to get the function name inside a function in PHP ?
To get the function name inside the PHP function we need to use Magic constants(__FUNCTION__). Magic constants: Magic constants are the predefined constants in PHP which is used on the basis of their use. These constants are starts and end with a double underscore (__). These constants are created by various extensions. Syntax: $string = __FUNCTION
1 min read
How to Check a Function is a Generator Function or not using JavaScript ?
Given an HTML document containing some JavaScript function and the task is to check whether the given function is generator function or not with the help of JavaScript. There are two examples to solve this problem which are discussed below: Example 1: In this example, we will use functionName.constructor.name property. It functionName.constructor.n
2 min read
How to implement a function that enable another function after specified time using JavaScript ?
Let us assume that we have been given a function add() which takes in two parameters a and b, and returns their sum. We are supposed to implement a function that should be able to call any function after the given delay amount of time. This can be done with the approaches as given below: Approach 1: Create a function that takes in the amount of del
2 min read
How to create a function that invokes function with partials appended to the arguments in JavaScript ?
In this article, we will learn to create a function that invokes a function with partials appended to the arguments it receives in JavaScript. Approach: We want to implement a function that invokes another function and provides the arguments it received. We can get the result by using (...) the spread/rest operator. Explanation: Let's say, we creat
3 min read
How to create a function that invokes the provided function with its arguments transformed in JavaScript ?
In programming, functions are used to reduce the effort of writing the same instance of code repeatedly. In this article let us see how we can create a function that invokes the provided function with its arguments transformed in JavaScript. In this article, the function transformer invokes the function scaling with its arguments, where the functio
2 min read
How to create a function that invokes each provided function with the arguments it receives using JavaScript ?
In this article, we will see how to create a function that invokes each provided function with the arguments it receives using JavaScript. It helps in reducing the effort of creating the same instance of code again and again. In this article let us see how to create a function that invokes each provided function with the arguments it receives and r
3 min read
How to create a function that invokes function with partials prepended arguments in JavaScript ?
In this article, we will see how to create a function that invokes functions with partials prepended to the arguments it receives in JavaScript. Before understanding the problem statement and approaching the solution for the same, let's, first of all, know what a function (also called a method) is and how a function gets executed. A function (or a
5 min read
Difference between Function.prototype.apply and Function.prototype.call
JavaScript treats everything as an object, even functions, and every object has its own properties and methods. Function objects have both apply() and call() methods on them. However, there is confusion about the two functions in JavaScript. The main difference between them is how they handle function arguments. There is no difference between these
2 min read
Explain the differences on the usage of foo between function foo() {} and var foo = function() {}
Here we see the differences on the usage of foo between function foo() {} and var foo = function() {} types of function declarations in JavaScript. function foo() {} is a Normal Function or traditional general way of Function Declaration which every user or developer finds it simpler to declare and use it every ever required and var foo = function(
4 min read