Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
Set circle size per array of numbers (min 20px, max 130px)

Here is the case, I need to draw a circle in pixels per array of numbers for example [22, 25, 36, 44, 115, 180]

The smallest circle should be 20px, and the largest should be 130px, in this case, the smallest number is 22 and it should be 20px, and the largest is 180 and the circle should be 130px.

So in any case of numbers in the array, we should start with the smallest circle from 20px and the largest 130px, everything between should scale accordingly.

const getSize = (values, value) => {
    let size;
    const volumes = values.map(a => a.value).sort((a, b) => a - b);
    const min = Math.min(...volumes);
    const max = Math.max(...volumes);
    console.log(min, max, volumes);

    return size;
};

The method will receive params from the server, and value from the single object where I need to return the size of the circle in style width and height, something like this below.

<span
                                    style={{
                                        bottom: 0,
                                        width: getSize(item.values, itemData.value),
                                        height: getSize(item.values, itemData.value),
                                        position: 'absolute',
                                        left: 0,
                                        right: 0,
                                        margin: 'auto',
                                    }}
                                />
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Compute a relative scale of each number as scale = (number - min) / (max - min) and then do the reverse using the desired min and max values:

numbers = [22, 25, 36, 44, 115, 180]
min = numbers[0]
max = numbers[numbers.length - 1]
scales = numbers.map(x => (x - min) / (max - min))

newMin = 20
newMax = 130

newNumbers = scales.map(x => newMin + x * (newMax - newMin))
console.log(newNumbers)

Add Math.floor if you need integers.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda