Because rotation at 90 or 270 degrees transposes x and y, and for such wide node it brings it very far from where you'd like it. You are way too fixed on the 270-degree rotation case where the rectangle is still aligned to the coordinate system's axes. Even then what you get after rotating node.Bounds around its center will have X and Y values transposed, if the center is at 0,0, and then with some offset when it's not in the general case. Here's some code that should give you a better idea -
for (int i = 0; i < 4; i++)
{
var coordinates = new RectangleF(20 + i * 40, 20, 30, 10);
var node = diagram.Factory.CreateShapeNode(coordinates);
node.RotationAngle = 0 + i * 30;
node.Text = node.RotationAngle.ToString();
node.TextFormat.LineAlignment = StringAlignment.Far;
node.RotateText = true;
var rotatedCoordinates = node.GetRotatedBounds();
rotatedCoordinates.Inflate(1, 1);
var rotatedFrame = diagram.Factory.CreateShapeNode(rotatedCoordinates);
rotatedFrame.Brush = rotatedFrame.ShadowBrush = new SolidBrush(Color.Transparent);
rotatedFrame.Pen = new Pen(Color.Black) { DashStyle = DashStyle.Dot };
var pinCoordinates = new RectangleF(node.GetCenter(), new SizeF(0, 0));
pinCoordinates.Inflate(0.5f, 1);
var pin = diagram.Factory.CreateShapeNode(pinCoordinates);
pin.Pen = new Pen(Color.Red);
pin.Shape = ArrowHeads.Arrow;
pin.RotationAngle = 150;
}
So all these nodes are on same Y position, but rotation brings their apparent positions to different Y values. You better think of Bounds as a structure specifying a pin position + width and height, where the rectangle's center is the pin position. RotationAngle rotates around that pin, i.e. around Bounds center. In order to align vertically the rightmost node from the image to the leftmost one, you'd have to translate the rotated frame and rotate back to find the actual position for its pin (and also width + height). So you can combine the code for finding that from my older post with your onNodeCreated handler, and it will place the resized container at expected apparent Y -
function onNodeCreated(sender, args)
{
var diagram = sender;
var node = args.getNode();
if (node.getRotationAngle() == 270)
{
var wantedRect = new Rect(
diagram.bounds.x, node.bounds.y, diagram.bounds.width, node.bounds.height);
var unrotated = Utils.rotateRect(wantedRect, wantedRect.center(), -270);
node.setBounds(unrotated);
}
}
Regards,
Slavcho