← Back to Components

diagram-host Component Documentation

{{componentName}}

qds-diagram-host

A web component that displays diagrams using diagrams.net (draw.io) viewer with optional Azure Blob Storage backend. Users can view diagrams and edit them in a popup editor window.

Features

Basic Usage

Without Storage (In-Memory)

<qds-diagram-host
  width="100%"
  height="600px">
</qds-diagram-host>

This creates an empty diagram that can be edited. Changes are kept in memory during the session.

With Diagram XML

<qds-diagram-host
  diagram="<mxGraphModel>...</mxGraphModel>"
  width="100%"
  height="600px">
</qds-diagram-host>

Read-Only Diagram

<qds-diagram-host
  diagram="<mxGraphModel>...</mxGraphModel>"
  editable="false"
  width="100%"
  height="600px">
</qds-diagram-host>

With Azure Blob Storage

Note: Storage integration requires authentication via the Quantum Auth Service.

<!-- Standard .drawio format using default storage account and container -->
<qds-diagram-host
  path="engineering/widget-x/assembly"
  drawing-name="main-diagram"
  width="100%"
  height="600px">
</qds-diagram-host>

<!-- SVG format with embedded diagram data -->
<qds-diagram-host
  path="engineering/widget-x/assembly"
  drawing-name="flowchart.drawio.svg"
  width="100%"
  height="600px">
</qds-diagram-host>

<!-- Using a custom storage account/container -->
<qds-diagram-host
  storage-account="yourstorageaccount"
  container="yourcustomcontainer"
  path="engineering/widget-x/assembly"
  drawing-name="main-diagram"
  width="100%"
  height="600px">
</qds-diagram-host>

Attributes

Display Attributes

Attribute Type Default Description
width String 100% Width of the diagram container
height String 600px Height of the diagram container
diagram String Empty diagram XML content of the diagram
editable Boolean true Whether the diagram can be edited (shows/hides Edit button)
libraries String Quantum Comma-separated list of custom library names to load (without .xml extension)

Storage Attributes

When all required storage attributes (path and drawing-name) are provided and the user is authenticated, the component will automatically load from and save to Azure Blob Storage using Azure AD authentication.

Default Values: The component uses Quantum’s production storage by default:

These defaults can be overridden by providing the respective attributes.

Attribute Type Required Default Description
storage-account String No qdqedprodqvc Azure storage account name
container String No qed-prod-diagrams Blob container name
path String Yes* - Storage path (forward-slash delimited, e.g., “engineering/widget-x/assembly”)
drawing-name String Yes* - Diagram filename (extension optional; defaults to .drawio if not provided)

* Required if using storage integration

Authentication Requirements:

Storage Path

Diagrams are stored using the path pattern:

{container}/{path}/{drawing-name}

If drawing-name doesn’t include a file extension, .drawio is automatically appended.

The component automatically detects the diagram format from the file extension and configures the editor accordingly. Supported formats include:

Examples (using default storage account qdqedprodqvc and container qed-prod-diagrams):

<!-- drawing-name="main-diagram" -->
qed-prod-diagrams/engineering/widget-x/assembly/main-diagram.drawio

<!-- drawing-name="flowchart.drawio.svg" -->
qed-prod-diagrams/engineering/widget-x/assembly/flowchart.drawio.svg

<!-- drawing-name="architecture.xml" -->
qed-prod-diagrams/engineering/widget-x/assembly/architecture.xml

The path attribute provides flexibility to organize diagrams using any folder structure. For example:

Custom Shape Libraries

The component supports loading custom shape libraries that will be available in the editor’s left panel. The Quantum Design System includes a default Quantum library with standard shapes.

Using Custom Libraries

<qds-diagram-host
  libraries="Quantum"
  width="100%"
  height="600px">
</qds-diagram-host>

Multiple libraries can be specified as a comma-separated list:

<qds-diagram-host
  libraries="Quantum,CustomLibrary,AnotherLibrary"
  width="100%"
  height="600px">
</qds-diagram-host>

Library Files

Custom library files must be:

Library files are automatically served from: https://cdn.q360.ai/assets/components/diagram-host/libraries/

Included Library:

Note: Custom libraries are always loaded from the CDN, even during local development. This is because the diagrams.net editor (which runs at https://embed.diagrams.net/) needs to fetch the library files, and cannot access localhost URLs. To test custom libraries during development, you must deploy them to the CDN first.

Creating Custom Libraries

To create custom libraries:

  1. Open diagrams.net desktop application
  2. Create or edit shapes in a library
  3. Click the pencil icon on the library
  4. Select “Export” and save as XML
  5. Place the XML file in src/components/diagram-host/libraries/
  6. Reference the library name (without .xml) in the libraries attribute

Note: Libraries are read-only in the web editor. To edit a library, use the diagrams.net desktop application, then re-export and replace the XML file.

Events

Event Detail Description
diagram-change { diagram: string } Fired when diagram content changes
diagram-loaded { diagram: string, path: string } Fired when diagram loads from storage
diagram-saved { diagram: string, path: string } Fired when diagram saves to storage successfully
diagram-error { error: string } Fired when a storage error occurs

JavaScript API

const diagramHost = document.querySelector('qds-diagram-host');

// Get current diagram XML
const xml = diagramHost.diagram;

// Set diagram XML programmatically
diagramHost.diagram = '<mxGraphModel>...</mxGraphModel>';

// Listen for changes
diagramHost.addEventListener('diagram-change', (event) => {
  console.log('Diagram updated:', event.detail.diagram);
});

// Listen for storage events
diagramHost.addEventListener('diagram-saved', (event) => {
  console.log('Saved to:', event.detail.path);
});

diagramHost.addEventListener('diagram-error', (event) => {
  console.error('Storage error:', event.detail.error);
});

User Interaction

  1. View Mode: Diagram is displayed using diagrams.net viewer with full toolbar

    • Zoom controls
    • Layer controls
    • Navigation controls
    • Print functionality
  2. Edit Mode: Click the “Edit Diagram” button in the top-right corner

    • Opens diagrams.net editor in popup window (1200x800)
    • Full editing capabilities
    • Save with Ctrl+S or File > Save
    • Popup automatically closes after save
    • Changes immediately reflected in viewer

Azure Blob Storage Setup

To use Azure Blob Storage integration, you need to:

  1. Configure CORS on your storage account
  2. Set up Azure AD authentication
  3. Assign RBAC roles to users

Required CORS Settings

Configure CORS on your Azure Storage account to allow browser access:

Allowed Origins: *
Allowed Methods: GET, PUT, OPTIONS
Allowed Headers: *
Exposed Headers: *
Max Age: 3600

Authentication Setup

1. Azure AD App Registration

The app using diagram-host must have an Azure AD app registration with:

2. Initialize Quantum Auth Service

// Initialize auth service (usually done at app startup)
import { initializeQuantumAuth } from 'quantum-design-system/services/auth';

const auth = initializeQuantumAuth({
  clientId: 'your-client-id',
  authority: 'https://login.microsoftonline.com/your-tenant-id',
  redirectUri: window.location.origin,
  scopes: ['User.Read', 'https://storage.azure.com/user_impersonation']
});

// Users must log in
await auth.login();

3. Assign Azure RBAC Roles

Users need appropriate roles on the storage account or container:

Azure CLI Setup

# Create storage account
az storage account create \
  --name youraccount \
  --resource-group yourgroup \
  --location eastus \
  --sku Standard_LRS

# Create container
az storage container create \
  --account-name youraccount \
  --name diagrams \
  --public-access off

# Set CORS
az storage cors add \
  --services b \
  --methods GET PUT OPTIONS \
  --origins '*' \
  --allowed-headers '*' \
  --exposed-headers '*' \
  --max-age 3600 \
  --account-name youraccount

Styling

The component supports CSS custom properties for theming:

qds-diagram-host {
  --theme-accent-primary: #445E89;
  --theme-accent-secondary: #3E495B;
  --theme-background-primary: #fff;
  --theme-border-primary: #e0e0e0;
  --theme-text-secondary: #666;
  --theme-error: #8B1F00;
}

The edit button can be styled using the ::part() selector:

qds-diagram-host::part(edit-button) {
  background: #custom-color;
}

Troubleshooting

Diagram doesn’t load from storage

Diagram doesn’t save to storage

Authentication errors

Editor is empty/grayed out

Browser Support

Requires support for:

License

Part of the Quantum Design System (QDS)