{"id":2252,"date":"2020-01-21T12:10:08","date_gmt":"2020-01-21T12:10:08","guid":{"rendered":"https:\/\/mindfusion.eu\/blog\/?p=2252"},"modified":"2021-01-25T16:10:12","modified_gmt":"2021-01-25T16:10:12","slug":"different-size-icons-in-the-js-diagram-nodelistview","status":"publish","type":"post","link":"https:\/\/mindfusion.dev\/blog\/different-size-icons-in-the-js-diagram-nodelistview\/","title":{"rendered":"Different-size Icons in the Js Diagram NodeListView"},"content":{"rendered":"<p>In this blog post we will learn how to add a <a title=\"MindFusion Diagramming for JavaScript: NodeListView\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Diagramming_NodeListView_Members.htm\">NodeListView<\/a> control to a <a title=\"MindFusion Diagramming for JavaScript: Diagram\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_Diagram_0.htm\">Diagram<\/a> and how to set its <a title=\"MindFusion Diagramming for JavaScript: ShapeNode\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_ShapeNode_Members_0.htm\">ShapeNode<\/a> -s to a different size. When <a title=\"MindFusion Diagramming for JavaScript: ShapeNode\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_ShapeNode_Members_0.htm\">ShapeNode<\/a> -s are dragged from the <a title=\"MindFusion Diagramming for JavaScript: NodeListView\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Diagramming_NodeListView_Members.htm\">NodeListView<\/a> the instances that will be created are proprtional in size to the size of the <a title=\"MindFusion Diagramming for JavaScript: ShapeNode\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_ShapeNode_Members_0.htm\">ShapeNode<\/a> that was dragged. Here is a screenshot of the final application:<\/p>\n<p><img decoding=\"async\" title=\"NodeListView with Various Size Nodes\" src=\"https:\/\/mindfusion.dev\/samples\/javascript\/diagram\/controls_nodelistview.png\" \/><\/p>\n<p><strong>I. General Settings<\/strong><\/p>\n<p>We create an HTML page and add to it references to the MindFusion JavaScript files that represent the diagramming library:<\/p>\n<pre id=\"line1\">&lt;<span class=\"start-tag\">script<\/span> <span class=\"attribute-name\">src<\/span>=\"<a class=\"attribute-value\" href=\"view-source:https:\/\/mindfusion.dev\/blog\/different-size-icons-in-the-js-diagram-nodelistview\/MindFusion.Common.js\">MindFusion.Common.js<\/a>\" <span class=\"attribute-name\">type<\/span>=\"<a class=\"attribute-value\">text\/javascript<\/a>\"&gt;&lt;\/<span class=\"end-tag\">script<\/span>&gt;\n<span id=\"line322\"><\/span>&lt;<span class=\"start-tag\">script<\/span> <span class=\"attribute-name\">src<\/span>=\"<a class=\"attribute-value\" href=\"view-source:https:\/\/mindfusion.dev\/blog\/different-size-icons-in-the-js-diagram-nodelistview\/MindFusion.Diagramming.js\">MindFusion.Diagramming.js<\/a>\" <span class=\"attribute-name\">type<\/span>=\"<a class=\"attribute-value\">text\/javascript<\/a>\"&gt;&lt;\/<span class=\"end-tag\">script<\/span>&gt;\n<span id=\"line323\"><\/span>&lt;<span class=\"start-tag\">script<\/span> <span class=\"attribute-name\">src<\/span>=\"<a class=\"attribute-value\" href=\"view-source:https:\/\/mindfusion.dev\/blog\/different-size-icons-in-the-js-diagram-nodelistview\/Controls.js\">Controls.js<\/a>\" <span class=\"attribute-name\">type<\/span>=\"<a class=\"attribute-value\">text\/javascript<\/a>\"&gt;&lt;\/<span class=\"end-tag\">script<\/span>&gt;<\/pre>\n<p>The last reference is to the Controls JavaScript file, where the code for the application is located.<\/p>\n<p>Then we create two Canvas-es: one is for the <a title=\"MindFusion Diagramming for JavaScript: NodeListView\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Diagramming_NodeListView_Members.htm\">NodeListView<\/a> and the other is for the <a title=\"MindFusion Diagramming for JavaScript: Diagram\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_Diagram_0.htm\">Diagram<\/a> The NodeListView component is bound to the canvas element below:<\/p>\n<pre id=\"line1\"><span class=\"start-tag\">&lt;div<\/span> <span class=\"attribute-name\">style<\/span>=\"<a class=\"attribute-value\">width: 200px; height: 100%; overflow-y: auto; overflow-x: hidden; position: absolute; top: 201px; left: 0px; right: 0px; bottom: 0px;<\/a>\"&gt;\n<span id=\"line328\"><\/span>    &lt;<span class=\"start-tag\">canvas<\/span> <span class=\"attribute-name\">id<\/span>=\"<a class=\"attribute-value\">nodeList<\/a>\" <span class=\"attribute-name\">width<\/span>=\"<a class=\"attribute-value\">200<\/a>\"&gt;&lt;\/<span class=\"end-tag\">canvas<\/span>&gt;<br \/>&lt;\/<span class=\"end-tag\">div<\/span>&gt;\n<br \/>......\n<span id=\"line332\"><\/span><span class=\"comment\"><br \/>&lt;!-- The Diagram component is bound to the canvas element below --&gt;<\/span>\n&lt;<span class=\"start-tag\">div<\/span> <span class=\"attribute-name\">style<\/span>=\"<a class=\"attribute-value\">position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: auto;<\/a>\"&gt;\n    &lt;<span class=\"start-tag\">canvas<\/span> <span class=\"attribute-name\">id<\/span>=\"<a class=\"attribute-value\">diagram<\/a>\" <span class=\"attribute-name\">width<\/span>=\"<a class=\"attribute-value\">2100<\/a>\" <span class=\"attribute-name\">height<\/span>=\"<a class=\"attribute-value\">2100<\/a>\"&gt;<br \/>        This page requires a browser that supports HTML 5 Canvas element.<br \/>    &lt;\/<span class=\"end-tag\">canvas<\/span>&gt;<br \/>&lt;\/<span class=\"end-tag\">div<\/span>&gt;<\/pre>\n<p>Both the <a title=\"MindFusion Diagramming for JavaScript: Diagram\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_Diagram_0.htm\">Diagram<\/a> and <a title=\"MindFusion Diagramming for JavaScript: NodeListView\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Diagramming_NodeListView_Members.htm\">NodeListView<\/a> controls require Canvas elements to render themselves onto.<\/p>\n<p><strong>II. Initializing the Controls<\/strong><\/p>\n<p>We create the <a title=\"MindFusion Diagramming for JavaScript: Diagram\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_Diagram_0.htm\">Diagram<\/a> using the id that we&#8217;ve provided to its Canvas in the web page:<\/p>\n<pre>\/\/ create a Diagram component that wraps the \"diagram\" canvas\ndiagram = Diagram.create(document.getElementById(\"diagram\"));\ndiagram.setBounds(new MindFusion.Drawing.Rect(0, 0, 500, 500));<\/pre>\n<p>We set a bigger size to the diagram in order to make it fill the web page.<\/p>\n<p>We create the <a title=\"MindFusion Diagramming for JavaScript: NodeListView\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Diagramming_NodeListView_Members.htm\">NodeListView<\/a> instance the same way we created the diagram:<\/p>\n<pre>\/\/ create a NodeListView component that wraps the \"nodeList\" canvas\nvar nodeList = MindFusion.Diagramming.NodeListView.create(document.getElementById(\"nodeList\"));\nnodeList.setTargetView(document.getElementById(\"diagram\"));<\/pre>\n<p>Now we need to add the settings that will make the <a title=\"MindFusion Diagramming for JavaScript: ShapeNode\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_ShapeNode_Members_0.htm\">ShapeNode<\/a> -s different in size when rendered onto the list:<\/p>\n<pre>nodeList.setIconSize(null);<\/pre>\n<p>The <a title=\"MindFusion Diagramming for JavaScript: setIconSize\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?M_MindFusion_Diagramming_NodeListView_setIconSize_1_Number.htm\">setIconSize<\/a> method is used to specify the default size of nodes in the <a title=\"MindFusion Diagramming for JavaScript: NodeListView\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Diagramming_NodeListView_Members.htm\">NodeListView<\/a> When we set the size to null, the control draws each node in the <a title=\"MindFusion Diagramming for JavaScript: NodeListView\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Diagramming_NodeListView_Members.htm\">NodeListView<\/a> with the size that was assigned to it:<\/p>\n<pre>function initNodeList(nodeList, diagram)\n{\n    \/\/ add some nodes to the NodeListView\n    var shapes = [\"Actor\", \"RoundRect\", \"Triangle\", \"Decision\"];\n    for (var i = 0; i &lt; shapes.length; ++i)\n    {\n        var node = new MindFusion.Diagramming.ShapeNode(diagram);\n        node.setText(shapes[i]);\n        node.setShape(shapes[i]);\n        node.setBounds(new MindFusion.Drawing.Rect(0, 0, (i+1)*10, (i+1)*10));\n        nodeList.addNode(node, shapes[i]);\n    }\n}<\/pre>\n<p>Here we increase the size of wach <a title=\"MindFusion Diagramming for JavaScript: ShapeNode\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_ShapeNode_Members_0.htm\">ShapeNode<\/a> with 10 points on each itereation. This makes the icons with various size but does not create them with different size when dropped on the diagram. In order to do this we must set:<\/p>\n<pre>nodeList.setDefaultNodeSize (null);<\/pre>\n<p>setDefaultNodeSize specifies the size of those nodes that are created when a <a title=\"MindFusion Diagramming for JavaScript: ShapeNode\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_ShapeNode_Members_0.htm\">ShapeNode<\/a> is dropped on the <a title=\"MindFusion Diagramming for JavaScript: Diagram\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_Diagram_0.htm\">Diagram<\/a> area. By setting this size to null we tell the control to read the size of the new <a title=\"MindFusion Diagramming for JavaScript: ShapeNode\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?CC_T_MindFusion_Diagramming_ShapeNode_Members_0.htm\">ShapeNode<\/a> from the instance in the <a title=\"MindFusion Diagramming for JavaScript: NodeListView\" href=\"https:\/\/www.mindfusion.dev\/onlinehelp\/javascript.pack\/index.htm?T_MindFusion_Diagramming_NodeListView_Members.htm\">NodeListView<\/a> control.<\/p>\n<p>With that our sample is ready. You can download the source code from this link:<\/p>\n<p align=\"center\"><a href=\"https:\/\/mindfusion.dev\/samples\/javascript\/diagram\/Controls1.zip\">JavaScript NodeListView with Various Size Nodes: Download Sample<\/a><\/p>\n<p><i>About Diagramming for JavaScript:<\/i> This native JavaScript library provides developers with the ability to create and customize any type of diagram, decision tree, flowchart, class hierarchy, graph, genealogy tree and more. The control offers rich event set, numerous customization options, animations, graph operations, styling and themes. You have more than 100 predefined nodes, table nodes and more than 15 automatic layout algorithms. Learn more about Diagramming for JavaScript at <a title=\"JavaScript Diagram Library\" href=\"https:\/\/mindfusion.dev\/javascript-diagram.html\">https:\/\/mindfusion.dev\/javascript-diagram.html<\/a>.<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post we will learn how to add a NodeListView control to a Diagram and how to set its ShapeNode -s to a different size. When ShapeNode -s are dragged from the NodeListView the instances that will be &hellip; <a href=\"https:\/\/mindfusion.dev\/blog\/different-size-icons-in-the-js-diagram-nodelistview\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[95,513,74],"tags":[3,602,44,626,569],"class_list":["post-2252","post","type-post","status-publish","format-standard","hentry","category-diagramming-2","category-javascript","category-sample-code","tag-diagram","tag-js-library","tag-library","tag-nodelistview","tag-sample-code"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3RlKs-Ak","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/2252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/comments?post=2252"}],"version-history":[{"count":7,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/2252\/revisions"}],"predecessor-version":[{"id":2654,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/2252\/revisions\/2654"}],"wp:attachment":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/media?parent=2252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/categories?post=2252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/tags?post=2252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}