How to use the recharts-scale.getNiceTickValues function in recharts-scale

To help you get started, we’ve selected a few recharts-scale examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github recharts / recharts / src / util / ChartUtils.js View on Github external
export const getTicksOfScale = (scale, opts) => {
  const { realScaleType, type, tickCount, originalDomain, allowDecimals } = opts;
  const scaleType = realScaleType || opts.scale;

  if (scaleType !== 'auto' && scaleType !== 'linear') {
    return null;
  }

  if (tickCount && type === 'number' && originalDomain && (
    originalDomain[0] === 'auto' || originalDomain[1] === 'auto')) {
    // Calculate the ticks by the number of grid when the axis is a number axis
    const domain = scale.domain();
    const tickValues = getNiceTickValues(domain, tickCount, allowDecimals);

    scale.domain(calculateDomainOfTicks(tickValues, type));

    return { niceTicks: tickValues };
  } if (tickCount && type === 'number') {
    const domain = scale.domain();
    const tickValues = getTickValuesFixedDomain(domain, tickCount, allowDecimals);

    return { niceTicks: tickValues };
  }

  return null;
};
github recharts / recharts / src / util / ChartUtils.ts View on Github external
export const getTicksOfScale = (scale: any, opts: any) => {
  const { realScaleType, type, tickCount, originalDomain, allowDecimals } = opts;
  const scaleType = realScaleType || opts.scale;

  if (scaleType !== 'auto' && scaleType !== 'linear') {
    return null;
  }

  if (tickCount && type === 'number' && originalDomain && (
    originalDomain[0] === 'auto' || originalDomain[1] === 'auto')) {
    // Calculate the ticks by the number of grid when the axis is a number axis
    const domain = scale.domain();
    if (!domain.length) {
      return null;
    }
    const tickValues = getNiceTickValues(domain, tickCount, allowDecimals);

    scale.domain(calculateDomainOfTicks(tickValues, type));

    return { niceTicks: tickValues };
  } if (tickCount && type === 'number') {
    const domain = scale.domain();
    const tickValues = getTickValuesFixedDomain(domain, tickCount, allowDecimals);

    return { niceTicks: tickValues };
  }

  return null;
};
github openforis / collect / collect-web / collect-webapp / frontend / vendor / recharts / src / util / CartesianUtils.js View on Github external
export const getTicksOfScale = (scale, opts) => {
  const { type, tickCount, ticks, originalDomain, allowDecimals } = opts;

  if (tickCount && type === 'number' && originalDomain && (
    originalDomain[0] === 'auto' || originalDomain[1] === 'auto')) {
    // Calculate the ticks by the number of grid when the axis is a number axis
    const domain = scale.domain();
    const tickValues = getNiceTickValues(domain, tickCount, allowDecimals);

    scale.domain(calculateDomainOfTicks(tickValues, type));

    return { niceTicks: tickValues };
  } else if (tickCount && type === 'number') {
    const domain = scale.domain();
    const tickValues = getTickValues(domain, tickCount, allowDecimals);

    return { niceTicks: tickValues };
  }

  return null;
};
github Vizzuality / climate-watch / app / javascript / app / utils / graphs.js View on Github external
negative: 0
    };
    for (let e = 0; e < yValues.length; e++) {
      let value = yValues[e][index];
      if (isArray(value)) value = value[1]; // Take the biggest value of the quantification pair
      total[getSign(value)] += value || 0;
    }
    totalValues.push(total);
  }

  const minValue = minBy(totalValues, 'negative').negative;
  const maxValue = maxBy(totalValues, 'positive').positive;
  return {
    min: minValue,
    max: maxValue,
    ticks: getNiceTickValues([minValue, maxValue], tickNumber, decimals)
  };
}
github openforis / collect / collect-web / collect-webapp / frontend / vendor / recharts / src / chart / RadarChart.js View on Github external
getTicksByItems(axisItem, tickCount) {
    const { data, children } = this.props;
    const { domain, allowDataOverflow } = axisItem ? axisItem.props : PolarRadiusAxis.defaultProps;
    const radarItems = findAllByType(children, Radar);
    const dataKeys = radarItems.map(item => item.props.dataKey);
    const extent = data.reduce((prev, current) => {
      const values = dataKeys.map(v => current[v] || 0);
      const currentMax = Math.max.apply(null, values);
      const currentMin = Math.min.apply(null, values);

      return [Math.min(prev[0], currentMin), Math.max(prev[1], currentMax)];
    }, [Infinity, -Infinity]);
    const finalDomain = parseSpecifiedDomain(domain, extent, allowDataOverflow);

    if (domain && (domain[0] === 'auto' || domain[1] === 'auto')) {
      return getNiceTickValues(finalDomain, tickCount);
    }

    return finalDomain;
  }

recharts-scale

Scale of Cartesian Coordinates

MIT
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis