As existing svg are not always the same and may countains different data structure and organizations, this cannot be a generic tutorial. Creating those maps in coda requires to examinate the svg code, find the most relevant keys & tags, to adapte your replacing strategy.
But at the end, the aim is always the same :
have countries/states/regions, one by <path> tag
inside each of those <path>, having a tag “fill={X}”, in order to apply a specific color to the given path (region, country, etc...).
I tried to make it as clear as possible, but please feel free to reach out for any question you may have regarding this template. And if you just want to use it, back to
Download it, and get the source code (or open it directly from your browser), for example by putting it directly one chrome to get source code. It should start by <svg and finish also by </svg> :
Juste select it all, and bulk paste it directly in a new table, you’ll obtain something with a lot of rows. That’s good.
You will obtain something like this. That looks awfull, but we do not matter, even if there are some blank rows. In my case, this links to the
, that will welcome the code and its transformation.
✅ Step 2 : Prepare your SVG Code to Format() function
The second part will be to prepare your code for the use of Format() function, that will allow us to put any color we want in the US state. If you check to the code in detail, you may see that the map is made with several pathtag, that contains already a fill attribute (but sometimes there is not, so you have to create this attribute). Then in our case, all fill attribute is set to fill:#f9f9f9 that is a lightgrey on the existing map.
We want to replace this to have something more like fill:{X} with X from 1 to the number of states.
Then, we start to check if a row contains this “fill:#f9f9f9” value, with a checkbox column
We make an increment to count from 1 to number of states, checking all the rows before current value that also contains #f9f9f9 in our case. That’s what we are going to use in Format()
Finally, we just need to replace initial code with combination of split/join, to remove #f9f9f9 and replace it by {X} :
At this stage, you know that we want to fill states with color. If you have a small map, you can create country/states by hand and check in which order they are to have the good increment. In our case, we’ll use the svg code again. Once more, have a good look on SVG Code. You may see there is a data-name tag, with all states. If I filter the source code rows with this tag, I obtain indeed the full list of states.
As the SVG is linear, the order of the states are the same than the increment number we used in step 2. Then, we just need to extract the name of the state and the current number using lots of cool coda formula’s 😎.