@emaarco/dmn-js-simulation
v0.7.0
Published
Simulate DMN decision tables directly in a dmn-js modeler — see which rules match and what the decision returns.
Maintainers
Readme
@emaarco/dmn-js-simulation
Simulate DMN decision tables directly in a dmn-js modeler — feed in concrete inputs and instantly see which rules match, which don't, and what the decision returns.

The idea behind this project
@emaarco/dmn-js-simulation is to DMN what bpmn-js-token-simulation is to BPMN: it lets you validate decision logic while you model it, instead of discovering mistakes later in process code, tests, or production. It supports all DMN hit policies (UNIQUE, FIRST, ANY, PRIORITY, COLLECT with SUM/MIN/MAX/COUNT, RULE ORDER, OUTPUT ORDER) and multi-decision DRD chaining.
Features
- Decision-table simulation — an input form appears above the table; run it to highlight the matched rule(s) and read off the result. Rules dropped by the hit policy (e.g. under
FIRST/PRIORITY) are shown as dimmed candidates, so the policy's effect is visible. - All hit policies, including
COLLECTaggregations and policy-violation warnings (e.g.UNIQUEmatched twice). - DRD chaining — simulate a whole decision requirement graph, down to a single decision with its input data: set the input-data leaves once, and every decision is evaluated in dependency order. Fired decisions are highlighted and annotated with their result; drilling into a decision reflects that run's row highlights.
- Drop-in — installs like any dmn-js module via
additionalModules;dmn-jsis a peer dependency, so it drives the modeler you already use. - Fits your host — switch it on and off, render it into your own container as one live row, and theme it through CSS variables that default to dmn-js's own tokens.
Installation
npm install @emaarco/dmn-js-simulationdmn-js (>= 17) is a peer dependency — install it if you haven't already.
Usage
import DmnModeler from 'dmn-js/lib/Modeler'
import DmnSimulationModule from '@emaarco/dmn-js-simulation'
import '@emaarco/dmn-js-simulation/assets/dmn-js-simulation.css'
const modeler = new DmnModeler({
container: '#canvas',
decisionTable: { additionalModules: [DmnSimulationModule.decisionTable] },
drd: { additionalModules: [DmnSimulationModule.decisionRequirementsDiagram] },
})
await modeler.importXML(dmnXml)Register only the view(s) you need. The modules are also exported individually:
import { DmnSimulationTableModule, DmnSimulationDecisionRequirementsDiagramModule } from '@emaarco/dmn-js-simulation'DRD view: make sure your app imports dmn-js's icon font (
dmn-js/dist/assets/dmn-font/css/dmn-embedded.css) alongside its other stylesheets — otherwise the DRD editor palette icons render blank.
Switch it on and off, and place it yourself
Every view registers a dmnSimulation service. Its options go under
dmnSimulation; put them in dmn-js's common options to reach every view:
const modeler = new DmnModeler({
container: '#canvas',
common: {
dmnSimulation: {
active: false, // start switched off
container: bottomBar, // render into your own element
layout: 'inline', // one row that wraps
evaluateOn: 'input', // evaluate as the user types
},
},
decisionTable: { additionalModules: [DmnSimulationModule.decisionTable] },
drd: { additionalModules: [DmnSimulationModule.decisionRequirementsDiagram] },
})
const simulation = modeler.getActiveViewer().get('dmnSimulation')
simulation.toggle() // flip it; toggle(true) or toggle(false) to set it
simulation.isActive()
simulation.isAvailable() // can this view be simulated at all?
modeler.getActiveViewer().on('dmnSimulation.toggle', ({ active }) => updateButton(active))
modeler.getActiveViewer().on('dmnSimulation.availability', ({ available }) => showButton(available))| Option | Default | What it does |
| ------------ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| active | true | Whether the simulation starts on. While off, no form, panel, row highlight or DRD badge is shown; the entered values and the last result stay. |
| container | — | An element, or (viewType: 'drd' \| 'decisionTable') => HTMLElement \| null. The form and the DRD panel render there instead of above the table and in the DRD's corner; null leaves a view without UI. |
| layout | 'stacked' | 'inline' puts inputs, Simulate, result and Reset in one row that wraps; the DRD panel drops its title. |
| evaluateOn | 'run' | 'input' evaluates once the user pauses typing and leaves out the Simulate button. |
The on/off state belongs to the modeler, not to a view: switching between the
DRD and a decision table keeps it. Whether a view can be simulated belongs to
the view: isAvailable() is always true in a decision table, and in the DRD
once the diagram has a decision and an input data. The DRD announces a change,
after an edit or an import, as dmnSimulation.availability; on a view switch,
ask the new view. With a container, only the view dmn-js
shows renders into it, so the DRD and the tables can share one element. The
add-on appends an element of its own and leaves the rest of your container
alone; there the UI has no card or position of its own, your container owns
them. The types are exported: DmnSimulation, DmnSimulationConfig,
DmnSimulationContainer, DmnSimulationLayout, DmnSimulationEvaluateOn,
DmnSimulationViewType, DmnSimulationToggleEvent and
DmnSimulationAvailabilityEvent.
Theming
The add-on takes its colours, radii and font from the dmn-js it runs in: unset,
every --dmn-sim-* variable falls back to the bpmn-io tokens dmn-js ships
(--bio-surface, --bio-text, --bio-primary, …), and the text inherits the
host's font. A host that switches --bio-* for dark mode gets a readable
simulation without overrides. To set a look of your own, set any
--dmn-sim-* variable, on :root or on a container:
:root {
--dmn-sim-accent: #0a7d4f;
--dmn-sim-font: 'Inter', sans-serif;
}The variables: --dmn-sim-font, --dmn-sim-font-mono, --dmn-sim-surface,
--dmn-sim-ink, --dmn-sim-muted, --dmn-sim-line, --dmn-sim-disabled-ink,
--dmn-sim-output-bg, --dmn-sim-panel-bg, --dmn-sim-accent,
--dmn-sim-accent-ink, --dmn-sim-accent-soft, --dmn-sim-on-accent,
--dmn-sim-success(-soft), --dmn-sim-warning(-soft), --dmn-sim-danger(-soft),
--dmn-sim-match-bg, --dmn-sim-match-accent, --dmn-sim-candidate-bg,
--dmn-sim-fired, --dmn-sim-space-1…3, --dmn-sim-radius-sm|md|lg|pill,
--dmn-sim-shadow-1…3, --dmn-sim-motion-fast and --dmn-sim-ease.
Evaluate without a modeler
The framework-free evaluation core is exported too, for tests or headless use:
import { DmnXmlReader, DecisionTableEvaluator } from '@emaarco/dmn-js-simulation'
const model = new DmnXmlReader().readDecisionTable(dmnXml)
const result = new DecisionTableEvaluator(model).evaluate(['Fall', 8])
// → { matchedRuleIndices, reportedRuleIndices, outputs, aggregation?, violation? }new DmnModdleReader().readDecisionRequirementsDiagram(definitions) + new DecisionRequirementsDiagramEvaluator(model).evaluate(inputValues) do the same for a whole DRD graph.
Contributing
Contributions are welcome — see CONTRIBUTING.md for the monorepo layout, scripts, and how to build, test and run the example locally.
Credits
- dmn-js by bpmn.io — the DMN modeler this add-on plugs into.
- Inspired by bpmn-js-token-simulation, the BPMN token simulator by bpmn.io.
License
MIT © Marco Schäck
