Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// use a number if passed, else find the index based on the ref type
let index = reference;
if (typeof reference !== 'number') {
index = data.findIndex(
(d, i) =>
(reference === 'first' && i === 0) ||
(reference === 'last' && i === data.length - 1) ||
(reference === 'min' && Math.abs(getY(d) - yMin) < ZERO_DELTA) ||
(reference === 'max' && Math.abs(getY(d) - yMax) < ZERO_DELTA),
);
}
const datum = data[index];
// use passed value if no datum, this enables custom x values
const refNumber = datum ? getX(datum) : index;
const scaledRef = xScale(refNumber);
const fromPoint = new Point({ x: scaledRef, y: y1 });
const toPoint = new Point({ x: scaledRef, y: y0 });
const label = renderLabel && renderLabel((datum && getY(datum)) || refNumber);
return (
let index = reference;
if (typeof reference !== 'number') {
index = data.findIndex(
(d, i) =>
(reference === 'first' && i === 0) ||
(reference === 'last' && i === data.length - 1) ||
(reference === 'min' && Math.abs(getY(d) - yMin) < ZERO_DELTA) ||
(reference === 'max' && Math.abs(getY(d) - yMax) < ZERO_DELTA),
);
}
const datum = data[index];
// use passed value if no datum, this enables custom x values
const refNumber = datum ? getX(datum) : index;
const scaledRef = xScale(refNumber);
const fromPoint = new Point({ x: scaledRef, y: y1 });
const toPoint = new Point({ x: scaledRef, y: y0 });
const label = renderLabel && renderLabel((datum && getY(datum)) || refNumber);
return (
strokeLinecap,
strokeWidth,
xScale,
yScale,
} = this.props;
if (!xScale || !yScale || !getY || !data.length) return null;
const [x0, x1] = xScale.range();
let refNumber = reference;
if (reference === 'mean') refNumber = mean(data, getY);
if (reference === 'median') refNumber = median(data, getY);
if (reference === 'max') refNumber = max(data, getY);
if (reference === 'min') refNumber = min(data, getY);
const scaledRef = yScale(refNumber);
const fromPoint = new Point({ x: x0, y: scaledRef });
const toPoint = new Point({ x: x1, y: scaledRef });
const label = renderLabel && renderLabel(refNumber);
return (
strokeWidth,
xScale,
yScale,
} = this.props;
if (!xScale || !yScale || !getY || !data.length) return null;
const [x0, x1] = xScale.range();
let refNumber = reference;
if (reference === 'mean') refNumber = mean(data, getY);
if (reference === 'median') refNumber = median(data, getY);
if (reference === 'max') refNumber = max(data, getY);
if (reference === 'min') refNumber = min(data, getY);
const scaledRef = yScale(refNumber);
const fromPoint = new Point({ x: x0, y: scaledRef });
const toPoint = new Point({ x: x1, y: scaledRef });
const label = renderLabel && renderLabel(refNumber);
return (