<?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 Jan Zak on Medium]]></title>
        <description><![CDATA[Stories by Jan Zak on Medium]]></description>
        <link>https://medium.com/@zakjan?source=rss-72aa7be0a59f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*u69bgkjV7yP6jEe4Zvd9cA.jpeg</url>
            <title>Stories by Jan Zak on Medium</title>
            <link>https://medium.com/@zakjan?source=rss-72aa7be0a59f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 14:25:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zakjan/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[Styling Ocean Depth Data in Mapbox Studio]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/nightingale/styling-ocean-depth-data-in-mapbox-studio-c03f71ba6a2a?source=rss-72aa7be0a59f------2"><img src="https://cdn-images-1.medium.com/max/2048/1*iw-pLWDLiJbtviQ8OW6RuQ.png" width="2048"></a></p><p class="medium-feed-snippet">How to obtain, process, and visualize bathymetry data</p><p class="medium-feed-link"><a href="https://medium.com/nightingale/styling-ocean-depth-data-in-mapbox-studio-c03f71ba6a2a?source=rss-72aa7be0a59f------2">Continue reading on Nightingale »</a></p></div>]]></description>
            <link>https://medium.com/nightingale/styling-ocean-depth-data-in-mapbox-studio-c03f71ba6a2a?source=rss-72aa7be0a59f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c03f71ba6a2a</guid>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[bathymetry]]></category>
            <category><![CDATA[mapbox]]></category>
            <category><![CDATA[mapbox-studio]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Jan Zak]]></dc:creator>
            <pubDate>Wed, 27 May 2020 13:01:01 GMT</pubDate>
            <atom:updated>2020-08-04T17:07:41.933Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Scale up your D3 graph visualisation, part 2]]></title>
            <link>https://medium.com/neo4j/scale-up-your-d3-graph-visualisation-part-2-2726a57301ec?source=rss-72aa7be0a59f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2726a57301ec</guid>
            <category><![CDATA[graph-visualization]]></category>
            <category><![CDATA[pixijs]]></category>
            <category><![CDATA[webworker]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[webgl]]></category>
            <dc:creator><![CDATA[Jan Zak]]></dc:creator>
            <pubDate>Thu, 19 Mar 2020 10:08:22 GMT</pubDate>
            <atom:updated>2020-04-26T20:36:56.406Z</atom:updated>
            <content:encoded><![CDATA[<h4>WebWorker layout and PIXI.js rendering performance improvements</h4><p>In the <a href="https://medium.com/neo4j/scale-up-your-d3-graph-visualisation-webgl-canvas-with-pixi-js-63f119d96a28">first part</a>, I started with a usual D3-based graph visualisation and replaced SVG rendering code with PIXI.js, a 2D drawing library, which uses WebGL with automatic fallback to Canvas. In this part, I’m going to present to you a few further possible performance improvements. I have also expanded available configuration with multiple layouts and sample graph generators, so that layout performance and visual quality can be compared.</p><p>The presented techniques are available in the <a href="https://observablehq.com/@zakjan/force-directed-graph-pixi">live demo</a>, feel free to tinker with the code.</p><figure><a href="https://observablehq.com/@zakjan/force-directed-graph-pixi"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_BJ22JEoPQZNnp--7cVs2A.png" /></a><figcaption>Live demo</figcaption></figure><h3>WebWorker layout</h3><p>Although JS supports async programming thanks to the event loop pattern, this is not a true parallelism. JS is a single-threaded language.</p><p>Any long-running function delays running other functions, potentially freezing UI responsiveness, because it affects user input event handlers as well. Graph layouts belong to this category, they are CPU-intensive algorithms with usual time complexity <em>O(n log n)</em> or worse.</p><p>This situation improved with the introduction of WebWorkers, a native browser feature that enables us to run code in a parallel background thread. WebWorker code doesn’t have access to the main thread global scope. Communication between threads happens strictly via message passing with postMessage method, which either clones the message payload, or transfers message ownership to WebWorker thread, so that it can’t be used by the main thread anymore. Note that this avoids the need for thread-safe data structures known from other languages. However, in the case of larger messages, it is recommended to strip the message only to fundamental properties or use the ownership transfer method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WWkznxJlP7GA3aBE7XMobQ.png" /><figcaption>WebWorker flow (<a href="https://medium.com/@lahin31/introduction-of-web-worker-3c28a8d8d9f5">source</a>)</figcaption></figure><p>If you use a build tool in your frontend development flow, such as Webpack or Rollup, take note that providing code to WebWorker thread is very different. This code can’t be part of the usual JS bundle, but it must be referenced as a standalone JS file. Therefore you’ll need to specify a separate main entry point in the build tool to get a separate bundle with dependencies.</p><p>For simple use cases, there is a shortcut. It is possible to store the code in a string in an in-memory blob, where you can import dependencies from external files by importScripts function and run this blob as a virtual file.</p><p>Combining all these tips, here is a minimal function running <a href="https://github.com/d3/d3-force">d3-force</a> layout inside WebWorker. It can be called from the main thread as any other usual function returning a promise:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e106be67ca8429f82d544ba33e0a0f2/href">https://medium.com/media/7e106be67ca8429f82d544ba33e0a0f2/href</a></iframe><h3>Culling and levels of detail</h3><p>There was a significant rendering performance issue in the previous demo. With many nodes, the visual experience during mouse interaction with the graph was sluggish, FPS was dropping to unacceptable low numbers. Measuring with <a href="https://spector.babylonjs.com/">Spector.js</a> helped me a lot to find the bottlenecks. The good rule of thumb is to limit the number of GPU calls and the number of active textures in GPU memory. Reusing textures to draw similar objects is highly preferable. In the rest of this article, I’m going to focus on reducing these numbers.</p><p>Culling is the process of removing objects that lie entirely outside of the viewport. It improves performance for zoomed-in views, where only a few graph elements are visible. I have implemented it with <a href="https://github.com/davidfig/pixi-cull">pixi-cull</a> library. However, it doesn’t help with zoomed-out, full graph views, which are also desired in graph viz.</p><p>For improving the performance of the full graph view, I have employed a technique of displaying different levels of detail by zoom level in 4 steps. When you start with a zoomed-out graph, only nodes as color circles are visible. When zooming in, first edges appear, then node icons, then node labels. This reduces the number of draw calls significantly for large graphs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TzqxaNu9traFSAAFx-xoCQ.gif" /><figcaption>Levels of detail</figcaption></figure><h3>Sprites</h3><p>When you start digging into how to optimize PIXI.js rendering, the most frequent suggestion is to use sprites wherever possible. Sprites are simple 2D objects with texture. The advantage is that PIXI.js batches drawing multiple of them into with a single WebGL shader.</p><p>Therefore I have replaced all PIXI.Graphics instances by pre-rendering into <a href="https://pixijs.download/dev/docs/PIXI.Texture.html">PIXI.Texture</a>, and later rendering it with <a href="https://pixijs.download/dev/docs/PIXI.Sprite.html">PIXI.Sprite</a>.</p><h3>Text rendering</h3><p>Remember that WebGL is primarily a low-level 2D API for GPU-accelerated drawing of triangles. It lacks high-level methods like fillText from Canvas, which allows simple drawing of text by any font available on the computer (including imported <a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Web_fonts">web fonts</a>). Generic support for rendering text is a massive feature on its own. There is an excellent write-up <a href="https://css-tricks.com/techniques-for-rendering-text-with-webgl/">Techniques for Rendering Text with WebGL in Three.js</a> I highly recommend to read about all possible solutions and font preprocessing. PIXI.js provides some of them ready-to-use so that you don’t have to implement the solutions manually.</p><h4>PIXI.Text</h4><p>Previously I used <a href="https://pixijs.download/dev/docs/PIXI.Text.html">PIXI.Text</a>. It is the most straightforward method, which doesn’t need any font preparation. You can render any font available, same as with rendering with Canvas. Internally it renders the full desired text string into Canvas and uses it as a texture for a sprite.</p><p>However, there is a severe performance drawback. Each PIXI.Text instance obviously produces a new texture, leading to many draw calls if there are lots of texts on the scene.</p><h4>PIXI.BitmapText</h4><p>I have switched to <a href="https://pixijs.download/dev/docs/PIXI.BitmapText.html">PIXI.BitmapText</a>. It expects you to provide a font preprocessed into an image (also called texture atlas) with all supported characters + <a href="http://www.angelcode.com/products/bmfont/doc/file_format.html">font descriptor file</a> defining coordinates of each character in the image (<a href="https://gist.github.com/zakjan/b61c0a26d297edf0c09a066712680f37">example</a>). The image is used as a shared texture, and any text is rendered by drawing separate characters next to each other from the texture with <a href="https://www.khronos.org/opengl/wiki/Transparency_Sorting#Alpha_test">alpha test</a> 0.5.</p><p>There is one caveat of bitmap format to keep in mind. The bitmap image must be pre-rendered with the maximum resolution used for the text font size, potentially even larger if you allow your users to zoom in. Scaling the text beyond pre-rendered resolution produces pixelated text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*RSNgA-_snLMA8OEZHF6b2w.png" /><figcaption>Bitmap texture atlas</figcaption></figure><h4>Distance Fields</h4><p>The last and most flexible technique uses a font preprocessed into a distance field and stored in Signed Distance Field (SDF) or more recent Multi-channel Signed Distance Field (MSDF).</p><p>In bitmap format, each pixel encodes only if the pixel is inside or outside the shape. In distance fields, each pixel encodes the distance from the shape edge. The significant benefit of distance fields is that you can scale from low resolution to higher resolutions for rendering with no pixelation.</p><p>SDF format encodes the distance in shades of gray. If you open SDF image, don’t get confused that the image looks blurry, it’s only the effect of that 50% gray effectively means the shape edge, &gt;50% means inside, &lt;50% means outside.</p><p>When you scale SDF text a lot, you start noticing chipped or rounded corners instead of sharp corners. To fix this, either you can increase the resolution of the pre-rendered SDF image, or switch to MSDF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*xg6GLmZh-AKvDGHT_hSthw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*6M6LsW0pl2SgyWzZij08HQ.png" /><figcaption>SDF texture atlas and scaling (<a href="https://computergraphics.stackexchange.com/questions/306/sharp-corners-with-signed-distance-fields-fonts/2151#2151">source</a>)</figcaption></figure><p>MSDF format encodes the distance in all three color channels, and for each pixel, all color channels participate in the decision that the pixel is inside or outside of the shape. If you open MSDF image, it looks really funky, but don’t be afraid. There are <a href="https://computergraphics.stackexchange.com/questions/306/sharp-corners-with-signed-distance-fields-fonts/2151#2151">clever tricks behind it</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*oC6f_l0ExyBccNKwIHasuw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*uPSliUqGCD_fywv3GylOFA.png" /><figcaption>MSDF texture atlas and scaling (<a href="https://computergraphics.stackexchange.com/questions/306/sharp-corners-with-signed-distance-fields-fonts/2151#2151">source</a>)</figcaption></figure><p>There is <a href="https://github.com/PixelsCommander/pixi-sdf-text">pixi-sdf-text</a> plugin for PIXI.js implementing text rendering from both SDF and MSDF formats. Unfortunately, it supports only PIXI.js v4. It hasn’t been upgraded to PIXI v5 yet. This is an opportunity to be contributed by the first engineer who strongly needs it :)</p><h3>Final words</h3><p>There are many ways of how the performance of a custom graph visualisation can be improved. This is an excerpt of techniques I have added to my <a href="https://observablehq.com/@zakjan/force-directed-graph-pixi">live demo of graph visualisation in PIXI.js</a>, and I’m exploring further options.</p><p>Of course, if your use case or engineering capacity doesn’t allow you to spend time with low-level graphical rendering, a great choice is ready-to-use commercial libraries (<a href="https://cambridge-intelligence.com/keylines/">Keylines</a>, <a href="https://doc.linkurio.us/ogma/latest/">Ogma</a>, <a href="https://www.yworks.com/products/yfiles-for-html">yFiles</a>, in alphabetical order). They already solved all the complexities, expose high-level methods that can be used immediately, and provide quick support.</p><p>Also, I have recently switched to continue my journey as an independent consultant. If you have an interesting problem to solve, don’t hesitate and drop me a line!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2726a57301ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/neo4j/scale-up-your-d3-graph-visualisation-part-2-2726a57301ec">Scale up your D3 graph visualisation, part 2</a> was originally published in <a href="https://medium.com/neo4j">Neo4j Developer Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scale up your D3 graph visualisation]]></title>
            <link>https://medium.com/neo4j/scale-up-your-d3-graph-visualisation-webgl-canvas-with-pixi-js-63f119d96a28?source=rss-72aa7be0a59f------2</link>
            <guid isPermaLink="false">https://medium.com/p/63f119d96a28</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[graph-visualization]]></category>
            <category><![CDATA[pixijs]]></category>
            <category><![CDATA[webgl]]></category>
            <dc:creator><![CDATA[Jan Zak]]></dc:creator>
            <pubDate>Thu, 19 Sep 2019 21:35:54 GMT</pubDate>
            <atom:updated>2020-03-19T11:10:28.997Z</atom:updated>
            <content:encoded><![CDATA[<h4>WebGL &amp; Canvas with PIXI.js</h4><p>Do you use <a href="https://d3js.org/">D3</a> for data visualisation and either you are considering, or already using it also for graph visualisation? Keep in mind that D3 uses SVG for rendering. While it is the easiest to work with API for drawing 2D graphics on the Web, its downside is that the browser keeps the entire DOM tree of vector elements in memory, even for elements that are effectively invisible. You might hit a performance drop with complex graphics, specifically for graph visualisation when you try drawing graphs larger than ~1000 nodes, or even less with complex SVG effects.</p><p>At this time you should reconsider why you run into performance issues in the first place. Why do you have such complex graph to draw, what is the purpose of the visualisation, and how is user going to interact with it? Sometimes too much information can result into meaningless graphics, if user doesn’t know what to do with it.</p><p>Since you’re still reading, you probably have reasons? Ok, I warned you :-)</p><p>In this article we are going to explore together how you can scale up your existing D3 graph visualisation. Another solution could be resorting to a commercial library, but we are not going to cover it here, because it could mean significant changes to your existing application. However if you are starting a new project, all of these libraries are great to work with and we suggest you evaluate them (listed in alphabetical order):</p><ul><li><a href="https://cambridge-intelligence.com/keylines/">Keylines</a> by Cambridge Intelligence,</li><li><a href="https://doc.linkurio.us/ogma/latest/">Ogma</a> by Linkurious or</li><li><a href="https://www.yworks.com/products/yfiles-for-html">yFiles</a> by yWorks.</li></ul><p>Canvas HTML element has a few available <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#Parameters">drawing APIs</a>, with different performance and browser support. The most advanced, WebGL, uses GPU for hardware-accelerated drawing. However this means that for the best coverage of drawing size, browser and hardware compatibility you would need to implement drawing code multiple times, for each chosen API separately.</p><p>Another complexity arises with mouse interaction, because with Canvas you can only detect the mouse position and color at the position. Detecting which element is at the position can be implemented for example by rendering a <a href="http://www.datamake.io/blog/d3-canvas-full">separate hidden canvas</a>, where color designates the element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*Yb4TecdI5YHFjzfnDUM1-A@2x.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*VwNxtWXXy81cDued4NNgVQ@2x.png" /><figcaption>Visible canvas / Separate hidden canvas for detecting clicked element</figcaption></figure><h3>PIXI.js</h3><p>Enter <a href="https://www.pixijs.com/">PIXI.js</a>, a 2D drawing library. It allows you to express a declarative render tree, similarly to SVG. However the render tree is processed in the JavaScript engine only, instead of in the DOM as in SVG. The browser only receives drawing instructions, as if you would write Canvas drawing code yourself.</p><p>PIXI.js uses WebGL by default if available, and supports fallback to Canvas otherwise. Mouse interaction complexities are also abstracted away from the developer. No wonder that this library has a <a href="http://www.html5gamedevs.com/forum/15-pixijs/">heavily active community</a> related to development of browser-based games.</p><h3>Implementation</h3><p>We are going to start by forking the <a href="https://observablehq.com/@d3/force-directed-graph">original D3 graph visualisation example</a>, which uses <a href="https://github.com/d3/d3-force">d3-force</a> for a force-directed layout.</p><p>Replacing SVG rendering with PIXI.js involves creating an instance of <a href="https://pixijs.download/dev/docs/PIXI.Application.html">PIXI.Application</a> and adding children to it, according to the desired style and interaction. Follow <a href="https://pixijs.download/dev/docs/index.html">API docs</a> for details, their <a href="https://github.com/pixijs/pixi.js/wiki/v4-Performance-Tips">Performance Tips</a> are also helpful. We can add richer features such as labels, font icons, hover effect, zoom &amp; drag viewport and a simple toolbar. Anything is possible!</p><p>A <a href="https://observablehq.com/@zakjan/force-directed-graph-pixi">live demo</a> of this exercise shows there is almost nothing left from the original code which was related to SVG rendering, it was replaced with code for a different rendering target. PIXI.js rendering runs on top of D3, which stays only for computing graph layout.</p><figure><a href="https://observablehq.com/@zakjan/force-directed-graph-pixi"><img alt="" src="https://cdn-images-1.medium.com/max/664/1*1ZxYqwFCTaARerKSS_deFA@2x.png" /></a><figcaption>Live demo</figcaption></figure><h3>Summary</h3><p>We have uncovered a hidden strength of D3. A few years ago, D3 was refactored with modularity in mind. A single monolithic library was split into many composable single-purpose libraries, which can be used also standalone. If you need to increase performance of your existing D3 data visualisation, you can replace rendering by another drawing library such as PIXI.js, while still using D3 for underlying layout computation.</p><p>Further performance improvement can involve moving layout computation to a separate WebWorker thread, so that it doesn’t block UI from other actions. I can see <a href="https://medium.com/neo4j/scale-up-your-d3-graph-visualisation-part-2-2726a57301ec">Part 2</a> of this article coming soon ;-)</p><p>Get in touch with <a href="https://graphaware.com/contact/">GraphAware</a> to see how we can help you with performant graph visualisations!</p><p><em>This article was originally published on September 5, 2019 at </em><a href="https://graphaware.com/visualization/2019/09/05/scale-up-your-d3-graph-visualisation-webgl-canvas-with-pixi-js.html"><em>GraphAware blog</em></a><em>, and is republished here with permission.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63f119d96a28" width="1" height="1" alt=""><hr><p><a href="https://medium.com/neo4j/scale-up-your-d3-graph-visualisation-webgl-canvas-with-pixi-js-63f119d96a28">Scale up your D3 graph visualisation</a> was originally published in <a href="https://medium.com/neo4j">Neo4j Developer Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>