Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Mindfussion diagram custom link shape (Read 3610 times)
Ex Member


Mindfussion diagram custom link shape
Dec 20th, 2021 at 9:01am
Print Post  
so i was trying the new mindfussion tutorial about custom diagram link shape, i assigned different onDiagramLinkCreated onto different behaviour that can be selected from a drop down menu so that i can select a link with custom element and arrow headshape, the code to input a shape in the middle of the link using args works just fine and the shape are immediately created with the link, but for the arrow headshape it doesn't work, when i tried using args to change it the arrow just stay at it's default shape, but when i use (this.state) it works but i need to create the link two times for the arrow headshape to change, does anyone have any idea what i did wrong?
  
Back to top
 
IP Logged
 
Forum Admin
YaBB Administrator
*****
Offline


Rock and Roll

Posts: 689
Joined: Apr 6th, 2003
Re: Mindfussion diagram custom link shape
Reply #1 - Dec 20th, 2021 at 9:40am
Print Post  
This Topic was moved here from Discussion [move by] Forum Admin.
  
Back to top
WWW  
IP Logged
 
Forum Admin
YaBB Administrator
*****
Offline


Rock and Roll

Posts: 689
Joined: Apr 6th, 2003
Re: Mindfussion diagram custom link shape
Reply #2 - Dec 20th, 2021 at 9:43am
Print Post  
Sorry there, I've hit the delete-account button while trying to move the post to proper category  Cry
  
Back to top
WWW  
IP Logged
 
Jessenberg
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Mindfussion diagram custom link shape
Reply #3 - Dec 20th, 2021 at 10:50am
Print Post  
hi there, i'm the original poster, i'm still a little bit confused on how i can attach a sandbox link to the post, i want to re-upload the post with a link to make it easier for everyone to understand my problem

thank you
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Mindfussion diagram custom link shape
Reply #4 - Dec 20th, 2021 at 11:16am
Print Post  
Hi,

The forum software should let you post files and links after a couple of posts. Do you mean the code below from Mindfusion's youtube channel, showing how to implement custom arrowheads? Generally if you can use standard arrowhead shapes and only need to set the one at link's end point, this should be enough to change it from linkCreated handler -

Code
Select All
args.link.headShape = Diagramming.Shape.fromId("Triangle"); 



Regards,
Slavcho

Code
Select All
import React, { Component } from 'react';
import * as Diagramming from '@mindfusion/diagramming';
import * as Drawing from '@mindfusion/drawing';
import { DiagramView } from '@mindfusion/diagramming-react';

class DiagramApp extends Component {

    constructor(props) {
      super(props);

      // create the diagram
      var diagram = new Diagramming.Diagram();
      diagram.bounds = new Drawing.Rect(10, 10, 400, 300);

      var beige = "#E0DA99";
      var green = "#858134";
      var crimson = "#5C1C09";
      var gray = "#4E493D";
      var yellow = "#D9BE48";

      var theme = new Diagramming.Theme();
      var shapeNodeStyle = new Diagramming.Style();
      shapeNodeStyle.brush = ({ type: 'LinearGradientBrush', color1: beige, color2: yellow, angle: 90 });
      shapeNodeStyle.stroke = (gray);
      shapeNodeStyle.textColor = (gray);
      shapeNodeStyle.fontName = ("Verdana");
      shapeNodeStyle.fontSize = (3);
      shapeNodeStyle.backBrush = (beige);
      shapeNodeStyle.nodeEffects = [];
      shapeNodeStyle.nodeEffects.push(new Diagramming.GlassEffect());
      theme.styles.set("std:ShapeNode", shapeNodeStyle);

      var linkStyle = new Diagramming.Style();
      linkStyle.stroke = (gray);
      linkStyle.brush = (green);
      linkStyle.backBrush = (crimson);

      linkStyle.textColor = "#585A5C";
      linkStyle.fontName = "Verdana";
      linkStyle.fontSize = 3;
      theme.styles.set("std:DiagramLink", linkStyle);

      diagram.theme = theme;

      diagram.defaultShape = ("Rectangle");

      this.state = {
        diagram: diagram
      };

    }

    onDiagramLinkCreated2(sender, args) {

           // change the arrowhead shape
           args.link.headShape = Diagramming.Shape.fromId("Triangle");
           args.link.baseShape = Diagramming.Shape.fromId("Triangle");

           args.link.onUpdateVisuals = function (link){

            for(var i =1; i <link.points.length-1; i++)
            {
                var linkShape = Diagramming.Shape.component("BowArrow", false);

                var headRenderer = linkShape.shapeRenderer;

                var current = link.points[i];
                var prev = link.points[i-1];

                headRenderer.updateArrowHeadData(link.headShapeBounds,
                current, prev);

                headRenderer.strokeThickness = link.effectiveHeadStrokeThickness;
                headRenderer.outlineBrush = link.effectiveHeadBrush;
                headRenderer.outlinePen = link.effectiveHeadStroke
                headRenderer.decorationPen = link.effectiveHeadStroke;
                headRenderer.strokeDashStyle = link.effectiveHeadStrokeDashStyle;

                link.graphicsContainer.content.push(headRenderer);
            }

        };

    }

    //set routeLinks to false when you enable this method
    onDiagramLinkCreated1(sender, args) {


        args.link.onUpdateVisuals = function (link){

          var linkShape = Diagramming.Shape.component("BowArrow", false);

          var headRenderer = linkShape.shapeRenderer;

          var sp = link.startPoint;
          var ep = link.endPoint;

          var middle = new Drawing.Point((sp.x + ep.x)/2, (sp.y + ep.y)/2 );

          if(link.points.length > 2)
            middle = link.points[1];

          headRenderer.updateArrowHeadData(link.headShapeBounds,
            middle, link.startPoint);

          headRenderer.strokeThickness = link.effectiveHeadStrokeThickness;
          headRenderer.outlineBrush = link.effectiveHeadBrush;
          headRenderer.outlinePen = link.effectiveHeadStroke
          headRenderer.decorationPen = link.effectiveHeadStroke;
          headRenderer.strokeDashStyle = link.effectiveHeadStrokeDashStyle;

          link.graphicsContainer.content.push(headRenderer);

        };

 }

 onDiagramLinkCreated(sender, args) {


    // change the arrowhead shape
	//	args.link.headShape = Diagramming.Shape.fromId("DoubleArrow");

    /* define a custom shape from coordinates
       var s = new Diagramming.Shape({ id: "MyShape", outline: "M50,0 L100,50 L49,18 L0,50 L50,0 Z" });

    // change the arrowhead shape
      args.link.headShape = s; */

   //with shape library
    var library = new Diagramming.ShapeLibrary();
    library.loadFromXml("MyLibrary.xml");


    library.loadFromXml("MyLibrary.xml", function(){
    var s = Diagramming.Shape.fromId("newShape1");
    args.link.headShape = s;

    });



		// add the box
		var label = args.link.addLabel(" ... ");
		label.brush = "#5C1C09";
		// uncomment the below line to 'hide' the dots
		label.textColor = "#D9BE48";
		label.horizontalAlign = Diagramming.Alignment.Center;
		label.verticalAlign = Diagramming.Alignment.Center;

    // change the arrowhead shape
  //  args.link.headShape = Diagramming.Shape.fromId("Triangle");
  //  args.link.baseShape = Diagramming.Shape.fromId("Triangle");

}

    render() {
        var props = {
          "allowInplaceEdit": true,
          "routeLinks": false,
          "showGrid": true,
          "backBrush": "#edeac4",
        };

        return (

            <div className="container">
              <div className="main">
                <DiagramView diagram={this.state.diagram} {...props}
                  onLinkCreated={(sender, args) => this.onDiagramLinkCreated(sender, args)} />
              </div>
            </div>

        );
      }
}
export default DiagramApp; 


  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Mindfussion diagram custom link shape
Reply #5 - Dec 20th, 2021 at 11:29am
Print Post  
Note that the sample code shows a few different linkCreated handlers, and one of them does not assign link.headShape (it's commented out at the end of the method). It should work if you uncomment that.
  
Back to top
 
IP Logged
 
Jessenberg
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Mindfussion diagram custom link shape
Reply #6 - Dec 20th, 2021 at 11:33am
Print Post  
so this is my code in sandbox :
https://codesandbox.io/s/charming-elion-6itrl?file=/src/DiagramApp.js

what i'm trying to do is selecting different onDiagramLinkCreated from the drop down menu, first to make a custom label and content and second to apply the apropriate arrowhead wich all come from the basic shape id, but the code seems to only work for the custom label and content of the link, while the shape of the arrow head remain to be the default arrow and not a triangle, tried using args but it doesn't change, used this.state and it changed but after i created two links

sorry if this is confusing
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Mindfussion diagram custom link shape
Reply #7 - Dec 20th, 2021 at 12:01pm
Print Post  
Hi,

I can see couple of things -

1. We've recently moved the diagram API to property-based syntax (in version 4 of the control) and the video and code there shows that, while apparently you've started your project with the older v3 get/set syntax. So if you prefer v3, you can set arrowheads like this:

Code
Select All
args.getLink().setHeadShape(mf.Diagramming.Shape.fromId("Triangle")); 



while this property assignment syntax will work only with v4:

Code
Select All
args.link.headShape = mf.Diagramming.Shape.fromId("Triangle"); 



2. This assignment in your linkCreated3 handler sets default head shape that the control automatically assigns to newly drawn links, but does not change the just-created link for which linkCreated event gets raised:

Code
Select All
this.state.diagram.setLinkHeadShape(headShape); 



So that's why you are seeing the expected shape when you draw link next time. You could move that code from linkCreated3 to onSelectChange, and stop setting args.link.headShape from linkCreated. Then the drop-down handler would change diagram's default linkHeadShape, and the diagram will automatically assign it to newly drawn links' own headShape property.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Jessenberg
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Mindfussion diagram custom link shape
Reply #8 - Dec 29th, 2021 at 4:39am
Print Post  
Slavcho wrote on Dec 20th, 2021 at 12:01pm:
Hi,

I can see couple of things -

1. We've recently moved the diagram API to property-based syntax (in version 4 of the control) and the video and code there shows that, while apparently you've started your project with the older v3 get/set syntax. So if you prefer v3, you can set arrowheads like this:

Code
Select All
args.getLink().setHeadShape(mf.Diagramming.Shape.fromId("Triangle")); 



while this property assignment syntax will work only with v4:

Code
Select All
args.link.headShape = mf.Diagramming.Shape.fromId("Triangle"); 



2. This assignment in your linkCreated3 handler sets default head shape that the control automatically assigns to newly drawn links, but does not change the just-created link for which linkCreated event gets raised:

Code
Select All
this.state.diagram.setLinkHeadShape(headShape); 



So that's why you are seeing the expected shape when you draw link next time. You could move that code from linkCreated3 to onSelectChange, and stop setting args.link.headShape from linkCreated. Then the drop-down handler would change diagram's default linkHeadShape, and the diagram will automatically assign it to newly drawn links' own headShape property.

Regards,
Slavcho
Mindfusion


hi there, thank you soo much for the help, the code now works properly but if you don't mind me asking, how do i apply a brush to the arrow shape? i tried calling it the same as the label brush :

Code (Javascript)
Select All
var headShape = mf.Diagramming.Shape.fromId("Triangle");
headShape.brush = 'black' 



when i try to console log it, the brush change to 'black' but the arrow is still in the same color

i'm trying to have a white and black arrow shape
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Mindfussion diagram custom link shape
Reply #9 - Dec 29th, 2021 at 9:37am
Print Post  
Hi,

Try setting headBrush / headStroke properties of DiagramLink.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Jessenberg
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Mindfussion diagram custom link shape
Reply #10 - Jan 1st, 2022 at 4:48am
Print Post  
thank you, turns out i just need to call brush on the link and not the headshape
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint