<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[urbanData Analytics - Medium]]></title>
        <description><![CDATA[We develop software, data, and services for Real Estate industry, trying to provide a bit of light and transparency to a traditionally opaque sector. - Medium]]></description>
        <link>https://medium.com/urbandataanalytics?source=rss----14aeb4aab971---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>urbanData Analytics - Medium</title>
            <link>https://medium.com/urbandataanalytics?source=rss----14aeb4aab971---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:22:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/urbandataanalytics" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fade swipe onwards and reverse animation with ReactJs and Styled-Components]]></title>
            <link>https://medium.com/urbandataanalytics/fade-swipe-onwards-and-reverse-animation-with-reactjs-and-styled-components-6229d3958d53?source=rss----14aeb4aab971---4</link>
            <guid isPermaLink="false">https://medium.com/p/6229d3958d53</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Nadine Thery]]></dc:creator>
            <pubDate>Fri, 23 Jul 2021 06:37:45 GMT</pubDate>
            <atom:updated>2021-07-23T06:37:45.252Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*oDQ_uv_cI-B0-PAx7T8E1w.gif" /><figcaption>Add a nice swipe animation to a buttonless form</figcaption></figure><p>How to add a swipe forward and reverse animation with different directions depending on user interaction with React Js.</p><p>Remember <a href="https://medium.com/urbandataanalytics/build-a-multi-step-form-with-no-buttons-in-reactjs-eba1494cdbc9">this fancy buttonless form</a> we did some time ago? Let’s add some more functionality to it by:</p><ul><li><strong>Adding the possibility of going back to the previous step</strong></li><li><strong>Adding a swipe animation with a different direction depending on the step</strong> we are going to: is the previous step or the following step?</li></ul><p>For this article, we are going to work on the base of the buttonless form mentioned above, but this can be actually applied to any next/previous-based interface you have.</p><p>If you came solely for the animation then go directly to the end of the article.</p><p>We will be using the styled-components library, but you can achieve the same with the same old CSS style sheet.</p><p>You can find the full code for <a href="https://github.com/NanyThery/multistep-form-no-buttons">this in the Github Repo</a>. For the basic version, check master . For this upgraded version we will be building check the feature/back-animation branch.</p><h3>Add a way to go back</h3><p>In our form, we hadn’t yet considered the possibility to go back for the user. The easiest way to do this would be by adding a ‘previous’ button. But since we don’t want to have an actual button, let’s create a discrete indicator that allows the user to go back like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*C7SG4J-BM-hsksAqyVm7lg.png" /></figure><p>Please find below the full code for the form container and the step indicator component. But let me briefly explain the steps I’ve been through to get there:</p><ol><li><strong>Store the previous step: </strong>we need to modify the state where we store the “step” in order to control not only the current step as we already were but also the previous one in order to be able to go back. We will also need to substitute all the places in our useEffect() where we are using this. That means:</li></ol><pre>\\From this</pre><pre>const [step, setStep] = useState(0);</pre><pre>\\ To this</pre><pre>const [step, setStep] = useState({ current: 0, previous: null });</pre><p><strong>2. Create the step indicator component</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97fd0b77a762f984081f28fe1f223f37/href">https://medium.com/media/97fd0b77a762f984081f28fe1f223f37/href</a></iframe><p>This component receives the currentStep in order to apply a certain class and make it look “active” — gray in this case. When a circle is clicked, it bubbles up to the parent the number of the step that has been clicked through the handleOnClick function.</p><p>This handleOnClick will trigger the parent’s function passed as a parameter as onClickStep.</p><p><strong>3. Bind the data with the form: </strong>we didn’t have this need when we first created our form. Since we never went back, we didn’t need to see the info that the user had already written but we do now. Unless we bind the state where we are storing the data with the value of the inputs, even though we have the data, the inputs will always be shown blank when we go back in a step.</p><h3>Add the swipe animation</h3><p>First things first, create a component with your animation (check the StyledAnimation component at the end of this article).</p><p><strong>What is this doing?</strong></p><p>This is mostly a wrapper for our steps components. Whenever we load this component all the content within passed as children will be shown after the animation has finished.</p><p>This also receives the direction this animation must come from. The component uses the show property to know if the component (step) must be rendered or not. This mostly substitutes our rendering condition in the parent.</p><p>Note: this component can be refactored in order to avoid duplicated code, but I will keep it like this for the sake of the explanation.</p><p><strong>The parent, in the meantime…</strong></p><p>Check out the complete code below. But this is roughly what we are doing:</p><ol><li>Add a <strong>function to check if we are going back or forward </strong>in order to indicate the directionto the animation: this was the whole point of registering the previous step.</li><li><strong>Change the conditional render of the steps. </strong>Instead of having now the steps being controlled by a conditional rendering structure, we are now wrapping our steps with our Fade animation. And the prop show is the rendering condition.</li><li><strong>Restructure the layout by adding a new wrapper</strong>, that allows us to position all the children&#39;s divs absolutely in the desired position. Otherwise, they will wrap during the animation while one fades out and the other one fades in.</li><li>Add a new condition when step 3 is in place since our logic has now changed.</li></ol><p>Again, this is a very specific example of how to implement a swipe animation and the steps indicators. Feel free to adapt it or if you have doubt about how to implement this within your project, write a comment below or contact me :D</p><p>I’ll leave you to the full code.</p><p>Peace and Code</p><p>Nadine.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/874c68cb5b0e58222713eed82eefea3c/href">https://medium.com/media/874c68cb5b0e58222713eed82eefea3c/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6229d3958d53" width="1" height="1" alt=""><hr><p><a href="https://medium.com/urbandataanalytics/fade-swipe-onwards-and-reverse-animation-with-reactjs-and-styled-components-6229d3958d53">Fade swipe onwards and reverse animation with ReactJs and Styled-Components</a> was originally published in <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create a reactive label within an input in ReactJS with Styled-Components]]></title>
            <link>https://medium.com/urbandataanalytics/how-to-create-a-reactive-label-within-an-input-in-reactjs-with-styled-components-ece6dcb0e491?source=rss----14aeb4aab971---4</link>
            <guid isPermaLink="false">https://medium.com/p/ece6dcb0e491</guid>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Nadine Thery]]></dc:creator>
            <pubDate>Thu, 15 Jul 2021 08:13:49 GMT</pubDate>
            <atom:updated>2021-07-15T08:13:49.159Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*5iigP4wojT6Vea7F_kakrg.png" /></figure><p>Let’s check how to create a label within an input that changes according to the content and vice-versa.</p><p>For this article, I will be taking the basic CSS component we made in the previous post of this series: <a href="https://medium.com/urbandataanalytics/how-to-create-an-input-with-an-inner-label-in-reactjs-and-styled-components-476edb4e4b0f">How to create an input with an inner label in ReactJs and Styled-Components</a></p><p>While in the previous post you could easily go with a simple CSS sheet, for this case, I really recommend you using styled-components to apply CSS-in-JS.</p><p>In the previous article, we spotted some limitations of our component especially when it came to dynamic content in the prefix label and the suffix.</p><p>On one side, we need to handle a maximum width for our label, while we also need the component to adjust its inner padding according to this dynamic width. Let’s go.</p><p>The result</p><p>To sum up, this is the final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*rac_EX0DRpQTvtzEHvcaVQ.gif" /></figure><p>And the final code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b161bb2d448b81e41e1addec7988584c/href">https://medium.com/media/b161bb2d448b81e41e1addec7988584c/href</a></iframe><p>Achtung!:</p><ul><li>I am using Storybook, so that’s why I also included the propTypes. If you want to learn about how to use Storybook with PropTypes to make awesome quick stories and documentation, c<a href="https://medium.com/urbandataanalytics/how-to-make-interactive-components-in-storybook-reactjs-with-controls-module-the-fast-way-5eed966c80a">heck out this article.</a></li></ul><h4>What was that?</h4><p>Ok a lot of things were going on there. Take your time to take a look at the code.</p><p>Starting from our plain input with fixed labels. This is what we’ve done to make our input dynamically adjust to the label size:</p><ol><li>Add conditional rendering to both the prefix and the suffix, so they will only render when any of these props are defined. Else, they won’t render.</li><li>Bind the value of the input too.</li><li>We declare a ref into the prefix and the suffix that directly passes the node to the function getPrefixWidth / getSuffixWidth and retrieves the width of the rendered prefix/suffix and stores the data within a state through the useState React hook.</li><li>We pass the variables suffixWidth and prefixWidth to the input so we can use them as params in our styled-components (lines 70–79).</li><li>We bind the input padding props to the width of the suffix and prefix, obtained through the refs. This way we make sure that the content does not overwrite the other text (lines 36–38). In order to add some extra pixels to separate, we use a calc function.</li></ol><p>From here on, you can iterate this as much as you need. Limiting the prefix width, or managing text over-flow… make it your own.</p><p>Peace and code</p><p>Nadine</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ece6dcb0e491" width="1" height="1" alt=""><hr><p><a href="https://medium.com/urbandataanalytics/how-to-create-a-reactive-label-within-an-input-in-reactjs-with-styled-components-ece6dcb0e491">How to create a reactive label within an input in ReactJS with Styled-Components</a> was originally published in <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create an input with an inner label in ReactJs and Styled-Components]]></title>
            <link>https://medium.com/urbandataanalytics/how-to-create-an-input-with-an-inner-label-in-reactjs-and-styled-components-476edb4e4b0f?source=rss----14aeb4aab971---4</link>
            <guid isPermaLink="false">https://medium.com/p/476edb4e4b0f</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Nadine Thery]]></dc:creator>
            <pubDate>Mon, 05 Jul 2021 08:42:14 GMT</pubDate>
            <atom:updated>2021-07-05T08:42:14.035Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*GcJn7iaHCqx59hfZ3XezbA.png" /></figure><p>Input HTML tags can be customized to the infinite. However, they do not admit other tags inside in order to nest other elements within. Let’s take a look at one way to achieve this through css trompe l’oil…</p><h4>An artsy intro</h4><p>Have you ever heard about the <em>trompe l’oeil</em> painting technique?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*K42j-nOo0t-4QadD.jpg" /><figcaption>John Pugh, CC BY-SA 4.0 &lt;<a href="https://creativecommons.org/licenses/by-sa/4.0">https://creativecommons.org/licenses/by-sa/4.0</a>&gt;, via Wikimedia Commons</figcaption></figure><blockquote><strong>Trompe l’oeil: a </strong><a href="https://dictionary.cambridge.org/dictionary/english/painting"><strong>painting</strong></a><strong> that is </strong><a href="https://dictionary.cambridge.org/dictionary/english/clever"><strong>cleverly</strong></a><strong> </strong><a href="https://dictionary.cambridge.org/dictionary/english/design"><strong>designed</strong></a><strong> to </strong><a href="https://dictionary.cambridge.org/dictionary/english/trick"><strong>trick</strong></a><strong> </strong><a href="https://dictionary.cambridge.org/dictionary/english/people"><strong>people</strong></a><strong> into </strong><a href="https://dictionary.cambridge.org/dictionary/english/thinking"><strong>thinking</strong></a><strong> that the </strong><a href="https://dictionary.cambridge.org/dictionary/english/object"><strong>objects</strong></a><strong> </strong><a href="https://dictionary.cambridge.org/dictionary/english/represent"><strong>represented</strong></a><strong> in it are really there. (according to the Cambridge dictionary).</strong></blockquote><p>At frontend development, we face design challenges that requires us to make this trompe l’oeils with the HTMLs elements we already have on a daily basis. HTML tags are limited but highly customized elements. And design ideas and UX needs are just endless.</p><p>All this intro to tell you that in order to achieve our goal we are going to trick the eye and recreate an input field with HTML elements and CSS but not only using an input tag.</p><p>For this article, I will be using React Js and styled-components library which will allow me to use CSS-in-JS syntax and a very flexible way to write atomic components.</p><h4>Long story-short</h4><ol><li>We create a group with all the elements we want to be within the input.</li><li>Remove default styles and style all the group like an input.</li></ol><h4>Create a group with all the elements we want</h4><p>This is the easy one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*FmmrNPcUWBRaUHOUOGtaxQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/273abfec59347b0f048613cf9e338ac1/href">https://medium.com/media/273abfec59347b0f048613cf9e338ac1/href</a></iframe><h4>Remove default styles and style all group like an input</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*KVJprX4Y2dHEVg5I_cFAVQ.gif" /><figcaption>Tadah! an input with prefix and suffix</figcaption></figure><p>Below you will find the full code and the breakdown of it to understand what’s going on in the formatting here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*sb0jTDXCkKxpoQmpQunKyQ.gif" /><figcaption>Can’t I just copy and paste it? Yeah, sure, but chances are you are going to need to adapt this, so… you’d better understand what’s going on down here.</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d474c75a10eced47dbdaea544c1ac0cb/href">https://medium.com/media/d474c75a10eced47dbdaea544c1ac0cb/href</a></iframe><ol><li>Let’s create styled-components for all the elements. The div , the input and the p tags. This will allow us to apply the CSS directly. At this point, you can actually do this with a plain old CSS style sheet if you wish.</li><li>We make the container relative in order to be able to position our tags absolute but only in relation to the container. Otherwise, it would be positioned in relation to the document.</li><li>We remove all the default styles of the input, by putting it transparent and removing the border. Some adjustments in the line height to make it a bit taller.</li><li>I apply two different class names to our p . Some characteristics are common such as the top position. Then I apply different side positions (left or right value 0) depending on the orientation of the label. Just position them where you want them to be.</li><li>Now that the tags are where they are supposed to, we need to apply style to the input: 100% width in order to fit the container. But also enough padding to prevent the input text to override the prefix and the suffix.</li></ol><p>And that’s it when it comes to just formatting our trompe l’oeil.</p><h4>Let’s talk about limitations</h4><ol><li>You need to limit the characters of the input to avoid overflow.</li><li>This works just fine as long as the prefix or the suffix is not dynamic (and has different widths).</li></ol><h4>What if I want to make a reactive label?</h4><p>A very cool use case of a prefix label is to have a reactive label that shows some results depending on the value in the input.</p><p>The suffix is usually used for units or more immutable text.</p><p>What does that imply in our component?</p><ul><li>We need to prepare our prefix to handle overflow</li><li>We need to make the input’s padding reactive to the size of the label</li><li>Maybe the alignment of the input should be different depending on the prefix use or not.</li><li>And of course, we need to make it reactive to the content.</li></ul><p>Worry not, we will tackle into all this in the next article about How to make a reactive text inside and input with ReactJs.</p><p>Peace and code</p><p>Nadine</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=476edb4e4b0f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/urbandataanalytics/how-to-create-an-input-with-an-inner-label-in-reactjs-and-styled-components-476edb4e4b0f">How to create an input with an inner label in ReactJs and Styled-Components</a> was originally published in <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make interactive components in Storybook (ReactJS) with ‘controls’ module the fast way]]></title>
            <link>https://medium.com/urbandataanalytics/how-to-make-interactive-components-in-storybook-reactjs-with-controls-module-the-fast-way-5eed966c80a?source=rss----14aeb4aab971---4</link>
            <guid isPermaLink="false">https://medium.com/p/5eed966c80a</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[storybook]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nadine Thery]]></dc:creator>
            <pubDate>Fri, 04 Jun 2021 08:00:02 GMT</pubDate>
            <atom:updated>2021-06-04T08:26:26.536Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*qVR4UiQgatLSpr0OcR-5PQ.gif" /><figcaption>Complete and interactive control variables for your components</figcaption></figure><p>Step by step guide on how to install and make the most of the controls add-on including customization and powered documentation.</p><p>For this article,<strong> I will assume that you already have set up your Storybook and want to add some interactivity to them. </strong>But if you would like to read about a more basic step-by-step guide on Storybook, please feel free to leave a comment about it 💬.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*DwsTfLL6YPyH3-4qt8zexA.gif" /><figcaption>You can have a highly customized interaction in your stories with Controls Add-on</figcaption></figure><h3>Long-story-short</h3><ol><li>You can <strong>quickly add interactive controls</strong> to your Storybook<strong> by just adding the </strong><strong>controls</strong> add-on to it. Everything will happen automatically.</li><li>You can make it even cooler by <strong>defining custom controls </strong>for each of them, description or categories for your tables <strong>through the </strong><strong>argTypes</strong> object in the export default of your story.</li><li><strong>Use </strong><strong>propTypes and </strong><strong>defaultProps</strong> in your components to get part of the above even faster.</li><li>Enjoy <strong>cool, interactive, and complete documentation automatically generated </strong>by Storybook based on the above.</li></ol><p>Now, let go dive deep into these…</p><h3>What about Knobs?</h3><p>Adding some interactivity to our components is not something new in Storybook. Storybook offered this functionality before with the “knobs” add-on.</p><p><a href="https://storybook.js.org/addons/@storybook/addon-knobs">Knobs</a> were (and are for some use cases) the best way of adding interactivity to our component’s stories in Storybook. It allowed live customization like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bp6gl8-ti1z_ghNSjX6dNQ.png" /><figcaption>The knobs tab held all the options previously defined in the story.</figcaption></figure><p>Whenever we wanted to add one of these dynamic options to our code, we had to write something like this in our code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf433f352dbbde75df8229d35d74a640/href">https://medium.com/media/cf433f352dbbde75df8229d35d74a640/href</a></iframe><p>You first had to import the knobs you needed. Then you must specify which knobs are applied to each variable and what values it should take.</p><p>Although this functionality was ok, it takes some extra work. The ‘controls’ add-on allows us to do this faster, and super faster if you combine it with React.PropTypes.</p><h3>Adding ‘controls’ to the storybook</h3><p>This add-on is now part of the Storybook Essentials, so maybe you already have it. Check your package.json to see if it has been already installed.</p><p>In case it doesn’t, just download the npm/yarn package as a devDependency:</p><pre>npm i -D @storybook/addon-controls</pre><pre>yarn add @storybook/addon-controls --dev</pre><p>After installing, you need to manually export the add-on in the .storybook/main.js file.</p><pre>module.exports = {<br>  addons: [&#39;@storybook/addon-controls&#39;],<br>};</pre><h3>Using controls</h3><p>So, once you have installed the add-on you really do not need to do anything else to have an interactive component. Controlswill automatically detect your variables and make controls out of them.</p><p>Our component will receive some arguments, which is what controls detects and creates controls for.</p><p>For a story like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a68e55edc7bcbf9dad3380d62cf1cd6e/href">https://medium.com/media/a68e55edc7bcbf9dad3380d62cf1cd6e/href</a></iframe><p>Storybook will automatically generate this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*j7yAe9X__ga51TaX9FVKNQ.png" /></figure><p>Did you notice how I used the args property in the export default ? This is also another cool functionality that Storybook gives us.</p><p>argsare mostly a default template of initial values for the controls we are going to use. They are passed on to the component as an argument, and you do not need to write anything extra (check the example above).</p><p>I will write a more detailed post about how to use args in a customized way in the near future. But for now, let’s take a look at how to make the stories even cooler.</p><h3>Customizing controls</h3><p>Besides the automatic creation of the interactive controls, you also have the power to customize them. For instance, let’s say you have size variable to play with. Controls will automatically create a string field for this. But wouldn’t it be nice to have a radio button that let the user choose between the options?</p><p>That&#39;s where the argTypes property comes into the scene. This property allows you to:</p><ul><li><strong>Choose a custom type of control different from the default </strong>(like a radio button instead of a text field)</li><li>Classify the controls <strong>in categories</strong> to make them look tidier.</li><li><strong>Disable controls for properties</strong> you do not want the users to play with.</li><li><strong>Add a description</strong> (this comes really handy regards the documentation).</li><li>Add <strong>custom controls that are not really a part of your component</strong> but helps to test and using it. Think of an icon or a list selector that interacts with your component in a way.</li></ul><p>Let’s look at a clear example of the custom format for our controls. Check out how our controls are now categorized, and how the size property is now shown with radio-buttons instead of a text field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*-r9hYPFTg3QMmar4W5IYBw.gif" /></figure><p>The code below is how it is achieved. Through the argTypes property. You just need to define the property name. If it coincides with an actual property of your component the add-on will map it.</p><p>Pay special attention to the size property and see how I defined that I wanted a radio button with options.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecf75bcee1d4ec447a08e5e0d090bcbc/href">https://medium.com/media/ecf75bcee1d4ec447a08e5e0d090bcbc/href</a></iframe><p>This part of the customization is a bit more laborious, but it’s still easier and more complete than what knobs offered.</p><h3>An even faster way</h3><p>If you include <a href="https://reactjs.org/docs/typechecking-with-proptypes.html"><strong>propTypes</strong></a><strong> in the component file</strong>, you will be not also adding some type-based control to your component, but also telling controls the exact types it should display for each case (not applicable for colour-picking though!).</p><p>For instance, when adding the propTypes for our size prop, the add-on automatically shows it as a radio-button with the defined options. For instance:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fca11e2a88f91e3b43949e63b3fff1dc/href">https://medium.com/media/fca11e2a88f91e3b43949e63b3fff1dc/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*DwsTfLL6YPyH3-4qt8zexA.gif" /><figcaption>Magic</figcaption></figure><p>You would only need to specify a control in the argTypes prop of your story when:</p><ul><li>You want to disable a control</li><li>You want a different control that the specified.</li></ul><p>Same for the default values! If your component has the defaultProps defined, ‘controls’ will automatically detect them and drop this info into the documentation.</p><h3>Powered documentation</h3><p>I know that setting up a fancy story as I mentioned is a bit laborious. But there is a really cool side-effect to it: <strong>documentation.</strong></p><p>Remember that description prop we’ve added to argTypes ? Take a look at the <strong>documentation tab </strong>of our component after defining the argTypes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*X8rswQ7x0EmkBVbonplCig.gif" /><figcaption>Complete documentation made with Storybook `controls`</figcaption></figure><p>How cool is that?! A complete but also interactive documentation. All this info in the documentation tab has been directly taken from the argTypes property. So even though we have to take some time to define the object, we have a double benefit.</p><p>See that ‘Default’ column? That comes directly from the defaultProps defined in our component.</p><p>Wow! that was long, yet complete I hope! Go ahead and boost your storybooks with this awesome functionality.</p><p>Peace and Code,</p><p>Nadine.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5eed966c80a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/urbandataanalytics/how-to-make-interactive-components-in-storybook-reactjs-with-controls-module-the-fast-way-5eed966c80a">How to make interactive components in Storybook (ReactJS) with ‘controls’ module the fast way</a> was originally published in <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Changing args values / state in Storybook (without useState hook)]]></title>
            <link>https://medium.com/urbandataanalytics/changing-args-values-state-in-storybook-without-usestate-hook-15cc096716f7?source=rss----14aeb4aab971---4</link>
            <guid isPermaLink="false">https://medium.com/p/15cc096716f7</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[storybook]]></category>
            <dc:creator><![CDATA[Nadine Thery]]></dc:creator>
            <pubDate>Fri, 30 Apr 2021 08:30:25 GMT</pubDate>
            <atom:updated>2021-06-04T08:03:31.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*Gv_vjrzA2QML2ASV730b5g.png" /><figcaption>Learn how to manage states natively in Storybook</figcaption></figure><h3>Changing args values / state in Storybook (without useState hook) + ReactJS</h3><p>A quick glance at how to change your stories args values within Storybook and ReactJs. To be combined with Storybook Controls.</p><p>If you find yourself wondering how to add functionality to your Storybook components that implies modifying your props values check out below.</p><p>For this article, I will assume that you already know <a href="https://storybook.js.org/">what StoryBook is</a> and that your are using <a href="https://storybook.js.org/docs/react/essentials/controls">StoryBook Controls add-on.</a></p><h3>An example based on a true story</h3><p>We have a story in which changing <strong>a certain prop in the playground’s controls should change a prop from your component</strong>.</p><p>We have this nice modal component that is opened whenever its isOpen property is true .</p><p>What are <strong>my options here to show or hide this Modal in my Story</strong>? Let’s see…</p><h4><strong>Have a ‘control’ for the property that allows me to change to true-false.</strong></h4><p>Before we move on, if you are wondering how to use ‘controls’ add-on in the first place, <a href="https://medium.com/urbandataanalytics/how-to-make-interactive-components-in-storybook-reactjs-with-controls-module-the-fast-way-5eed966c80a">check out this other article I have on this.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*7gZ7c9lJnfF_1l_eumoe5Q.gif" /><figcaption>Having a control property that simple changes the prop value</figcaption></figure><p><strong>Problem solved.</strong> It mostly does what we need to. You could leave it like that if you don’t want to show any other behaviour (like closing with a button) and if you are ok with that blick white background shown when it is closed.</p><p>And you are also ok with the fact that your ‘Close button” has no functionality because it cannot change the value of isOpen when clicked on the Story.</p><p>Cons of this approach:</p><ul><li>You need to set the isOpen prop as true in order to show something when the user opens the story</li><li>If you do so, the modal will also be open in your documentation tab and guess what? your Modal close button does not do anything and won’t be able to dismiss it from the documentation tab.</li><li>It doesn’t feel pretty intuitive for the user right?</li></ul><h4><strong>Ignore the </strong><strong>args properties and use </strong><strong>useState hook instead.</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df557b2de1fc5f0c50a8620b151af054/href">https://medium.com/media/df557b2de1fc5f0c50a8620b151af054/href</a></iframe><p>With this approach, you can mostly handle UI elements to change the props passed down to your component in your story. However, using this basically <strong>undermines the functionality of </strong><strong>args , and causes ‘controls’ add-on to be out of sync with your props and your component.</strong></p><p>For this approach to work properly you should disable the controls related to the props you are changing with the useState hook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*8iw0EhPRXRs5YmuWk32TdA.gif" /><figcaption>See that the isOpen is not synced with the component prop now?</figcaption></figure><h4>The native useArgs hook</h4><p>This is so far the best approach I found🕵️‍♀️ to solve this. It requires using the <a href="https://www.npmjs.com/package/@storybook/client-api">@storybook/client-api library</a> in order to be able to apply the useArgs hook.</p><p>This hook provided by the Storybook library directly modifies the props passed down to your story component. This way you can <strong>add functionality to UI elements in your story and also keep controls synced with your props.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c13dca477573fef4e0eb03f3052b56a/href">https://medium.com/media/7c13dca477573fef4e0eb03f3052b56a/href</a></iframe><p>In this story, I have also added a button to handle the open without the need to use the control, while they keep perfectly synced.</p><p><strong>It is as easy as importing the </strong><strong>useArgs hook, and applying it to the properties you want to change (check line 23 and 28 for example)</strong></p><p>Using this is pretty simple and straight-forward, but please feel free to leave a comment 💬 if you would like to clarify or suggest anything :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*Ne1JwVcOMICIZrNsDHlGNw.gif" /></figure><p>I hope this helps you in <strong>making awesome and interactive stories.</strong></p><p>Peace &amp; Code</p><p>Nadine</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15cc096716f7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/urbandataanalytics/changing-args-values-state-in-storybook-without-usestate-hook-15cc096716f7">Changing args values / state in Storybook (without useState hook)</a> was originally published in <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick-tip: filtering an object for a value contained in an array within]]></title>
            <link>https://medium.com/urbandataanalytics/quick-tip-filtering-an-object-for-a-value-contained-in-an-array-within-c3ad09959edb?source=rss----14aeb4aab971---4</link>
            <guid isPermaLink="false">https://medium.com/p/c3ad09959edb</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[objects]]></category>
            <dc:creator><![CDATA[Nadine Thery]]></dc:creator>
            <pubDate>Fri, 26 Mar 2021 11:02:25 GMT</pubDate>
            <atom:updated>2021-03-26T11:32:16.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2qtZexPTPtNhLsE8YJGRg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@didsss?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Didssph</a> on <a href="https://unsplash.com/s/photos/russian-doll?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>JavaScript quick-tip: filtering an object for a value contained in an array within</h3><p>It sounds weird, but sometimes you need to filter an object according to some value contained in an array within its props. Check out one easy-peasy way to solve this.</p><p>Let’s say you own a “Magazines and Newspapers” website that sells subscriptions. And you are designing a level-up subscription page in which you will show <strong>all the non-free plans your company</strong> offers.</p><p>It should be as easy as calling your endpoint with the subscriptions info and paint it out with a map() function and some .jsx . But… what if the response returns more<strong> info that you actually do not want?</strong></p><p>It’s time to do some cleaning. Filtering is often pretty straight-forward with <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter">the </a><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter">filter() functions of JavaScript ES6</a>. But this only works with arrays.</p><p>In our case, our API <strong>is returning an object </strong>with the different products we offer. Every product owns an array of properties describing the different pass or subscription options available. Like this:</p><pre>{<br>      cool_magazine: [<br>        {<br>          id: &#39;free-pass&#39;,<br>          label: &#39;Free Pass&#39;<br>        },<br>        {<br>          id: &#39;seasons-pass&#39;,<br>          label: &#39;Seasons Pass&#39;<br>        }<br>      ],<br>				<br>      boring_newspaper: [<br>        {<br>          id: &#39;free-pass&#39;,<br>          label: &#39;Free Pass&#39;<br>        },<br>        {<br>          id: &#39;seasons-pass&#39;,<br>          label: &#39;Seasons Pass&#39;<br>        }<br>      ]<br> };</pre><p>We need to get rid of those “free-pass” subscriptions within the arrays of each object’s props. Sounds like a lot of nesting, and it is! But let’s create a function that returns an already filtered object we can render on our website:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0162c8e4397bc7968a10c77cf3fee857/href">https://medium.com/media/0162c8e4397bc7968a10c77cf3fee857/href</a></iframe><p>Let’s break this down:</p><ol><li>Let’s create a brand new clean object that will hold the final results of the cleaning. For this, we replicate the original object structure by using Object.assign() . This will make an exact copy of productPass but all the values will be empty.</li><li>We need to iterate throughout all the props of our original object of products in order to perform some stuff. But since objects are not iterable, we need to make an iterator with Object.keys() . This function will virtually create an array with the keys of our object: [&#39;cool_magazine&#39;, &#39;boring_newspaper&#39;] allowing us to use the array methods that JS has.</li><li>Now that we have an array, we will iterate through each key with the forEach() method.</li><li>As our key corresponds to the product’s name both in newData and productPass we can use it to directly locate the array of props of each product with filter()</li><li>We can finally filter the array within each product and extract only those that do not contain the ‘free’ word in it. Plain old includes() function here.</li></ol><p>So, with this function up and running you just need to process your object, JSON, or API response before using it or storing it in your Redux store.</p><p>Big shout out and thanks to <a href="https://medium.com/u/2a452dacccfb">Miguel A Gutiérrez</a> that was the big brain behind this easy but tricky solution.</p><p>Peace &amp; Code</p><p>Nadine</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3ad09959edb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/urbandataanalytics/quick-tip-filtering-an-object-for-a-value-contained-in-an-array-within-c3ad09959edb">Quick-tip: filtering an object for a value contained in an array within</a> was originally published in <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a multi-step form with no buttons in ReactJS]]></title>
            <link>https://medium.com/urbandataanalytics/build-a-multi-step-form-with-no-buttons-in-reactjs-eba1494cdbc9?source=rss----14aeb4aab971---4</link>
            <guid isPermaLink="false">https://medium.com/p/eba1494cdbc9</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[useeffect]]></category>
            <dc:creator><![CDATA[Nadine Thery]]></dc:creator>
            <pubDate>Tue, 02 Mar 2021 14:21:32 GMT</pubDate>
            <atom:updated>2021-03-02T14:21:32.728Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0RvFncCEaG_zo6hwvnYDyQ.jpeg" /><figcaption>Featured Image by <a href="https://unsplash.com/@jamessutton_photography?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">James Sutton</a> on <a href="https://unsplash.com/s/photos/buttons?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Why would you want to get rid of your next and previous buttons in the first place? Well… because it’s fancy now.</p><p>To be honest, this won’t be completely <em>button-less, nor a form </em>🤔<em>.</em> This is actually a way you can implement a form of any type, whether with Formik, just a plain old form or just gather info and send it to Redux. You name it.</p><p>For the sake of simplicity, we will still have one submit button at the end in order to finish the process. But you can apply the same logic if you wish to get rid of that button too.</p><p>For this project, we will be using <strong>plain React </strong>with <a href="https://styled-components.com/"><strong>styled-components</strong></a> library to manage the styling.</p><p>I will assume that you have already created your main app structure. We will not dive into Forms in this article, <strong>but leave a comment if it’s something you would like to see in this blog </strong>👁️‍🗨️<strong>.</strong></p><p>You can follow along with the steps in this article in<a href="https://github.com/NanyThery/multistep-form-no-buttons"> this repository</a> (each step is a branch).</p><h3>The goal</h3><p>Our form will have three stages in which we will ask for a name and other nonsense questions with text inputs and radio button inputs. In the last stage, we will have a submit button that will activate only when the previous steps are completed.</p><p>Component-translated means that we will have:</p><ul><li>Form Container that will handle the rendering of other components.</li><li>Four components one for each stage.</li></ul><h3>Step 1: Create the structure</h3><p>First things first, create and export your container and components:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*V7snppqbAHuXtC1EoluAOw.png" /><figcaption>Separated container and components</figcaption></figure><p>A basic step component will look kind of like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a5244904eb63ae3d68f2eb239973739/href">https://medium.com/media/8a5244904eb63ae3d68f2eb239973739/href</a></iframe><p>Then, create the form container. From here we will call the steps and control the state in order to call one or another.</p><p>I will also add some styling…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b6bb577367cee0e100c87f39d0c5643/href">https://medium.com/media/4b6bb577367cee0e100c87f39d0c5643/href</a></iframe><p>Let’s break this down a bit:</p><ul><li>Components are just basic for now. Put a p inside and export them.</li><li>Our FormContainer will need to import the <strong><em>useState</em></strong> React Hook in order to manage the rendering of the components.</li><li>Import all the components for the steps.</li><li>Create a step<strong><em> state hook</em></strong> inside the FormContainer. We will use this hook to mutate the state and conditionally render the components.</li></ul><h3>Step 2: Send the info to the parent</h3><p>In this step, we will create a state in the parent that will receive all the information from the steps and store it while it gets ready to be sent.</p><p>We will also prepare <em>“step 0”</em> to send the user name info to the parent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*EJh_SceeUuy42B8Bmvfswg.gif" /></figure><ul><li>We insert a cute input field that has and id and a value associated with the same prop we want to update in our parent. By putting this id named after the prop, we will be able to reuse our handleChange method.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1916956061b6eb384928525b7344e79/href">https://medium.com/media/e1916956061b6eb384928525b7344e79/href</a></iframe><ul><li>Create a method in the parent that receives the event from the input (whatever the type it is), and extract the id and the value in order to update the state of that prop in our formData object.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d5ef8e0c68dce91f75b4ea2438e309e/href">https://medium.com/media/6d5ef8e0c68dce91f75b4ea2438e309e/href</a></iframe><h3>Step 3: Waiting for the user to finish writing</h3><p>Ok, here’s the problem: we have a text input that sends the event to the parent whenever a key is pressed down.</p><p>So, before we call a new component we need to be sure that the user has finished writing and Step 0 is complete.</p><p><strong>Whenever we need to watch for changes in React JS, we can use the </strong><strong>useEffect hook.</strong></p><p>This is what we will do:</p><ol><li>Create a new state called completedSteps</li><li>Set a UseEffect() function that will watch for changes on the formData object.</li><li>As soon as formDataupdates, it will evaluate if the step is complete or not. Step 0 only has one input, and we could do this directly. But we can have more than one input to check (we will do that in the next step).</li><li>A second UseEffect() will monitor the whole component and call the new component as soon as we detect that the step is completed.</li><li>As the user is typing we need to give enough time for the user to finish before showing the new component. We will achieve this by <strong>setting a 1000 ms timer ( </strong><strong>setTimeOut()) </strong>that will start with the first pressed key and reset whenever a key is pressed. As soon as no other key is pressed in a 1000 ms interval, the new component will render.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*1Epyq5rJYOJfHMZq5PKrtg.gif" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0d8064ebde0fa5cd6c649348f4d3d2e/href">https://medium.com/media/a0d8064ebde0fa5cd6c649348f4d3d2e/href</a></iframe><h3>Step 4: Enter inputs and step completion validation for the other steps</h3><p>From here on you can add as many inputs and steps as you wish. Ideally, you should also add a way to go back and change info, or maybe a swipe animation between steps…?</p><p>Define your submit process accordingly and you are all set.</p><p>Check out the full repository for the full example and play around with it. Also, take a look at step1.js to see how we manage two different inputs in the same step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*Zkjsy50sZDehCgZl7jNHvQ.gif" /></figure><p>For any questions, please feel free to leave a comment.</p><p>Peace &amp; Code</p><p>Nadine.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eba1494cdbc9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/urbandataanalytics/build-a-multi-step-form-with-no-buttons-in-reactjs-eba1494cdbc9">Build a multi-step form with no buttons in ReactJS</a> was originally published in <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Measuring urban footprint to understand city behavior]]></title>
            <link>https://medium.com/urbandataanalytics/measuring-urban-footprint-to-understand-city-behavior-42d45384442c?source=rss----14aeb4aab971---4</link>
            <guid isPermaLink="false">https://medium.com/p/42d45384442c</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[urban-planning]]></category>
            <category><![CDATA[gis]]></category>
            <dc:creator><![CDATA[Alejandro Cantera]]></dc:creator>
            <pubDate>Tue, 11 Jun 2019 11:17:39 GMT</pubDate>
            <atom:updated>2020-06-09T16:32:02.687Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D4D6oN0Ews_w7QBewob59w.png" /><figcaption>Urban Footprint Extension</figcaption></figure><p>The cities where we live are in constant development and evolution. Over the last few centuries, they have seen how their size and capacity has increased in an accelerated way, hosting every year a bigger amount of population. According to global data from the UN World Urbanization Prospects, 55% of the population lived in urban areas by 2018 (74% in Europe), a rate that is expected to grow to 68% by 2050.</p><p>In this urban horizon of constant growth, it seems logical the need to <strong>promote an efficient and responsible management of the expansion of our cities</strong>, with the aim of mitigating the social, economic and environmental impact that derives of this development.</p><p>Thanks to the increase in the amount of georeferenced data and Open sources, we can design new tools that allow us to improve the knowledge that we have about cities behavior. One of these urban analysis new applications, is the one that we have developed in <strong>uDA</strong>, for the quantification and the qualification of the Spanish Urban Footprint. <strong>uDA Tech</strong> will present a series of articles around this concept, studying its different characteristics such as size, density, typology, etc. The main goal of this first section is to define the concept and quantify its dimension in main metropolitan areas with a simple visualization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z2A0qbxsAi-XX3nqD1xNlg.gif" /><figcaption>Orthophoto / Urban Footprint comparison</figcaption></figure><h3>First steps: What is Urban Footprint and how to measure it</h3><p><strong>The urban footprint measures the expansion of a city in the territory. </strong>Cities are great sources of cultural and economic wealth as well as an optimal environment for people to develop their lives, but they also have a great impact on the environment due to the pollution that they cause, the consumption of natural and energy resources, as well as the construction of infrastructures (transport, communication, services) that they need for their correct operation.The analysis of the urban footprint allows us to <strong>quantify the degree of impact </strong>and soil consumption, as well as helping us to know the spatial distribution of people and services in a determined metropolitan area.</p><p>For a correct Urban Footprint evaluation, it is not only important to be able to quantify its dimension, but also how the density is distributed in its interior. It is possible to identify different types of cities according to their pressure on the territory, for example the models with a large urban footprint and low density are less efficient and they increase the territory impact compared to other cities where the urban density is bigger and the extension smaller.</p><p>For this reason, in the current context of constant urban growth,the study of the Urban Footprint helps us, assuming that cities are indeterminate and unpredictable organisms, to improve the urban knowledge to guide how to design future resilience strategies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vv-idzaSrJD7ZH15Bzy9Vw.png" /><figcaption>Spanish Urban Footprint Map</figcaption></figure><blockquote>Spanish territory covers a 87,013,900 hectares, of which 2,846,400 hectares are urban area, representing just 3% of the total.</blockquote><p>The tool that we have developed in uDA allows us to calculate the extension of the Urban Footprint at the present time from the Spanish Cadastre open data and to qualify its density from the data of the National Statistics Institute (INE) and National Register. It is constructed from the urban cadastral blocks of the whole country, quantifying the growth of cities in a synchronized way with the Cadastre.</p><p>The consideration or delimitation of<em> urban area</em> has been taken directly from the one determined in the Cadastre Law*, which includes not only land consolidated with building and services, but also incorporates all soils for urban development (future areas where cities will grow) and areas occupied by public areas and services.</p><p><em>* Real Decreto Legislativo 1/2004, Ley del Catastro Inmobiliario</em></p><p>The main goal will be to quantify the size of the expansion of Spain’s principal metropolitan areas. For that reason,we decided to do the analysis at Functional Urban Area (FUA) scale. The choice to select this scale compared to the municipality scale is due to the fact that municipality dimension scale is sometimes variable in the Spanish territory and in many cases there is no correlation between the importance of the urban area and its municipality extension (a clear example is Barcelona, with a very small municipal size for its great importance).On the other hand, the delimitation of the FUA covers not only the extension of the main city, but also its area of influence. According to the definition of the Urban Audit:</p><blockquote>The Functional Urban Area (FUA) consists of the city and its commuting zone. Once all cities have been defined, a commuting zone can be identified based on commuting patterns using the following steps:</blockquote><blockquote>1: If 15 % of employed persons living in one city work in another city, these cities are treated as connected cities. In this case, the first city is a part of the Functional Urban Area of the second city and does not have its own FUA. (…)</blockquote><blockquote>2: All municipalities with at least 15 % of their employed residents working in a city are identified.</blockquote><blockquote>3: Municipalities surrounded by a single functional area are included and non-contiguous municipalities are dropped.</blockquote><blockquote>In Spain, there are 80 FUAs, representing a total of 1262 municipalities.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tjgtpAGkyfbKPgD3ipJiCg.png" /><figcaption>Spanish Functional Urban Areas Map</figcaption></figure><h4>Let’s get down to business: a quick guide to urban footprint viz</h4><p>The goal in this section will be to construct a visualization, which in a quick and simple way, can understand the extent of the urban footprint and the proportion of soil consumed for each of the FUAs in Spain. We will call it Urban Footprint Extension Atlas. In order to build this Atlas, the urban footprint layer has first been generated by transformation, cleaning and topological correction geoprocesses of the Cadastre urban blocks .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qjz5X3od_MtzXL_tdddK4w.png" /><figcaption>Principal Spanish FUA’s Urban Footprint</figcaption></figure><p>Once we have a clean urban footprint geometry table, the Urban Footprint Extension Atlas can be constructed by following the steps below:</p><p><strong>Step 1: Aggregate urban footprint extension data to FUA scale.</strong></p><p>It consists in calculating the total area of the urban footprint, the extent of the FUA and the proportion it represents. In order to do this, it is necessary to know the set of municipalities that belong to each of the FUAs. This information is available in the <a href="https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/urban-audit">Urban Audit download section</a>.</p><p>The aggregated values table has the following fields:</p><ul><li><strong>name</strong>: Name of the FUA.</li><li><strong>footprint</strong>: Extension of the urban footprint in hectares.</li><li><strong>area_auf</strong>: area of the FUA in hectares.</li><li><strong>percentage</strong>: proportion of the urban footprint in relation to the total FUA.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*sHj451_o_jtCsW_Xtxy5gA.png" /><figcaption>Aggregated data table example</figcaption></figure><p><strong>Step 2: Defining the style of the base diagram (for an unique FUA)</strong></p><p>Once we have the clean data for each of the FUA (80 FUA/row), we will generate a diagram for one of it (i.e. FUA Madrid), to determine the style.</p><ul><li>We are going to draw two circles, each of them representing a area. On the one hand, the dark circle represents the complete FUA area, while the white represents the Urban Footprint area. To do this we will calculate the radius of each of the circles:</li></ul><pre>radio_auf = sqrt(auf_agg[&#39;area_auf&#39;][0] / pi)<br>radio_hu = sqrt(auf_agg[&#39;footprint&#39;][0] / pi)</pre><ul><li>Now let’s plot them. We need to create a canvas with the the diagram’s dimensions. We are going to represent both circles being tangent in the lower part, so that in this way both areas can be compared in a simple way.</li></ul><pre>fig, ax = plt.subplots()<br>fig.set_size_inches(4,8)</pre><pre>ax.add_patch(plt.Circle((0, radio_auf),radio_auf , color=&#39;black&#39;)) <br>ax.add_patch(plt.Circle((0, radio_hu), radio_hu , color=&#39;white&#39;))</pre><ul><li>At last we introduce labels to see the FUA data associated.</li></ul><pre>ax.annotate(auf_agg[&#39;name&#39;][0], (0, -0.5),ha=&#39;center&#39;, va=&#39;center&#39;, size=16,weight=&quot;bold&quot;,color=&#39;black&#39;)<br>ax.annotate(&#39;{} %&#39;.format(round(auf_agg[&#39;percentage&#39;][0]*100,2)), (0, -1),ha=&#39;center&#39;, va=&#39;center&#39;, size=12)<br>ax.annotate(&#39;HU: {} ha&#39;.format(int(round(auf_agg[&#39;footprint&#39;][0]*10**5))), (0, -1.4),ha=&#39;center&#39;, va=&#39;center&#39;, size=10)<br>ax.annotate(&#39;AUF: {} ha&#39;.format(int(round(auf_agg[&#39;area_auf&#39;][0]*10**5))), (0, -1.7),ha=&#39;center&#39;, va=&#39;center&#39;, size=10)<br>  <br>    <br>ax.set_aspect(&#39;equal&#39;, adjustable=&#39;datalim&#39;)<br>ax.set_axis_off()<br>fig.savefig(&#39;01_output/images/madrid_footprint.png&#39;, dpi=300) <br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kjdfJgzWRSbJKR66A4S0lA.jpeg" /><figcaption>Madrid FUA extension diagram</figcaption></figure><p><strong>Step 3: Generate a diagrams grid</strong></p><p>Once we have defined the diagram style , in a simple way we can visualize a range of a set of FUA (i.e. the first 8).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*McUuKuB7Uoa5uJHZNR6HeQ.jpeg" /><figcaption>Principal FUA extension diagrams</figcaption></figure><p>In addition, to add information to the diagram, you can introduce a new plotting variable such as color. In the following example, a range of colors characterize the percentage of urban footprint with respect to the total FUA area. You just have to define the cmap at the beginning and then introduce it into a loop:</p><pre><em>cmap = plt.cm.get_cmap(&#39;YlGnBu&#39;)</em></pre><pre><em>for index in range(8):</em></pre><pre><em>(…)</em></pre><pre><em>color_map = auf_agg[&#39;percentage&#39;][index]<br>    rgba = cmap(color_map*5)<br>    </em>ax.add_patch(plt.Circle((0,radio_auf),radio_auf, color=rgba))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ijggI7_kYpIMdZYstM4Daw.jpeg" /><figcaption>Principal FUA extension diagrams with colors</figcaption></figure><p><strong>Step 4: Creation of the complete Atlas.</strong></p><p>Once you have decided the style of the Atlas, the choice of colours and the size of the typography, you can launch the code for all the FUAs. There are 80 FUAs, so it is decided to order them in rows of 10. In the final result, furthermore, has been included a chart with the maps of the Spanish Urban Footprint to improve the complete understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0SAIKLmhJ9kw1THk5JV2fw.jpeg" /><figcaption>Urban Footprint Extension Atlas (<a href="http://www.urbandataanalytics.com/techblog/Urban_footprint_extension_atlas.pdf">HQ version available here</a>)</figcaption></figure><p>The <strong>Urban Footprint Extension Atlas </strong>that we have generated is a clear and simple representation of a complex and abstract concept such as the Urban Footprint. Now, we can easily compare the degree of urbanization of each Functional Urban Areas, and discover aspects more intuitively than looking at a simple table. For example:</p><ul><li>Madrid is the FUA with the largest footprint area, however it only represents 19% compared to 35% in Barcelona or 21% in Valencia.</li><li>There are FUA of similar size, but with a very different urban footprint, such as the FUA of Barcelona and Zaragoza.</li><li>There are FUA with a similar Urban Footprint but with a very different FUA dimension, such as Tarragona and Pamplona.</li></ul><p>In the following articles related to the Urban Footprint, we will seek to qualify each of the footprints according to their density, looking for patterns according to their location or population size, <strong>so keep in touch</strong>!</p><p>Research Team: Alejandro Cantera</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42d45384442c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/urbandataanalytics/measuring-urban-footprint-to-understand-city-behavior-42d45384442c">Measuring urban footprint to understand city behavior</a> was originally published in <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Superset as a bridge between devs and domain experts]]></title>
            <link>https://medium.com/urbandataanalytics/superset-as-a-bridge-between-devs-and-domain-experts-fb10719f116a?source=rss----14aeb4aab971---4</link>
            <guid isPermaLink="false">https://medium.com/p/fb10719f116a</guid>
            <category><![CDATA[superset]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[business-intelligence]]></category>
            <category><![CDATA[dataviz]]></category>
            <dc:creator><![CDATA[Juanlu]]></dc:creator>
            <pubDate>Thu, 25 Apr 2019 08:59:32 GMT</pubDate>
            <atom:updated>2019-04-25T08:59:32.763Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes it is difficult to create a product that is both built by developers and non-devs or non-technical people. Why would you want something like that? I’m going to explain a simple problem that happened to us here at <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a>.</p><p>Sometimes, to complete several processes, we needed to build and interpret different visualizations. Usually, two particular profiles come into play:</p><ul><li><strong>A developer:</strong> knows how to build a cool <a href="https://www.elastic.co/products/kibana">Kibana</a>, <a href="https://prometheus.io/docs/introduction/overview/">Prometheus</a> or hand-crafted dashboard (using Python’s <a href="https://ggplot2.tidyverse.org/">ggplot</a>, for example). We’ll refer to them from now on as <strong>Dev</strong>.</li><li><strong>A business expert:</strong> knows how to interpret and act based on the dashboard’s visualizations, they are domain experts. We’ll refer to them from now on as <strong>Biz</strong>.</li></ul><p>Now, let’s say <strong>Biz </strong>has realized a plot is incorrect because the data is not using the correct columns and the color combination is awful. What would <strong>Dev’s </strong>work cycle?</p><ol><li>Discuss the issue with <strong>Biz</strong> (hopefully a brief conversation in Slack is enough)</li><li>Add the task to <strong>Dev’s</strong> queue and prioritize it somehow</li><li>Find the place in which the change must happen</li><li>Modify the code</li><li>Modify the tests (no excuses!)</li><li>Deploy the project (hopefully you’ve automated it and it won’t be a pain in the ass)</li></ol><p>What if the non-technical people could directly address this easy problem and solve it by themselves? Let me introduce you to… <a href="https://github.com/apache/incubator-superset"><strong>Superset</strong></a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*m5R3khcXNqioOeA-x53g1g.gif" /><figcaption>via <a href="https://giphy.com/gifs/Originals-moody-reactions-xUA7aPEybD1cLJl6cU">GIPHY</a></figcaption></figure><p><strong>Superset</strong> is an open-source product originally developed by <a href="https://medium.com/airbnb-engineering">AirBnB</a> that, as stated in their docs:</p><blockquote>Apache Superset (incubating) is a modern, enterprise-ready business intelligence web application.</blockquote><p>What’s more important, it manages to give tools for both technical and non-tech people to work with it. You can easily build a plot using data from a table in your database, a <em>csv</em> file or a <a href="http://druid.io/">Druid</a> cluster. But in case you need to customize a plot, or to obtain data from a overly-complicated query, you still have the ways to do so, nice!</p><p>So… let’s install it?</p><p><strong><em>Disclaimer:</em></strong><em> I’m going to install locally (Ubuntu 18.04), as a first approach to working with Superset. I do not recommend following the same steps in a production environment!</em></p><ol><li>First you need to install both <a href="https://docs.docker.com/install/">Docker</a> and <a href="https://docs.docker.com/compose/install/">docker-compose</a></li><li>Clone the Superset <a href="https://github.com/apache/incubator-superset/">repo</a></li></ol><pre>git clone <a href="https://github.com/apache/incubator-superset/">https://github.com/apache/incubator-superset/</a></pre><p>3. Navigate to the folder in which the docker files are placed</p><pre>cd incubator-superset/contrib/docker</pre><p>4. Run docker-compose specifying file <em>docker-init.sh</em> as entrypoint</p><pre>docker-compose run --rm superset ./docker-init.sh</pre><p>This is going to download (the first time it may take a long time) and configure three containers: one with Superset, another one with a <a href="https://redis.io/">Redis</a> instance (to handle cache) and a last one with <a href="https://www.postgresql.org/">Postgres</a> (handles metadata). You’ll be asked for an user and password in this process.</p><p>5. Launch it!</p><pre>docker-compose up -d</pre><p>Now you should be able to access to your Superset service using <a href="http://localhost:8088/login/">http://localhost:8088/login/</a>, congrats!</p><p>As specified in the <em>docker-compose.yaml</em> file, the containers will be automatically run when restarting docker (or the computer), so you don’t have to worry about rerunning <em>docker-compose</em> when restarting.</p><p><strong>Quick Note:</strong> If the last step fails for you have to modify file <em>incubator-superset/contrib/docker/docker-compose.yaml</em> and set the environment to production:</p><pre>SUPERSET_ENV: production<br>#SUPERSET_ENV: development</pre><p>This is an already documented problem (<a href="https://github.com/apache/incubator-superset/issues/6887">Link to Github issue</a>) and hopefully there is a fix coming soon enough.</p><p>Ok, that was way too boring, let’s import our first datasource and build some cool graphics!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*6e8ssdGCkluaa_CFABb3HQ.gif" /><figcaption>via <a href="https://giphy.com/gifs/tmnt-teenage-mutant-ninja-turtles-cFdHXXm5GhJsc">GIPHY</a></figcaption></figure><p>The data I’ve used includes information on all property sales in England and Wales that were sold for full market value in 2018 (<a href="https://www.gov.uk/government/statistical-data-sets/price-paid-data-downloads">source</a>). I’ve downloaded the <em>csv</em> and dumped it into a table in Postgres.</p><p>First of all, we need to create a connection from Superset to our database, which is done on section <em>Sources &gt;</em> <em>Databases</em>. Once in there, the connector is specified via <a href="https://docs.sqlalchemy.org/en/12/core/engines.html#database-urls">SQLAlchemy</a> url, which supports a wide range of databases. Here is how I’ve done it with Postgres:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2L_MMQnCAqkIngMtcVpeLw.png" /><figcaption>The Superset connector uses SQLAlchemy</figcaption></figure><p>Then, it is needed to add each of the tables that we want to use in our visualizations. That action is performed in section <em>Sources &gt; Tables</em>.</p><p>Now we have to play with Superset two main objects: dashboards and charts. Each dashboard is composed of several charts that we can arrange as we please. The process of building a basic chart and composing a dashboard is really simple, so I’m not going to explain how to do it, go and learn!</p><p>In just about 15 minutes, I’ve managed to build this dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*joQDQbdKjiMzZplOxO87CQ.png" /><figcaption>A simple dashboard displaying some basic graphs</figcaption></figure><p>The magic of it is that, as we play with the different filters, the visualizations will be updated without refreshing the page. Don’t believe me? Just watch the following gif, in which first I apply a filter by city and later a temporal one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zaKoDs-OEmxq7HQVs5Mo6g.gif" /><figcaption>Visualizations are re-rendered as soon as a filter is applied</figcaption></figure><p>Take into account that each visualizations needs to execute, at least, one query. If your dataset is huge and you change filters very fast, you may block your database (sometimes patience is the word).</p><p>Ok, this is very fancy and good-looking, but it has a huge flaw. The chart creator dialog only lets us choose one table, so we can’t join data from different tables… or can we? Yes, we can! (no Obama pun intended) Thanks to <strong>SQL Lab</strong>, which is a section in which we can query our database, save the results and use them as a visualizations’ data source. For example, if I launch the following query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*V1SrZIVtJHeXDxPlGIV38Q.png" /><figcaption>SQL Lab query composer dialog</figcaption></figure><p>To build a plot based on the results of this query, it is as simple as running the query and then clicking on the <em>Explore</em> button that appears on the left bottom corner. Then, we will be redirect to the visualization creation view, nice! This is the part where <strong>Dev </strong>has to work, because <strong>Biz </strong>is not supposed to know anything about SQL syntax (I mean, if they do, you should be happy).</p><p>So, at the end of the day:</p><ul><li><strong>Dev’s</strong> workload is decreased.</li><li><strong>Biz</strong> is able to create and modify its own visualizations, as they please.</li><li>There is no need to read a lot of documentation to start producing results.</li><li>Dashboard documents are stored in <em>JSON</em> files, so they can be added to your version control system.</li><li>Visualizations look nice 😍 (even though sometimes are annoying)</li></ul><p>Of course, Superset is not perfect and have some flaws:</p><ul><li>Deployment in production can be a pain in the ass (we used k8s and kinda wanted to kill the developers at some point).</li><li>The user roles management tab is nearly impossible to understand.</li><li>You have to stick with the already implemented plots (they have a good PR policy so we can expect more to come soon).</li><li>You have to update frequently, as they launch <a href="https://github.com/apache/incubator-superset/releases">releases</a> in a high pace (hmm… maybe this is more of an advantage :D)</li></ul><p>That’s all! Thank you for reading, hopefully you’ve been able to create your first dashboard with no difficulties. I’ll leave below a short list of resources in case you need more information/help.</p><p>To learn more about Superset:</p><ul><li><a href="https://medium.com/airbnb-engineering/superset-scaling-data-access-and-visual-insights-at-airbnb-3ce3e9b88a7f">AirBnB post introducing Superset</a>.</li><li>A <a href="https://medium.com/@InDataLabs/superset-benefits-and-limitations-of-the-open-source-data-visualization-tool-by-airbnb-8dc8ac81efa9">cool post explaining some basics</a> by <a href="https://medium.com/@InDataLabs">InDataLabs</a>.</li><li><a href="https://superset.incubator.apache.org/">Superset docs</a>.</li><li><a href="https://github.com/apache/incubator-superset">Superset github project</a>: if you found a issue, maybe it’s been already reported.</li><li><a href="https://stackoverflow.com/questions/tagged/superset">Stack Overflow</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb10719f116a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/urbandataanalytics/superset-as-a-bridge-between-devs-and-domain-experts-fb10719f116a">Superset as a bridge between devs and domain experts</a> was originally published in <a href="https://medium.com/urbandataanalytics">urbanData Analytics</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>