Skip to content
These are the v1 docs and are no longer maintained. See the current docs.

Template Extension

A development template and reference extension that provides a starting point for creating custom extensions for modernGraphTool.

The Template extension serves as a comprehensive example and starting point for developers who want to create custom extensions for modernGraphTool.

It demonstrates best practices, proper API usage, and common patterns used in extension development.

  • Complete Extension Structure: Full example of extension architecture
  • API Demonstrations: Examples of using core modernGraphTool APIs
  • Event Handling: Proper event listening and dispatching patterns
  • UI Integration: Shadow DOM and component integration examples
  • Configuration Handling: Extension configuration management
  • Development Tools: Built-in development and debugging utilities
PropertyValue
Extension Nametemplate
Latest Version1.0.0
Minimum Core API Level1
Minimum Core Version1.0.0
I18N SupportPartial (demonstrates i18n patterns)
{
NAME: "template",
DESCRIPTION: "sample description",
ENABLED: false, // Disabled by default as it's a development template
}

The template extension showcases usage of modernGraphTool’s core APIs:

  • MenuState: Accessing and managing application menu state
  • DataProvider: Reading frequency response data and metadata
  • MetadataParser: Parsing headphone metadata information
  • GtToast: Displaying toast notifications to users
  • StringLoader: Internationalization and string management (if I18N_ENABLED)
  • CoreEvent: Event system integration
// Example from template extension
import { MenuState, DataProvider, MetadataParser, GtToast } from '../../core.min.js';
// Access current frequency response data
const frDataMap = DataProvider.getFRDataMap();
// Access phone metadata
const phoneMetadata = DataProvider.getPhoneMetadata();
// Show toast notification
GtToast.show('Template extension loaded!', 'info');
template/
├── main.js // Main extension entry point
└── README.md // Extension documentation (if needed)
export default class TemplateElement extends HTMLElement {
constructor(config = {}) {
super();
this.config = config; // Store extension configuration
this.attachShadow({ mode: 'open' }); // Create shadow DOM
// Initialize extension
this._initializeExtension();
}
}

The template demonstrates proper Shadow DOM implementation:

// Create shadow DOM
const shadow = this.attachShadow({ mode: 'open' });
// Create and style container
const container = document.createElement('div');
container.classList.add('container');
shadow.appendChild(container);

Examples of proper event management:

// Event listener setup
this._setupEventListeners();
// Button click handlers
button.addEventListener('click', (e) => {
this._handleButtonClick(e);
});

How to handle extension configuration:

constructor(config = {}) {
this.config = config;
// Use configuration values
if (this.config.SOME_OPTION) {
// Handle configuration option
}
}
  1. Copy the template folder to create your new extension
  2. Rename the folder to your extension name
  3. Update the main.js file with your extension logic
export const EXTENSION_METADATA = {
name: 'your-extension-name', // Update with your extension name
version: '1.0.0', // Your extension version
apiLevel: 1, // Keep current API level
coreMinVersion: '1.0.0', // Minimum modernGraphTool version
coreMaxVersion: '1.0.x', // Maximum compatible version
description: 'Your extension description',
author: 'Your Name'
};
{
NAME: "your-extension-name", // Must match folder name
DESCRIPTION: "Your extension description",
ENABLED: true, // Enable for development
I18N_ENABLED: false, // Enable if you need i18n
CONFIG: {
// Your custom configuration options
YOUR_OPTION: "default_value",
},
}

Replace the template content with your extension logic:

export default class YourExtensionClass extends HTMLElement {
constructor(config = {}) {
super();
// Your extension initialization
}
// Your methods and functionality
}