ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Infographics chart. Changing position depending on value.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dean Mallory
Infographics chart. Changing position depending on value.
on Oct 13, 2019 at 1:20:53 pm

Hey everyone,
It is my first post here.
I'm trying to manage horizontal chart in after effects.
I've downloaded a project, where everything is set, except changing bar's position, if its' value becomes bigger than other bars have.
For instance we have:
Bar 1 value (connected to slider) 70

Bar 2 value 50

Bar 3 value 30

So if I change - Bar 2 value to 80, it should look like this:

Bar 2 value 80

Bar 1 value 70

Bar 3 value 30

I've tried this expression (probably will appear in Expressions Code box below(as I said, it's my first post here).

In "arr" I've set the positions for 1st, 2nd and 3rd places. And I need somehow "myNum" to change automatically to 0, 1 or 2, depending on each Bar's value.

For instance: if Bar 2 has highest value, so its' expression will have "myNum = 0" and after 10 seconds, its' value becomes lower than Bar 1, so "myNum" should automatically change to 1.

Here is the example how everything should look like






Thank you for any help.

myNum = 0;
arr = [411, 540, 668];
x = value[0];
y = arr[myNum];
[x, y];


Return to posts index

Dan Ebberts
Re: Infographics chart. Changing position depending on value.
on Oct 13, 2019 at 7:20:35 pm

I'd start with something like this:


arr = [668, 540, 411];
myVal = effect("Slider Control")("Slider").value;
myNum = 0;
for (i = 1; i <= thisComp.numLayers; i++){
if (i == index) continue;
if (thisComp.layer(i).effect("Slider Control")("Slider").value < myVal){
myNum++;
}else if (thisComp.layer(i).effect("Slider Control")("Slider").value == myVal){
if (index < thisComp.layer(i).index){
myNum++;
}
}
}
y = arr[myNum];
[value[0],y]


It assumes that all layers in the comp are participating. If that's not the case, you'll need to adapt the loop to only include participating layers. You need to have an array entry for each one.

Dan



Return to posts index

Dean Mallory
Re: Infographics chart. Changing position depending on value.
on Oct 14, 2019 at 3:11:29 pm



Return to posts index


Dan Ebberts
Re: Infographics chart. Changing position depending on value.
on Oct 14, 2019 at 4:42:17 pm

This should work for the way you have things set up:


arr = [668, 540, 411];
firstLayer = thisComp.layer("Line 1").index;
totalLayers = 3;
ctrl = thisComp.layer("Adjustment Layer 8");
myIdx = index - firstLayer + 1;
myVal = ctrl.effect("Object " + myIdx)("Slider").value;
myNum = 0;
for (i = 0; i < totalLayers; i++){
if (i+firstLayer == index) continue;
if (ctrl.effect("Object " + (i+1))("Slider").value < myVal){
myNum++;
}else if (ctrl.effect("Object " + (i+1))("Slider").value == myVal){
if (index < thisComp.layer(i+firstLayer).index){
myNum++;
}
}
}
y = arr[myNum];
[value[0],y]


You need to apply the same exact expression to each of the the line layers' position property.


Dan



Return to posts index

Dean Mallory
Re: Infographics chart. Changing position depending on value.
on Oct 14, 2019 at 5:33:11 pm

Wooow, it works, thanks!!!!!
One more question. Is it possible to make time delay for 2sec?
Now that position change happens momentally, and it would look more nice if it would look animated, how Lines are changing their positions.


Return to posts index

Dan Ebberts
Re: Infographics chart. Changing position depending on value.
on Oct 14, 2019 at 6:08:52 pm

Definitely possible, but a lot more work. The expression would need to loop back through time, frame by frame, to see if the layer's stacking order had changed in the last 2 seconds. If so, then ease from the old position to the new position. Do-able, but tricky.

Dan



Return to posts index


Dean Mallory
Re: Infographics chart. Changing position depending on value.
on Oct 14, 2019 at 6:22:30 pm

Ok, I will keep it as it is. It's a looot better than it was a few days ago, when I was doing those position changes manually.
Thank you again!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]