Text of connector is not centered

Hi Again !

I have another issue with connectors in a very simple configuration:

Place two rectangles, connect them with a straight connector and add some text to the connector.

The text is placed either on the left side of the connector or completely outside of the connector – depend on the order of shapes that it connects to.

When doing the same work from Visio – the text is centered.

See attached – example with a source code and stencil.

I will appreciate a workaround / a stencil with a fixed connector.

Thanks !

Tamir.

Hi Tamir,

Thank you for contacting support. Please note, there is a “Controls” tab under each shape sheet. Its X and Y properties allow to adjust shape’s text position. You can formulate horizontal properties of the connectors before saving into the VDX file format by using Aspose.Diagram API as follows:

[Java]

// set text position

connector1.getControls().get(0).getX().getUfe().setF("(GUARD(EndX-BeginX)/2)");

connector2.getControls().get(0).getX().getUfe().setF("(GUARD(EndX-BeginX)/2)");
// save Visio diagram
diagram.save(“c:\MyOutput1.vdx”, options);

We hope, this helps.

Thanks for your answer.

The solution you suggested works – but only with the exact positioning of the rectangle as in my example.

If I place the rectangles differently, for example:

long rectangle1 = page.addShape(1, 7, 1, 1, "Rectangle");
long rectangle2 = page.addShape(7, 1, 1, 1, "Rectangle");
long rectangle3 = page.addShape(2, 9, 1, 1, "Rectangle");
long rectangle4 = page.addShape(9, 2, 1, 1, "Rectangle");

Then the text is again not centered.

I need a way to keep the text in the center of the connector – in all possible angles.

I took a look at the shape sheet control tab – but unfortunately I don’t understand what value should be given there.

Note again that when using the same connector from within the Visio application – the text is always centered.

Your help will be very appreciated.

Thanks !

Tamir.

Hi Tamir,

Thank you for the inquiry. For the diagonal connector, we need to formulate both horizontal and vertical properties. Please modify your sample code as follows:

[Java]

// set text position
connector1.getControls().get(0).getX().getUfe().setF(“GUARD(Width<em>0.5)");
connector1.getControls().get(0).getY().getUfe().setF("GUARD(Height</em>0.5)”);

connector2.getControls().get(0).getX().getUfe().setF(“GUARD(Width<em>0.5)");
connector2.getControls().get(0).getY().getUfe().setF("GUARD(Height</em>0.5)”);

// save Visio diagram
diagram.save(“c:\MyOutput1.vdx”, options);

Please let us know in case of any further assistance or questions.

Thank you very much Imran, this works perfectly !

I really wish there was more documentation for the code with more usage examples.

For example this code that you provided – I would never know how to do it just by reading the documentation.

I still don't understand exactly what it is doing and what similar options are available.

Note also that the search option in the following page does not work (the top left search) :

http://www.aspose.com/docs/display/diagramjava/Home

Thank you !

Tamir.

Hi Tamir,

Thank you for the details. Please note, in the above sample code, we’re calculating the shape’s text position by taking half of its width and height. Furthermore, the GUARD method prevents unexpected changes to the shape’s appearance. Please refer to the following MSDN help topic: GUARD Function

tamirl1:
I really wish there was more documentation for the code with more usage examples.

Well, it is our common practice to add more help topics in the Aspose APIs Wiki docs. We keep adding help topics from time to time. We have noted your feedback and also planned to review the above use case perspective.

tamirl1:
Note also that the search option in the following page does not work (the top left search) :
Aspose.Diagram for Java|Documentation

You’re right because it concatenates an id with the keyword phrase using AND operator. However, when we removed operator and id from the text box and again clicked on the search button, it works perfectly. So as a workaround, please use this approach. We have forward this issue to our Web team (ticket id: MARKETING-14445). They will fix it soon. We’re sorry for the inconvenience caused.

ControlCollection returns an empty ArrayList.

Shape ifConnectorFalse = new Shape();
long ifConnectorIdFalse = diagram.addShape(ifConnectorFalse, connectorMaster, 0);
ifConnectorFalse.getText().getValue().add(new Txt(“False”));
ControlCollection cc = ifConnectorFalse.getControls();
ifConnectorFalse.getControls().get(0).getX().getUfe().setF("(GUARD(EndX-BeginX)/2)");
ifConnectorFalse.getControls().get(0).getX().getUfe().setF("(GUARD(EndX-BeginX)/2)");

The last two lines throw an IndexOutOfBounds Exception as a result of the empty ArrayList.

Hi Fili,


Thank you for posting here. Please provide us your source Visio diagram along with the complete sample code. We’ll investigate and reply you appropriately.

Attached is a Zip file of the Java project and stencil in the root folder. The output is VDX but the same problem exists regardless of the output format.

In the code, I am just adding two rectangles and then a connector between the two.

When I set the connector text it is offset towards the beginning/start of the connector.

Thanks for looking into this for me.

Ok, I found this solution:


<a href="https://forum.aspose.com/t/6261

Which has the correct solution for this case.

I’m still not clear on why the Props method doesn’t seem to work because I know I will have other cases where I would like to set shapesheet properties.

Thanks

Hi Fili,


Thank you for supplying the details. We’re working over your query and shall get back to you soon.

Hi Fili,

fili.tine:
I’m still not clear on why the Props method doesn’t seem to work because I know I will have other cases where I would like to set shapesheet properties.
Thank you for being patient. Please note, you can add shape properties by initializing Prop class object and PropCollection class offers add method. Please elaborate a bit more about the Props method problem like which shape property are you setting? It’ll help us to be more specific.