<org-chart> is a native JavaScript custom element backed by the MIT-licensed OrgChart 8.0.0 DOM engine. It uses the original chart markup and stylesheet in light DOM, so node templates, selectors, CSS variables, keyboard interactions and bubbling events work as in the original. No jQuery, TypeScript, polyfill or build step is required.
Serve this repository over HTTP and import its module once:
<link rel="stylesheet" href="./src/orgchart-webcomponents.css">
<org-chart id="team" pan zoom node-content="title"></org-chart>
<script type="module">
import './src/orgchart-webcomponents.js';
const team = document.getElementById('team');
team.data = {
id: 'director', name: 'Lao Lao', title: 'Director',
children: [{ id: 'manager', name: 'Bo Miao', title: 'Manager' }]
};
team.setOptions('minimap', true);
console.log(team.getHierarchy());
</script>For classic scripts, load src/js/orgchart.js followed by src/js/orgchart-element.js. The 46 English demos use this form. PNG export needs window.html2canvas; PDF additionally needs window.jspdf.jsPDF. See the PDF demo for the script order. The map demo uses external OpenLayers resources.
import OrgChartElement, { OrgChart } from 'orgchart-webcomponents';
import 'orgchart-webcomponents/style.css';
const team = new OrgChartElement({ data: datasource, nodeContent: 'title' });
document.body.append(team);The named OrgChart export is the original imperative controller: new OrgChart(container, options) and new OrgChart({ chartContainer, ...options }) retain their original behavior. The default export is the element constructor; append it where the chart should live. Do not mount both APIs into the same container. Import the library on the browser side in applications with server-side rendering.
- Set
element.optionsor callelement.init(options)to provide data and callbacks together. Setelement.datato replace the datasource. Both properties can be assigned before connection or before the element definition loads.element.datatakes precedence overoptions.dataduring upgrade. - The element is its own
chartContainer;element.chartis the rendered.orgchartornull. Use native node elements as method arguments. Chainable methods return the element.element.controllerexposes the underlying instance when needed. - HTML attributes include
direction,visible-level,node-title,node-contentandchart-class.pan,zoom,minimap,export-buttonandtoggle-siblings-respare boolean attributes: presence enables them. Removal restores the option default. All original options, including callback functions and custom icons, are available through JavaScript. - Removing the element releases its chart, observers, interaction handlers, minimap and export controls. Reconnection rebuilds from the current datasource. Reacquire node references after a rebuild. Call
destroy()to clear a connected chart andinit()to render it again.
See the API reference for all datasource formats, options, methods, return values, events and CSS customization. For migration from 0.x, use visibleLevel in place of depth; fetch remote data before assigning it. The on-demand loading demo shows how to load relatives when a control is activated.
Use Node.js 24 and npm. Install with npm ci; npm start serves the demo index. No build is needed for either the library or the demos.
| Command | Coverage |
|---|---|
npm run unit-tests |
Original controller methods and the E2E failure gate |
npm run integration-tests |
Rendered hierarchy, edits, options and custom-element lifecycle |
npm run compatibility-tests |
Option combinations and real-browser layout/export checks |
npm run e2e-tests |
All Cypress specs against the actual component demos |
npm test |
All four suites; a failing suite fails the command |
Browser tests need the Puppeteer browser and Cypress binary (npx puppeteer browsers install and npx cypress install if npm skipped their install scripts). Cypress uses Chrome by default; set CYPRESS_BROWSER to another installed Cypress-supported browser to override. Run one spec with npm run e2e-tests -- test/cypress/e2e/local-datasource.cy.js.