function timeseriesTicksInterval(
  xInterval,
  timeRangeMilliseconds,
  maxTickCount,
) {
  // first we want to find out where in TIMESERIES_INTERVALS we should start looking for a good match. Find the
  // interval with a matching interval and count (e.g. `hour` and `1`) and we'll start there.
  let initialIndex = _.findIndex(
    TIMESERIES_INTERVALS,
    ({ interval, count }) => {
      return interval === xInterval.interval && count === xInterval.count;
    },
  );
  // if we weren't able to find soemthing matching then we'll start from the beginning and try everything
  if (initialIndex === -1) {
    initialIndex = 0;
  }

  // now starting at the TIMESERIES_INTERVALS entry in question, calculate the expected tick count for that interval
  // based on the time range we are displaying. If the expected tick count is less than or equal to the target
  // maxTickCount, we can go ahead and use this interval. Otherwise continue on to the next larger interval, for
  // example every 3 hours instead of every one hour. Continue until we find something with an interval large enough
  // to keep the total tick count under the max tick count
  for (const interval of _.rest(TIMESERIES_INTERVALS, initialIndex)) {
    if (expectedTickCount(interval, timeRangeMilliseconds) <= maxTickCount) {
      return interval;
    }
  }

  // If we still failed to find an interval that will produce less ticks than the max then fall back to the largest
  // tick interval (every 100 years)
  return TIMESERIES_INTERVALS[TIMESERIES_INTERVALS.length - 1];
}
/// and the max number of ticks we want to show (itself calculated from chart width).
and the max number of ticks we want to show (itself calculated from chart width).
and the max number of ticks we want to show ( itself calculated from chart width ) .
function timeseriesTicksInterval(
  xInterval,
  timeRangeMilliseconds,
  maxTickCount,
) {
  let initialIndex = _.findIndex(
    TIMESERIES_INTERVALS,
    ({ interval, count }) => {
      return interval === xInterval.interval && count === xInterval.count;
    },
  );
  if (initialIndex === -1) {
    initialIndex = 0;
  }
  for (const interval of _.rest(TIMESERIES_INTERVALS, initialIndex)) {
    if (expectedTickCount(interval, timeRangeMilliseconds) <= maxTickCount) {
      return interval;
    }
  }
  return TIMESERIES_INTERVALS[TIMESERIES_INTERVALS.length - 1];
}
function timeseriesTicksInterval ( xInterval , timeRangeMilliseconds , maxTickCount , ) { let initialIndex = _ . findIndex ( TIMESERIES_INTERVALS , ( { interval , count } ) => { return interval === xInterval . interval && count === xInterval . count ; } , ) ; if ( initialIndex === - 1 ) { initialIndex = 0 ; } for ( const interval of _ . rest ( TIMESERIES_INTERVALS , initialIndex ) ) { if ( expectedTickCount ( interval , timeRangeMilliseconds ) <= maxTickCount ) { return interval ; } } return TIMESERIES_INTERVALS [ TIMESERIES_INTERVALS . length - 1 ] ; }
and the max number of ticks we want to show (itself calculated from chart width).
and the max number of ticks we want to show ( itself calculated from chart width ) .
// first we want to find out where in TIMESERIES_INTERVALS we should start looking for a good match. Find the // interval with a matching interval and count (e.g. `hour` and `1`) and we'll start there. // if we weren't able to find soemthing matching then we'll start from the beginning and try everything // now starting at the TIMESERIES_INTERVALS entry in question, calculate the expected tick count for that interval // based on the time range we are displaying. If the expected tick count is less than or equal to the target // maxTickCount, we can go ahead and use this interval. Otherwise continue on to the next larger interval, for // example every 3 hours instead of every one hour. Continue until we find something with an interval large enough // to keep the total tick count under the max tick count // If we still failed to find an interval that will produce less ticks than the max then fall back to the largest // tick interval (every 100 years)