Menu

Tutorial 81: Smart Bar Graphs

Joe Clay | Jul 28, 2017

This week, we go over a requested tutorial to lock items to the end of a bar graph. Since this uses a nifty way to determine the lengths of the bars, you can use real world data. Set up your Max Value slider to your largest data point, and set each bar's Value slider to its actual data point. Adjusting your Max Length will adjust how long the bars will display. I would recommend setting up one, and then making a control layer with sliders to link to Max Value, Max Length, and Thickness so you can control all of those parameters of the entire graph at once—especially if you have a lot of data points!

Patrons can find the links to the preset, and a Quiver expression file in the respective folders, but I'll also put up a quick post with direct links!

If you're building this yourself, here are the expressions used in this tutorial:

//Apply to Rectangle Size
val = effect("Value")("Slider");
maxVal = effect("Max Value")("Slider");
maxLength = effect("Max Length")("Slider");
thickness = effect("Thickness")("Slider");
length = val/maxVal*maxLength;
horizontal = effect("Horizontal")("Checkbox");
if(horizontal > 0) {
    [length,thickness];
} else {
    [thickness,length];
}
//Apply to Rectangle Position
horizontal = effect("Horizontal")("Checkbox");
if(horizontal > 0) {
    offset = content("Rectangle 1").content("Rectangle Path 1").size[0]/2;
    [offset,0];
} else {
    offset = content("Rectangle 1").content("Rectangle Path 1").size[1]/-2;
    [0,offset];
}
//Apply to Position point expression control
horizontal = effect("Horizontal")("Checkbox");
x = content("Rectangle 1").content("Rectangle Path 1").size[0];
y = content("Rectangle 1").content("Rectangle Path 1").size[1];
if(horizontal > 0) {
    [x,0];
} else {
    [0,-y];
}

For layers/nulls that you want to connect to the end of the bar, parent them to the bar layer. Then add this expression to the position property:

//Apply to postion property
this.parent.effect("Position")("Point")+value; //set the value of position to 0,0 to lock to the edge of the bar

If you'd like to help support Workbench, check out my Patreon page. Thank you for even considering clicking this link to support what I'm doing. I appreciate it.