Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Need to change Arrow at run time. (Read 2067 times)
Shafi
Full Member
***
Offline


I Love MindFusion!

Posts: 109
Joined: Nov 8th, 2016
Need to change Arrow at run time.
Sep 27th, 2017 at 11:55am
Print Post  
We have a combo box which is populated with different types of Arrow Head please have look at the fig.
I am trying to change  arrow head according to user selection please have a look at my code
Code (Javascript)
Select All
   reRenderDiagram(result: Options) {
        debugger;
        switch (+result.linkType) {
            case 0:
                this.option.linkType = MindFusion.Graphs.TreeLayoutLinkType.Default;
                break;
            case 1:
                this.option.linkType = MindFusion.Graphs.TreeLayoutLinkType.Straight;
                break;
            case 2:
                this.option.linkType = MindFusion.Graphs.TreeLayoutLinkType.Cascading;
                break;
        }
        this.option.viewType = result.viewType === ViewType.netViewHorizontal ?
            MindFusion.Graphs.LayoutDirection.LeftToRight : MindFusion.Graphs.LayoutDirection.TopToBottom;
        this.option.nodeDistance = +result.nodeDistance;
        this.option.levelDistance = +result.levelDistance;
        this.diagram.setLinkHeadShape(this.option.arrowType);
        if (this.selectedLayout === DiagramLayoutEnum.TREE) {
            NodeHelper.TreeLayout(this.diagram, this.option);
        } else {
            NodeHelper.FractalLayout(this.diagram, this.option);
        }
        this.diagram.resizeToFitItems();
    }
 


Code (Javascript)
Select All
     static TreeLayout(diagram: any, option: Options) {
        const layout = new MindFusion.Graphs.TreeLayout();
        layout.keepGroupLayout = true;
        layout.direction = option.viewType;
        layout.linkType = option.linkType;
        layout.levelDistance = option.levelDistance;
        layout.nodeDistance = option.nodeDistance;
        diagram.arrange(layout);
    }

    /**
     * This function creates the diagram in fractal layout
     * @param digram
     */
    static FractalLayout(diagram: any, option: Options) {
        const layout = new MindFusion.Graphs.FractalLayout();
        layout.root = diagram.nodes[0];
        layout.keepGroupLayout = true;
        diagram.arrange(layout);

    }
 



Each and every other configuration works fine only changing arrow head is not working what ever i select from combo box it show only arrow sign
Code (Javascript)
Select All
this.diagram.setLinkHeadShape("Circle");
 

  

arrowhead-combo.PNG ( 19 KB | 77 Downloads )
arrowhead-combo.PNG
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Need to change Arrow at run time.
Reply #1 - Sep 27th, 2017 at 12:01pm
Print Post  
Diagram.setLinkHeadShape only changes the default for newly created links. If links already exist and you need to change their arrowheads, loop over the diagram.links collection and call link.setHeadShape(...);

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Shafi
Full Member
***
Offline


I Love MindFusion!

Posts: 109
Joined: Nov 8th, 2016
Re: Need to change Arrow at run time.
Reply #2 - Sep 27th, 2017 at 12:22pm
Print Post  
Is there any API which will reRender whole diagram according to user selection Arrow Head. As you can see the code in which user can change the node distance and layout which works perfectly. That is why i am assuming there must be an api which work for Arrow head also.

As suggested by you I am working like that only.

Can you please let me know what should i pass as an argument in below API(setHeadShape). i.e. what will the value of arrow type is for circle argument is "Circle" and for triangle argument is "Triangle"

this.diagram.getLinks().forEach(link => { link.setHeadShape(this.option.arrowType); });
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Need to change Arrow at run time.
Reply #3 - Sep 27th, 2017 at 5:13pm
Print Post  
Node and level distances are properties of the layout class and applied by Diagram.arrange method, which does nothing about visual attributes of individual diagram elements.

JavaScript version of setHeadShape takes either string id or Shape instance, but I guess the TypeScript definition is strongly-typed to only accept Shape argument. You could change the shape by calling link.setHeadShape(Shape.fromId(...));

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Shafi
Full Member
***
Offline


I Love MindFusion!

Posts: 109
Joined: Nov 8th, 2016
Re: Need to change Arrow at run time.
Reply #4 - Oct 3rd, 2017 at 2:23pm
Print Post  
Thanks It works
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint