After effects: how to make a text follow top of animated bar in bar chart - animation

I want to animate a horizontal bar chart. The bars (squares) start at zero and grow within two easy-ease keyframes from 0 to a specific value. This value is displayed in a text layer. I have set up a slider which goes from zero to the specific value and controls both the text layer (value) and the size of the bar (width of square).
Problem: I want the value to follow the top of the bar chart as in here:
https://www.instagram.com/p/B7_5SOQFrW6/?utm_source=ig_web_copy_link
I tried to set easy-ease keyframes for the text layer too and adjust the values in the diagram editor. Result was too shaky and not nice to look at. Is there a solution with expressions?
source text of text layer for first Bar (1):
Math.round(thisComp.layer("controler").effect("1")("slider"))
source for square (first bar):
temp = thisComp.layer("controler").effect("1")("slider");
he_ = thisComp.layer("controler").effect("height")("slider");
[temp,wi_]
info: width is a slider with which I control the height of the bars.

Check this sample project, with both vertical and horizontal bars: https://url.io/ae_barchart
You can use sourceRectAtTime (like in the sample project), or calculate the position of the top side of your bar, knowing it's height and bottom Y coordinate and then translate it into Composition space from the bar layer`s space, so you can apply it to your Text Layer position.
If you check the position property of "bar_horizontal_text" / "bar_vertical_text" layers you'll see what I mean.
The rest of the setup is extra... just "fooling around". :-)

Related

Adding Text to Objects During Zooming

I am evaluating fabricjs and wondering if you can dynamically add text to shapes while you are zooming. So for example while zoomed out, the shapes are too small to show the text but as you zoom and they get to a certain size, the text can be shown. Or is this part of the base control? In other words if I add text to an object but it cannot be shown because it is too small it automatically hides?

Map image and get pixel color

I have 2 images, with same dimension and same picture, a shape.
In the first image (that I show on screen), the shape is monocromatic, in the second image, shape is mapped with different color.
When I move the mouse, on the image, I want to show different text based on the color mapped on second (hidden) image.
I don't want to map square area, but irregular areas, this is my problem.
For example, when mouse cursor is on head (right image), I get color red on the left image (cached but not visualized) and I put a specific text.
How can I load second image an get pixel color? Gosu doesn't permit to get image info (only width and height).
Any ideas?
At the end I choose this GEM chunky_png, because it has no dependency from other gems or library and it's perfect to my needs:
#map_image = ChunkyPNG::Image.from_file('map_shape.png')
# Test pixel color
if #map_image[mouse_x - #main_image_x, mouse_y - #main_image_y] == ChunkyPNG::Color.rgb(255, 0,0)
# Do something
end

two labels horizontally in tableview?

I would like to have two labels in my tableview.
but the label resize option is disabled.
How to have the two labels horizontally?
Select UIlabel instead of the cell and then you can set Auto resize like follow.
You may need AutoLayout and Custom Tableview Call. Use two different labels, e.g. one for username (left aligned text) and another for garbage text (right aligned text).
Now, set Content Compression Resistance Priority for one of both label, according to your requirement for data visibility when there is long texts in user name.
Look at these snapshots:
Labels with default content compression resistance priority
I changed content compression resistance priority for label blablabla blablabla, from 750 to 749.
Result is:
For more details see Apple document: Setting Content-Hugging and Compression-Resistance Priorities
Drag a horizontal UIStackView from object library and set it's constraints like this inside the cell
//
drag 2 labels inside it and make the distribution .FillEqually
//
Are you sure you have selected Label?
If you know about Layout constraints, it will be easier than this auto resizer.
Label 1==> Set Leading, Top & Bottom constraints to SuperView. Set Trailing constraint to Label2.
Label2==> Set Trailing, Top & Bottom constraints to SuperView. Set Trailing constraint to Label2.
Now, after this, it will show Red error arrow. Now, you have to decide which Lable width is a priority. After deciding, select that Lable and set Horizontal Content Hugging to 251(High) and Comprehensive to 751(High). Also, change lower priority label Content Hugging and Comprehensive to 249 and 749 respectively. Now, Red error arrow will not be shown and in the cell it will show all text in both labels without and cut.
if you want a easy and quick fix for it, implement a stack view inside the tableview cell. You can change the stackview as you want and also you dont have to worry about applying constraints.

How to keep the size of the bar constant on my bar chart

Using dc.js, I want to keep the size of the bar constant on my bar chart.
The number of bars may vary from 1 to 10. Currently when there is only one bar it occupies the complete chart space.
I tried limiting the bar width by adding
MAX_BAR_WIDTH = 250;
but now the ticks and bar position do not match.
Automatic calculation of the domain is a feature which can be turned off. The bar width will be calculated based on the domain and the number of bars which can be shown in that domain.
You should probably set the x domain manually and turn off "elastic":
var minX, maxX; // calculate these however you want
chart
.x(d3.scale.linear().domain([minX, maxX])
.elasticX(false)
Documentation:
coordinateGridMixin.x
coordinateGridMixin.elasticX

Controlling visual stacking order of images and colour bars in Matlab

How do I control the visual stacking order of images and colour bars in Matlab?
I have 6 images that I show on a 2 x 3 grid using subplot. I add colour bars to each of the images, but some of the colour bars appear behind the images, rendering them invisible. In my example, colour bars belonging to image 3 and 5 (counting as in the subplot command) appear behind their respective images.
I do not think I will be able to use the order of axes children objects, as each axes apparently only has one child, i.e. the image, and the colour bar object is child of the figure (Must be the same as its associated axes).
I have also tried uistack (with top for colour bars, and bottom for images), and although it does change appearances, in the end, other colour bars will wind up behind the images. It seems random which ones, for example after uistack on the image and colour bar belonging to subplot 5, the colour bar of subplot 2 will suddenly appear behind its image.
PS I also tried reordering the children of the figure, but they do not change (even with painters render)
It is very strange: When I just prepared the MCVE, the problem did not reproduce, but I have no idea what is different! Maybe a Windows update? Anyway, the original output with the problem is shown here http://i.stack.imgur.com/LJVG2.png, and the prepared example output which looks as it should here http://i.stack.imgur.com/F1LMX.png. So for now, there is no problem...
The code is
function example()
I1=ones(96,96);
I2=ones(96,96)+1;
I3=ones(96,96)+2;
I4=ones(96,96)+3;
I5=ones(96,96)+4;
I6=ones(96,96)+5;
pos=[10 10 12 9];
fig=figure
fig.Units='centimeters';
fig.Position=pos;
set(gcf,'PaperPositionMode','auto');
h(1)=veryTightSubPlot(2,3,1);
imshow(I1,[0,6]);
h(2)=veryTightSubPlot(2,3,2);
imshow(I2,[0,6]);
h(3)=veryTightSubPlot(2,3,3);
imshow(I3,[0,6]);
h(4)=veryTightSubPlot(2,3,4);
imshow(I4,[0,6]);
h(5)=veryTightSubPlot(2,3,5);
imshow(I5,[0,6]);
h(6)=veryTightSubPlot(2,3,6);
imshow(I6,[0,6]);
V=[0.315,0.65,0.97,0.315,0.65,0.97,0.315,0.65,0.97];
for i=1:6
p=get(h(i),'Position');
c=colorbar(h(i),'Axislocation','in','FontSize',8);
c.Color=[0,0,0];
cp=c.Position;
h(i).Position=p;
cp(3)=cp(3)/2;
c.Position=[V(i) cp(2:4)];
end
colormap(parula);
end
function [ax] = veryTightSubPlot(rows, columns,index)
ix = mod(index-1,columns);
iy = floor((index-1)/columns);
pos = [ix/columns,1-(iy+1)/rows,1/columns,1/rows];
ax = axes('ActivePositionProperty','outerposition','Position',pos);
end

Resources