@apptane/react-ui-charts
Version:
Chart components in Apptane React UI framework
30 lines (25 loc) • 986 B
JavaScript
/**
* Returns inverse function for d3-scaleBand
*/
export function scaleBandInvert(scale) {
var _scale;
const domain = scale.domain();
const step = scale.step();
const offset = (_scale = scale(domain[0])) !== null && _scale !== void 0 ? _scale : 0;
const paddingInnerHalf = scale.paddingInner() * step * 0.5;
return function (value) {
let index = Math.floor((value - offset) / step);
if (value > offset + (index + 1) * step - paddingInnerHalf) {
index++;
}
return domain[Math.max(0, Math.min(index, domain.length - 1))];
};
}
/**
* Finds primary or secondary value that matches the criteria in the predicate.
*/
export function findValue(datum, predicate) {
var _datum$pri$find, _datum$sec;
return (_datum$pri$find = datum.pri.find(predicate)) !== null && _datum$pri$find !== void 0 ? _datum$pri$find : (_datum$sec = datum.sec) === null || _datum$sec === void 0 ? void 0 : _datum$sec.find(predicate);
}
//# sourceMappingURL=common.js.map