First off we need a master composition where we later will put everything together. I named it simply Diagram. This requires nothing special. The only thing you should add to it at this point is a Dummy layer or Null object called Controller and apply some Expression controls to it.
Go to the Effects menu and choose the Slider control from the Expression controls category. Your Effect palette will appear with a effect called Slider control. Select it, hit Return and rename it to Spacing horizontal.
Repeat this step and create sliders for Vertical Lines Thickness, Line Thickness and Point Scale.I suggest that you set the values to something other than 0 to avoid later complications with our expressions (the dreaded "Illegal division by zero"). Now choose the Color control from the Effects menu, apply it three times and rename it Line Color, Point Color and Mask Color respectively.
Next we create a composition called Diagram Points. This one holds the actual values of the diagram in the form of the points' Y position value. For reasons of flexibility I created the actual point shape in yet another sub comp called Point Marker. This way you can easily change the appearance of the points ranging from simple dots to cross hairs to complex blinking symbols.
Make sure all elements are white and have proper alpha if you want to use the Point Color from the Diagram composition's Controller layer.. In order to do so, apply the Tint effect to the layer and link its Map White to property to the respective color control in the Diagram composition. Set the Amount to Tint to 100 %. The placement of the points is in part derived from the Spacing horizontal slider in the Diagram comp using an expression as follows:
[comp("Diagram").layer("Controller").effect("Spacing horizontal")("Slider")*2*(index-1), position]This expression will calculate the X position from the slider, but use the keyframed Y position.
Notice the differently colored layer with visibility turned off? This layer is actually only needed for our calculations later on but it must be there. You can animate it just the same as the other layers, but just to be on the safe side you should change its position expression to.
[0, position]You should not forget to connect the point scale to the slider on the Controller layer in the Diagram comp. This will make it easier to balance the point size and line thickness.
In the next step we create a composition called Diagram Lines in which we will put our lines that connect our points. This is done using a 100x100 pixels solid and some expressions. All that will be required later is to clone the Line layer to match the number of points.
The most important expressions are the position and rotation. To get proper results for those values you need to place the layer's anchor point on its left most edge and at half the height of the layer. For the position use the following expression:
comp("Diagram Points").layer(index).positionThis will place a line at each point. Since the layer does not yet know about its target point it should connect to it will be perfectly horizontal. In order to change this use
diffX=position-comp("Diagram Points").layer(index+1).position;on the rotation parameter. What does this expression do? It takes the layer's position and calculates the difference to the position of the next point (which is the target point). Then those values are used to calculate the arcus tangens which is then converted into an angular value.
You will notice that, depending on your Spacing horizontal value the Line layer will not reach or overshoot the next point. All that is required to fix this, is some simple calculations on the scale parameter.
thickness=comp("Diagram").layer("Controller").effect("Line Thickness")("Slider");This is a more complex calculation using Pythagoras' rule (yeah, it was late when I first put my mind on this project ;o) ) but you surely will prefer
thickness=comp("Diagram").layer("Controller").effect("Line Thickness")("Slider");In one go we also connected the Y scale of the solid to act as the line thickness. All that is now left to do is to apply the Tint effect to the layer and connect it to our Controller just as we did with our points.
Basically we now already have a usable diagram if we put our Diagram Points and Diagram Lines compositions in the main Diagram composition. It does not look very exciting, though. So once more unto the breach.
First off we want to have some sort of fill below our curve. How do we do that? Well, we could use a layer with a mask and trace our lines. Isn't that boring? It also limits our flexibility once we decide to change something. So we need a better solution. And here it comes!
Create a new composition named Diagram Mask and add a solid to it. Apply the Corner Pin effect to this layer.
The Corner Pin effect is originally intended to be used in combination with tracking data. This way you could for instance replace footage on a TV screen and match the perspective or apply a different logo to a car.
Instead of using tracking data, we will feed the position values of the four corners with data from our points. The expressions are as follows:
[comp("Diagram Points").layer(index).position-2,comp("Diagram Points").layer(index).position-2]Upper Right:
[comp("Diagram Points").layer(index+1).position+2,comp("Diagram Points").layer(index+1).position+2]Lower Left:
[comp("Diagram").layer("Controller").effect("Spacing horizontal")("Slider")*2*(index-2)-1,thisComp.height]Lower Right:
[comp("Diagram").layer("Controller").effect("Spacing horizontal")("Slider")*2*index+2,thisComp.height]I added 2 pixels to each value so the layers would overlap once I cloned them. This avoids potential problems with the alpha because the Corner Pin effect will create antialiased edges that do not line up exactly. This is a minor drawback, but wont be noticeable since the unclean areas will be covered by the lines and points. Color the layer to your taste or once more use the Tint effect as I did.
Potential viewers like to have some reference on how they should interpret a diagram, so it's a good idea to add some rulers or grid style elements. Take a look at how I created some of those effects in the supplied project file or create your own look. It's really just a matter of cleverly combining effects or once more cloned layers that are tied to expressions.
You could come up with something like that:
Feel free to ask questions regarding this tutorial in the After Effects forum at Creativecow.net
Please visit our forums at Creativecow.net if you found this page from a direct link.