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.
<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.
<qds-diagram-host
diagram="<mxGraphModel>...</mxGraphModel>"
width="100%"
height="600px">
</qds-diagram-host>
<qds-diagram-host
diagram="<mxGraphModel>...</mxGraphModel>"
editable="false"
width="100%"
height="600px">
</qds-diagram-host>
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>
| 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) |
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:
qdqedprodqvcqed-prod-diagramsQuantumThese 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:
https://storage.azure.com/user_impersonation API permissionStorage Blob Data Contributor (for read/write access)Storage Blob Data Reader (for read-only access)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:
.drawio or .xml - Standard XML format (default).drawio.svg or .svg - SVG with embedded diagram data.drawio.png or .png - PNG with embedded diagram data.html - HTML with embedded diagram dataExamples (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:
engineering/widget-x/assemblyprojects/2024/q1/project-alphateam/design/mockupsThe 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.
<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>
Custom library files must be:
libraries folder within the diagram-host component directory.xml extension (e.g., Quantum.xml)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.
To create custom libraries:
src/components/diagram-host/libraries/libraries attributeNote: 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.
| 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 |
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);
});
View Mode: Diagram is displayed using diagrams.net viewer with full toolbar
Edit Mode: Click the “Edit Diagram” button in the top-right corner
To use Azure Blob Storage integration, you need to:
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
1. Azure AD App Registration
The app using diagram-host must have an Azure AD app registration with:
https://storage.azure.com/user_impersonation (Delegated)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:
Storage Blob Data Contributor - For read/write access (recommended)Storage Blob Data Reader - For read-only access# 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
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;
}
getQuantumAuth() should return an auth service)Storage Blob Data Reader or Storage Blob Data Contributor role on the storage accountStorage Blob Data Contributor role (read-only role won’t work for saves)https://storage.azure.com/user_impersonation permissionRequires support for:
Part of the Quantum Design System (QDS)