Search results

Page Settings in Blazor Diagram component

Page settings enable to customize the appearance, width, and height of the diagram page.

Page size and appearance

  • The size and appearance of the diagram pages can be customized with the page settings property.

  • The Width and Height properties of page settings define the size of the page and based on the size, the Orientation will be set for the page. In addition to that, the appearance of the page can be customized with Source and set of appearance specific properties.

  • The Color property is used to customize the background color and border color of the page.

  • The Margin property is used to define the page margin.

  • To explore those properties, refer to Page Settings.

@using Syncfusion.Blazor.Diagrams
@using System.Collections.ObjectModel
<SfDiagram Width="1000px" Height="580px" id="diagram">
    <DiagramSnapSettings>
        <HorizontalGridlines LineColor="#e0e0e0" />
        <VerticalGridlines LineColor="#e0e0e0" />
    </DiagramSnapSettings>
    @*Initialize the page settings with page orientation and break lines*@
    <DiagramPageSettings Height="300" Width="300" Orientation="@orientation" ShowPageBreaks="true">
        @*Set the page background image*@
        <DiagramBackground Source="https://www.w3schools.com/images/w3schools_green.jpg" />
        @*Set the page margin*@
        <PageSettingsMargin Left="10" Top="10" Bottom="10" />
    </DiagramPageSettings>
</SfDiagram>

@code
{
    //Sets the page orientation as landscape.
    public PageOrientation orientation = PageOrientation.Landscape;

    //Defines diagram's nodes collection
    public ObservableCollection<DiagramNode> NodeCollection = new ObservableCollection<DiagramNode>();

    public DiagramConstraints diagramConstraints = DiagramConstraints.Default;

    protected override void OnInitialized()
    {
        DiagramNode node = new DiagramNode()
        {
            Id = "group",
            OffsetX = 200,
            OffsetY = 200,
            Width = 100,
            Height = 100,
            Annotations = new ObservableCollection<DiagramNodeAnnotation>()
            {
                new DiagramNodeAnnotation()
                {
                    Content = "Node1",
                    Style = new AnnotationStyle()
                    {
                        Color = "white",
                    }
                }
            },
            Style = new NodeShapeStyle() { Fill = "cornflowerblue", StrokeColor = "white" }
        };
        NodeCollection.Add(node);
    }
}

Set background image

Stretch and align the background image anywhere over the diagram area. The Source property of Background allows you to set the path of the image. The Scale and the Align properties help to stretch/align the background images.

The following code illustrates how to stretch and align the background image.

@using Syncfusion.Blazor.Diagrams
<SfDiagram Width="1000px" Height="500px" id="diagram">
    <DiagramSnapSettings>
        <HorizontalGridlines LineColor="#e0e0e0"/>
        <VerticalGridlines LineColor="#e0e0e0"/>
    </DiagramSnapSettings>
    @*Initialize the page settings with page orientation and break lines*@
    <DiagramPageSettings Height="300" Width="300" Orientation="@orientation" ShowPageBreaks="true">
        <DiagramBackground Source="https://www.w3schools.com/images/w3schools_green.jpg"/>
        <PageSettingsMargin Left="10" Top="10" Bottom="10"/>
    </DiagramPageSettings>
</SfDiagram>

@code
{
    //Sets the page orientation as landscape.
    public PageOrientation orientation = PageOrientation.Landscape;
}

Multiple page and page breaks

When multiple page is enabled, the size of the page dynamically increases or decreases in multiples of page width and height and completely fits diagram within the page boundaries. Page breaks is used as a visual guide to see how pages are split into multiple pages.

The MultiplePage and ShowPageBreak properties of page settings allow you to enable/disable multiple pages and page breaks respectively. The following code illustrates how to enable multiple page and page break lines.

@using Syncfusion.Blazor.Diagrams
<SfDiagram Width="1000px" Nodes="@NodeCollection" Height="500px" id="diagram">
    <DiagramSnapSettings>
        <HorizontalGridlines LineColor="gray"/>
        <VerticalGridlines LineColor="gray"/>
    </DiagramSnapSettings>
    @*Initialize the page settings with page orientation and multiple pages*@
    <DiagramPageSettings Height="300" Width="300" MultiplePage="true" Orientation="@orientation" ShowPageBreaks="true">
        <DiagramBackground Color="lightblue"/>
        <PageSettingsMargin Left="10" Top="10" Bottom="10"/>
    </DiagramPageSettings>
</SfDiagram>

@functions
{
    //Sets the page orientation as landscape.
    public PageOrientation orientation = PageOrientation.Landscape;

    //Defines diagram's nodes collection
    public ObservableCollection<DiagramNode> NodeCollection = new ObservableCollection<DiagramNode>();

    public DiagramConstraints diagramConstraints = DiagramConstraints.Default;

    protected override void OnInitialized()
    {
        DiagramNode node = new DiagramNode()
        {
            Id = "group",
            OffsetX = 200,
            OffsetY = 200,
            Width = 100,
            Height = 100,
            Annotations = new ObservableCollection<DiagramNodeAnnotation>()
            {
                new DiagramNodeAnnotation()
                {
                    Content = "Node1",
                    Style = new AnnotationStyle()
                    {
                        Color = "white",
                    }
                }
            },
            Style = new NodeShapeStyle() { Fill = "cornflowerblue", StrokeColor = "white" }
        };
        NodeCollection.Add(node);
    }
}

Boundary constraints

The diagram provides support to restrict/customize the interactive region, out of which the elements cannot be dragged, resized, or rotated. The BoundaryConstraints property of page settings allows you to customize the interactive region. To explore the boundary constraints, refer to Boundary Constraints.

The following code example illustrates how to define boundary constraints with respect to the page.

@using Syncfusion.Blazor.Diagrams
<SfDiagram Width="1000px" Nodes="@NodeCollection" Height="500px">
    <DiagramSnapSettings>
        <HorizontalGridlines LineColor="gray"/>
        <VerticalGridlines LineColor="gray"/>
    </DiagramSnapSettings>
    @*Initialize the page settings with page orientation and break lines*@
    <DiagramPageSettings Height="300" Width="300" MultiplePage="true" Orientation="@orientation" BoundaryConstraints="@boundaryConstraints" ShowPageBreaks="true">
        <DiagramBackground Color="lightblue"/>
        <PageSettingsMargin Left="10" Top="10" Bottom="10"/>
    </DiagramPageSettings>
</SfDiagram>

@Code
{
    //Reference to diagram
    SfDiagram diagram;

    public PageOrientation orientation = PageOrientation.Landscape;

    public BoundaryConstraints boundaryConstraints = BoundaryConstraints.Page;

    //Defines diagram's nodes collection
    public ObservableCollection<DiagramNode> NodeCollection = new ObservableCollection<DiagramNode>();

    public DiagramConstraints diagramConstraints = DiagramConstraints.Default;

    protected override void OnInitialized()
    {
        DiagramNode node = new DiagramNode()
        {
            Id = "group",
            OffsetX = 200,
            OffsetY = 200,
            Width = 100,
            Height = 100,
            Annotations = new ObservableCollection<DiagramNodeAnnotation>()
            {
                new DiagramNodeAnnotation()
                {
                    Content = "Node1",
                    Style = new AnnotationStyle()
                    {
                        Color = "white",
                    }
                }
            },
            Style = new NodeShapeStyle() { Fill = "cornflowerblue", StrokeColor = "white" }
        };
        NodeCollection.Add(node);
    }
}