We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Text Align (textAlign) Not Working

Thread ID:

Created:

Updated:

Platform:

Replies:

118174 Feb 8,2015 02:59 PM Feb 9,2015 11:26 PM ASP.NET Web Forms 4
loading
Tags: Diagram
Jim Jacobs
Asked On February 8, 2015 02:59 PM

Hi,

I am unable to get the textAlign to work at all.

Here's my code:

function AlignText(alignment) {
    for (var i = 0; i < diagram.model.selectedItems.children.length; i++) {
        var object = diagram.model.selectedItems.children[i];
        if (object.type == 'node') { // A node or a text object
            if (object.shape.type == 'text') { // text object
                if (object.shape.textBlock) {
                    diagram.updateLabel(object.name, object.shape.textBlock, { textAlign: alignment });
                }
            } else { // node
                if (object.labels[0]) {
                    diagram.updateLabel(object.name, object.labels[0], { textAlign: alignment });
                }
            }
        } else { // Must be a connector
            if (object.labels[0]) {
                diagram.updateLabel(object.name, object.labels[0], { textAlign: alignment });
            }
        }
    }
}

I've put alerts in the above so I know it is being called.
I am using almost identical code to set other properties such as fontFamily and that works fine.

What am I doing wrong?

Thanks as usual.

Jim

Jim Jacobs
Replied On February 8, 2015 04:34 PM

Hi again,

Just in case you're wondering, I am passing one of three values to my function:
  left, right or center (all lowercase)

Jim

Shyam G [Syncfusion]
Replied On February 9, 2015 08:24 AM

Hi Jim

Thanks for using Syncfusion products.

We suggest you to set an “offset for an label of text node in order to achieve your requirement and you can define the label offset value from 0 to 1. Please refer the code snippet and sample below.

Code snippet:

function updatelabel() {            

            var diagram = $("#Diagram1").ejDiagram("instance");

            var node = diagram.selectionList[0];

            if (node) {

                if (node.shape.textBlock) {                 

                    var obj = new Object();

                    obj.textAlign = "left";

                    //offset for left align

                    obj.offset = ej.datavisualization.Diagram.Point(0, 0.5);  

                    //update text node label

                    diagram.updateLabel(node.name, node.shape.textBlock, obj);

                }

            }

        }

Sample: http://www.syncfusion.com/downloads/support/directtrac/118174/WebApplication2905723546.zip

Please let me know if any concerns.

Regards,

Shyam G



Jim Jacobs
Replied On February 9, 2015 11:31 AM

Hi Shyam,

Thanks for the code.
It got me going in the right direction.
I found I had to tweak the X offset depending on the object type.

For the benefit of others than might be playing with this, here's what I ended up using:

Text object:
  Left:  obj.offset = ej.datavisualization.Diagram.Point(0.30, 0.5);
  Right:  obj.offset = ej.datavisualization.Diagram.Point(0.70, 0.5);

Node:
  Left:  obj.offset = ej.datavisualization.Diagram.Point(0.15, 0.5);
  Right:  obj.offset = ej.datavisualization.Diagram.Point(0.85, 0.5);

Connector:
  Left:  obj.offset = ej.datavisualization.Diagram.Point(0.25, 0.5);
  Right:  obj.offset = ej.datavisualization.Diagram.Point(0.75, 0.5);

And of course the center alignment used:  obj.offset = ej.datavisualization.Diagram.Point(0.5, 0.5); for all object types.

Thanks again.

Jim

Shyam G [Syncfusion]
Replied On February 9, 2015 11:26 PM

Hi Jim

Thanks for the update

Please let me know if you require further assistance on this.

Regards,

Shyam G



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;