<?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: Son Pham</title>
    <description>The latest articles on DEV Community by Son Pham (@sonph02).</description>
    <link>https://dev.to/sonph02</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%2F278548%2F5c021540-139a-4ae6-8dcc-202a90aefb8c.png</url>
      <title>DEV Community: Son Pham</title>
      <link>https://dev.to/sonph02</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sonph02"/>
    <language>en</language>
    <item>
      <title>Build a hierarchy force graph by D3v7 and React + Vite</title>
      <dc:creator>Son Pham</dc:creator>
      <pubDate>Wed, 13 Dec 2023 08:28:28 +0000</pubDate>
      <link>https://dev.to/sonph02/build-a-hierarchy-force-graph-by-d3v7-and-react-vite-19d1</link>
      <guid>https://dev.to/sonph02/build-a-hierarchy-force-graph-by-d3v7-and-react-vite-19d1</guid>
      <description>&lt;p&gt;In recent features, I was involved to building graph visualization which built used &lt;strong&gt;D3js(v7)&lt;/strong&gt;. In this post, i'll show you how to create simple hierarchy force graph using &lt;strong&gt;D3&lt;/strong&gt; for visualizing connections in your data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating The App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We'll start by creating a new React app using &lt;strong&gt;Vite&lt;/strong&gt; and &lt;strong&gt;TypeScript&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn create vite d3-hierarchy-force-graph --template react-ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This command will generate a new &lt;strong&gt;Vite&lt;/strong&gt; and &lt;strong&gt;React Typescript&lt;/strong&gt; project. After the project was created, get into the app folder and add &lt;strong&gt;D3&lt;/strong&gt; to it by using the following command:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add d3 @types/d3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now that all the libraries we need are in the project, it’s time to move forward&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Building Graph&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is the code for the &lt;strong&gt;Graph&lt;/strong&gt; component container:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;We will add the &lt;strong&gt;D3&lt;/strong&gt; to generate the graph&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;When the graph is ready we will add nodes and links to simulation then add a few event handlers to handle what is going to happen when tick is happening&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now that everything is set in place you can run the app and look at your fancy force graph.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3l0qI0S_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ut3ovehg9wskev2azoii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3l0qI0S_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ut3ovehg9wskev2azoii.png" alt="Hierarchy force graph" width="563" height="529"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
In the post I showed how to create a hierarchy force graph using &lt;strong&gt;React + Vite&lt;/strong&gt; and &lt;strong&gt;D3&lt;/strong&gt;. You can find the graph code &lt;a href="https://github.com/son021293/d3-hierarchy-force-graph"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>d3</category>
      <category>typescript</category>
      <category>react</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
