Overview in React Diagram component

6 Dec 202424 minutes to read

The Overview control allows you to see a preview or an overall view of the entire content of a diagram. This helps you to grasp the overall picture of a large diagram and navigate, pan, or zoom to a specific position on the page.

Usage scenario

When working on a very large diagram, it can be challenging to know which part you are actually focusing on or to navigate from one section to another. One solution for navigation is to zoom out to view the entire diagram and locate your position. Then, you can zoom in on the specific area you need. However, this method is not ideal for frequent navigation.

The Overview control addresses these issues by providing a preview, or overall view, of the entire diagram. A rectangle indicates the viewport of the diagram, making navigation easy by dragging this rectangle to the desired section.

Create overview

To create an overview, the sourceID property of the overview should be set with the corresponding diagram Id for the overall view.

The width and height properties of the overview allow you to define its size.

The following code illustrates how to create an overview:

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { DiagramComponent, OverviewComponent, SnapConstraints } from '@syncfusion/ej2-react-diagrams';

// A node is created and stored in nodes array.
let node = [
  { id: 'node1', offsetX: 400, offsetY: 400, height: 100, width: 200 },
];
// Initializes the Diagram control
function App() {
  return (
    <div style={{ display: 'flex' }}>
      <div style={{ flex: 7 }}>
        <DiagramComponent
          id="container"
          height={'790px'}
          width={'100%'}
          nodes={node}
          scrollSettings={{ scrollLimit: 'Diagram' }}
          // Sets the constraints of the SnapSettings
          snapSettings={{ constraints: SnapConstraints.None }}
        ></DiagramComponent>
      </div>
      <div
        style={{
          flex: 3,
          height: 250,
          padding: 0,
          right: 30,
          bottom: 20,
          border: '#eeeeee',
          background: '#f7f7f7',
        }}
      >
        <OverviewComponent
          id="overview"
          sourceID="container"
          width={'300px'}
          height={'150ppx'}
        />
      </div>
    </div>
  );
}
const root = ReactDOM.createRoot(document.getElementById('diagram'));
root.render(<App />);
import * as React from "react";
import * as ReactDOM from "react-dom";
import { DiagramComponent, OverviewComponent, NodeModel, SnapConstraints } from '@syncfusion/ej2-react-diagrams';
// A node is created and stored in nodes array.
let node: NodeModel[] = [ { id: 'node1', offsetX: 400, offsetY: 400, height: 100, width: 200 },];
// Initializes the Diagram control
function App() {
  return (
    <div style={{ display: 'flex' }}>
    <div style={{ flex: 7 }}>
      <DiagramComponent
        id="container"
        height={'790px'}
        width={'100%'}
        nodes={node}
        scrollSettings={{ scrollLimit: 'Diagram' }}
        // Sets the constraints of the SnapSettings
        snapSettings={{ constraints: SnapConstraints.None }}
      ></DiagramComponent>
    </div>
    <div
      style={{
        flex: 3,
        height: 250,
        padding: 0,
        right: 30,
        bottom: 20,
        border: '#eeeeee',
        background: '#f7f7f7',
      }}
    >
      <OverviewComponent
        id="overview"
        sourceID="container"
        width={'300px'}
        height={'150ppx'}
      />
    </div>
  </div>
  );
}
const root = ReactDOM.createRoot(document.getElementById('diagram'));
root.render(<App />);

Overview interactions

In the overview, the viewport of the diagram is highlighted with a red color rectangle. You can zoom and pan the diagram by interacting with this rectangle.

You can interact with the overview as follows:

  • Resize the rectangle: Zooms in/out of the diagram.
  • Drag the rectangle: Pans the diagram.
  • Click on a position: Navigates to the clicked region.
  • Select a specific region by clicking and dragging: Navigates to the specified region.
import * as React from "react";
import { createRoot } from 'react-dom/client';
import { DataManager, Query } from '@syncfusion/ej2-data';
import { StackPanel, TextElement, DataBinding, OverviewComponent, HierarchicalTree, DiagramTools, DiagramComponent, Inject } from "@syncfusion/ej2-react-diagrams";
/**
 * Overview
 */

let data = [{
        'Id': 'parent',
        'Name': 'Maria Anders',
        'Designation': 'Managing Director',
        'IsExpand': 'true',
        'RatingColor': '#C34444'
    },
    {
        'Id': 1,
        'Name': 'Ana Trujillo',
        'Designation': 'Project Manager',
        'IsExpand': 'false',
        'RatingColor': '#68C2DE',
        'ReportingPerson': 'parent'
    },
    {
        'Id': 2,
        'Name': 'Anto Moreno',
        'Designation': 'Project Lead',
        'IsExpand': 'false',
        'RatingColor': '#93B85A',
        'ReportingPerson': 'parent'
    },
    {
        'Id': 3,
        'Name': 'Thomas Hardy',
        'Designation': 'Senior S/w Engg',
        'IsExpand': 'false',
        'RatingColor': '#68C2DE',
        'ReportingPerson': 1
    },
    {
        'Id': 4,
        'Name': 'Christina kaff',
        'Designation': 'S/w Engg',
        'IsExpand': 'false',
        'RatingColor': '#93B85A',
        'ReportingPerson': 2
    },
    {
        'Id': 5,
        'Name': 'Hanna Moos',
        'Designation': 'Project Trainee',
        'IsExpand': 'true',
        'RatingColor': '#D46E89',
        'ReportingPerson': 2
    },
];
let diagramInstance;
let items = new DataManager(data, new Query().take(7));
let layout = {
    type: 'HierarchicalTree',
    margin: {
        top: 20
    },
    getLayoutInfo: (node, tree) => {
        if (!tree.hasSubTree) {
            tree.orientation = 'Vertical';
            tree.type = 'Alternate';
        }
    },
}
// Initializes the Diagram control
function App() {
    return (<>
      <div style={{ width: '100%', float: 'left' }}>
        <DiagramComponent id="container" ref={(diagram) => (diagramInstance = diagram)} height={'499px'}  created={() => {
        //To draw an object once, activate draw once
        diagramInstance.tool = DiagramTools.ZoomPan;
        diagramInstance.dataBind();
      }}
      layout={layout} dataSourceSettings={{
            id: 'Id',
            parentId: 'ReportingPerson',
            dataManager: items,
        }} getNodeDefaults={(node) => {
            node.height = 50;
            node.style.fill = '#6BA5D7';
            node.borderColor = 'white';
            node.style.strokeColor = 'white';
            return node;
        }} getConnectorDefaults={(obj) => {
            obj.style.strokeColor = '#6BA5D7';
            obj.style.fill = '#6BA5D7';
            obj.style.strokeWidth = 2;
            obj.targetDecorator.style.fill = '#6BA5D7';
            obj.targetDecorator.style.strokeColor = '#6BA5D7';
            obj.targetDecorator.shape = 'None';
            obj.type = 'Orthogonal';
            return obj;
        }} setNodeTemplate={(obj, diagram) => {
            let content = new StackPanel();
            content.id = obj.id + '_outerstack';
            content.style.strokeColor = 'darkgreen';
            content.style.fill = '#6BA5D7';
            content.orientation = 'Horizontal';
            content.padding = {
                left: 5,
                right: 10,
                top: 5,
                bottom: 5,
            };
            let innerStack = new StackPanel();
            innerStack.style.strokeColor = 'none';
            innerStack.style.fill = '#6BA5D7';
            innerStack.margin = {
                left: 5,
                right: 0,
                top: 0,
                bottom: 0,
            };
            innerStack.id = obj.id + '_innerstack';
            let text = new TextElement();
            text.content = obj.data['Name'];
            text.style.color = 'white';
            text.style.strokeColor = 'none';
            text.style.fill = 'none';
            text.id = obj.id + '_text1';
            let desigText = new TextElement();
            desigText.margin = {
                left: 0,
                right: 0,
                top: 5,
                bottom: 0,
            };
            desigText.content = obj.data['Designation'];
            desigText.style.color = 'white';
            desigText.style.strokeColor = 'none';
            desigText.style.fill = 'none';
            desigText.style.textWrapping = 'Wrap';
            desigText.id = obj.id + '_desig';
            innerStack.children = [text, desigText];
            content.children = [innerStack];
            return content;
        }}>
          <Inject services={[DataBinding, HierarchicalTree]}/>
        </DiagramComponent>
      </div>
      <OverviewComponent id="overview"  sourceID="container" width={'100%'} height={'250px'}/>
    </>);
}
const root = createRoot(document.getElementById('diagram'));
root.render(<App />);
import * as React from "react";
import * as ReactDOM from "react-dom";
import { DataManager, Query } from '@syncfusion/ej2-data';
import { StackPanel, TextElement, DataBinding, OverviewComponent, HierarchicalTree, DiagramTools, DiagramComponent, Inject } from "@syncfusion/ej2-react-diagrams";
/**
 * Overview
 */
let data: object[] = [{
        'Id': 'parent',
        'Name': 'Maria Anders',
        'Designation': 'Managing Director',
        'IsExpand': 'true',
        'RatingColor': '#C34444'
    },
    {
        'Id': 1,
        'Name': 'Ana Trujillo',
        'Designation': 'Project Manager',
        'IsExpand': 'false',
        'RatingColor': '#68C2DE',
        'ReportingPerson': 'parent'
    },
    {
        'Id': 2,
        'Name': 'Anto Moreno',
        'Designation': 'Project Lead',
        'IsExpand': 'false',
        'RatingColor': '#93B85A',
        'ReportingPerson': 'parent'
    },
    {
        'Id': 3,
        'Name': 'Thomas Hardy',
        'Designation': 'Senior S/w Engg',
        'IsExpand': 'false',
        'RatingColor': '#68C2DE',
        'ReportingPerson': 1
    },
    {
        'Id': 4,
        'Name': 'Christina kaff',
        'Designation': 'S/w Engg',
        'IsExpand': 'false',
        'RatingColor': '#93B85A',
        'ReportingPerson': 2
    },
    {
        'Id': 5,
        'Name': 'Hanna Moos',
        'Designation': 'Project Trainee',
        'IsExpand': 'true',
        'RatingColor': '#D46E89',
        'ReportingPerson': 2
    },
];
let diagramInstance: DiagramComponent;
let items: DataManager = new DataManager(data as JSON[], new Query().take(7));
let layout: any = {
  type: 'HierarchicalTree',
  margin: {
    top: 20
  },
  getLayoutInfo: (node, tree) => {
    if (!tree.hasSubTree) {
      tree.orientation = 'Vertical';
      tree.type = 'Alternate';
    }
  },
}
// Initializes the Diagram control
function App() {
  return (
    <div>
      <div style={{ width: '100%', float: 'left' }}>
        <DiagramComponent
          id="container"
          ref={(diagram) => (diagramInstance = diagram)}
          height={'499px'}
          created={() => {
            //To draw an object once, activate draw once
            diagramInstance.tool = DiagramTools.ZoomPan;
            diagramInstance.dataBind();
          }}
          layout={layout}
          dataSourceSettings={{
            id: 'Id',
            parentId: 'ReportingPerson',
            dataManager: items,
          }}
          getNodeDefaults={(node) => {
            node.height = 50;
            node.style.fill = '#6BA5D7';
            node.borderColor = 'white';
            node.style.strokeColor = 'white';
            return node;
          }}
          getConnectorDefaults={(obj) => {
            obj.style.strokeColor = '#6BA5D7';
            obj.style.fill = '#6BA5D7';
            obj.style.strokeWidth = 2;
            obj.targetDecorator.style.fill = '#6BA5D7';
            obj.targetDecorator.style.strokeColor = '#6BA5D7';
            obj.targetDecorator.shape = 'None';
            obj.type = 'Orthogonal';
            return obj;
          }}
          setNodeTemplate={(obj, diagram) => {
            let content = new StackPanel();
            content.id = obj.id + '_outerstack';
            content.style.strokeColor = 'darkgreen';
            content.style.fill = '#6BA5D7';
            content.orientation = 'Horizontal';
            content.padding = {
              left: 5,
              right: 10,
              top: 5,
              bottom: 5,
            };
            let innerStack = new StackPanel();
            innerStack.style.strokeColor = 'none';
            innerStack.style.fill = '#6BA5D7';
            innerStack.margin = {
              left: 5,
              right: 0,
              top: 0,
              bottom: 0,
            };
            innerStack.id = obj.id + '_innerstack';
            let text = new TextElement();
            text.content = obj.data['Name'];
            text.style.color = 'white';
            text.style.strokeColor = 'none';
            text.style.fill = 'none';
            text.id = obj.id + '_text1';
            let desigText = new TextElement();
            desigText.margin = {
              left: 0,
              right: 0,
              top: 5,
              bottom: 0,
            };
            desigText.content = obj.data['Designation'];
            desigText.style.color = 'white';
            desigText.style.strokeColor = 'none';
            desigText.style.fill = 'none';
            desigText.style.textWrapping = 'Wrap';
            desigText.id = obj.id + '_desig';
            innerStack.children = [text, desigText];
            content.children = [innerStack];
            return content;
          }}
        >
          <Inject services={[DataBinding, HierarchicalTree]} />
        </DiagramComponent>
      </div>
      <OverviewComponent
        id="overview"  
        sourceID="container"
        width={'100%'}
        height={'250px'}
      />
    </div>
  );
}
const root = ReactDOM.createRoot(document.getElementById('diagram'));
root.render(<App />);

The following Gif image displays the interactions with overview.

Overview-interaction