<?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: Rômulo Rodrigues</title>
    <description>The latest articles on DEV Community by Rômulo Rodrigues (@romulorod).</description>
    <link>https://dev.to/romulorod</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%2F973136%2Fc52dbca9-86d0-442c-b7da-33d9fefd9501.jpeg</url>
      <title>DEV Community: Rômulo Rodrigues</title>
      <link>https://dev.to/romulorod</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/romulorod"/>
    <language>en</language>
    <item>
      <title>How to create custom node shapes in G6/Graphin</title>
      <dc:creator>Rômulo Rodrigues</dc:creator>
      <pubDate>Sat, 11 Feb 2023 10:59:24 +0000</pubDate>
      <link>https://dev.to/romulorod/how-to-create-custom-node-shapes-in-g6graphin-3ob</link>
      <guid>https://dev.to/romulorod/how-to-create-custom-node-shapes-in-g6graphin-3ob</guid>
      <description>&lt;p&gt;So, &lt;a href="https://graphin.antv.vision/en-US/"&gt;Graphin&lt;/a&gt; is an awesome library, it is indeed a React toolkit for the &lt;a href="https://g6.antv.antgroup.com/en"&gt;G6 library&lt;/a&gt; which is and I quote: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;G6 is graph visualization engine with simplicity and convenience. Based on the ability of customize, it provides a set of elegant graph visualization solutions, and helps developers to build up applications for graph visualization, graph analysis, and graph editor.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While I was working with it on a new project, I had the necessity to render nodes with different shapes, in order to a user differentiate them at first sight and therefore improve the UX.&lt;/p&gt;

&lt;p&gt;Graphin docs are great but it took me some time to find this section of it to create a custom node shape and it was even harder to create some side effect interaction which I will get to in another article. Let's get to the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Graphin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Utils&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;GraphinData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@antv/graphin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

&lt;span class="nx"&gt;Graphin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;registerNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;custom-node&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// This is the shape name, you can choose yours.&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
      &lt;span class="na"&gt;stateStyles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;hover&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
        &lt;span class="na"&gt;selected&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cfg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;group&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cfg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;keyshape&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addShape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rect&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// This the node configuration and 'rect' stands for rectangle, and you can modify its shape to a square changing the width and height properties as I have done.&lt;/span&gt;
        &lt;span class="na"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;circle-floor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;black&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;draggable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;circle-floor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="nx"&gt;group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addShape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// This is the label configuration.&lt;/span&gt;
        &lt;span class="na"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;cfg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// This stands for the node ID&lt;/span&gt;
          &lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#ddd&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;draggable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;keyshape&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;single-node&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// This is to tell Graphin whether this is a single node or a combo.&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, we got our square node but how can you tell Graphin to use this node shape instead of the default (graphin-circle) one?&lt;/p&gt;

&lt;p&gt;Graphin nodes have the "type" attribute, which by default is graphin-circle.&lt;/p&gt;

&lt;p&gt;So there are 2 ways you can change the nodes type or default shape. If you want to render all the nodes using your custom shape, you can change the default node configuration and therefore you don't have to add the type property to every single node of yours which will save you some parsing time.&lt;/p&gt;

&lt;p&gt;Screenshot of how to do: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6VgO65xn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/il17g4jlkhk4y7ct3af8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6VgO65xn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/il17g4jlkhk4y7ct3af8.png" alt="Passing default node type to Graphin" width="502" height="72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But let's say you want to have both the graphin-circle and square-node shapes in your network graph, obviously the nodes will either be your custom shape or the graphin-circle default conditionally, then you'll have to loop through the nodes and add the type property.&lt;br&gt;
Such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;conditional&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphin-circle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;square-node&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And bum! You'll have some black squared nodes and some default circle nodes as you can see here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DSRE1szp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j596hiizgfjhdm30xbcz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DSRE1szp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j596hiizgfjhdm30xbcz.png" alt="Square nodes and circle nodes" width="417" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And as you can see in the previous drawing custom shapes code, there are a lot of attributes you can change and customize to your custom node-shapes!&lt;/p&gt;

&lt;p&gt;I hope you've enjoyed so far and now you can create cool shapes using Graphin!!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>graphs</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>How to get rid of your "wheeled bike" on software engineering</title>
      <dc:creator>Rômulo Rodrigues</dc:creator>
      <pubDate>Tue, 15 Nov 2022 18:30:34 +0000</pubDate>
      <link>https://dev.to/romulorod/how-to-get-rid-of-your-wheeled-bike-on-software-engineering-b2b</link>
      <guid>https://dev.to/romulorod/how-to-get-rid-of-your-wheeled-bike-on-software-engineering-b2b</guid>
      <description>&lt;p&gt;Today I went to the grocery store with my daughter and she was on her bike, which does have wheels, those side-wheels that helps kids while they are yet learning how to proper ride a bicycle. I was joking around with her saying that I'd take off the side-wheels so she would learn properly and for good and she went:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No dad, please don't! Or I'll keep falling forever&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But isn't this how we usually learn? We must make mistakes and learn from them, improve ourselves and keep repeating the cycle until we don't make the same mistakes again. That's how I learnt at least, and that's how I LIKE to learn.&lt;/p&gt;

&lt;p&gt;I have obviously watch video tutorials for this and that but that's my point. Keep coding tutorial content is like riding a wheeled bike. You can do that, but at the moment you get yourself into the market, get a big project or something, you're lost, and doomed.&lt;/p&gt;

&lt;p&gt;If you're a beginner which just started learning or someone who is already learning for a while, looking for your first opportunity, STOP WATCHING VIDEO TUTORIALS, NOW. This will NOT give you what you're looking for.&lt;/p&gt;

&lt;p&gt;One of the fastest way to learn new technology is a 2 steps guide:&lt;/p&gt;

&lt;h1&gt;
  
  
  1 - Read the docs
&lt;/h1&gt;

&lt;h1&gt;
  
  
  2 - Code
&lt;/h1&gt;

&lt;p&gt;Did you notice I didn't add a "watch a youtube tutorial for it?" Because that's not gonna get you to learn stuff, you will be just a code-parrot, at the most. Code parrot is someone that only knows how to reproduce/copy-and-paste code.&lt;/p&gt;

&lt;p&gt;To get a job you must know some answers and those answers are only given to you when you practice, when you try to code and debug why the heck it is not working, and keep digging the problem and the internet about it until you finally solve that issue, and my friend, that is the precise moment where you learn the most. &lt;/p&gt;

&lt;p&gt;And it doesn't really matter "what to code". &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Oh Rômulo, but I have no ideas, how can I start?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It doesn't really matter what you will code, don't expect you're build a world saving startup on your first projects, as a matter of fact, you should even delete that code after you're done with it. Just keep coding, useless stuff, that's how you practice. &lt;/p&gt;

&lt;p&gt;So this is my advice to you, stop copying and pasting tutorial's code from youtube, start creating your own code, from the scratch, and if you're out of ideas on what to create, why don't you help open-source projects, libraries? That might even get you that job you're looking for, or at least some real-world experience to leverage the next interview ;)&lt;/p&gt;

&lt;p&gt;There's this tag about open-source issues which is "good-first-contribution". That's usually issues easy to solve and help you get started with some real-world coding challenges, that's gonna get you to the next level quickly.&lt;/p&gt;

&lt;p&gt;It's time to put your wheeled bike aside and get yourself into the real world, shall we?&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>opensource</category>
      <category>career</category>
    </item>
  </channel>
</rss>
