Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getDefaultMin = (axis) => {
const defaultZero = Scale.getType(scale[axis]) === "log"
? 1 / Number.MAX_SAFE_INTEGER
: 0;
const domain = scale[axis].domain();
const minY = Collection.getMinValue(domain);
const maxY = Collection.getMaxValue(domain);
let defaultMin = defaultZero;
if (minY < 0 && maxY <= 0) {
defaultMin = maxY;
} else if (minY >= 0 && maxY > 0) {
defaultMin = minY;
}
return Collection.containsDates(domain) ? new Date(defaultMin) : defaultMin;
}
const getBrushDomain = (brushDomain, fullDomain) => {
if (brushDomain) {
const brushMin = Collection.getMinValue(brushDomain);
const brushMax = Collection.getMaxValue(brushDomain);
const domainMin = Collection.getMinValue(fullDomain);
const domainMax = Collection.getMaxValue(fullDomain);
const defaultMin = brushMin < domainMin ? domainMin : domainMax - SMALL_NUMBER;
const defaultMax = brushMax > domainMax ? domainMax : domainMin + SMALL_NUMBER;
const min = withinBound(brushMin, fullDomain) ? brushMin : defaultMin;
const max = withinBound(brushMax, fullDomain) ? brushMax : defaultMax;
return [min, max];
}
return fullDomain;
};
const getBrushDomain = (brushDomain, fullDomain) => {
if (brushDomain) {
const brushMin = Collection.getMinValue(brushDomain);
const brushMax = Collection.getMaxValue(brushDomain);
const domainMin = Collection.getMinValue(fullDomain);
const domainMax = Collection.getMaxValue(fullDomain);
const defaultMin = brushMin < domainMin ? domainMin : domainMax - SMALL_NUMBER;
const defaultMax = brushMax > domainMax ? domainMax : domainMin + SMALL_NUMBER;
const min = withinBound(brushMin, fullDomain) ? brushMin : defaultMin;
const max = withinBound(brushMax, fullDomain) ? brushMax : defaultMax;
return [min, max];
}
return fullDomain;
};
const getDefaultMin = (axis) => {
const defaultZero = Scale.getType(props.scale[axis]) === "log"
? 1 / Number.MAX_SAFE_INTEGER
: 0;
let defaultMin = defaultZero;
const minY = Collection.getMinValue(props.domain[axis]);
const maxY = Collection.getMaxValue(props.domain[axis]);
if (minY < 0 && maxY <= 0) {
defaultMin = maxY;
} else if (minY >= 0 && maxY > 0) {
defaultMin = minY;
}
return datum[`_${axis}`] instanceof Date ? new Date(defaultMin) : defaultMin;
};
const _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y");
renderHandles(props) {
const { handleComponent, handleStyle, id, brushDomain, datum = {}, activeBrushes = {} } = props;
if (!brushDomain) {
return null;
}
const handleDimensions = this.getHandleDimensions(props);
const style = assign({}, fallbackProps.handleStyle, handleStyle);
const minDatum = assign({ handleValue: Collection.getMinValue(brushDomain) }, datum);
const maxDatum = assign({ handleValue: Collection.getMaxValue(brushDomain) }, datum);
const minHandleProps = assign(
{
key: `${id}-min`,
style: Helpers.evaluateStyle(style, minDatum, activeBrushes.minHandle)
},
handleDimensions.min
);
const maxHandleProps = assign(
{
key: `${id}-max`,
style: Helpers.evaluateStyle(style, maxDatum, activeBrushes.maxHandle)
},
handleDimensions.max
);
return [
React.cloneElement(handleComponent, minHandleProps),
scale(currentDomain, originalDomain, factor) {
const [fromBound, toBound] = originalDomain;
const [from, to] = currentDomain;
const range = Math.abs(from - to);
const midpoint = +from + (range / 2);
const newRange = (range * factor) / 2;
return [
Collection.getMaxValue([midpoint - newRange, fromBound]),
Collection.getMinValue([midpoint + newRange, toBound])
];
},