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. Image for the cookie policy date

How to change properties of Text object

Hi,

Now that I have the textTool working (thanks for that), I am having trouble trying to change any of its properties.

The following code will successfully change the text color for nodes and connectors, but does nothing for text objects.

function ApplyTextColor(color) {
    for (var i = 0; i < diagram.model.selectedItems.children.length; i++) {
        var object = diagram.model.selectedItems.children[i];
        diagram.updateLabel(object.name, object.labels[0], { fontColor: color });
    }
}

How do I accomplish this for text objects (if that's the correct term) ?

Thanks

Jim

3 Replies

SG Shyam G Syncfusion Team January 28, 2015 09:09 AM UTC

Hi Jim

Thanks for using Syncfusion products.

We suggest you to update the shape's "textblock" property in the "updateLabel" API to update the Text node instead of updating the node's Label. Please see the code snippet below.

Code snippet:

 

function updatelabel() {           

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

            var node = diagram.selectionList[0];

            if (node) {

                if (node.shape.textBlock) {

                    //update text node label

                    diagram.updateLabel(node.name, node.shape.textBlock, { fontSize: 20, fontColor: "red" });

                }

            }

        }

Sample: http://www.syncfusion.com/downloads/support/directtrac/118065/textblock429359551.zip

Please let me know if any concerns.

Regards,

Shyam G




JJ Jim Jacobs February 3, 2015 12:38 AM UTC

Hi Shyam,

You got me pointed in the right direction.
I ended up coding the following (which works) to toggle the bold property on/off.

function toggleTextBold() {
    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) {
                    if (object.shape.textBlock.bold) {
                        diagram.updateLabel(object.name, object.shape.textBlock, { bold: !object.shape.textBlock.bold });
                    } else {
                        diagram.updateLabel(object.name, object.shape.textBlock, { bold: true });
                    }
                }
            } else { // node
                if (object.labels[0].bold) {
                    diagram.updateLabel(object.name, object.labels[0], { bold: !object.labels[0].bold });
                } else {
                    diagram.updateLabel(object.name, object.labels[0], { bold: true });
                }
            }
        } else { // Must be a connector
            if (object.labels[0]) {
                if (object.labels[0].bold) {
                    diagram.updateLabel(object.name, object.labels[0], { bold: !object.labels[0].bold });
                } else {
                    diagram.updateLabel(object.name, object.labels[0], { bold: true });
                }
            }
        }
    }
}

Jim


SG Shyam G Syncfusion Team February 3, 2015 01:16 PM UTC

Hi Jim

Thanks for the update

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

Regards,

Shyam G



Loader.
Live Chat Icon For mobile
Up arrow icon