## Curvy Timeline Macro

I’ve created a curvy timeline for two of my visualisation in Tableau that you can find here. I did this by following Ken Flerlage blog on how to create a curvy timeline in Tableau. So I decided to re-create Ken’s method in Alteryx and create a dynamic macro that will output a curvy timeline – you can download this here to create your own timeline -> https://bit.ly/2zTvSCb

I’m going to explain how I approached and created this macro:

This macro relies on the user having a Year column this will get updated with the years that the end-user has from the interface tool, where they can select their start and end year. The generate rows tool will create the years from the start year – the end year with this loop expression. The start year and end year is updated through the two numeric up and down interface tools that are connected to the generate rows tool:

Afterwards, we use the record ID to create a field called shape ID this will be used later in the formula tool.

In the bottom stream, we have the generate rows tool that creates 20 points, this is because we want to do data densification so we can create the curves.

The summarise tools retrieve the maximum number of points we then append this back to our points stream, then append this section to our main data source up top. So now every year is duplicated 20 times as you can see in the example below:

We have 2 formulas, which are just 2 values:

The first one is called **Y spacing**: 1. This value represents the spacing between each row.

The 2nd formula is **Year per row** the default value is 20, this is connecting to the numeric up and down interface tool. The end-user will be able to edit this and specify how many years per row they want in their curvy timeline.

We then want to find out what the first year and last year is and have them as separate columns, we do this by using the summarise tool and selecting the minimum year and maximum year. This is then appended back into the data source. We then sort this by Year and Points ascending.

We now reach the formula tool which contains 19 calculations that I will detail below:**First Year**

([Min Year]/[Years Per Row])*[Years Per Row]**Offset**

([First Year]/[Years Per Row])**Row**

We use the FLOOR function to round down the results of this calculation:

(FLOOR([Year]/[Years per Row])-[Offset])+1 **ID**

This field will be used to tell the coordinates which sequence they should go to create the timeline

[Year]*100 + [Points]**Y**

This will be the Y coordinates before we curve it

(FLOOR([Year]/[Years Per Row])-[Offset])*[Y Spacing]**mod1**

Mod([Year], [First Year])**Part 1**

This is part 1 of the X coordinates function

IF [Year] = [Last Year] AND [Points]!= 0

THEN Null()

ELSE Mod([mod1], [Years Per Row])+[Points]/[Number of Points]

ENDIF **Part 2**

This is part 2 of the X coordinates function

IF [Year] = [Last Year] AND [Points]!= 0

THEN Null()

ELSE

[Years Per Row]-1-Mod([mod1], [Years Per Row])-[Points]/[Number of Points]

ENDIF **X**

This is the non curved X coordinates

IF Mod([Row],2) = 1 THEN [part 1]

ELSE [part 2]

ENDIF **Curved**

This formula specifies when the curve should happen

IF [X]>([Years Per Row]-1) THEN

“RIGHT”

ELSEIF [X]<0 THEN

“LEFT”

ELSE

“NONE”

ENDIF **Angle Spacing**

180/([Number of Points]+1)**Angle**

IF [Curved]!=”NONE” THEN

-90+([Points]*[Angle Spacing])

ELSE Null()

ENDIF **Event: **

Event marks which each year is on the timeline – this will be the field that will represent what happened in each year.

IF [Points]=0 THEN

[X]

else Null()

ENDIF **Radians Part 1**

This will form the X curved coordinates

([Years Per Row]-1)+0.5*COS(PI()*[Angle]*(2/360))**Radians Part 2**

0-0.5*COS(PI()*[Angle]*(2/360))

X Curved

IF [Curved] = “LEFT” THEN

[Radians Part 1]

ELSE

[Radians Part 2]

ENDIF

Centre Y

[Y] + [Y Spacing]/2

Y Curved

IF [Curved]!=”NONE” THEN

[Centre Y]+([Y Spacing]/2)*SIN(PI()*[Angle]*(2/360))

ELSE

[Y]

ENDIF **X2**

This X coordinate combines the curved coordinates with the rest of the timelines

IF [Curved] = “NONE” THEN [X] ELSE [X curved]

ENDIF

We will then use the create points tool and specify X2 and Y curved, this will result in the curved timeline: