{"record":{"id":"f815e41c2714d995","repo":"plotly/plotly.js","slug":"array-attribute-refattr-has-fewer-entries-than-e","errorCode":null,"errorMessage":"Array attribute <refAttr> has fewer entries than expected, extending with default value","messagePattern":"Array attribute <refAttr> has fewer entries than expected, extending with default value","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/plots/cartesian/axes.js","lineNumber":178,"sourceCode":"axes.coerceRefArray = function(containerIn, containerOut, gd, attr, dflt, extraOption, expectedLen) {\n    const axLetter = attr.charAt(attr.length - 1);\n    var axlist = gd._fullLayout._subplots[axLetter + 'axis'];\n    const refAttr = attr + 'ref';\n    var axRef = containerIn[refAttr];\n\n    // Build the axis list, which we use to validate the axis references\n    if(!dflt) dflt = axlist[0] || (typeof extraOption === 'string' ? extraOption : extraOption[0]);\n    axlist = axlist.concat(axlist.map(x => x + ' domain'));\n    axlist = axlist.concat(extraOption ? extraOption : []);\n\n    // Handle array length mismatch\n    if(axRef.length > expectedLen) {\n        // if the array is longer than the expected length, truncate it\n        Lib.warn('Array attribute ' + refAttr + ' has more entries than expected, truncating to ' + expectedLen);\n        axRef = axRef.slice(0, expectedLen);\n    } else if(axRef.length < expectedLen) {\n        // if the array is shorter than the expected length, extend using the default value\n        Lib.warn('Array attribute ' + refAttr + ' has fewer entries than expected, extending with default value');\n        axRef = axRef.concat(Array(expectedLen - axRef.length).fill(dflt));\n    }\n\n    // Clean all axis references, replace with default if invalid\n    for(var i = 0; i < axRef.length; i++) {\n        axRef[i] = axisIds.cleanId(axRef[i], axLetter, true) || axRef[i];\n        if(!axlist.includes(axRef[i])) axRef[i] = dflt;\n    }\n\n    containerOut[refAttr] = axRef;\n    return axRef;\n};\n\n/*\n * Get the type of an axis reference. This can be 'range', 'domain', or 'paper'.\n * This assumes ar is a valid axis reference and returns 'range' if it doesn't\n * match the patterns for 'paper' or 'domain'.\n *","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/plots/cartesian/axes.js#L160-L196","documentation":"Companion to the truncation warning: when an axis array reference attribute has FEWER entries than expectedLen, plotly.js warns and pads the array with the default value (dflt) until it matches the expected length. The attribute still works, but the padding is implicit and the missing entries use defaults rather than your intent.","triggerScenarios":"Supplying an array-valued axis reference attribute with fewer elements than the number of axes/domains it is applied to, e.g. one entry where the grid has several axes or domains.","commonSituations":"Removing axes from a config but forgetting to shorten/keep arrays consistent; hand-written layouts with partial arrays; programmatically built arrays that skipped axes without data.","solutions":["Provide one explicit entry per expected axis/domain in the array.","If default behavior for missing axes is fine, pad the array yourself with the documented default value for clarity.","Verify how many axes your subplot grid produces (including 'xN domain' pseudo-axes) and size the array accordingly."],"exampleFix":"// before\nlayout.xaxis.arrayref = ['x']; // grid has 2 axes\n// after\nlayout.xaxis.arrayref = ['x', 'x2'];","handlingStrategy":"validation","validationCode":"function requireFullAxisRefArray(arr, expectedLen, dflt) {\n  if (!Array.isArray(arr)) throw new TypeError('expected an array');\n  if (arr.length < expectedLen) {\n    console.warn(`padding axis ref array from ${arr.length} to ${expectedLen}`);\n    return arr.concat(Array(expectedLen - arr.length).fill(dflt));\n  }\n  return arr;\n}","typeGuard":"const isCompleteArray = (arr, n) => Array.isArray(arr) && arr.length >= n;","tryCatchPattern":null,"preventionTips":["Always supply explicit values for every axis/domain slot.","Keep array length in sync with grid changes.","Pad intentionally with the documented default rather than relying on implicit padding.","Account for the extra '<axis> domain' pseudo-entries when computing expected length."],"tags":["layout","axes","array-length"],"backgroundTag":"array-length-mismatch","analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}