plotly/plotly.js · error

Multiple implied roots, cannot build <trace.type> hierarchy

Error message

Multiple implied roots, cannot build <trace.type> hierarchy of <trace.name>. These roots include: <impliedRoots.join(', ')>

What it means

In src/traces/sunburst/calc.js:107, when labels/parents imply more than one root (multiple entries whose parent is empty), the hierarchy is ambiguous. d3 stratify needs exactly one root, so Plotly warns 'Multiple implied roots' and skips building that trace's hierarchy, leaving the sunburst empty.

Source

Thrown at src/traces/sunburst/calc.js:107

        for(k in parent2children) {
            if(!refs[k]) {
                impliedRoots.push(k);
            }
        }

        // if an `id` has no ref in the `parents` array,
        // take it as being the root node

        if(impliedRoots.length === 1) {
            k = impliedRoots[0];
            cd.unshift({
                hasImpliedRoot: true,
                id: k,
                pid: '',
                label: k
            });
        } else {
            return Lib.warn([
                'Multiple implied roots, cannot build', trace.type, 'hierarchy of', trace.name + '.',
                'These roots include:', impliedRoots.join(', ')
            ].join(' '));
        }
    } else if(parent2children[''].length > 1) {
        var dummyId = Lib.randstr();

        // if multiple rows linked to the root node,
        // add dummy "root of roots" node to make d3 build the hierarchy successfully

        for(var j = 0; j < cd.length; j++) {
            if(cd[j].pid === '') {
                cd[j].pid = dummyId;
            }
        }

        cd.unshift({
            hasMultipleRoots: true,

View on GitHub (pinned to 1d090e0b5f)

Solutions

  1. Add a single explicit root node and set every former implied root's parent to that root's id.
  2. Split the data into separate traces, one per tree.
  3. Audit the parents array so exactly one entry (or one implied root) has an empty parent.

Example fix

// before
ids: ['a','b','a1'], parents: ['', '', 'a'] // two implied roots a and b
// after
ids: ['root','a','b','a1'], parents: ['', 'root', 'root', 'a']
Defensive patterns

Strategy: validation

Validate before calling

const rootCount = ids.reduce((n, id, i) => (parents[i] === '' ? n + 1 : n), 0);
const hasExplicitRoot = ids.some(id => parents.every(p => p !== '' ) === false && parents[ids.indexOf(id)] === undefined);
if (rootCount > 1) throw new Error('Multiple implied roots: ' + ids.filter((_, i) => parents[i] === ''));

Type guard

function hasSingleRoot(ids, parents) {
  const roots = ids.filter((_, i) => parents[i] === '');
  return roots.length <= 1;
}

Prevention

When it happens

Trigger: A sunburst (or treemap/icicle) trace where ids/parents produce two or more nodes with pid '' that are not the designated root — e.g. parents: ['', '', ...] for several top-level entries without a single explicit root id.

Common situations: Converting multiple trees to one sunburst without a common root; data where several categories have empty parent strings by mistake; renaming the root id while children still reference the old parent.

Related errors


AI-assisted analysis of plotly/plotly.js@1d090e0b5f (2026-09-02). Data as JSON: /api/errors/dd2c16a4594b193f. Report an issue: GitHub.