As part of an upcoming product that I’m working on (reciprocal.dev if you want to sign up early) I’ve been looking at how to render a user journey map on a webpage.
I’ve created maps before in tools like Miro and Figma but never had to put much thought into the code that sits behind these tools — turns out thanks to Konva (and react-konva) this is actually pretty simple to do.
While this might not be the final solution I use, this approach is a nice introduction into how to use SVG to create the objects in a design program and render them to a canvas in the browser.
Creating the user journey map
For my example user journey I’ll pick using JiffyCV (another app I’ve built) to create and print a CV.
In order to create the map I dragged the screens from the app into Figma and created a vector outline of an iPhone 11 around them by grabbing a .png from the Apple developer website and tracing the outer and inner outlines.
I had some issues with Figma extracting the inner outline from the outer in order to create one path so I used Adobe Illustrator to do this before pasting that into Figma.
I then applied some styling to the device outline so it looked a little less flat and applied this same outline to the other screens.
Linking everything up
The next step was to add connections between the parts of the screen’s UI and where that would take the user, as the example user journey is pretty simple this wasn’t too hard but as things scale up this could get a bit messy.
To create these links I decided on two different connection types; a positive connection that moves the user towards the end goal and a negative connection that takes the user back away from the end goal.
I then used the pen tool in Figma to draw the lines between the screens and added caps to the start and end of the line to indicate the direction of the flow.
I then added rectangles to the line which text would sit on to act as a label to explain what the connection represented.
Recreating the user journey map with Konva
As I like to use React I chose to use the react-konva library but this approach should work for any implementation of Konva.
Building a device screen component
Just like with the user journey map in Figma I decided to focus on the device screens first.
To create the component I exported the device outline object to an SVG file and used the data attribute of the path (called d) to recreate the path in Konva’s Path component.
As Konva follows SVG’s layering convention (top item gets rendered first) I then added the image for the screen above the outline path, this means the outline would be shown on-top of the image.
To load the image into Konva I used the use-image hook which makes it easy to load external images into Konva and rendered that image into Konva’s Image component.
Finally I exported just the outer outline of the device from Figma and added this above the image so I could use this to apply the drop-shadow. Konva, unlike SVG doesn’t require a complex filter set up to achieve a drop-shadow and instead you supply parameters for the shadow as props on the Path component.
In order to make the component easy to re-use I then exposed some props such as image url, outline colour and X & Y positioning and used these to create the set of screens as I had it in Figma.
Building the connections
I followed a similar approach to create the connections, although this required more exporting than the device screen due to the paths being unique but there was only five connections to deal with so this wasn’t too taxing.
I decided that I would have one component deal with both positive and negative connections as the only difference between the two was the styling and the placement of the cap elements.
To create the component, I added a path for which I would use the data attribute from the exported lines to define the connection’s shape and added a circle and triangle for the caps.
I then added some logic to the component to handle different styling and cap placement for the positive and negative lines and added props to allow the lines data, connection type, colour and X & Y position.
As well as ordering the components in the order you want them shown you can also create separate layers in Konva so that you can treat each class of component differently.
I decided to separate the device screens and the connections into separate layers to keep things clean.
With the user journey map rendered in React I can now use this to embed the map into any React website I build (such as further updates to the JiffyCV website) and add some more interactivity to it.
The user journey map is a key concept in the product I’m currently building, reciprocal.dev — a tool that helps you understand the bigger picture of the products you build.