lib/Charts/ChartRenderer.js
function findSelectedData(data, x) {
  // For each chart line (pointArray), find the point with the closest x to the mouse.
  const closestXPoints = data.map(line =>
    line.points.reduce((previous, current) =>
      Math.abs(current.x - x) < Math.abs(previous.x - x) ? current : previous
    )
  );
  // Of those, find one with the closest x to the mouse.
  const closestXPoint = closestXPoints.reduce((previous, current) =>
    Math.abs(current.x - x) < Math.abs(previous.x - x) ? current : previous
  );
  const nearlyEqualX = thisPoint =>
    Math.abs(thisPoint.x - closestXPoint.x) < threshold;
  // Only select the chart lines (pointArrays) which have their closest x to the mouse = the overall closest.
  const selectedPoints = closestXPoints.filter(nearlyEqualX);

  const isSelectedArray = closestXPoints.map(nearlyEqualX);
  const selectedData = data.filter((line, i) => isSelectedArray[i]);
  selectedData.forEach((line, i) => {
    line.point = selectedPoints[i];
  }); // TODO: this adds the property to the original data - bad.
  return selectedData;
}
function findSelectedData(data, x) {
  // For each chart line (pointArray), find the point with the closest x to the mouse.
  const closestXPoints = data.map(line =>
    line.points.reduce((previous, current) =>
      Math.abs(current.x - x) < Math.abs(previous.x - x) ? current : previous
    )
  );
  // Of those, find one with the closest x to the mouse.
  const closestXPoint = closestXPoints.reduce((previous, current) =>
    Math.abs(current.x - x) < Math.abs(previous.x - x) ? current : previous
  );
  const nearlyEqualX = thisPoint =>
    Math.abs(thisPoint.x - closestXPoint.x) < threshold;
  // Only select the chart lines (pointArrays) which have their closest x to the mouse = the overall closest.
  const selectedPoints = closestXPoints.filter(nearlyEqualX);

  const isSelectedArray = closestXPoints.map(nearlyEqualX);
  const selectedData = data.filter((line, i) => isSelectedArray[i]);
  selectedData.forEach((line, i) => {
    line.point = selectedPoints[i];
  }); // TODO: this adds the property to the original data - bad.
  return selectedData;
}
function findSelectedData ( data , x ) { // For each chart line (pointArray), find the point with the closest x to the mouse. const closestXPoints = data . map ( line => line . points . reduce ( ( previous , current ) => Math . abs ( current . x - x ) < Math . abs ( previous . x - x ) ? current : previous ) ) ; // Of those, find one with the closest x to the mouse. const closestXPoint = closestXPoints . reduce ( ( previous , current ) => Math . abs ( current . x - x ) < Math . abs ( previous . x - x ) ? current : previous ) ; const nearlyEqualX = thisPoint => Math . abs ( thisPoint . x - closestXPoint . x ) < threshold ; // Only select the chart lines (pointArrays) which have their closest x to the mouse = the overall closest. const selectedPoints = closestXPoints . filter ( nearlyEqualX ) ; const isSelectedArray = closestXPoints . map ( nearlyEqualX ) ; const selectedData = data . filter ( ( line , i ) => isSelectedArray [ i ] ) ; selectedData . forEach ( ( line , i ) => { line . point = selectedPoints [ i ] ; } ) ; // TODO: this adds the property to the original data - bad. return selectedData ; }
Returns only the data lines which have a selected point on them, with an added "point" property for the selected point.
Returns only the data lines which have a selected point on them with an added point property for the selected point .