<?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 Richard Zimerman on Medium]]></title>
        <description><![CDATA[Stories by Richard Zimerman on Medium]]></description>
        <link>https://medium.com/@zimrick?source=rss-4cdde420ce94------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ebFA093zS6vlxBbwdlIb7A.jpeg</url>
            <title>Stories by Richard Zimerman on Medium</title>
            <link>https://medium.com/@zimrick?source=rss-4cdde420ce94------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 01:03:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zimrick/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[How to add SVG waves to your next web project]]></title>
            <link>https://blog.prototypr.io/how-to-add-svg-waves-to-your-next-web-project-b720efe1c692?source=rss-4cdde420ce94------2</link>
            <guid isPermaLink="false">https://medium.com/p/b720efe1c692</guid>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Richard Zimerman]]></dc:creator>
            <pubDate>Mon, 19 Aug 2019 05:43:47 GMT</pubDate>
            <atom:updated>2020-07-22T10:33:55.041Z</atom:updated>
            <content:encoded><![CDATA[<h4>SVG waves can add some softness to section breaks in html, but creating naturally looking waves can be tricky. That’s where <a href="https://getwaves.io/">getwaves.io</a> comes in!</h4><h4>Note: I have moved my blog to <a href="https://zcreativelabs.com/blog/">zcreativelabs.com/blog/</a>. You can find an updated version of <a href="https://zcreativelabs.com/blog/how-to-add-svg-waves-to-your-next-web-project/">this article</a> and more there. Future articles will only be published there. Please subscribe to the z creative labs newsletter to receive my latest articles in your inbox.</h4><p>With <a href="https://getwaves.io/">getwaves.io</a> you can easily create smooth and unique SVG waves. By using the randomizer you can be sure that you don’t create repetitive designs. You can then either download your wave as an SVG, or copy the SVG code directly. In this tutorial, I will focus on how to get those waves into your html design and make them look good.</p><p>Here are some examples of what waves can look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cdJghs5XvkHSlXk5LzR4Rg.png" /><figcaption>Some examples of wave section breaks in the wild</figcaption></figure><p>There are a couple of approaches to how you can embed these waves in your designs. In this tutorial I will concentrate on a more advanced use case, where you can have an image in the background, and a wave that overlaps with the image.</p><h3>1. Set up a project</h3><p>For this project we will only need one index.html file and a styles.css. If you already have a project, just use whichever html file/template you want the wave in. Here’s my project structure 😉:</p><pre>index.html<br>styles.css</pre><p>Here is the outline of index.html:</p><pre>&lt;!DOCTYPE <em>html</em>&gt;<br>  &lt;html <em>lang</em>=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta <em>charset</em>=&quot;UTF-8&quot;&gt;<br>    &lt;meta <em>name</em>=&quot;viewport&quot; <em>content</em>=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;meta <em>http-equiv</em>=&quot;X-UA-Compatible&quot; <em>content</em>=&quot;ie=edge&quot;&gt;<br>    &lt;title&gt;Make some waves!&lt;/title&gt;<br>    &lt;link <em>rel</em>=&quot;stylesheet&quot; <em>href</em>=&quot;styles.css&quot;&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;div <em>class</em>=&quot;wave-container&quot;&gt;<br>      <em>&lt;!-- Your wave goes here... --&gt;<br>    </em>&lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Here is the outline of styles.css:</p><pre>html {<br>  box-sizing: border-box;<br>}<br>*,*<em>::before</em>,*<em>::after</em> {<br>  box-sizing: inherit;<br>}<br>body {<br>  margin: 0;<br>}<br><em>.wave-container</em> {<br>  background: #EEE;<br>}<br><em>.wave-container</em> &gt; svg {<br>  display: block;<br>}</pre><p>If you use a background image, you can assign that to the wave-container. It will be automatically masked by the SVG element containing the wave. The rest of the styles are fairly self-explanatory. Make sure that your SVG has display: block; set, otherwise you will have a white space below your SVG element (You can also set display: inline-block; and vertical-align: middle;).</p><h3>2. Make some waves!</h3><p>Now you can go to <a href="https://getwaves.io/">getwaves.io</a> and make some SVG waves. Once you find a wave you like, copy the SVG code and paste that code into the .wave-container in your index.html file (<em>&lt;!-- Your wave goes here... --&gt;</em>).</p><p>Your wave will be positioned inside the wave-container, and it will scale proportionately, based on the viewBox attribute. Add some more elements, and you get a pretty nice header.</p><pre>&lt;div <em>class</em>=&quot;wave-container&quot;&gt;<br>  &lt;h1&gt;Hello, world!&lt;/h1&gt;<br>  &lt;p&gt;Check out my awesome waves!&lt;/p&gt;<br>  &lt;svg <em>xmlns</em>=&quot;http://www.w3.org/2000/svg&quot; <em>viewBox</em>=&quot;0 0 1440 320&quot;&gt;<br>    &lt;path <em>fill</em>=&quot;#FFF&quot; <em>d</em>=&quot;…&quot;&gt;&lt;/path&gt;<br>  &lt;/svg&gt;<br>&lt;/div&gt;</pre><p>Here are the styles to make this look a little bit better:</p><pre>body {<br>  margin: 0;<br>  font-family: system-ui, sans-serif;<br>}<br><em>.wave-container</em> {<br>  position: relative;<br>  background: #09F;<br>  color: #FFF;<br>  text-align: center;<br>  overflow: hidden;<br>}<br>h1 {<br>  font-size: 5rem;<br>  margin: 7rem 1.25rem 2.5rem 1.25rem;<br>}<br>p {<br>  font-size: 1.5rem;<br>  margin: 0 1.25rem 5rem 1.25rem;<br>}</pre><p>Here’s the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lCV5lid-7zfbLBu1cxVg-Q.png" /><figcaption>It’s a start…</figcaption></figure><h3>3. Animate your wave</h3><p>One cool thing with these kinds of waves is that it is really easy to animate them, and add some nice movement to your website. If you are dreading some advanced javascript tweening, don’t worry, there is a much easier way to get some nice animation going here. All you need are some transforms and css keyframe animations.</p><pre><em>@keyframes</em> animateWave {<br>  0% {<br>    transform: scale(1,0);<br>  }<br>  100% {<br>    transform: scale(1,1);<br>  }<br>}<br><em>.wave-container</em> &gt; svg {<br>  display: block;<br>  transform-origin: bottom;<br>  animation: animateWave 1000ms cubic-bezier(0.23, 1, 0.32, 1) forwards;<br>}</pre><p>By transforming scale y, we make sure that the wave grows only vertically, not horizontally. By using transform-origin: bottom; you can make the wave “rise” from the bottom, rather than expand from the middle. I added some <a href="https://easings.net/en#easeOutQuint">custom easing</a> just for fun.</p><p>And here’s the final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-QCNdfNnHynFUctvEg89Hg.gif" /><figcaption>Final result with an animated wave.</figcaption></figure><p>So there you have it, a simple way to add some animated waves into your next project. You can also hook this animation up to a waypoint trigger (using intersection observer) if you are using waves somewhere further down in your designs. Either way, give it a try. Head on over to <a href="https://getwaves.io/">getwaves.io</a>, and make some waves!</p><p>If waves are not your thing, you can also try the same exercise using the other curve options from <a href="https://getwaves.io/">getwaves.io</a> (steps or peaks).</p><h3>Waves + Blobs = ❤️🔥😎</h3><p>Waves can be paired really nicely with blobs, so if you are looking for unique, natural, and organic blob shapes, check out <a href="https://blobmaker.app/">blobmaker.app</a>. If you combine the two, you can create some really nice designs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ksrM4_0MoQhOh2v-zAOMMA.jpeg" /><figcaption><a href="https://dribbble.com/shots/6997322-Exploring-waves-and-blobs">Exploring waves and blobs on dribbble</a></figcaption></figure><h3>Keep in touch!</h3><p>If you like using getwaves.io, give us an upvote on <a href="https://www.producthunt.com/posts/get-waves">Product Hunt</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcards.producthunt.com%2Fcards%2Fposts%2F164553%3Fv%3D1&amp;url=https%3A%2F%2Fwww.producthunt.com%2Fposts%2Fget-waves&amp;image=https%3A%2F%2Fph-files.imgix.net%2Ff994752d-ee16-4323-b607-007ab38a0ba5%3Fauto%3Dformat%26fit%3Dmax%26h%3D405%26w%3D500&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=producthunt" width="500" height="405" frameborder="0" scrolling="no"><a href="https://medium.com/media/64e168c9f0c20b0d9abfc20a6d7bf684/href">https://medium.com/media/64e168c9f0c20b0d9abfc20a6d7bf684/href</a></iframe><p>Have fun making 🌊🌊🌊!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b720efe1c692" width="1" height="1" alt=""><hr><p><a href="https://blog.prototypr.io/how-to-add-svg-waves-to-your-next-web-project-b720efe1c692">How to add SVG waves to your next web project</a> was originally published in <a href="https://blog.prototypr.io/">Prototypr</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we made Blobmaker]]></title>
            <link>https://blog.prototypr.io/how-we-made-blobmaker-d2c1985d484a?source=rss-4cdde420ce94------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2c1985d484a</guid>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[d3js]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ui]]></category>
            <dc:creator><![CDATA[Richard Zimerman]]></dc:creator>
            <pubDate>Thu, 03 Jan 2019 16:21:58 GMT</pubDate>
            <atom:updated>2020-07-22T10:35:06.476Z</atom:updated>
            <content:encoded><![CDATA[<h4>Organic blob shapes have been trending in web design for a while. Making them can be a bit of a pain though. Enter <a href="https://www.blobmaker.app/">Blobmaker</a>, a simple tool to make lots of beautiful SVG blobs easily.</h4><h4>Note: I have moved my blog to <a href="https://zcreativelabs.com/blog/">zcreativelabs.com/blog/</a>. You can find an updated version of <a href="https://zcreativelabs.com/blog/how-we-made-blobmaker/">this article</a> and more there. Future articles will only be published there. Please subscribe to the z creative labs newsletter to receive my latest articles in your inbox.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*emdeN_2FSytKj2GkEOhvxQ.jpeg" /></figure><p>A while back <a href="https://medium.com/u/5013041fa264">Ian Latchmansingh</a> wrote an article called “<a href="https://medium.com/@usonesinbetween/2017-the-year-of-the-blob-a3d899c9b071">2017: The Year of the Blob</a>” on how organic shapes became a pervasive design trend. Since the article came out, more and more blobs have made their way online as part of illustrations, elements used to delimit sections, or simply as visual elements on landing pages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JasDbAxQVSTZftIO0C2HGQ.png" /><figcaption>Blobs are everywhere.</figcaption></figure><p>Creating smooth and organic shapes can be a challenge. Working on one shape is one thing, but once you have to make many unique blobs, things can get really tedious. I wanted something faster that would allow me to discover, rather than to engineer shapes.</p><p>I work a lot with data visualisation, and by chance, when I was playing with a d3 radar chart for another project, I noticed that when using a basis interpolation on a polar line, I got a very smooth curve that resembled a blob. For the prototype, I built the simplest possible radar chart, just a radial line without axes, numbers, or labels. This worked quite nicely, but more control was necessary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kzUAuUD0rC-WDf94K23uqQ.png" /><figcaption>From left to right: linear, cardinal, and basis.</figcaption></figure><h4>Complexity and Contrast</h4><p>There are two control parameters to control the blob shapes generated with Blobmaker: complexity and contrast.</p><p>Complexity determines how many points are used to create the blob. The more points you add, the more complex the blob <em>can</em> be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4nkl5i-En2M1DwYpIpIRbw.gif" /><figcaption>The more data points a blob uses, the more complex the shape can be.</figcaption></figure><p>Contrast on the other hand determines the range of data points that will be fed to the chart. The smaller the contrast, the closer the blob resembles a circle. The more contrast, the more whacky the shapes can be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmBNJiLYjAzyjjfkOQkW5w.gif" /><figcaption>More contrast means that a shape can have more spikes and dents.</figcaption></figure><h4>Serendipity</h4><p>The most fun feature of Blobmaker is its ability to generate many random shapes quickly. Just tap that refresh button until you find the blob of your dreams ;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXUmxFeOv5_IzfZKTZHjhQ.gif" /><figcaption>Blobs for days with the refresh button.</figcaption></figure><p>I hope this article gives you some insight into the reasoning and story behind this small app. If you haven’t used it already, check out <a href="https://www.blobmaker.app/">Blobmaker</a> and spread the word :)</p><p>P.S. we don’t only make blobs. Check out some of our other work on <a href="https://www.zcreativelabs.com/">z creative labs</a> or follow us on <a href="https://twitter.com/zcreativelabs">twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2c1985d484a" width="1" height="1" alt=""><hr><p><a href="https://blog.prototypr.io/how-we-made-blobmaker-d2c1985d484a">How we made Blobmaker</a> was originally published in <a href="https://blog.prototypr.io/">Prototypr</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New: Globe and Albers USA support in React-Simple-Maps v.0.11]]></title>
            <link>https://medium.com/@zimrick/new-globe-and-albers-usa-support-in-react-simple-maps-v-0-11-9acd2957734d?source=rss-4cdde420ce94------2</link>
            <guid isPermaLink="false">https://medium.com/p/9acd2957734d</guid>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[d3js]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Richard Zimerman]]></dc:creator>
            <pubDate>Mon, 26 Feb 2018 18:13:10 GMT</pubDate>
            <atom:updated>2020-07-22T10:36:35.151Z</atom:updated>
            <content:encoded><![CDATA[<h4>With the release of v.0.11, <a href="https://github.com/zcreativelabs/react-simple-maps">react-simple-maps</a> now has proper support for rotating globes and the Albers USA projection.</h4><h4>Note: I have moved my blog to <a href="https://zcreativelabs.com/blog/">zcreativelabs.com/blog/</a>. You can find an updated version of <a href="https://zcreativelabs.com/blog/globe-and-albers-USA-support-in-react-simple-maps-v-0-11/">this article</a> and more there. Future articles will only be published there. Please subscribe to the z creative labs newsletter to receive my latest articles in your inbox.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vv5Ziy1XPGc4K8x8XqeCsA.jpeg" /><figcaption>With the new Albers USA projection support, mapping the US is significantly easier.</figcaption></figure><h3>Globes</h3><p>While creating static globes with react-simple-maps has been technically possible until now, the new &lt;ZoomableGlobe /&gt; component takes globes to the next level. &lt;ZoomableGroup /&gt; relies on a custom panning and zooming implementation that makes regular maps significantly more performant than modifying scale on the projection.</p><p>This approach is however not possible when using the <a href="https://github.com/d3/d3-geo-projection#geoOrthographic">orthographic projection</a> as we need to modify the rotation parameter. &lt;ZoomableGlobe /&gt; aims to remedy this problem by modifying the projection itself, and enabling globe rotation on drag.</p><p>A general globe implementation in react-simple-maps v.0.11 now looks fairly simple:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fq7wwmxmjv4%3Fautoresize%3D1%26hidenavigation%3D1&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fq7wwmxmjv4%3Fautoresize%3D1%26hidenavigation%3D1&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fq7wwmxmjv4%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/699ab8fd7fd67b38c627e9018cbdbf3a/href">https://medium.com/media/699ab8fd7fd67b38c627e9018cbdbf3a/href</a></iframe><p>Tada! It’s as simple as that and you have an interactive globe that you can use with all the great features that react-simple-maps normally provides to &lt;ZoomableGroup /&gt;. This means that like before you can use <a href="https://github.com/chenglou/react-motion">react-motion</a> to animate your maps:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F2j3povypxp%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F2j3povypxp%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F2j3povypxp%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb3f1d8994c7d70c646a146dd02209d3/href">https://medium.com/media/bb3f1d8994c7d70c646a146dd02209d3/href</a></iframe><h4>Using Markers with Globes</h4><p>Markers present a special challenge when implementing globes as they now have to become invisible as they move behind the globe during the rotation. In addition to default, hover, and pressed, there is now a new hidden property on the style object that gets passed to each marker. These hidden styles will be activated once the marker moves behind the globe.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Frjm2p4k08m%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Frjm2p4k08m%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Frjm2p4k08m%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c72cfc8ecffbd58c6141a02e8e2bd98/href">https://medium.com/media/1c72cfc8ecffbd58c6141a02e8e2bd98/href</a></iframe><p>To see the new &lt;ZoomableGlobe /&gt; component in action with data, check out the <a href="https://github.com/zcreativelabs/react-simple-maps/tree/master/examples/globe">new biggest cities by population example on github</a>.</p><h3>Albers USA</h3><p>The other major feature that react-simple-maps v.0.11 adds is proper support for the <a href="https://github.com/d3/d3-geo/blob/master/README.md#geoAlbersUsa">Albers USA projection</a>. The challenge there has been that react-simple-maps performs certain calculations that relied on rotation, and this was causing problems with projections that do not have a rotation property.</p><p>The other challenge with projections like Albers USA is that they have undefined coordinates, since they are clipped.</p><p>This means that using the conventional approach with react-motion will not yield a smooth animation between e.g. New York and Honolulu, since there is a jump in coordinates. Using a css transition however will yield good results in the browsers that support css transitions on SVG elements.</p><p>To create a map of the US using the Albers USA projection, all you need to do is add projection=”albersUsa” to &lt;ComposableMap /&gt;.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F434kw81l4w%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F434kw81l4w%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F434kw81l4w%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/f15ac4844ae126e724d509ab457c7723/href">https://medium.com/media/f15ac4844ae126e724d509ab457c7723/href</a></iframe><p>You can check out a working <a href="https://github.com/zcreativelabs/react-simple-maps/tree/master/examples/albers-usa">choropleth example of the US on github</a>.</p><p>If you are into data visualisation and mapping, make sure to give the new react-simple-maps a try. If you find any issues or bugs, report them on <a href="https://github.com/zcreativelabs/react-simple-maps/issues">issues in the github repo</a>.</p><p>Happy mapping :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9acd2957734d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mapping Tutorial: Combining Victory Charts and React-Simple-Maps]]></title>
            <link>https://medium.com/hackernoon/mapping-tutorial-combining-victory-charts-and-react-simple-maps-4e839d803865?source=rss-4cdde420ce94------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e839d803865</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[d3js]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[maps]]></category>
            <dc:creator><![CDATA[Richard Zimerman]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 15:24:34 GMT</pubDate>
            <atom:updated>2020-07-22T10:37:28.479Z</atom:updated>
            <content:encoded><![CDATA[<h4>Creating a beautiful map of Switzerland’s language distribution by canton using donut charts on a map.</h4><h4>Note: I have moved my blog to <a href="https://zcreativelabs.com/blog/">zcreativelabs.com/blog/</a>. You can find an updated version of <a href="https://zcreativelabs.com/blog/mapping-tutorial-combining-victory-charts-and-react-simple-maps/">this article</a> and more there. Future articles will only be published there. Please subscribe to the z creative labs newsletter to receive my latest articles in your inbox.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zwa9vLSbzdYM3OuSYTYeyg.png" /><figcaption>This is the end result of this tutorial.</figcaption></figure><p><a href="https://www.react-simple-maps.io/">React-simple-maps</a> is a <a href="https://hackernoon.com/tagged/react">react</a> component library to help make SVG mapping with d3-geo, TopoJSON, and React easier. One of the strengths of using react-simple-maps is that it gives React full control over the DOM and does not treat the SVG map as a black box. This means that react-simple-maps can easily take advantage of the entire React ecosystem and all the good things that come with it.</p><p>React-simple-maps was partially inspired by the declarative api of Victory charts. If you haven’t heard about Victory, take a look on <a href="https://github.com/FormidableLabs/victory">github</a>, or see the <a href="http://formidable.com/open-source/victory/gallery">examples</a> and <a href="http://formidable.com/open-source/victory/guides">guides</a> on their <a href="http://formidable.com/open-source/victory/">website</a>.</p><p>The great thing about Victory charts is that it does not have to be used standalone, but that it can be embedded in already existing SVG containers. This makes it possible to combine Victory charts with any SVG visual, e.g. a map ;)</p><p>This tutorial will go over how to combine the two libraries and create the map shown on the cover of this article. If you are just interested in the final code, head on over to the <a href="https://github.com/zcreativelabs/react-simple-maps/tree/master/examples/with-victory">github repo</a>.</p><p>Here’s what this tutorial will cover:</p><ol><li>About the visualisation</li><li>The repo and the app structure</li><li>Setting up a basic map (TopoJSON, projection, style)</li><li>The data</li><li>Rendering &lt;VictoryPie /&gt; inside &lt;Marker /&gt; components</li></ol><p>Let’s get started.</p><h3>About the Visualisation</h3><p>The visualisation for this tutorial shows the language distribution in Switzerland by canton. Even though Switzerland has a population of slightly more than 8 million, it has four official languages: German, French, Italian, and Romansh. This results in Switzerland being divided into three distinct linguistic regions, each with its own culture. Romansh constitutes a special case, as it is only spoken by 0.5% of the Swiss population, mostly in the canton of Graubünden.</p><p>While most cantons will identify predominantly with one language, there are some (Fribourg, Valais, Bern, and Graubünden) that have quite a diverse linguistic environment.</p><h3>The Repo and App Structure</h3><p>In order to simplify the setup for this tutorial, I will be using next.js to create an app scaffold. To get started, install these dependencies:</p><pre>$ npm install react react-dom react-simple-maps victory next --save</pre><p>In terms of scaffolding, here’s what the app structure will look like:</p><pre>┬ app<br>├─┬ data<br>│ └── index.js<br>├─┬ pages<br>│ └── index.js<br>├─┬ static<br>│ └── cantons.json<br>├── node_modules<br>└── package.json</pre><p>Don’t forget to add the next dev script in package.json.</p><pre>// ./package.json<br>...<br>scripts: {<br>  &quot;dev&quot;: &quot;next&quot;,<br>  ...<br>}<br>...</pre><h3>Setting up a Basic Map</h3><p>Every mapping visualisation starts with a good base map, and a solid TopoJSON file. If you are new to TopoJSON, check out the <a href="https://github.com/topojson/topojson">docs</a> here. If you are new to creating your own TopoJSON files, you can check out my article on <a href="https://hackernoon.com/how-to-convert-and-prepare-topojson-files-for-interactive-mapping-with-d3-499cf0ced5f">How to convert and prepare TopoJSON files for interactive mapping with d3</a>.</p><p>The original shapefile used to create the TopoJSON file came from <a href="http://www.gadm.org/country">gadm.org</a>.</p><p>The projection for the map of Switzerland was derived from <a href="https://bl.ocks.org/mbostock/4207744">this block</a>, made by Mike Bostock. In order to use the <a href="https://github.com/d3/d3-geo-projection#geoAlbers">Albers projection</a> with react-simple-maps, we need to load in <a href="https://github.com/d3/d3-geo">d3-geo</a>. Since react-simple-maps uses d3-geo internally, it should already be installed. Using geoAlbers from d3-geo, you can easily create a custom projection, and pass it into the projection prop of &lt;ComposableMap /&gt;.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad9ae1654905115da6e7dc522e99f6d7/href">https://medium.com/media/ad9ae1654905115da6e7dc522e99f6d7/href</a></iframe><p>You can now run the app. Just type $ npm run dev in the terminal, and go to <a href="http://localhost:3000/">http://localhost:3000</a>.</p><h3>The Data</h3><p><a href="https://www.bfs.admin.ch/asset/fr/je-f-21.03.02">The dataset</a> for this tutorial comes from the <a href="https://www.bfs.admin.ch/bfs/en/home.html">Swiss Federal Statistics Office</a>. In order to not mess with asynchronous data loading, this small dataset can be easily converted into a <a href="https://hackernoon.com/tagged/javascript">javascript</a> object, and loaded in as a normal script. Here’s an excerpt:</p><pre>// ./data/index.js</pre><pre>export const cantons = [<br>  {<br>    id: 25,<br>    canton: &quot;Zurich&quot;,<br>    coordinates: [ 8.6356, 47.3595 ],<br>    languages: [<br>      { name: &quot;German&quot;, value: 83.1 },<br>      { name: &quot;French&quot;, value: 3 },<br>      { name: &quot;Italian&quot;, value: 5.9 },<br>      { name: &quot;Romansh&quot;, value: 0.4 },<br>    ]<br>  },<br>...</pre><p>The data can now be easily imported into the app:</p><pre>// ./pages/index.js</pre><pre>import { cantons } from &quot;../data&quot;<br>...</pre><h3>Rendering Victory Charts As Markers</h3><p>The final step is now to use the data to render out react-simple-maps &lt;Marker /&gt; components and render &lt;VictoryPie /&gt; charts into those markers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe7aaeca98ea53f55f502ca6034c94c1/href">https://medium.com/media/fe7aaeca98ea53f55f502ca6034c94c1/href</a></iframe><p><strong><em>Note:</em></strong> The two &lt;circle /&gt; elements added on lines 67-68, are just for decorative purposes.</p><h3>Conclusion</h3><p>This tutorial covered how to use react-simple-maps together with Victory charts to create a nice little map of Switzerland’s language distribution by canton. The two libraries play well together, so give it a try. Thanks for reading, and happy mapping! ;)</p><h4>Resources</h4><p>For the complete code example, see <a href="https://github.com/zcreativelabs/react-simple-maps/tree/master/examples/with-victory">this github repo</a>.</p><p>For more information on declarative mapping, check out <a href="https://medium.com/@zimrick/how-to-create-pure-react-svg-maps-with-topojson-and-d3-geo-e4a6b6848a98">How to create pure react SVG maps with topojson and d3-geo</a>.</p><p>For information on how to convert shapefiles into TopoJSON to use with react-simple-maps, or d3, check out <a href="https://hackernoon.com/how-to-convert-and-prepare-topojson-files-for-interactive-mapping-with-d3-499cf0ced5f">How to convert and prepare TopoJSON files for interactive mapping with d3</a>.</p><p><a href="https://www.react-simple-maps.io/">More information about react-simple-maps</a></p><p><a href="http://formidable.com/open-source/victory/">More information about Victory.</a></p><h4>Mentions</h4><p>Thanks to the folks at <a href="https://medium.com/u/900ee8ad3db9">Formidable</a>, for creating the awesomeness that is Victory and of course <a href="https://medium.com/u/c918c478bb49">Mike Bostock</a>, and <a href="https://twitter.com/jasondavies">Jason Davies</a> for their work on d3 and for being a continuous source of inspiration.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e839d803865" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/mapping-tutorial-combining-victory-charts-and-react-simple-maps-4e839d803865">Mapping Tutorial: Combining Victory Charts and React-Simple-Maps</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</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 pure react SVG maps with topojson and d3-geo]]></title>
            <link>https://medium.com/@zimrick/how-to-create-pure-react-svg-maps-with-topojson-and-d3-geo-e4a6b6848a98?source=rss-4cdde420ce94------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4a6b6848a98</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[d3js]]></category>
            <dc:creator><![CDATA[Richard Zimerman]]></dc:creator>
            <pubDate>Wed, 24 May 2017 11:24:23 GMT</pubDate>
            <atom:updated>2020-07-22T10:32:03.665Z</atom:updated>
            <content:encoded><![CDATA[<h4>Since d3 has been split into smaller components in v4, pairing it with react has become more streamlined. Making declarative SVG maps with react, topojson, and d3-geo has never been easier.</h4><h4>Note: I have moved my blog to <a href="https://zcreativelabs.com/blog/">zcreativelabs.com/blog/</a>. You can find an updated version of <a href="https://zcreativelabs.com/blog/How-to-create-pure-react-SVG-maps-with-topojson-and-d3-geo/">this article</a> and more there. Future articles will only be published there. Please subscribe to the z creative labs newsletter to receive my latest articles in your inbox.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LIWWDGD7UPby8K08YTSWjg.jpeg" /></figure><p>This article will show you how to create pure <a href="https://facebook.github.io/react/">react</a> SVG maps with <a href="https://github.com/topojson/topojson-client">topojson-client</a> and <a href="https://github.com/d3/d3-geo">d3-geo</a>. The techniques outlined here will help you make your own reusable SVG mapping components.</p><h3>What this article covers</h3><ol><li>The anatomy of an SVG map independent of react</li><li>Structure of example app and npm dependencies</li><li>Loading topojson and rendering a basic SVG map with react and d3-geo</li><li>Adding events</li><li>Example data-driven world map with markers</li></ol><h3>Code</h3><p>The code for this tutorial is available in the <a href="https://github.com/zimrick/react-svg-maps-tutorial">react-svg-maps-tutorial</a> repo on github.</p><p><strong><em>Note:</em></strong><em> </em>This tutorial covers the creation of a simple SVG map. If you need more functionalities, such as zooming, panning and annotations, I put together a library of reusable components called <a href="https://github.com/zcreativelabs/react-simple-maps">react-simple-maps</a>.</p><h3>1. The anatomy of an SVG map</h3><p>In order to create a map with react and d3-geo let’s first take a look at what the output of such a map could look like:</p><pre>&lt;svg&gt;<br>  &lt;g class=&quot;wrapper&quot;&gt;<br>    &lt;g class=&quot;countries&quot;&gt;<br>      &lt;path d=&quot;...&quot; class=&quot;country&quot; /&gt;<br>      &lt;path d=&quot;...&quot; class=&quot;country&quot; /&gt;<br>    &lt;/g&gt;<br>    &lt;g class=&quot;markers&quot;&gt;<br>      &lt;circle class=&quot;marker&quot; r=10 /&gt;<br>      &lt;circle class=&quot;marker&quot; r=10 /&gt;<br>    &lt;/g&gt;<br>  &lt;/g&gt;<br>&lt;/svg&gt;</pre><p>This structure is completely independent from whether you are using react or any other framework/tool to render a map.</p><p>Instead of using d3 to manipulate the DOM and manage the above elements, we can use react. In JSX the above structure virtually stays the same (except for class, which becomes className).</p><pre>&lt;svg&gt;<br>  &lt;g className=&quot;wrapper&quot;&gt;<br>    &lt;g className=&quot;countries&quot;&gt;<br>      &lt;path d=&quot;...&quot; className=&quot;country&quot; /&gt;<br>      &lt;path d=&quot;...&quot; className=&quot;country&quot; /&gt;<br>    &lt;/g&gt;<br>    &lt;g className=&quot;markers&quot;&gt;<br>      &lt;circle className=&quot;marker&quot; r=10 /&gt;<br>      &lt;circle className=&quot;marker&quot; r=10 /&gt;<br>    &lt;/g&gt;<br>  &lt;/g&gt;<br>&lt;/svg&gt;</pre><p>The only tricky part is generating the d-path for each country. In order to do that you will first need a geo-file (topojson) containing some json describing the country paths. Then you will need a library that can translate such geographical data into coordinates. <a href="https://github.com/topojson/topojson-client">Topojson-client</a> and <a href="https://github.com/d3/d3-geo">d3-geo</a> are ideally suited for these tasks. The former allows you to use topojson files, <a href="https://github.com/topojson/topojson#topojson">which are significantly smaller than geojson</a>, and the latter allows you to easily manage geo-projections and translate geo data into a coordinate system. Using d3-geo also allows you to take advantage of the <a href="https://github.com/d3/d3-geo-projection">extensive collection of projections</a> created by Mike Bostock.</p><h3>2. Dependencies and structure</h3><p>In order to create a map with react you will need a basic react project. For my own example, I used the simplest boilerplate possible using next.js so I don’t have to mess with webpack. See the <a href="https://github.com/zimrick/react-svg-maps-tutorial">tutorial github repo</a> for more information.</p><p>For the map I will be using d3-geo and topojson-client (assuming you have already installed next, react, and react-dom), so let’s start by installing these libraries:</p><pre>npm install d3-geo topojson-client --save</pre><p>The code structure for this example will look like this:</p><pre>┬ app<br>├─┬ components<br>│ └── WorldMap.js<br>├─┬ pages<br>│ └── index.js<br>├─┬ public<br>│ ├── favicon.ico<br>│ └── world-110m.json<br>├── package.json<br>└── node-modules</pre><h3>3. The WorldMap component</h3><p>The WorldMap component will render a map based on the <a href="https://github.com/topojson/world-atlas#world/110m.json">world-110m map from the topojson-worldatlas</a>. Since I want to customise the projection and reuse it for markers, I created a separate method that returns an <a href="https://en.wikipedia.org/wiki/Equal_Earth_projection">Equal earth projection</a> with some scale and offset customisations. I also take advantage of the SVG viewBox property to prepare the map for variable screen sizes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f4437b14a4bcae9f8d0aad15dd80159/href">https://medium.com/media/0f4437b14a4bcae9f8d0aad15dd80159/href</a></iframe><p>Start by defining geographies as part of the WorldMap component state (line 13). This will be an empty array in the beginning, and the data will be loaded asynchronously, once the component mounts (see useEffect on line 15). The empty array avoids throwing an error when iterating over worldData before the map is loaded (see line 32).</p><p>To fetch world-110m.json I use Chrome’s built-in fetch function, but you can use any AJAX library of your choice (e.g. <a href="https://github.com/mzabriskie/axios">axios</a>, <a href="https://github.com/visionmedia/superagent">superagent</a>).</p><p>The projection is used to render the d-path of the country paths, as well as the cx and cy property of the marker circles. Since the projection is customised, it makes more sense to store it in a separate variable(see line 8).</p><p>In order to not make all countries the same colour, I use the index of the country within the worldData array to set the opacity of the country path fill. If you have data, you can use the same strategy to create a choropleth map.</p><p><strong><em>Note:</em></strong><em> </em>If you are making choropleth maps, always use an equal area projection. For the world map <a href="https://en.wikipedia.org/wiki/Equal_Earth_projection">Equal earth</a> and <a href="https://en.wikipedia.org/wiki/Mollweide_projection">Mollweide</a> are good options. If you do not use an equal area projection, your map will not show correct relationships between countries or areas in different parts of the world and therefore will not be accurate.</p><h3>4. Events</h3><p>Adding events to your SVG paths works the same way as <a href="https://facebook.github.io/react/docs/handling-events.html">adding events to any other element in JSX</a>. The below code shows how to add an onClick handler to the country paths.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2e017f945e28ac361e12a7d6a1960a4/href">https://medium.com/media/b2e017f945e28ac361e12a7d6a1960a4/href</a></iframe><p>The same approach can be used for other events (e.g. mouseEnter, mouseLeave, mouseMove) for countries, but also for markers.</p><h3>5. Data example: Most populous cities of the world</h3><p>Let’s try to add some data to the mix and output the <a href="http://www.worldatlas.com/citypops.htm">world’s most populous cities</a> on the world map. The marker size will be determined by the population size of the city.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45f63a62b5b097d05e7a130303e11be7/href">https://medium.com/media/45f63a62b5b097d05e7a130303e11be7/href</a></iframe><p><strong><em>Note: </em></strong>I have also added an onClick event to the markers, outputting the currently clicked city to the console (see lines 61 and 65).</p><p>Your map should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ARDj4sToZisUMXoW7Nhu3Q.png" /><figcaption>The output of WorldMap.js should look like this. The countries are coloured based on the index of the country within the geographies array. The circle sizes are determined by the population size of each city displayed.</figcaption></figure><p>If you want to add tooltips to your map, you can use the technique outlined above for event handling. To render the actual tooltip, you can use a library like <a href="https://github.com/wwayne/react-tooltip">react-tooltip</a>.</p><h3>Next steps</h3><p>For simple maps, the techniques outlined in this article should be enough to get you started, but once you want to add more complex functionality, such as panning, zooming, etc. it gets a little bit more complicated. Performance is a particularly tricky issue with react SVG maps.</p><p>As mentioned before, I have put together a set of reusable components in the <a href="https://github.com/zcreativelabs/react-simple-maps">react-simple-maps</a> library, which help make more performant SVG maps with react and d3-geo. The library handles the more complex logic related to resizing, panning, and performance optimisation, so that you can focus on making beautiful and engaging visualisations.</p><h3>Inspiration</h3><p>If you are interested in reading more about using react and d3 together, check out <a href="https://medium.com/@Elijah_Meeks/interactive-applications-with-react-d3-f76f7b3ebc71">“Interactive Applications with React and D3”</a> by Elijah Meeks, or <a href="https://hackernoon.com/how-and-why-to-use-d3-with-react-d239eb1ea274">“How and why to use d3 with react”</a> by Dan Scanlon.</p><p>If you have any questions or thoughts about the code in this article, please leave a message below. If you found this article helpful, feel free to share and recommend. Happy mapping!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4a6b6848a98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up a postcss pipeline with variable sharing in gulp]]></title>
            <link>https://medium.com/hackernoon/how-to-set-up-a-postcss-pipeline-with-variable-sharing-in-gulp-4e77624cc749?source=rss-4cdde420ce94------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e77624cc749</guid>
            <category><![CDATA[gulp]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[postcss]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cssnext]]></category>
            <dc:creator><![CDATA[Richard Zimerman]]></dc:creator>
            <pubDate>Sun, 09 Apr 2017 16:09:42 GMT</pubDate>
            <atom:updated>2019-05-22T04:54:53.262Z</atom:updated>
            <content:encoded><![CDATA[<h4>Create a style pipeline from scratch taking advantage of <a href="http://postcss.org/">postcss</a> and future-proof css with <a href="http://cssnext.io/">cssnext</a>, as well as variable sharing between css and js.</h4><p>Setting up a basic <a href="https://hackernoon.com/tagged/workflow">workflow</a> for postcss with gulp is fairly straightforward. Cssnext also allows us to specify variables in a central <a href="https://hackernoon.com/tagged/javascript">javascript</a> file that can be used across your entire codebase. This means that you can standardise styles further, for those cases where styling in both css and javascript is sometimes unavoidable (e.g. data visualization).</p><p>I will mainly focus on providing support for variables, custom media queries and partial imports. In order to keep this tutorial reasonably short I can’t cover more than that, but I hope that by the end you will have enough of an overview to be able to add your own plugins to take advantage of more advanced features of postcss.</p><p>The source code for this examples can be found on <a href="https://github.com/zimrick/postcss-starter-gulp">github</a>.</p><h3>1. Basic setup for gulp</h3><p>To get started initialise a new folder with npm. In this folder you will need a src and css folder. The src folder will contain the uncompiled css, and the css folder will contain the processed/compiled css files.</p><pre>$ mkdir postcss-starter-gulp &amp;&amp; cd postcss-starter-gulp<br>$ npm init<br>...<br>$ mkdir src css</pre><h3>2. Add gulp dependencies</h3><p>Next you will have to install gulp and some additional gulp packages. Make sure that they are all listed in package.json.</p><pre>$ npm install gulp gulp-postcss autoprefixer postcss-cssnext postcss-partial-import --save-dev</pre><h3>3. Add gulpfile</h3><p>Create a gulpfile.js in the root of your project. Here’s what the file should look like:</p><pre><em>// gulpfile.js</em></pre><pre>var gulp = require(&quot;gulp&quot;)<br>var postcss = require(&quot;gulp-postcss&quot;)<br>var partialImport = require(&quot;postcss-partial-import&quot;)<br>var cssnext = require(&quot;postcss-cssnext&quot;)</pre><pre>gulp.task(&quot;css:build&quot;, function() {<br>    var processors = [<br>        partialImport(),<br>        cssnext({<br>            browsers: [&quot;&gt; 1%&quot;],<br>        })<br>    ]<br>    return gulp.src(&quot;./src/main.css&quot;)<br>               .pipe(postcss(processors))<br>               .pipe(gulp.dest(&quot;./css&quot;))<br>})</pre><pre>gulp.task(&quot;default&quot;, function() {<br>    gulp.watch(&quot;./src/**/*.css&quot;, [&quot;css:build&quot;])<br>})</pre><p>Our gulpfile contains two tasks, one for building the css files, and the default task for watching the src directory for changes. The watcher will run the build command when anything in the src folder changes. The build task will look for a main.css file in the src directory, and will process that file using the processors specified (in this case partialImport and cssnext). <a href="http://cssnext.io/usage/#browsers">Cssnext will transform the css to be compatible with browsers that have more than 1% market share (according to caniuse database)</a>. The processed css will be output to the ./css directory.</p><p>To run the gulp tasks in our project without installing gulp globally, we need to add some npm scripts to our package.json.</p><pre><em>// package.json</em></pre><pre>...<br>  &quot;scripts&quot;: {<br>    &quot;css:watch&quot;: &quot;gulp&quot;,<br>    &quot;css:build&quot;: &quot;gulp css:build&quot;, <br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>...</pre><p>Now we can run the gulp tasks using npm, $ npm run css:watch and $ npm run css:build.</p><h3>4. Add sample css</h3><p>Create a main.css file in the src directory and add some sample css (as shown below) to check the compilation process.</p><pre><em>// ./src/main.css</em></pre><pre>:root {<br>  --color-blue: #2196F3;<br>  --color-pink: #E91E63;<br>}</pre><pre>@custom-media --md-viewport (min-width: 62em);</pre><pre>.blue-container {<br>  background: var(--color-blue);<br>}</pre><pre><a href="http://twitter.com/media">@</a>media (--md-viewport) {<br>  .blue-container {<br>    background: var(--color-pink);<br>  }<br>}</pre><p>Once you run the gulp task via npm…</p><pre>$ npm run css:build</pre><p>…the above css should successfully compile to this:</p><pre><em>// ./css/main.css</em></pre><pre>.blue-container {<br>  background: #2196F3;<br>}</pre><pre><a href="http://twitter.com/media">@</a>media (min-width: 62em) {<br>  .blue-container {<br>    background: #E91E63;<br>  }<br>}</pre><h3>5. Add js variables and js media queries</h3><p>To go one step further, we can make the variables color-blue and color-pink available for both css files and javascript files. To do this you will have to create a ./src/styleVariables.js, a ./src/mediaQueries.js, and alter ./src/main.css and gulpfile.js.</p><p>To begin with, remove all variable definitions and custom media query definitions from main.css. You should be left with this:</p><pre><em>// ./src/main.css</em></pre><pre>.blue-container {<br>  background: var(--color-blue);<br>}</pre><pre><a href="http://twitter.com/media">@</a>media (--md-viewport) {<br>  .blue-container {<br>    background: var(--color-pink);<br>  }<br>}</pre><p>Next, define your variables in a simple javascript object in ./src/styleVariables.js.</p><pre><em>// ./src/styleVariables.js</em></pre><pre>module.exports = {<br>  &quot;color-blue&quot;: &quot;#2196F3&quot;,<br>  &quot;color-pink&quot;: &quot;#E91E63&quot;,<br>}</pre><p>Then define your media queries also as a simple javascript object in ./src/mediaQueries.js.</p><pre><em>// ./src/mediaQueries.js</em></pre><pre>module.exports = {<br>  &quot;md-viewport&quot;: &quot;(min-width: 62em)&quot;,<br>}</pre><p>Finally, you will have to make the cssnext processor aware of the existence of styleVariables.js and mediaQueries.js. In order to do that you will have to add some code to gulpfile.js. To do this, import the styleVariables.js and mediaQueries.js into your gulpfile and plug them into the cssnext options.</p><pre><em>// gulpfile.js</em></pre><pre>var gulp = require(&quot;gulp&quot;)<br>var postcss = require(&quot;gulp-postcss&quot;)<br>var partialImport = require(&quot;postcss-partial-import&quot;)<br>var cssnext = require(&quot;postcss-cssnext&quot;)</pre><pre><strong>var styleVariables = require(&quot;./src/styleVariables&quot;)<br>var mediaQueries = require(&quot;./src/mediaQueries&quot;)</strong></pre><pre>gulp.task(&quot;css:build&quot;, function() {<br>    var processors = [<br>        partialImport(),<br>        cssnext({<br>            browsers: [&quot;&gt; 1%&quot;],<br>            <strong>features: {<br>              customProperties: {<br>                variables: styleVariables,<br>              },<br>              customMedia: {<br>                extensions: mediaQueries,<br>              }<br>            }</strong><br>        })<br>    ]<br>    return gulp.src(&quot;./src/main.css&quot;)<br>               .pipe(postcss(processors))<br>               .pipe(gulp.dest(&quot;./css&quot;))<br>})</pre><pre>gulp.task(&quot;default&quot;, function() {<br>    gulp.watch(&quot;./src/**/*.css&quot;, [&quot;css:build&quot;])<br>})</pre><p>So now you have a simple postcss processor that allows you to share variables between css and js. For other cool stuff that you can add to this setup, check out the <a href="https://github.com/postcss/postcss#plugins">postcss github repo</a>.</p><p>You can find the code used for this tutorial on <a href="https://github.com/zimrick/postcss-starter-gulp">github</a>.</p><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a>family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>To learn more, <a href="https://goo.gl/4ofytp">read our about page</a>, <a href="http://bit.ly/HackernoonFB">like/message us on Facebook</a>, or simply, <a href="https://goo.gl/k7XYbx">tweet/DM @HackerNoon.</a></blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e77624cc749" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-set-up-a-postcss-pipeline-with-variable-sharing-in-gulp-4e77624cc749">How to set up a postcss pipeline with variable sharing in gulp</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</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 convert and prepare TopoJSON files for interactive mapping with d3]]></title>
            <link>https://medium.com/hackernoon/how-to-convert-and-prepare-topojson-files-for-interactive-mapping-with-d3-499cf0ced5f?source=rss-4cdde420ce94------2</link>
            <guid isPermaLink="false">https://medium.com/p/499cf0ced5f</guid>
            <category><![CDATA[3d]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[topojson]]></category>
            <dc:creator><![CDATA[Richard Zimerman]]></dc:creator>
            <pubDate>Mon, 20 Mar 2017 13:12:52 GMT</pubDate>
            <atom:updated>2020-07-22T10:40:09.078Z</atom:updated>
            <content:encoded><![CDATA[<h4>This tutorial will show you how to convert publicly available shapefiles to <a href="https://github.com/topojson/topojson">TopoJSON</a> to create interactive maps with <a href="https://github.com/d3/d3">d3</a>/<a href="https://github.com/d3/d3-geo">d3-geo</a>.</h4><h4>Note: I have moved my blog to <a href="https://zcreativelabs.com/blog/">zcreativelabs.com/blog/</a>. You can find an updated version of <a href="https://zcreativelabs.com/blog/how-to-convert-and-prepare-TopoJSON-files-for-interactive-mapping-with-d3/">this article</a> and more there. Future articles will only be published there. Please subscribe to the z creative labs newsletter to receive my latest articles in your inbox.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nc6zBGgExmTsHkWM-LjZlg.jpeg" /></figure><p>Iwill show you how to do this without the use of the <a href="https://hackernoon.com/tagged/command">command</a> line so you can get into experimenting with d3 as fast as possible. If you are interested in working with shapefiles and TopoJSON in a more advanced fashion, I suggest you take a look at Mike Bostock’s <a href="https://medium.com/@mbostock/command-line-cartography-part-1-897aa8f8ca2c#.i8ojtzq2z">recent multipart tutorials on command-line cartography</a>.</p><h3>World maps</h3><p>One of the first maps you may want to get your hands on is the world <a href="https://hackernoon.com/tagged/map">map</a>. A great resource for this is <a href="http://www.naturalearthdata.com/downloads">Natural Earth</a>, a public domain map dataset available at 1:10m, 1:50m, and 1:100 million scales. For each scale (level of detail), Natural Earth provides cultural, physical, and raster maps.</p><h4>Step 1 — Getting a map</h4><p>Select your preferred map according to level of detail (1:10m, 1:50m, and 1:100m) and category (cultural, physical and raster). When building maps for the web the level of detail is important as it will impact file size and rendering speed significantly, especially when rendering maps with <a href="https://en.wikipedia.org/wiki/Scalable_Vector_Graphics">SVG</a>.</p><p>To create world maps based on country data (<a href="http://data.worldbank.org/data-catalog/GDP-ranking-table">GDP</a>, <a href="http://data.worldbank.org/indicator/SP.POP.TOTL">population</a>, etc.) you should choose the cultural vectors. In the next steps I will create a TopoJSON map based on the <a href="http://www.naturalearthdata.com/downloads/50m-cultural-vectors/">1:50m cultural vectors Admin 0 countries map</a>.</p><h4><strong>Step 2 — Choosing what to use</strong></h4><p>The downloaded folder will contain a number of files with different extensions such as .dbf, .prj, .shp, and .shx. To convert the shapefile into TopoJSON, you will need the .shp file, as well as a .dbf file (in case it’s available).</p><h4>Step 3 — <strong>Import the shapefiles into mapshaper</strong></h4><p>To convert shapefiles into TopoJSON, you can use <a href="http://mapshaper.org/">mapshaper</a>, a tool for shape simplification and conversion from one geo format to another. It supports Shapefiles, GeoJSON and TopoJSON formats. While mapshaper can be used on the commandline, the online tool also provides a nice visual interface for the simplification process.</p><p>Import the files ending in .shp and .dbf into mapshaper. Make sure that the “detect line intersections” option is checked. You can also check “snap vertices” to fix topology errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BjQpDDi0gG5uxvY1Uk9Nag.png" /><figcaption>Once you import the .shp and .dbf files into mapshaper you should see a preview of the map.</figcaption></figure><h4>Step 4 — <strong>Optional step: Simplify your map</strong></h4><p>The simplify option allows you to adjust the level of detail by dragging a slider. The more you simplify the less precision and detail you will have in your final map. A simplified map will be smaller and often simplifying a map (sometimes even by 50%) will not result in any visible loss of detail.</p><h4>Step 5 — <strong>Exporting your TopoJSON map</strong></h4><p>Once you are happy with the level of detail on your map, export your map as a TopoJSON file. You’re done!</p><h3>Country level and lower administrative level maps</h3><p>World maps are great, but sometimes you want to visualize a more detailed view of a particular region, country, or even a more specific administrative area. If you are doing non-commercial work, one great resource for individual country shapefiles is the <a href="http://gadm.org/country">Global Administrative Areas</a> website.</p><p>The site offers maps in a number of formats. Make sure to choose shapefile as a format when downloading the files from <a href="http://gadm.org/country">here</a>.</p><p>Once you unzip the downloaded files, you will have multiple sets of shapefiles (admin0, admin1, admin2… etc). These represent the different <a href="https://en.wikipedia.org/wiki/Administrative_division">administrative divisions</a>. Using the United States as an example, admin0 would refer to the country, admin1 to the individual states, admin2 to counties etc.</p><p>Once you decide which level to choose, you can repeat steps 2–5, just like with the world map.</p><p>If you have any suggestions for other resources where to get shapefiles, please drop a comment below and I will try to include them into the article.</p><p>Thank you for reading and if have any questions or comments reply below. Happy mapping!</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=499cf0ced5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-convert-and-prepare-topojson-files-for-interactive-mapping-with-d3-499cf0ced5f">How to convert and prepare TopoJSON files for interactive mapping with d3</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>