Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!