Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to define custom behaviour for diagramming component? (Read 2752 times)
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
How to define custom behaviour for diagramming component?
Oct 4th, 2016 at 11:53am
Print Post  
Hello,

Is it possible to define custom behaviour for diagramming component?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: How to define custom behaviour for diagramming component?
Reply #1 - Oct 4th, 2016 at 1:52pm
Print Post  
Hi,

If you only need to change the type of diagram elements being drawn to a custom type, it's enough to set Behavior=Custom and CustomNodeType=typeof(...) as shown in IconNodes sample project.

If you need to decide the type of items at runtime, there's no documented method of doing it, but you could create a custom JS BehaviorBase -derived class and assign its instance to Diagram.currentBehavior field. The default behavior that draws either nodes or links is implemented like this -

Code
Select All
startDraw: function (point)
{
    var ist;
    var handle = null;
    var originNode = this.diagram.getNodeAt(point, true, true);
    if (originNode != null && originNode.acceptLinks(true))
    {
        var link = this.createLink(originNode, point);
        handle = { item: link, index: link.points.length - 1 };
        ist = new mdiag.InteractionState(link, mdiag.Action.Create, handle, point);
        this.diagram.addItem(link);
    }
    else
    {
        var w = this.diagram.getAlignToGrid() ? this.diagram.getGridSizeX() : 1;
        var h = this.diagram.getAlignToGrid() ? this.diagram.getGridSizeY() : 1;
        var node = this.createNode();
        var alignedPoint = this.diagram.alignResize(node, point, mdiag.AdjustmentHandles.ResizeTopLeft);
        node.setBounds(new MindFusion.Drawing.Rect(alignedPoint.x, alignedPoint.y, w, h));
        handle = { item: node, index: 2 };
        ist = new mdiag.InteractionState(node, mdiag.Action.Create, handle, point);
        this.diagram.addItem(node);
    }
    return ist;
}, 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint