implement expand collapse


Author
Message
yoav Roytenberg
yoav Roytenberg
Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)
Group: Forum Members
Posts: 13, Visits: 1

Can you send me a simple example of how to implement and expand collapse on a tree diagram?

thanks.


Reply
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hello Yoav,

You can take a look at the Help Documentation: Diagram for .NET > User's Guide > Document Object Model > Models > Shapes > Decorators

 

The following code example will generate a tree diagram with show-hide subtree decorator for each shape that has children:

 

using Nevron.Diagram;

using Nevron.Diagram.Shapes;

using Nevron.Diagram.WinForm;

using Nevron.Diagram.Templates;

using Nevron.Diagram.Filters;

using Nevron.Diagram.Layout;

using Nevron.Diagram.DataStructures;

NDrawingView view = new NDrawingView();

NDrawingDocument document = new NDrawingDocument();

this.Controls.Add(view);

 

view.Document = document;

view.BeginInit();

 

view.Dock = DockStyle.Fill;

view.ViewLayout = ViewLayout.Fit;

view.Grid.Visible = false;

view.GlobalVisibility.ShowPorts = false;

 

document.BeginInit();

 

// create a random tree

NGenericTreeTemplate treeTemplate = new NGenericTreeTemplate();

treeTemplate.BranchNodes = 3;

treeTemplate.VerticesSize = new NSizeF(50, 50);

treeTemplate.Balanced = false;

treeTemplate.Levels = 5;

treeTemplate.Create(document);

 

// add show-hide subtree decorator for each shape that has children

foreach (NShape shape in document.ActiveLayer.Children(NFilters.Shape2D))

{

    if (shape.GetOutgoingShapes().Count == 0)

        continue;

 

    // create the decorators collection

    shape.CreateShapeElements(ShapeElementsMask.Decorators);

 

    NShowHideSubtreeDecorator decorator = new NShowHideSubtreeDecorator();

    decorator.Offset = new NSizeF(-11, 11);

    decorator.Size = new NSizeF(15, 15);

    decorator.Alignment = new NContentAlignment(ContentAlignment.TopLeft);

    shape.Decorators.AddChild(decorator);

}

 

document.AutoBoundsMinSize = new NSizeF(400, 400);

 

// layout with a layered tree layout

NLayoutContext context = new NLayoutContext();

context.GraphAdapter = new NShapeGraphAdapter(true);

context.BodyAdapter = new NShapeBodyAdapter(document);

context.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document);

 

NLayeredTreeLayout layout = new NLayeredTreeLayout();

layout.VertexSpacing = 50;

layout.LayerSpacing = 50;

layout.Layout(document.ActiveLayer.Children(null), context);

 

// size to visible shapes

document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding, NFilters.Visible);

 

document.EndInit();

view.EndInit();

 

Related examples:

Windows Forms: Document Object Model - Shapes - Decorators folder

Web Forms: Show/Hide Subtree Decorator

Best Regards,
Nevron Support Team


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search