Data Vis 101 - Dynamic Bar Chart Count

To make our Bar Chart rig from THIS TUTORIAL more dynamic, we can add some auto width sizing. This example is a bit on the exaggerated side, but this concept is useful to build rigs that can auto adjust themselves when clients make last minute changes.

This example will be driven by the Title Text Layer’s Width Attribute. Connect that to the Rectangle Shape’s Width attribute. At first this is much too wide, so we need to add an Expression to the Width. Right click and select Add Expression, and type ‘ 0.85’. This will multiply the incoming value by 0.85 to reduce the value. Connect the Text Layer's Width Attribute to the Duplicator's Size Attribute. The spacing may look correct at first depending on how your text is auto formatting, however, technically the duplicated text boxes will be touching each other, so depending on how the text formats it could look weird. Add an expression on that Duplicator Size Attribute ' 1.1' to make the spacing just a bit bigger.

For this next part, think about the max number of rows that you want to account for. For this example I'm accounting for 25 possible rows. You could technically account for hundreds of rows, but it would end up not actually looking good.

Create a Number Range and connect the Data Spreadsheet Utility's Row Count Attribute into the Value Attribute, and flip the Graph as well. Flipping the Graph reverses the values so that the more bars we have, the thinner they will be. Set the Source Minimum to be 1, the Source Maximum to the highest amount of rows that you determined earlier (25). The Output Minimum and Maximum Attributes will have to be figured out by testing different values. To test different values, first temporarily disconnect the Row Count value from the Duplicator's Count Attribute, and connect the Duplicator's Count Attribute into the Number Range's Value Attribute. With this temporary setup, you can manually adjust the Duplicator's Count Attribute to simulate different amounts of bars.

Set the Duplicator's Count Attribute to 2 and then adjust the Number Range's Output Maximum Attribute until it looks good. In my example I found that 260 looked good. Set the Duplicator's Count Attribute to 25 (or whatever maximum number you chose) and then adjust the Number Range's Output Minimum Attribute until it looks good. In my example I found that 65 looked good. Next, adjust the Number Range's Graph Attribute and test numbers between your minimum and maximum to make sure the spacing looks good for any number of bars. In my example I set my Graph to a downward curve from left to right. Your Graph may need to be different, so just play around with it and find what works best.

Once you have these numbers sorted out, you need to reconnect everything to how it was previously. Reconnect the Data Spreadsheet Utility's Row Count Attribute to the Duplicator's Count Attribute, and to the Number Range's Value Attribute.

Obviously there are limitations to this rig when the numbers get pushed too extreme. The text resizing is nice, but in some cases is too small or too large since it's only doing a basic 'shrink', but these concepts are useful to implement if you think your client may change 1 or 2 things last minute.

Dynamic Texture Add an Image Shader to the Rectangle Shape's Fill Attribute, add whatever texture you want to use, and resize it to your liking. Test out different Blend Modes on the texture. For my example I set it to Luminosity and reduced the opacity. Add a Stagger Behavior to the X Offset Attribute (Right Click > Add Behavior > Stagger), and set the Maximum Attribute as you like. You can also do the same on the Y Offset Attribute.

Support me - If you want to support the content I’m making, the easiest way to support is to subscribe and share my Youtube channel. If you are learning Cavalry you can buy some of my tutorial Cavalry files here, and I am also making my own plugins for Cavalry here.

Previous
Previous

Data Vis 101 - Pie Charts

Next
Next

Data Visualization - Simple Bar Charts