<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sai Kiran</title>
    <description>The latest articles on DEV Community by Sai Kiran (@saikiran).</description>
    <link>https://dev.to/saikiran</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F224909%2Fa883a609-c3b5-498b-9744-c9e83e52a8e5.jpeg</url>
      <title>DEV Community: Sai Kiran</title>
      <link>https://dev.to/saikiran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saikiran"/>
    <language>en</language>
    <item>
      <title>D3js fundamentals Part 5 Joins And Enter/Exit</title>
      <dc:creator>Sai Kiran</dc:creator>
      <pubDate>Sun, 16 Feb 2020 17:17:16 +0000</pubDate>
      <link>https://dev.to/saikiran/d3js-fundamentals-part-5-joins-and-enter-exit-170h</link>
      <guid>https://dev.to/saikiran/d3js-fundamentals-part-5-joins-and-enter-exit-170h</guid>
      <description>&lt;p&gt;Last article we learnt about scales which help in converting our data as data point for svg.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/saikiran" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F224909%2Fa883a609-c3b5-498b-9744-c9e83e52a8e5.jpeg" alt="saikiran"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/saikiran/d3js-fundamentals-part-4-scales-18og" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;D3js fundamentals Part 4 Scales&lt;/h2&gt;
      &lt;h3&gt;Sai Kiran ・ Nov 22 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#d3js&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;Data visualization means working with data. We want to access the data we want in efficient way. Joins helps us to bind data to the DOM element in efficient way.&lt;/p&gt;

&lt;p&gt;To join data to DOM you just need to call &lt;code&gt;.data()&lt;/code&gt; on the selected d3 element and pass your data as parameter. In the below example we have 5 circles elements. Select all the elements and call &lt;code&gt;.data()&lt;/code&gt; by passing the data to it.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/krngd2/embed/MWWdxvB?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.data()&lt;/code&gt; function will loop through the data and will bind data to each node one by one. Press F12, reload the page and check the logs. You will find the list of nodes that we selected and expand the first element scroll down to bottom where you can see &lt;code&gt;__data__&lt;/code&gt; which has the  respective data bonded to the element which you can access whenever you &lt;code&gt;select&lt;/code&gt; that particular element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbk82p3gcym25wgxcngp0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbk82p3gcym25wgxcngp0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have observed or not, our data is only 4 in length but we have bonded that data to 5 selected elements. Check the fifth element from the same logs, there will be no &lt;code&gt;__data__&lt;/code&gt; property to it.&lt;br&gt;
D3 gives us easy way to adjust the DOM elements to the data with the help of &lt;code&gt;.enter()&lt;/code&gt; function for adding data and &lt;code&gt;.exit()&lt;/code&gt; function for removing the data. Both fucntions returns the extra data but &lt;code&gt;.enter()&lt;/code&gt; followed by &lt;code&gt;.append()&lt;/code&gt; will add extra elements and &lt;code&gt;.exit()&lt;/code&gt; followed by &lt;code&gt;.remove()&lt;/code&gt; will remove the extra elements.&lt;/p&gt;
&lt;h3&gt;
  
  
  Remove Example
&lt;/h3&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/krngd2/embed/JjjqVGG?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Append example
&lt;/h3&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/krngd2/embed/xxGVXON?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Every function will get the bonded data as the call back parameter with which we can do verity for tricks. Like changing the values of its attributes and css properties. &lt;/p&gt;

&lt;p&gt;In the example below we are changing the fill color of the circle elements based on its radius. If it is less than 35 its fill color should be of red and otherwise orange. Note here that condition applies to only extra elements as we used the condition after the enter statement. We need again select all the circles in order to make the condition for all. &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/krngd2/embed/ExjKwZJ?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>d3js</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>D3js fundamentals Part 4 Scales</title>
      <dc:creator>Sai Kiran</dc:creator>
      <pubDate>Fri, 22 Nov 2019 15:32:14 +0000</pubDate>
      <link>https://dev.to/saikiran/d3js-fundamentals-part-4-scales-18og</link>
      <guid>https://dev.to/saikiran/d3js-fundamentals-part-4-scales-18og</guid>
      <description>&lt;p&gt;Last article we learnt about &lt;code&gt;path&lt;/code&gt; data. &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/saikiran" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F224909%2Fa883a609-c3b5-498b-9744-c9e83e52a8e5.jpeg" alt="saikiran"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/saikiran/d3js-fundamentals-part-3-svg-path-1bhh" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;D3js fundamentals Part 3 SVG Path&lt;/h2&gt;
      &lt;h3&gt;Sai Kiran ・ Nov 22 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#d3js&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
As I wrote in the last article, it is not necessary to learn about the &lt;code&gt;path&lt;/code&gt; data if you want to learn d3js, you can skip that part as it sometimes become too confusing to pickup the concepts and it just helps you in understanding what goes on in the background when you make a &lt;code&gt;path&lt;/code&gt;.

&lt;p&gt;If you see in this example, We have used data to match our svg width and height, like we used data 100,100 to start from point 100,100 of the svg but we will never be getting data that can match. Some data may be in floating point , some may be in long int, some in date format etc. Here comes the &lt;code&gt;Scales&lt;/code&gt; in d3js to solve this problem. D3js have some neat features to play with data. &lt;/p&gt;

&lt;p&gt;Lets see the simplest example&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/krngd2/embed/JjjzMBv?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;d3.scaleLinear()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;In the above example we converted marks to percentages, simply means we took a range of values and fitted it into 0 to 100 range. This we use to fit our range of data, fit into width or height range of the &lt;code&gt;svg&lt;/code&gt;. Look at this example&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/krngd2/embed/oNNVEyv?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We took a different set of data that wouldn't fit in our svg and then scaled it to fit in.&lt;/p&gt;

&lt;p&gt;This is our data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let data = [
       {x:-60,y:1120},
       {x:50,y:400},
       {x:160,y:220},
       {x:190,y:280},
       {x:330,y:360},
       {x:420,y:80},
       {x:560,y:560},
       {x:620,y:120},
       {x:930,y:700},
       {x:1120,y:-60}
     ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the previous article example we have just passed the data directly to the line generator but in this example our data is very different, so we have to define accessor to the line generator for x and y values like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let lineGenerator = d3.line()
                      .x(d =&amp;gt; d.x)
                      .y(d =&amp;gt; d.y) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Line generator will loop through the data array to get x and y values as returned by the accessor function &lt;code&gt;.x(d =&amp;gt; d.x).y(d =&amp;gt; d.y)&lt;/code&gt; and then generate path data. In order to fit in the data to svg, data needs to scaled accordingly. We have to scale it before it gets passed to the x and y values. &lt;br&gt;
First we initialize the scale by passing the smallest and largest value to domain and 0 to width or height of the svg to range, when the value gets passed it return the appropriate points on the svg.&lt;br&gt;
Lowest point in our svg is -60 and largest value is 1120 which can be passed to domain and svg width is 500px which can be passed to range.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let scale = d3.scaleLinear()
                      .domain([-60, 1120])
                      .range([0, 500])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and convert data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let lineGenerator = d3.line()
                      .x(d =&amp;gt; scale(d.x))
                      .y(d =&amp;gt; scale(d.y))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can get min and max values of the given data with the help of &lt;code&gt;d3.extent(data, accessor)&lt;/code&gt;, it will return an array. To get single minimum or maximum value use &lt;code&gt;d3.min(data,accessor)&lt;/code&gt; and &lt;code&gt;d3.max(data,accessor)&lt;/code&gt;. You can know more about the array method in d3js &lt;a href="https://github.com/d3/d3-array" rel="noopener noreferrer"&gt;here d3-array&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are 12 types of scaling in d3js which are classified into 3 types&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Continuous input and continuous output

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/d3/d3-scale#linear-scales" rel="noopener noreferrer"&gt;&lt;code&gt;d3.scaleLinear()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Continuous input and discrete output

&lt;ul&gt;
&lt;li&gt;d3.scaleQuantize()&lt;/li&gt;
&lt;li&gt;d3.scaleQuantile()&lt;/li&gt;
&lt;li&gt;d3.scaleThreshold()&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Discrete input and discrete output

&lt;ul&gt;
&lt;li&gt;d3.scaleOrdinal()&lt;/li&gt;
&lt;li&gt;d3.scaleBand()&lt;/li&gt;
&lt;li&gt;d3.scalePoint()&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can learn about them &lt;a href="https://github.com/d3/d3-scale" rel="noopener noreferrer"&gt;here d3-scale&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>d3js</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>D3js fundamentals Part 3 SVG Path</title>
      <dc:creator>Sai Kiran</dc:creator>
      <pubDate>Fri, 22 Nov 2019 15:30:02 +0000</pubDate>
      <link>https://dev.to/saikiran/d3js-fundamentals-part-3-svg-path-1bhh</link>
      <guid>https://dev.to/saikiran/d3js-fundamentals-part-3-svg-path-1bhh</guid>
      <description>&lt;p&gt;In the last article we learnt about svg, svg shapes and basic line generator using d3js and why &lt;code&gt;path&lt;/code&gt; is used for generating lines. &lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/saikiran" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F224909%2Fa883a609-c3b5-498b-9744-c9e83e52a8e5.jpeg" alt="saikiran"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/saikiran/d3js-fundamentals-part-2-5bek" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;D3js fundamentals Part 2 SVG&lt;/h2&gt;
      &lt;h3&gt;Sai Kiran ・ Nov 19 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#d3js&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;In this article we will learn about &lt;code&gt;path&lt;/code&gt; data and how we can make any shape we want with it. It is not necessary to learn about the &lt;code&gt;path&lt;/code&gt; data if you want to just learn d3js, you can skip this part as this sometimes become too confusing to pickup the concepts and it just helps you in understanding what goes on in the background when you make a &lt;code&gt;path&lt;/code&gt;. &lt;br&gt;
Lets take a simplest example making a line &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/krngd2/embed/LYYvNNX?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The data we passed to &lt;code&gt;path&lt;/code&gt; is &lt;strong&gt;M100,100 L400,400&lt;/strong&gt;.&lt;br&gt;
Path data always starts with &lt;code&gt;M&lt;/code&gt; means move, from which point you want to start drawing, every co-ordinate take two point x and y. We gave &lt;code&gt;M100,100&lt;/code&gt; which starts from 100,100 co-ordinates of the svg. There is also lowercase &lt;code&gt;m&lt;/code&gt; which moves according to its relative parent instead of svg. After that we have &lt;code&gt;L400,400&lt;/code&gt; representing line and its co-ordinates, line is drawn from the start point of &lt;code&gt;M&lt;/code&gt; or &lt;code&gt;m&lt;/code&gt;. Lower case &lt;code&gt;l&lt;/code&gt; takes points from its parent instead of svg.&lt;/p&gt;

&lt;p&gt;Similarly we have &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Move          M m &lt;/li&gt;
&lt;li&gt;Line          L l &lt;/li&gt;
&lt;li&gt;Horizontal    H h =&amp;gt; To draw a line horizontally&lt;/li&gt;
&lt;li&gt;Vertical      V v =&amp;gt; To draw a line Vertically&lt;/li&gt;
&lt;li&gt;Close path    Z   =&amp;gt; joins the start and end points with a line &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are some examples of Horizontal, Vertical and Close Path  &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/krngd2/embed/ExxJNRO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;And to make curves we have, I have built some visualizers to make it easy to understand. Play with the slider and see which values effects which part of the curve.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cubic Bézier

&lt;ul&gt;
&lt;li&gt;C, c 
&lt;iframe height="600" src="https://codepen.io/krngd2/embed/RwwvmVW?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/li&gt;
&lt;li&gt;S, s
&lt;iframe height="600" src="https://codepen.io/krngd2/embed/RwwvmMR?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Quadratic Bézier

&lt;ul&gt;
&lt;li&gt;Q, q
&lt;/li&gt;
&lt;li&gt;T, t
&lt;iframe height="600" src="https://codepen.io/krngd2/embed/wvvNbVy?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Elliptical arc

&lt;ul&gt;
&lt;li&gt;A, a
&lt;iframe height="600" src="https://codepen.io/krngd2/embed/PoogNPo?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://dev.to/saikiran/d3js-fundamentals-part-4-scales-18og"&gt;https://dev.to/saikiran/d3js-fundamentals-part-4-scales-18og&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>d3js</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>D3js fundamentals Part 2 SVG</title>
      <dc:creator>Sai Kiran</dc:creator>
      <pubDate>Tue, 19 Nov 2019 07:20:38 +0000</pubDate>
      <link>https://dev.to/saikiran/d3js-fundamentals-part-2-5bek</link>
      <guid>https://dev.to/saikiran/d3js-fundamentals-part-2-5bek</guid>
      <description>&lt;p&gt;In the last article, &lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/saikiran" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xh0IbO5y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--yy9rmbsw--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/224909/a883a609-c3b5-498b-9744-c9e83e52a8e5.jpeg" alt="saikiran image"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/saikiran/d3-fundamentals-23bo" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;D3js fundamentals Part 1&lt;/h2&gt;
      &lt;h3&gt;Sai Kiran ・ Nov 17 '19 ・ 2 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#d3js&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
 We have gone through set-up, selections and append(updated) in d3js. This article we will learn svg elements. Scalable Vector Graphics(SVG) is the building blocks of 2D data visualization on the web. It is an XML-based markup language for describing two dimensional based vector graphics. SVG has now become mainstream and widely supported.

&lt;p&gt;Lets create a svg with tag &lt;code&gt;&amp;lt;svg&amp;gt;&amp;lt;/svg&amp;gt;&lt;/code&gt;&lt;br&gt;
By default svg takes up 300px width and 150px height if not declared. You can declare width and height either as attributes or style element. &lt;br&gt;
ex: &lt;code&gt;&amp;lt;svg width="500px" height="500px"&amp;gt;&amp;lt;/svg&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;click on HTML, CSS or JS tabs to look at the code&lt;/em&gt;&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/krngd2/embed/QWWzrpG?height=600&amp;amp;default-tab=html,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now think of svg as 500x500 pixel grid where we will place elements using these grid co-ordinates. &lt;br&gt;
Lets try to make basic shapes onto SVG&lt;/p&gt;
&lt;h3&gt;
  
  
  Line
&lt;/h3&gt;

&lt;p&gt;A line requires 2 points start and end, start as x1,y1 and end as x2,y2. &lt;br&gt;
Any element in svg needs to have a stroke color in order to show up on the screen&lt;br&gt;
ex: &lt;code&gt;&amp;lt;line x1="100" y1="100" x2="400" y2="400" stroke="black"/&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;click on HTML, CSS or JS tabs to look at the code&lt;/em&gt;&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/krngd2/embed/dyyweKE?height=600&amp;amp;default-tab=html,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a line with d3
&lt;/h3&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**`d3.line()`**
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;click on HTML, CSS or JS tabs to look at the code&lt;/em&gt;&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/krngd2/embed/ZEEwGPN?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We initialize a line generator using &lt;code&gt;d3.line()&lt;/code&gt; and then call it by passing our data to it. Line generator will loop through the data array to get x and y values and then generate path data. Which we can pass to &lt;code&gt;d&lt;/code&gt; attribute of &lt;code&gt;path&lt;/code&gt;. We will learn more about line generators in coming articles.&lt;/p&gt;

&lt;p&gt;Now you may be wondering why we have appended a &lt;code&gt;path&lt;/code&gt; instead of &lt;code&gt;line&lt;/code&gt;. So basically &lt;code&gt;path&lt;/code&gt; can take up any shape, so people at d3 used &lt;code&gt;path&lt;/code&gt; for most of the elements to make it less complex. I showed the example of &lt;code&gt;&amp;lt;line&amp;gt;&lt;/code&gt; tag to make it easy to understand how things are placed in SVG. &lt;/p&gt;

&lt;p&gt;Click on edit on codepen on top right corner of the codepen example and un-comment the second data variable and comment out first data variable and check how the line is shaped, which we cannot achieve with the single &lt;code&gt;line&lt;/code&gt; tag. &lt;/p&gt;

&lt;p&gt;While building data visuals, there will be times where you want to statically place shapes for which you dont need a generator function. So its better to know the basic shapes. &lt;/p&gt;

&lt;p&gt;There are 6 shape tags in svg &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Line -&amp;gt; &lt;code&gt;&amp;lt;line x1="0" y1="0" x2="200" y2="200" /&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Rectangle -&amp;gt; &lt;code&gt;&amp;lt;rect x="50" y="20" width="150" height="150" &amp;gt;&lt;/code&gt; 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5FN5Z-CE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dtalqrvf1q4y4b4sk3hu.PNG" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Circle -&amp;gt; &lt;code&gt;&amp;lt;circle cx="50" cy="50" r="50"/&amp;gt;&lt;/code&gt; 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xOIfThjG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/121u9c0g45nj38tcijjl.PNG" alt="Alt Text"&gt; &lt;/li&gt;
&lt;li&gt;Ellipse -&amp;gt; &lt;code&gt;&amp;lt;ellipse cx="200" cy="80" rx="100" ry="50" /&amp;gt;&lt;/code&gt; 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wTu1oGDy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dvqy12734sr4bl7ua1si.PNG" alt="Alt Text"&gt; &lt;/li&gt;
&lt;li&gt;Polygon -&amp;gt; &lt;code&gt;&amp;lt;polygon points="220,10 300,210 170,250 123,234" /&amp;gt;&lt;/code&gt; 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lpG7bwMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/sqow0kay2c65k5aylmlg.PNG" alt="Alt Text"&gt; &lt;/li&gt;
&lt;li&gt;Polyline -&amp;gt; &lt;code&gt;&amp;lt;polyline points="20,20 40,25 60,40 80,120 120,140 200,180" /&amp;gt;&lt;/code&gt; 
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qkRt7qHI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/5t5e4ce0513t67kz8s9i.PNG" alt="Alt Text"&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Path -&amp;gt; which can take up any shape, Which we will discuss further&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Group -&amp;gt; &lt;code&gt;&amp;lt;g&amp;gt;&lt;/code&gt; Its like a div for svg, which is used to grouping multiple elements and manipulating. &lt;/li&gt;
&lt;li&gt;Text -&amp;gt; &lt;code&gt;&amp;lt;text x="0" y="15" &amp;gt;I love SVG!&amp;lt;/text&amp;gt;&lt;/code&gt; is used to place text &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many elements for SVG. If you want to know more about SVG shapes, head on to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element"&gt;MDN SVG elements&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;d3js also provide basic shape generator &lt;br&gt;
Which you &lt;a href="https://bl.ocks.org/d3indepth/raw/bae221df69af953fb06351e1391e89a0/"&gt;check out here&lt;/a&gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s2D9eLVT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/03d5t9613hxgy7rzcid7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s2D9eLVT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/03d5t9613hxgy7rzcid7.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In next article we will go details about how &lt;code&gt;path&lt;/code&gt; works.  &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>d3js</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>D3js fundamentals Part 1</title>
      <dc:creator>Sai Kiran</dc:creator>
      <pubDate>Sun, 17 Nov 2019 10:56:57 +0000</pubDate>
      <link>https://dev.to/saikiran/d3-fundamentals-23bo</link>
      <guid>https://dev.to/saikiran/d3-fundamentals-23bo</guid>
      <description>&lt;p&gt;If you know jQuery, it makes manipulating and working with DOM elements very easy. Think of D3js as jQuery made for data which makes manipulating the DOM according to data super easy. D3js also comes with vitalization specific features which will we go through another series of articles. This article is to get a knowledge on D3js fundamentals. &lt;/p&gt;

&lt;h3&gt;
  
  
  Pre-requisites :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;CSS &lt;/li&gt;
&lt;li&gt;Javascript&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  SetUp
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;script src="https://d3js.org/d3.v5.min.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt; CDN way&lt;/li&gt;
&lt;li&gt;NPM way &lt;code&gt;npm install d3&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We will stick to CND way for the sake of keeping it simple to make beginners understand easily. Just include the script tag inside the head of your html file and you are good to go. &lt;/p&gt;

&lt;h3&gt;
  
  
  1.Selection
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;d3.select("&lt;em&gt;selection query&lt;/em&gt;")&lt;/li&gt;
&lt;li&gt;d3.selectAll("&lt;em&gt;selection query&lt;/em&gt;")&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Open console by pressing f12, there will be logs of the selections at the end.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;click on HTML, CSS or JS tabs to look at the code&lt;/em&gt;&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/krngd2/embed/jOOXNJR?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Most of the functions in d3js returns the context, that means you can chain your functions one after the other, You will see such chaining in next examples. &lt;/p&gt;

&lt;h3&gt;
  
  
  2.DOM Manipulation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Styling 

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;d3.select("*selection query*").style("color","red")&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Attributes

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;d3.select("*selection query*").attr("width","20%")&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Switching Classes

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;d3.select("*selection query*").classed("active","true")&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Inner Text

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;d3.select("*selection query*").text("Some Text")&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Inserting HTML

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;d3.select("*selection query*").html("&amp;lt;div class="block"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div&amp;gt;0 - 10&amp;lt;/div&amp;gt;")&lt;/code&gt;
&lt;iframe height="600" src="https://codepen.io/krngd2/embed/JjjwoOx?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Changing Properties

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;d3.selectAll('.checkbox').property('checked', false)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Appending Elements 

&lt;ul&gt;
&lt;li&gt; &lt;code&gt;d3.select("*selection query*").append("*tag*")&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/krngd2/embed/pooGJZQ?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Next article we will go through SVG fundamentals &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/saikiran" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xh0IbO5y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--yy9rmbsw--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/224909/a883a609-c3b5-498b-9744-c9e83e52a8e5.jpeg" alt="saikiran image"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/saikiran/d3js-fundamentals-part-2-5bek" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;D3js fundamentals Part 2 SVG&lt;/h2&gt;
      &lt;h3&gt;Sai Kiran ・ Nov 19 '19 ・ 3 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#d3js&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>d3js</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Number.isNaN is not isNaN.</title>
      <dc:creator>Sai Kiran</dc:creator>
      <pubDate>Thu, 03 Oct 2019 04:36:20 +0000</pubDate>
      <link>https://dev.to/saikiran/number-isnan-is-not-isnan-5hhp</link>
      <guid>https://dev.to/saikiran/number-isnan-is-not-isnan-5hhp</guid>
      <description>&lt;p&gt;Came across some interesting Tip for JavaScript developers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bWyrXC-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ep6cvsqhti0efdgw0hd7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bWyrXC-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ep6cvsqhti0efdgw0hd7.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;blockquote class="twitter-tweet"&gt;
&lt;br&gt;
&lt;p&gt;&lt;a href="https://twitter.com/hashtag/JavaScript?src=hash&amp;amp;ref_src=twsrc%5Etfw"&gt;#JavaScript&lt;/a&gt; tip for today:&lt;br&gt;&lt;br&gt;Number.isNaN is not isNaN.&lt;br&gt;&lt;br&gt;Wait, what?!&lt;br&gt;&lt;br&gt;Yes, the global &lt;code&gt;isNaN&lt;/code&gt; returns true for some unexpected values ({}, "hello", undefined), while &lt;code&gt;Number.isNaN&lt;/code&gt; will only return true for the actual &lt;code&gt;NaN&lt;/code&gt;. &lt;a href="https://t.co/b0CftzrIGB"&gt;pic.twitter.com/b0CftzrIGB&lt;/a&gt;&lt;/p&gt;— Tomek Sułkowski (&lt;a class="comment-mentioned-user" href="https://dev.to/sulco"&gt;@sulco&lt;/a&gt;
) &lt;a href="https://twitter.com/sulco/status/1179365654769668098?ref_src=twsrc%5Etfw"&gt;October 2, 2019&lt;/a&gt;&lt;br&gt;
&lt;/blockquote&gt;  

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>My Very First JavaScript Khan Academy Challenge</title>
      <dc:creator>Sai Kiran</dc:creator>
      <pubDate>Tue, 01 Oct 2019 10:51:00 +0000</pubDate>
      <link>https://dev.to/saikiran/my-very-first-javascript-khan-academy-challenge-1003</link>
      <guid>https://dev.to/saikiran/my-very-first-javascript-khan-academy-challenge-1003</guid>
      <description>&lt;p&gt;5 years ago when I was just getting into programming world, I started with khan academy JavaScript. One of the challenge i got was to design a character. &lt;br&gt;
I thought of making something unique and searched kids drawing on google and found this frog image and started working my way through. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BD5cHcsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/idhberbxwxjkdm14awsa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BD5cHcsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/idhberbxwxjkdm14awsa.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After Completing the frog, I wanted to make it a little interactive. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.khanacademy.org/computer-programming/spin-off-of-project-ad-design/5581176423317504"&gt;View the project here&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var draw = function() {
   background(1, 0, 5);
   textSize(17);
   fill(97, 143, 125);
   text("The only limit is your imagination", 30, 82);
   var positionF = pmouseX;
   var eyeY = pmouseY;
   var eyeSize = 100;
   var eyeBall1 = 70;
   var eyeBall2 = 50;
   var eyeBall3 = 35;
   var eyeBall4 = 15;
   stroke(7, 61, 2);
   strokeWeight(5);
   fill(45, 135, 27);
   ellipse(positionF,eyeY+80,278,200);// face
   ellipse(positionF-75,eyeY,eyeSize,eyeSize);// left eye
   ellipse(positionF+75,eyeY,eyeSize,eyeSize);// right eye
   strokeWeight(2);
   fill(247, 250, 250);
   ellipse(positionF-80,eyeY,eyeBall1,eyeBall1);//eyeball 1 white
   ellipse(positionF+80,eyeY,eyeBall1,eyeBall1);//eyeball 1 white
   noStroke();
   fill(16, 204, 54);
   ellipse(positionF-76,eyeY+5,eyeBall2,eyeBall2);//eyeball 2 light green
   ellipse(positionF+76,eyeY+5,eyeBall2,eyeBall2);//eyeball 2 light green
   fill(0, 0, 0);
   ellipse(positionF-80,eyeY+10,eyeBall3,eyeBall3);//eyeball 3 black
   ellipse(positionF+80,eyeY+10,eyeBall3,eyeBall3);//eyeball 3 black
   fill(252, 249, 249);
   ellipse(positionF-89,eyeY+3,eyeBall4,eyeBall4);//eyeball 4 white
   ellipse(positionF+89,eyeY+3,eyeBall4,eyeBall4);//eyeball 4 white
   //face dots
   stroke(208, 219, 123);
   strokeWeight(10);
   point(positionF+17,eyeY+44);
   strokeWeight(7);
   point(positionF+36,eyeY+64);
   strokeWeight(10);
   point(positionF+-36,eyeY+61);
   strokeWeight(9);
   point(positionF+-11,eyeY+59);
   strokeWeight(12);
   point(positionF+-1,eyeY+33);
   strokeWeight(8);
   point(positionF+-24,eyeY+83);
   //Smile
   noFill();
   stroke(0, 0, 0);
   strokeWeight(10);
   arc(positionF,eyeY+40,227,208,34,146);
   strokeWeight(7);
   arc(positionF+182,eyeY+40,206,190,137,154);
   arc(positionF-182,eyeY+40,206,190,29,43);
   fill(86, 230, 14);
   textSize(39);
   text("Kiran Animations inc.", 30, 53);


    eyeSize = eyeSize+1;
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://www.khanacademy.org/computer-programming/spin-off-of-project-crazy-painter/6363921338597376"&gt;Another work &lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
