in src/RangeBarChart.js [158:210]
static getSpacing(props) {
const {
barThickness,
horizontal,
x,
y,
xScale,
yScale,
data,
xDomain,
yDomain,
} = props;
const P = barThickness / 2; // padding
const barsDomain = horizontal ? yDomain : xDomain;
const barsScale = horizontal ? yScale : xScale;
const barsAccessor = horizontal ? makeAccessor2(y) : makeAccessor2(x);
const barsDataDomain = domainFromData(data, barsAccessor);
// find the edges of the tick domain, and map them through the scale function
const [domainHead, domainTail] = [first(barsDomain), last(barsDomain)]
.map(barsScale)
.sort(); // sort the pixel values return by the domain extents
// find the edges of the data domain, and map them through the scale function
const [dataDomainHead, dataDomainTail] = [
first(barsDataDomain),
last(barsDataDomain),
]
.map(barsScale)
.sort(); // sort the pixel values return by the domain extents
// find the necessary spacing (based on bar width) to push the bars completely inside the tick domain
const [spacingTail, spacingHead] = [
clamp(P - (domainTail - dataDomainTail), 0, P),
clamp(P - (dataDomainHead - domainHead), 0, P),
];
if (horizontal) {
return {
spacingTop: spacingHead,
spacingBottom: spacingTail,
spacingLeft: 0,
spacingRight: 0,
};
}
return {
spacingTop: 0,
spacingBottom: 0,
spacingLeft: spacingHead,
spacingRight: spacingTail,
};
}