<?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[Stories by Jordan Carroll on Medium]]></title>
        <description><![CDATA[Stories by Jordan Carroll on Medium]]></description>
        <link>https://medium.com/@jordancarroll.dev?source=rss-e7378dbaf6c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Rq83TOg8f4omEdKP1v2GjA.jpeg</url>
            <title>Stories by Jordan Carroll on Medium</title>
            <link>https://medium.com/@jordancarroll.dev?source=rss-e7378dbaf6c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:44:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jordancarroll.dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Lightweight Skeleton Loading States for your JavaScript Data Visualizations]]></title>
            <link>https://medium.com/front-end-weekly/lightweight-skeleton-loading-states-for-your-javascript-data-visualizations-ec0eb364aa85?source=rss-e7378dbaf6c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec0eb364aa85</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[d3js]]></category>
            <category><![CDATA[user-experience]]></category>
            <dc:creator><![CDATA[Jordan Carroll]]></dc:creator>
            <pubDate>Thu, 19 Dec 2019 15:50:39 GMT</pubDate>
            <atom:updated>2019-12-20T16:30:03.177Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9rN9LBOp3fDp_LyuJWiKQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@lukechesser?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Luke Chesser</a> on <a href="https://unsplash.com/s/photos/chart?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I’ve made quite a few different data visualizations in my day and recently came across a unique way to improve the user experience of any app that uses data visualizations. I am a front end software engineer and extremely passionate about creating a great experience for my users. I love to build beautiful, fast, and innovative interfaces that people love to use.</p><p>A few years ago I decided to begin building skeleton loading components for all of my React components. (See this article <a href="https://uxdesign.cc/what-you-should-know-about-skeleton-screens-a820c45a571a">https://uxdesign.cc/what-you-should-know-about-skeleton-screens-a820c45a571a</a> for more information on skeleton loading states specifically.) Skeleton loading states also began to feel like a great place to have <a href="https://reactjs.org/docs/code-splitting.html#reactlazy">code-splitting</a> points. Some of my components required a lot of code to create, so serving up a lightweight skeleton decreased the main bundle size of my apps. This was especially true when it came to graphical data visualization components.</p><p>In this article, I want to share a method I’ve been using to create lightweight, but meaningful, skeleton loading states for data visualizations — specifically visualizations that are created using SVG. To use a specific example, I’m going to walk through how to do this using a scatterplot chart and the React library that wraps D3 called react-vis.</p><p>Here’s what our scatterplot will ultimately look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*djZTOosKmShKUJWCuPFMNQ.png" /><figcaption>The scatterplot we’re going to build.</figcaption></figure><p>When I first began to think about and research solutions to the problem of creating a skeleton for complex data visualizations I had a few brainstormed thoughts. I thought “I could just reuse my chart component and pass in some fake data to the props that will closely resemble what a data-filled chart might look like.” Or “I could just find a nice scatterplot icon and throw up a nice skeleton that tells in words or with a picture what the final component and data might be.” But both of these solutions suffered from some pretty major problems. The first would require that I still include large amounts of code in the main bundle and would not gain from code-splitting. The second is not quite as helpful to the end-user.</p><p>“So,” I thought, “is there a way that I can have the best of both worlds? Something lightweight and visually descriptive of what the component+data will look like?”</p><h3>The Solution</h3><p>Then a lightbulb went off! In the past, I had worked with attempting to extract SVG visualizations as static images and remembered that there were some tools that I used (specifically a browser extension) that would find an SVG on a page and extract it as an image. This seemed very promising! As it turns out, this wasn’t the best final solution, but it was close!</p><p>So, since I use storybook for building all of my components, I began to pass in some fake data to the data visualization in the isolated storybook environment that looked, generally, like the data that would be the result. The rendered result looked like a great skeleton to represent the final chart that the user would see.</p><p>The next step was to extract the SVG. This was simple and I ended up not using any other tools. I opened the chrome dev tools, found the SVG element, and copied it to my computer clipboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKXexuBPndI7BNnzgPD1Kg.gif" /><figcaption>Copying the SVG element from the browser dev tools.</figcaption></figure><p>Once I had copied the SVG element, I went to a <a href="https://www.smooth-code.com/open-source/svgr/playground/">web app svgr playground. This tool</a> converts SVG code directly into a react component. I copied the output of the conversion to React and pasted that into a file in my app.</p><p>For this example (and in my actual apps), I am using React.Suspense and React.lazy to lazily load the actual component and I use this extracted SVG code as the `fallback` component for Suspense. The main purpose of this article isn’t to explain how to use Suspense or lazy , but the specific implementation will be included in the codesandbox link at the end of the article.</p><p>So, now we have a static SVG react component and are lazily loading the actual component that will render our data from the api. Let’s take a look at the difference this makes with the final bundle size!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tuedoamOiAfGNxl0NbD-Qw.png" /><figcaption>Before lazy loading the scatterplot component.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wxPlG_yP3oMphzBq2r1ifw.png" /><figcaption>After lazy loading the scatterplot component.</figcaption></figure><p>Since we’re now lazily loading the code needed to generate the chart we’re saving just over 300KB (not g-zipped) in our main bundle! We shaved off 64% of the bundle size by not including react-vis and D3 until necessary AND we have a meaningful skeleton loading state that can give the end-user a great representation of what their data will ultimately look like once it loads!</p><p>To further improve things, since the SVG is simply a React component, we can add animations to the loading state to give the user confidence that something is happening. I also removed the axis labels from the static SVG so that there is no actual data shown, just an idea of what is to come. The skeleton looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oFqDTK8tjEBT1ZeP2KiPrw.gif" /><figcaption>Skeleton loading state.</figcaption></figure><p>One final tip — we can also set the height and width to 100% , set the viewbox to the actual size of the generated SVG, and preserveAspectRatio=”none” so that the static SVG is somewhat responsive. Now, this isn’t perfect, because it will stretch the contents of the chart if the viewport it’s rendered in is significantly different from the actual dimensions of the chart, so some static guesswork and assumptions must be made. I’m not 100% sure of a way to alleviate this concern — so if you have any ideas, I’d love to hear them! It hasn’t been much of an issue for me in any of my apps, yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*15qXAOQYM6rRmi26eNBpFw.gif" /></figure><p>So that’s it! Build a beautiful skeleton for your data visualizations, save a large amount on your main bundle size, and give your end-user a great and fun experience of your app!</p><h3>The Example in Code</h3><p>To see a complete example — see this codesandbox. <a href="https://codesandbox.io/s/exciting-colden-2fpcu">https://codesandbox.io/s/exciting-colden-2fpcu</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec0eb364aa85" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/lightweight-skeleton-loading-states-for-your-javascript-data-visualizations-ec0eb364aa85">Lightweight Skeleton Loading States for your JavaScript Data Visualizations</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>