# diagram-local-data

> Diagram sample binding local shape data and connector relationships for a simple business flow.

**Framework:** javascript  **Component:** Diagram  **Variant:** local-data

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/javascript/diagram-local-data.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-diagrams
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/diagram-local-data/diagram.html

```html
<div class="control-section">
    <div style="width: 100%">
        <div id="container"></div>
    </div>
</div>
```

### src/components/diagram-local-data/diagram.ts

```typescript
import type { NodeModel, ConnectorModel } from '@syncfusion/ej2-diagrams';
import {
    Diagram, DataBinding, HierarchicalTree, DiagramTools
} from '@syncfusion/ej2-diagrams';
import { DataManager } from '@syncfusion/ej2-data';
import { species } from '../datasource/diagram-data';

export interface DataInfo {
    [key: string]: string;
}

Diagram.Inject(DataBinding, HierarchicalTree);

//Sets the default values of nodes
function getNodeDefaults(obj: NodeModel): NodeModel {
    //Initialize shape
    obj.shape = { type: 'Basic', shape: 'Rectangle' };
    obj.style = { strokeWidth: 1 };
    obj.width = 95;
    obj.height = 30;
    return obj;
}

//Sets the default values of connectors
function getConnectorDefaults(connector: ConnectorModel): ConnectorModel {
    connector.type = 'Orthogonal';
    connector.style!.strokeColor = '#4d4d4d';
    connector.targetDecorator!.shape = 'None';
    return connector;
}

export interface EmployeeInfo {
    Role: string;
    color: string;
}

// tslint:disable-next-line:max-func-body-length
export function initLocalDataDiagram(): void {
    //Initializes diagram control
    let diagram: Diagram = new Diagram({
        width: '100%', height: '350px',
        //Configures data source
        dataSourceSettings: {
            id: 'Name', parentId: 'Category', dataSource: new DataManager(species),
            //binds the external data with node
            doBinding: (nodeModel: NodeModel, data: DataInfo) => {
                nodeModel.annotations = [
                    {
                        /* tslint:disable:no-string-literal */
                        content: data['Name'],
                        style: { color: 'black' }
                    }
                ];
                nodeModel.style = { fill: '#ffeec7', strokeColor: '#f5d897', strokeWidth: 1 };
            }
        },
        //Configrues HierarchicalTree layout
        layout: {
            type: 'HierarchicalTree', horizontalSpacing: 15, verticalSpacing: 50,
            margin: { top: 10, left: 10, right: 10, bottom: 0 },
        },
        //Sets the default values of nodes
        getNodeDefaults: getNodeDefaults,
        //Sets the default values of connectors
        getConnectorDefaults: getConnectorDefaults,
        //Disables all interactions except zoom/pan
        tool: DiagramTools.ZoomPan,
        snapSettings: { constraints: 0 }
    });
    diagram.appendTo('#container');
}

```
