Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
};
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;
};
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;
};
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)
};
}
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;
};
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;
};
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;
};
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;
}