In vis-network, how to align nodes on the same vertical position? - vis.js

This problem is driving me crazy
My requirement is simple, I want to put node x and y on the same vertical position. I've looked at this and this question, the answer seem to suggest manually setting the x position. However I don't really want to do that, is there a better way?
https://jsfiddle.net/laike9m/dg8Lzt7c/31/
The following graph is what I currently have:
Ideally, I want the left part unchanged, but y is placed on the same vertical position with x:

Join them with a transparent edge:
{
"from": "x",
"to": "y",
"color": "rgba(0, 0, 0, 0)"
}

Related

Draw circle with an EllipsePolygon in ImageSharp

I've just started using ImageSharp to draw images. The documentation on Six Labors web page is clean, but there is no examples to find anywhere about ImageSharp. So I struggle from time to time, all by myself :)
I want to draw a circle with PathBuilder and a given position in x and y as a center point, and a given radius.
I tried to use an EllipsePolygon where you can define x, y, and radius. And then I wanted to draw it in my PathBuilder but PathBuilder only has "AddEllipticalArc" what I can find.
So I have used this function to draw circles instead, like this for example:
pb.AddEllipticalArc(new Point(300, 200), 10, 10, 0, 0, 360);
Is there a better way to draw circles? Or am I supposed to use AddEllipticalArc?
Bonus question: I also have to draw Arcs with only a centerPoint, startPoint and endPoint given to me. But I guess I have to translate these given points and calculate the startAngle and sweepAngle myself. What could be the easiest alternative for this?

Matrix transformation - rotate about object origin

With the following Code i move a object along the x axis, and rotate it relative to its position every frame.
quad.getModel().setIdentity();
quad.getModel().scale(new Vector3f(10, 10, 10));
quad.getModel().translate(new Vector3f(x, 0, 0));
quad.getModel().rotate(x * 2, new Vector3f(0, 1f, 0f));
Now i want to remove the model.setIdentity(). How i can achieve the same thing now?
Okay, i figured out the solution my self.
I just had to rotate it back every frame, then move it, than rotate it back.
The reason is, that rotation changes the object-relative axis. So translating
also moves along this new axis. Moving along the origin, or, the "old" axis,
just needs to reset the rotation before that.

How does masking work in C4?

I've set up a shape and an image that I'd like to mask my shape with. I set both their centers to the center of the canvas and then I wrote:
shape.mask = img;
But this gives me very strange results. The shape appears to be masked... sort of... the only part that shows up is the bottom right corner, the left half and the top half are cut off.
I also tried with two images, and with two shapes. Neither seems to work.
Am I missing a step? Perhaps the image I'm trying to mask with doesn't have any alpha values (I'm guessing here, I saw it mentioned in another question that they have to be images with alpha values and they mentioned .png files, so that's what I used)?
When I tried with two shapes, I tried setting the alpha value of the fill of the shape I wanted to mask with to 0.5 and 0.0 and also just setting the fillColor to Nil... still nothing.
I also (in a desperate last attempt) tried the method described here: Mask a view in Objective-C but I'm not very good with objective-c on its own so that didn't work either.
What is the correct way to mask in C4?
You're masking the right way.
What's going on is that an object's mask must be positioned based on the coordinate space of the object itself. When you add a subview to an object, it gets positioned relative to the object's {0,0}.
The following code will work and show you 2 things.
First, the masking shape is positioned to the center of the object, and NOT the center of the canvas:
s.center = CGPointMake(m.width/2,m.height/2);
Second, when you touch the canvas the animation will trigger the mask to move to the "center" coordinate of the canvas, but you'll notice that it goes further off. This is because it counts its position from the origin of the image.
#implementation C4WorkSpace {
C4Image *m;
C4Shape *s;
}
-(void)setup {
m = [C4Image imageNamed:#"C4Sky"];
s = [C4Shape ellipse:CGRectMake(0, 0, m.height, m.height)];
m.center = self.canvas.center;
s.center = CGPointMake(m.width/2,m.height/2);
m.mask = s;
[self.canvas addImage:m];
}
-(void)touchesBegan {
s.animationDuration = 1.0f;
s.center = self.canvas.center;
}
#end

Rectangle in a grid - I need help on the edge cases

The problem I'm trying to solve is the following:
In a 2-D space, Given a grid size and a rectangle, calculate the grid cells
occupied (partially or totally) by the rectangle.
By "Grid size" I mean something like: "A 16x16 grid" or "A 32x32 grid". All grids are centered on the origin of coordinates (0,0).
The rectangle is defined by 4 floats: the left, top, width and height.
The result of this operation is always a rectangle. I'd like to return the coordinates of top-left cell (i.e. 0,0) followed by the number of cells the retangle occupies to the right and down (a bit like width and height, but for cells)
So far I've been able to write an algorithm that mostly works. What it does first, is calculating the cell coordinates where a single dot resides in the grid. Then, given the rectangle, I calculate where its top-left and lower-rights corner are on the grid, and then it's a simple substraction:
-- given a world coordinate, return the coordinates of the cell that would contain it
local function _toGrid(wx, wy)
return math.floor(wx / __cellSize), math.floor(wy / __cellSize)
end
-- given a box in world coordinates, return a box in grid coordinates that contains it
-- returns the x,y coordinates of the top-left cell, the number of cells to the right and the number of cells down.
local function _toGridBox(l, t, w, h)
local gl,gt = _toGrid(l, t) -- top left grid corner
local gr,gb = _toGrid(l+w, t+h) -- bottom-right grid corner
return gl, gt, gr-gl+1, gb-gt+1 -- return top,left,cells to the right, cells to bottom
end
Notes:
The source code is Lua, but I will accept solutions in any programming language, as long as they are intelligible.
The y-coordinate goes "down when increasing"; that's how a lot of screen systems work. I don't think that's significant for this problem, but don't get confused by that).
In a 16x16 grid, a rectangle on 0,0, with width=10 and height=20, gr will be 0 and gt 1, so _toGrid will return 0,0,1,2 (1 row, two columns, on the 0,0 cell).
The problem happens when the rectangle "touches" (not crosses) either the lower or right side of one cell from inside. In that case, _toGrid returns "one more cell" than I'd like it to.
For example, if I move the previous rectangle to the left 6 pixels (so it is on 10,0), it will be "touching" the left-side border of its containing grid, which goes from 0 to 16. Then gr will be 1, and the returned data will be 0,0,2,2.
I'd like to avoid this, if at all possible. For a rectangle going to 16 "from the left", I'd like it to remain on the first grid cell. I'd like it to begin "occupying the next cell" as soon as it surpasses 16 - for example when it's at 16.00000001 .
Also, notice that this only applies to the right and bottom sides. The left and upper sides work as I want them to. For example, a rectangle whose left coordinate is 16, should appear on the "second cell to the right", not on the first.
I'm sure the solution isn't complicated, but I've been thinking about this for a while now and I don't seem to find it. Any help will be appreciated.
For the bottom and right hand side, you need to use ceil instead of floor. I don't know any Lua, so this may not be syntactically correct, but you would want something along these lines:
local function _toGridBox(l, t, w, h)
local gl = math.floor(l / _cellSize)
local gt = math.floor(t / _cellSize)
local gr = math.ceil((l+w) / _cellSize)
local gb = math.ceil((t+h) / _cellSize)
return gl, gt, gr-gl, gb-gt -- return top,left,cells to the right, cells to bottom
end
Your problem, essentially, is that the function _toGrid is the wrong abstraction for your purpose because it always uses floor. Apparently, you locked yourself into using that abstraction, which then made it difficult to come up with the right answer.

How to get actual position of qtoolbar?

I am just trying to get the actual x, y values or Qt::ToolBarArea area of my QToolBar.
Is there any function to get it so?
Check out QWidget::mapTo and associated functions. I reckon you want to do something like:
yourWidget->mapToParent(0, 0) - maps the top left corner of yourWidget (i.e. 0, 0) to the coordinate system of its parent widget.

Resources