@microsoft/fabric-visuals-web-components
v5.4.0
Published
Vega-Lite visualization web component for Fabric Apps - Analytics
Readme
@microsoft/fabric-visuals-web-components
Framework-agnostic Web Component for the Fabric Apps - Analytics Vega-Lite visualization system. This package wraps the React VegaVisual component as a standard custom element (<fabric-vega-visual>), bundling React internally so consumers do not need a React dependency.
For the DataGrid web component, see
@microsoft/fabric-datagrid-web-components.
Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.
Installation
npm install @microsoft/fabric-visuals-web-componentsSibling dependency
@microsoft/fabric-visuals-core— providesDataTable,ColumnDef,VisualTheme, and design tokens consumed by properties of this component.
Note: React and ReactDOM are bundled internally — you do not need to install them.
Architecture
@microsoft/fabric-visuals-core (framework-agnostic types & tokens)
↓
@microsoft/fabric-visuals (React VegaVisual component)
↓
@microsoft/fabric-visuals-web-components (this package — wraps React as a custom element)
↓
@microsoft/fabric-visuals-angular (optional Angular wrapper)Quick Start
<script type="module">
import { registerFabricVegaVisual } from '@microsoft/fabric-visuals-web-components';
// Register the <fabric-vega-visual> custom element (idempotent)
registerFabricVegaVisual();
const el = document.querySelector('fabric-vega-visual');
el.spec = {
$schema: 'https://vega.github.io/schema/vega-lite/v6.json',
mark: 'bar',
encoding: {
x: { field: 'city', type: 'nominal' },
y: { field: 'pop', type: 'quantitative' },
},
};
el.theme = {
foreground: '#111',
foregroundSecondary: '#444',
brandForeground: '#0078d4',
brandBackground: '#0078d4',
background: '#fff',
backgroundSecondary: '#f5f5f5',
backgroundHover: '#e8e8e8',
stroke: '#d0d0d0',
};
el.data = {
columns: [
{ name: 'city', displayName: 'City' },
{ name: 'pop', displayName: 'Population' },
],
rows: [
['New York', 8336817],
['London', 8982000],
],
};
</script>
<fabric-vega-visual style="height: 400px"></fabric-vega-visual>Public API
All exports come from the package entry point:
registerFabricVegaVisual(tagName?)
Registers the custom element with the browser. Must be called before using <fabric-vega-visual> in the DOM.
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| tagName | string | 'fabric-vega-visual' | Custom element tag name. Override to avoid conflicts. |
Returns: true if registration occurred, false if the tag was already registered to this class.
Throws: If the tag is already registered to a different constructor.
FabricVegaVisualElement
The custom element class (extends HTMLElement). Properties are set as JavaScript object properties — not HTML attributes — because they carry complex data.
Properties
| Property | Type | Required | Description |
|----------|------|----------|-------------|
| spec | VisualizationSpec \| string | yes | A Vega-Lite spec object or a JSON string. |
| theme | VisualTheme | yes | Semantic color theme from @microsoft/fabric-visuals-core. |
| data | DataTable \| Record<string, DataTable> \| null | no | One table or named datasets. |
| selections | readonly SemanticSelection[] | no | Accepted source selection; omitted is local, [] is controlled and cleared. |
| selectableFields | readonly string[] | no | Raw identity fields, including eligible hidden keys. |
| groupOnKeys | Readonly<Record<string, readonly string[]>> | no | Key fields by field ID. With managed selections, a text value shared by more than one key is shown with a suffix. |
| isCrossHighlightActive | boolean | no | The highlight flag paired with the displayed datasets. |
| configVegaLite | VegaLiteConfig | no | Custom Vega-Lite configuration merged with the built-in base theme. |
| capabilities | VegaVisualCapabilities | no | Compilation and rendering options. |
| header | HeaderProps | no | Title and optional subtitle: { title, subtitle? }. |
| visualContainerCapabilities | VisualContainerCapabilities | no | Copy is enabled by default; opt out with { allowCopyVisual: false }. |
| chromeless | boolean | no | Removes all framing when true. Defaults to false. |
| containerRootClassName | string | no | CSS class for the internal React frame's outer root, not this custom element. Apply dashboard grid/flex placement to the host element itself. |
| containerClassName | string | no | CSS class for the inner card surface: background, border, radius and padding. |
| view | View \| null | — | Read-only. The current Vega View instance, or null if not rendered. |
Reassign framing properties to update; set them to undefined to restore defaults.
Replace capabilities to update options; omitted keys restore defaults.
Events
| Event | Type | Description |
|-------|------|-------------|
| vegaevent | CustomEvent<VegaVisualEventDetail> | Fired for all visualization lifecycle events (render, error, vega, specUpdate). Bubbles and is composed. |
el.addEventListener('vegaevent', (e) => {
console.log(e.detail.type, e.detail.message);
});Re-exported Types
VisualizationSpec,VegaLiteConfig,VegaVisualCapabilities,VegaVisualEventDetail,VegaVisualEventType,VegaVisualEventLevel,VegaVisualEventCallback,VegaVisualProps,VegaVisualHandle,LogLevelNameHeaderProps,VisualContainerCapabilities,VisualFramingProps
Re-exported Utilities
| Function | Description |
|----------|-------------|
| registerVbaFormatter() | Registers the vbaFormat custom format type with Vega. Idempotent. |
| LOG_LEVEL_MAP | Maps friendly names to Vega numeric log level constants. |
Using with Angular
For Angular applications, use the @microsoft/fabric-visuals-angular package which provides a thin Angular wrapper (<fabric-vega-visual-ng>) with @Input/@Output bindings. See its README for details.
