Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Problem adding custom ShapeNode to a NodeListView (Read 8779 times)
CrushJelly
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Oct 20th, 2016
Problem adding custom ShapeNode to a NodeListView
Oct 20th, 2016 at 12:13pm
Print Post  
Hi,

I defined a new class that derives from ShapeNode class.
I try to add my custom ShapeNode class to a NodeListView (canavas mode), but when I run my application there is nothing in the NodeListView, it's not displaying anything.
But when I use Mindfusions ShapeNode class, nodes are displayed in the NodeListview.

My code ex.:

Code
Select All
var workflowStart = new CustomShapeNode(WorkflowShapeType.WorkflowStart);

var start = new MindFusion.Diagramming.ShapeNode();

nodeListView.AddNode(workflowStart, "Start"); // This node is not displayed when running app

nodeListView.AddNode(start, "Workflow");
 



So what is the problem, why it is not displaying anything, maybe I need something to declare?
« Last Edit: Oct 21st, 2016 at 7:44am by CrushJelly »  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Problem adding custom ShapeNode to a NodeListView
Reply #1 - Oct 20th, 2016 at 1:27pm
Print Post  
Hi,

If using the default Canvas mode, you will have to implement your custom node class in JavaScript too, along with JSON serialization for any properties you are adding. For an example, see IconNodes\Scripts\CustomNode.js in installed sample projects.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
CrushJelly
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Oct 20th, 2016
Re: Problem adding custom ShapeNode to a NodeListView
Reply #2 - Oct 21st, 2016 at 7:29am
Print Post  
Slavcho wrote on Oct 20th, 2016 at 1:27pm:
Hi,

If using the default Canvas mode, you will have to implement your custom node class in JavaScript too, along with JSON serialization for any properties you are adding. For an example, see IconNodes\Scripts\CustomNode.js in installed sample projects.

Regards,
Slavcho
Mindfusion



Well, I had implemented node class in JS and created and registered converters, I did this by example that you mentioned.

Maybe I need something to declare in order it to work?

I tried adding NodeListView to MindFusion IconNodes sample, I am getting same problem.

Added this code to IconNode Example:

Code
Select All
<ndiag:NodeListView
  ID="nodeListView"
  runat="server"
  ClientSideMode="Canvas"
JsLibraryLocation="Scripts/MindFusion/MindFusion.Diagramming.js"
style="position: absolute; top: 5px; left: 0px; right: 0px; bottom: 0px; width: 200px; height: auto; overflow: auto;" />
 



Code
Select All
var custom= new CustomNode();
 nodeListView.AddNode(custom, "Custom"); // NodeListView not showing this node
 



It works only if I use as prototype:

Code
Select All
var workflowStart = new CustomNode();
workflowStart.Shape = Shapes.Arrow3;

var start = new MindFusion.Diagramming.ShapeNode(workflowStart); 


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


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Problem adding custom ShapeNode to a NodeListView
Reply #3 - Oct 21st, 2016 at 10:12am
Print Post  
Hi,

You will have to call same RegisterItemType / RegisterConverters methods on the NodeListView instance.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
CrushJelly
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Oct 20th, 2016
Re: Problem adding custom ShapeNode to a NodeListView
Reply #4 - Oct 21st, 2016 at 12:24pm
Print Post  
Slavcho wrote on Oct 21st, 2016 at 10:12am:
Hi,

You will have to call same RegisterItemType / RegisterConverters methods on the NodeListView instance.

Regards,
Slavcho
Mindfusion



I didn't change Mindfusions example code, I just added custom code, that add node to a NodeListView.


Code
Select All
    protected void Page_Init(object sender, EventArgs e)
    {
        // register custom item types, their serialization identifiers and JavaScript class names

		// this class demonstrates custom drawing in Canvas mode, see Scripts/CustomNode.js
        diagramView.RegisterItemType(typeof(CustomNode), "CustomNode", "CustomNode", 100);

		// these classes demonstrate custom drawing in ImageMap mode, see IconNode.cs and IconLink.cs
        diagramView.RegisterItemType(typeof(IconNode), "IconNode", "IconNode", 100);
        diagramView.RegisterItemType(typeof(IconLink), "IconLink", "IconLink", 100);

		// register converters for serializing .NET items into JSON objects
        diagramView.RegisterConverters(new JavaScriptConverter[]
		{
            new CustomNodeConverter(diagramView),
            new IconNodeConverter(diagramView),
            new IconLinkConverter(diagramView)
		});
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        diagramView.ClientSideMode = radioButtonList.SelectedIndex == 0 ?
			ClientSideMode.Canvas : ClientSideMode.ImageMap;

        // let users draw CustomNode objects in Canvas mode
        if (diagramView.ClientSideMode == ClientSideMode.Canvas)
        {
            diagramView.CustomNodeType = typeof(CustomNode);
            diagramView.NodeClickedScript = "onNodeClicked";
        }

        // let users draw IconNode/IconLink objects in ImageMap mode
        else if (diagramView.ClientSideMode == ClientSideMode.ImageMap)
        {
            diagramView.CustomNodeType = typeof(IconNode);
            diagramView.CustomLinkType = typeof(IconLink);
        }

        // ***** CUSTOM NODE *****
        var custom = new CustomNode();
        nodeListView.AddNode(custom, "Custom");
    }
 


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


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Problem adding custom ShapeNode to a NodeListView
Reply #5 - Oct 21st, 2016 at 1:01pm
Print Post  
Apart from adding NodeListView instance, you must also call its nodeListView.Register* methods as done for the DiagramView, or otherwise the NodeListView won't know how to serialize your custom node to send to client side.
  
Back to top
 
IP Logged
 
CrushJelly
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Oct 20th, 2016
Re: Problem adding custom ShapeNode to a NodeListView
Reply #6 - Oct 21st, 2016 at 1:21pm
Print Post  
Slavcho wrote on Oct 21st, 2016 at 1:01pm:
Apart from adding NodeListView instance, you must also call its nodeListView.Register* methods as done for the DiagramView, or otherwise the NodeListView won't know how to serialize your custom node to send to client side.


Ok that worked.
Thank you Smiley

Last question, can I declare node style just in the C# class or, do I need to declare in the javascript to?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Problem adding custom ShapeNode to a NodeListView
Reply #7 - Oct 22nd, 2016 at 7:39am
Print Post  
Quote:
Last question, can I declare node style just in the C# class or, do I need to declare in the javascript to?


If you mean attribute values you assign to node.Style, it should be enough to set them from C# code. They are transferred via JSON to JavaScript side where you can access them too via node.getStyle().

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
CrushJelly
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Oct 20th, 2016
Re: Problem adding custom ShapeNode to a NodeListView
Reply #8 - Oct 24th, 2016 at 2:23pm
Print Post  
Slavcho wrote on Oct 21st, 2016 at 1:01pm:
Apart from adding NodeListView instance, you must also call its nodeListView.Register* methods as done for the DiagramView, or otherwise the NodeListView won't know how to serialize your custom node to send to client side.


Well, it works fine now. Thank you! Smiley

But I ran into a problem, can I adjust seperate ShapeNodes sizes in the NodeListView?

(ex. ShapeNode1(width = 80, height = 40),
ShapeNode2 width = 40, height = 40), like one node is bigger, than the other is smaller);

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


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Problem adding custom ShapeNode to a NodeListView
Reply #9 - Oct 25th, 2016 at 7:59am
Print Post  
It happens we've added support for variable sized node recently in the JavaScript library (diagramming.js file is the same, just overwrite over one from ASP.NET version) -
https://mindfusion.eu/_beta/jsdiag271.zip

Call nodelist.setIconSize(null) from JavaScript, and NodeListView will use sizes from node.Bounds instead.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
CrushJelly
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Oct 20th, 2016
Re: Problem adding custom ShapeNode to a NodeListView
Reply #10 - Oct 31st, 2016 at 9:43am
Print Post  
Slavcho wrote on Oct 25th, 2016 at 7:59am:
It happens we've added support for variable sized node recently in the JavaScript library (diagramming.js file is the same, just overwrite over one from ASP.NET version) -
https://mindfusion.eu/_beta/jsdiag271.zip

Call nodelist.setIconSize(null) from JavaScript, and NodeListView will use sizes from node.Bounds instead.

Regards,
Slavcho
Mindfusion


I supposed to declare it like this?:

Because like this it is not working.

Code
Select All
        <div>
            <table>
                <tr>
                    <td>
                        <ndiag:NodeListView
                            ID="nodeListView"
                            runat="server"
                            ClientSideMode="Canvas"
                            JsLibraryLocation="../../Scripts/MindFusion/MindFusion.Diagramming.js"
                            style="position: absolute; top: 15px; left: 5px; right: 0px; bottom: 0px; width: 200px; height: auto; overflow: auto; margin: 5px;" />
                    </td>
                    <td>
                        <ndiag:DiagramView
                            ID="diagramView"
                            runat="server"
                            ClientSideMode="Canvas"
                            JsLibraryLocation="../../Scripts/MindFusion/MindFusion.Diagramming.js"
                            ShapeLibraryLocation="~/Designer/Dependencies/DlxCustomShapeLibrary.xml"
                            style="position: absolute; left: 201px; top: 0px; right: 0px; bottom: 0px;">
                            <Diagram GridStyle="Lines" AlignToGrid="True" ShowGrid="True" GridColor="#1B000000" GridSizeY="10" GridSizeX="10"></Diagram>
                        </ndiag:DiagramView>
                    </td>

                </tr>
            </table>
        </div>
 



JS code:

Code
Select All
 <script type="text/javascript">
        Sys.Application.add_init(function () {

            var nodeList = $get("nodeListView");
            if (nodeList != null) {
                nodeList.setIconSize(null);
                alert("NodeList set");
            }

            // Refresh shape library after load
            MindFusion.Diagramming.Shape.loadFromLibPending = true;

        });
    </script>
 


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


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Problem adding custom ShapeNode to a NodeListView
Reply #11 - Oct 31st, 2016 at 6:46pm
Print Post  
$get is the MSAjax shortcut to getElementById and it gives you the Canvas DOM element. Call $find instead to get the NodeListView instance associated with that Canvas.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
CrushJelly
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Oct 20th, 2016
Re: Problem adding custom ShapeNode to a NodeListView
Reply #12 - Nov 3rd, 2016 at 9:42am
Print Post  
Is it possible to arrange Nodes in the NodeListView like this?
  

Nodelist.PNG ( 9 KB | 170 Downloads )
Nodelist.PNG
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Problem adding custom ShapeNode to a NodeListView
Reply #13 - Nov 4th, 2016 at 9:58am
Print Post  
Nothing built-in, but you could replace the NodeListView's layout function as in attached file. We'll think of some properties for next release to let you set that with public API.
  

func.txt ( 1 KB | 165 Downloads )
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint