{"record":{"id":"dd2c16a4594b193f","repo":"plotly/plotly.js","slug":"multiple-implied-roots-cannot-build-trace-type","errorCode":null,"errorMessage":"Multiple implied roots, cannot build <trace.type> hierarchy of <trace.name>. These roots include: <impliedRoots.join(', ')>","messagePattern":"Multiple implied roots, cannot build <trace\\.type> hierarchy of <trace\\.name>\\. These roots include: <impliedRoots\\.join\\(', '\\)>","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/traces/sunburst/calc.js","lineNumber":107,"sourceCode":"        for(k in parent2children) {\n            if(!refs[k]) {\n                impliedRoots.push(k);\n            }\n        }\n\n        // if an `id` has no ref in the `parents` array,\n        // take it as being the root node\n\n        if(impliedRoots.length === 1) {\n            k = impliedRoots[0];\n            cd.unshift({\n                hasImpliedRoot: true,\n                id: k,\n                pid: '',\n                label: k\n            });\n        } else {\n            return Lib.warn([\n                'Multiple implied roots, cannot build', trace.type, 'hierarchy of', trace.name + '.',\n                'These roots include:', impliedRoots.join(', ')\n            ].join(' '));\n        }\n    } else if(parent2children[''].length > 1) {\n        var dummyId = Lib.randstr();\n\n        // if multiple rows linked to the root node,\n        // add dummy \"root of roots\" node to make d3 build the hierarchy successfully\n\n        for(var j = 0; j < cd.length; j++) {\n            if(cd[j].pid === '') {\n                cd[j].pid = dummyId;\n            }\n        }\n\n        cd.unshift({\n            hasMultipleRoots: true,","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/traces/sunburst/calc.js#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a single explicit root node and set every former implied root's parent to that root's id.","Split the data into separate traces, one per tree.","Audit the parents array so exactly one entry (or one implied root) has an empty parent."],"exampleFix":"// before\nids: ['a','b','a1'], parents: ['', '', 'a'] // two implied roots a and b\n// after\nids: ['root','a','b','a1'], parents: ['', 'root', 'root', 'a']","handlingStrategy":"validation","validationCode":"const rootCount = ids.reduce((n, id, i) => (parents[i] === '' ? n + 1 : n), 0);\nconst hasExplicitRoot = ids.some(id => parents.every(p => p !== '' ) === false && parents[ids.indexOf(id)] === undefined);\nif (rootCount > 1) throw new Error('Multiple implied roots: ' + ids.filter((_, i) => parents[i] === ''));","typeGuard":"function hasSingleRoot(ids, parents) {\n  const roots = ids.filter((_, i) => parents[i] === '');\n  return roots.length <= 1;\n}","tryCatchPattern":null,"preventionTips":["Always include one explicit root node with parent '' and attach all top-level nodes to it.","Validate that exactly one entry has an empty parent before Plotly.react/Plotly.newPlot.","When merging multiple trees, insert a synthetic root instead of leaving several empty parents."],"tags":["sunburst","hierarchy","tree-structure","data-validation"],"backgroundTag":"multiple-hierarchy-roots","analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}