You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Bar.js picks out the legend data for keys, it looks at all the bars with index 0, i.e. the first group or stack of bars, then uses these to generate the legend.
// nivo/packages/nivo-bar/src/Bar.js line 157constlegendDataForKeys=result.bars.filter(bar=>bar.data.index===0).map(bar=>({label: bar.data.id,fill: bar.data.fill ? bar.data.fill : bar.color,})).reverse()
However, if the value of a given data key on the first bar is 0 then that bar is not included in result.bars, presumably to reduce the rendering load by hiding zero-height bars. However, this means that when legendDataForKeys looks for bars, it misses out those keys.
One possible fix would be to include zero-height bars by amending generateVerticalGroupedBars in compute/grouped.js so that it does not exclude bars if they have no height.
// nivo/packages/nivo-bar/src/compute/grouped.js line 88if(barWidth>0){keys.forEach((key,i)=>{range(xScale.domain().length).forEach(index=>{constx=xScale(getIndex(data[index]))+barWidth*i+innerPadding*iconsty=getY(data[index][key])constbarHeight=getHeight(data[index][key],y)if(barWidth>0/*&& barHeight > 0*/){// Remove this conditionconstbarData={id: key,
This has the disadvantage that we lose the performance benefit of not rendering zero-height bars so it should be possible to filter them out after the legend keys have been generated.
When
Bar.js
picks out the legend data for keys, it looks at all the bars with index 0, i.e. the first group or stack of bars, then uses these to generate the legend.However, if the value of a given data key on the first bar is 0 then that bar is not included in
result.bars
, presumably to reduce the rendering load by hiding zero-height bars. However, this means that whenlegendDataForKeys
looks for bars, it misses out those keys.One possible fix would be to include zero-height bars by amending
generateVerticalGroupedBars
incompute/grouped.js
so that it does not exclude bars if they have no height.This has the disadvantage that we lose the performance benefit of not rendering zero-height bars so it should be possible to filter them out after the legend keys have been generated.
The text was updated successfully, but these errors were encountered: