Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit (Read 6196 times)
ChristianC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Jun 24th, 2015
(CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Jun 26th, 2015 at 12:33pm
Print Post  
Hello,

after looking at the custom node example I could create a very basic custom node with a second text property.

I brought the text to the bottom of the node. But how can I center the text in the node. My problem is that I dont know to get the real width of the text. And the x coordinate depends on the length and width of the text.

With the normal text i could simply use setTextAlignment method and no need to worry.

Here is what I have so far ...

Code (Javascript)
Select All
OrgChartNode.prototype =
{
    // draw logic
    updateCanvasElements: function (node)
    {
        MindFusion.AbstractionLayer.callBaseMethod(OrgChartNode, this, 'updateCanvasElements');
        var titleFont = Font.copy(this.getEffectiveFont());
        titleFont.size = titleFont.size - 0.3;
        var titleLabel = new Text(this.getTitle(), new Rect(
                this.bounds.x,
                this.bounds.y + this.bounds.height - titleFont.size - 1,
                this.bounds.width,
                titleFont.size)
        );
        titleLabel.font = titleFont;

        if ( this.title !== "")
        console.log(titleLabel);
        this.graphicsContainer.content.push(titleLabel);
    },

    getTitle: function ()
    {
        return this.title;
    },

    setTitle: function (value)
    {
        if (this.title !== value)
        {
            this.title = value;
        }
    }
};
 



Lastly I'd like to change the measure unit from mm to px for everything in the framework: fontsizes, bounds, grid, etc

diagram.getMeasureUnit() returns 6.



In the meantime, thank you so much for your attention and participation.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #1 - Jun 26th, 2015 at 1:13pm
Print Post  
Hi,

Try this:

Code
Select All
var titleLabel = new Text(this.getTitle(), this.bounds);
titleLabel.font = titleFont;
titleLabel.textAlignment = MindFusion.Diagramming.Alignment.Center;
titleLabel.lineAlignment = MindFusion.Diagramming.Alignment.Far;
titleLabel.fitInBounds = true; 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
ChristianC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Jun 24th, 2015
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #2 - Jun 26th, 2015 at 1:50pm
Print Post  
Smiley Smiley Smiley

Thank you very much. That worked very well. And super fast answer!!!

I nearly had this solution but I did not set fitInBounds ... looked strange  Roll Eyes
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #3 - Jun 26th, 2015 at 2:08pm
Print Post  
I've copied it from the code for standard node texts, and it seems to enable line wrapping actually, while also aligning to left/center/right of specified bounds value. If you skip it, the text won't wrap and will align relatively to top-left corner only.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
ChristianC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Jun 24th, 2015
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #4 - Jun 29th, 2015 at 9:22pm
Print Post  
It's me again ...

I have another question. Is is possible to change the rotation of text in a ShapeNode or the ShapeNode itself? I need to get the text rotated by 90°.

And I discovered a strange behavior regarding links and setting StrokeThickness. The link/headshape does not stop at the border of the connected node, instead it reaches into the node. Without StrokeThickness the headshape ends where expected/defined.

Code (Javascript)
Select All
link.setStrokeThickness(3);
link.setHeadShapeSize(3);
link.setHeadShape("Triangle");
link.setHeadBrush("black");
 



Thank you sir.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #5 - Jun 30th, 2015 at 6:28am
Print Post  
Hi,

There's a setRotationAngle method inherited from DiagramNode. You might try rotating the text independently from node by setting Text.rotationAngle, however the ShapeNode could set it too as specified by its RotateText property (enabled by default).

StrokeThickness is also applied to arrowhead paths, and half the thickness is drawn outside of the path so that thick lines are centered around their actual coordinates. We are not aware of any Canvas attributes that would draw paths with inner strokes, so you will need to override the thickness set for the arrowhead. Try this:

Code
Select All
var drawLink = DiagramLink.prototype.updateCanvasElements;
DiagramLink.prototype.updateCanvasElements = function ()
{
	drawLink.apply(this, []);
	if (this.headShapeObj.outlinePath)
		this.headShapeObj.outlinePath.strokeThickness = 0;
}; 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
ChristianC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Jun 24th, 2015
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #6 - Jun 30th, 2015 at 9:55am
Print Post  
Hello I tried two things to get the text rotated:

First I tried MindFusion.Drawing.Text and rotationAngle:

Code (Javascript)
Select All
        diagramNode.setText("");
        var titleLabel = new Text(text, bounds);
        titleLabel.font = new Font(dfont, 4.1, false, false);
        titleLabel.textAlignment = MindFusion.Diagramming.Alignment.Center;
        titleLabel.lineAlignment = MindFusion.Diagramming.Alignment.Far;
        titleLabel.rotationAngle=270;
        titleLabel.fitInBounds = true;
        diagramNode.text = titleLabel;
 



The rotationAngle had no impact. The property rotationAngle of titleLabel stayed at 0 -> console.log(titleLabel).

My Second try was to create a new node and rotate the whole node. But i need to have the rotated node take up the same space as the unrotated version. I fliped the width and height of the bounds. But i dont know how to set x and y properly.  Roll Eyes

Code (Javascript)
Select All
    var textNode = new MindFusion.Diagramming.ShapeNode();
    textNode.setBounds(bounds);

    textNode.setText(text);
    textNode.setBrush('yellow');
    //textNode.setTransparent(true);
    textNode.setTextColor('black');

    textNode.setTextAlignment(1);
    textNode.setLineAlignment(1);

    textNode.setFont(new Font(dfont, 4.1, false, false));
    textNode.setZIndex(0);
    textNode.setShadowOffsetX(0);
    textNode.setShadowOffsetY(0);
    textNode.setRotationAngle(270);
    textNode.setLineAlignment(1);

    console.log(bounds);

    var newbounds = {}
    var temp = {};
    temp.width = textNode.getBounds().height;
    temp.height = textNode.getBounds().width;
    jQuery.extend( newbounds, textNode.getBounds(), temp);
    console.log(newbounds);
    textNode.setBounds(newbounds);
    diagram.addItem(textNode);
 



Thank you Sir.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #7 - Jun 30th, 2015 at 11:30am
Print Post  
Hi,

If that's the text field of standard ShapeNode, its rotationAngle will be overwritten next time the node is rendered. You could set it from ShapeNode.prototype.onUpdateVisuals as in previous thread to avoid that. You'd also have to modify the original label instead of replacing, as it is already added as a child element to node's visual tree at the time when onUpdateVisuals is called.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
ChristianC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Jun 24th, 2015
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #8 - Jun 30th, 2015 at 1:19pm
Print Post  
Thank you very much,

setting rotationAngle in onUpdateVisuals worked.

Last question and then I think I am done:
I need to prevent line breaks for whitespaces for this special Text.

I did a dirty workaround and removed spaces with underscore. But I would rather keep the spaces and have the text in one line.

Code (Javascript)
Select All
    if ( ( this.Tag == "swimlane" || this.Tag == "prozess" ) && this.getText() != "" && orientation == 0 ) {

        this.text.rotationAngle = 270;
        var text = this.getText();
        text = text.replace(" ", "_");
        this.setText(text);
}
 



I am really sorry for asking that often, but I keep having issues finding solutions in the online documentation.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #9 - Jul 1st, 2015 at 8:11am
Print Post  
There's no option to disable wrapping available at this time in the public API. You could still set Text.fitInBounds to false, but would also have to modify the text's boundaries then if you need to center or right-align it. It looks easier to replace the Text object's wrapping function with a non-wrapping one for that special case:

Code
Select All
if (...)
{
    // ...
    this.text.getLines = function (context, rect) { this.lines = [this.text] };
}
else
{
    // ...
    delete this.text.getLines; // use one from prototype
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
ChristianC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Jun 24th, 2015
Re: (CustomNode Question - ) MindFusion.Drawing.Text centered in ShapeNode bounds and measureunit
Reply #10 - Jul 1st, 2015 at 10:16am
Print Post  
Your code worked nicely. I overwrote the fuction just for the ShapeNodes that should not wrap the text.

Thank you very much again  Smiley Cool
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint