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

191
Views
Horizontal Scaling Formula Issues

I'm currently working with image generation, and have stumbled across an issue that's left me stumped for a few hours. Here's a brief explanation. Below are two profile pictures (tributes) with their respective districts hovering above them. In the case of two tributes, the district text will center above them as shown below.

enter image description here

In the case of more than two, the first two tributes should have the District centered between them, while the last person has it centered above them.

enter image description here

In terms of code, I've found a way to detect such cases. But haven't figured out how the textDestinationX could use the loop to calculate the desired position of the text.

drawDistrictText(ctx, tributeArray) {
        ctx.font = 'bold 28px arial';
        ctx.textBaseline = 'alphabetic';
        ctx.fillStyle = '#ffffff';
        ctx.textAlign = 'center';

        const districtCount = Math.max(Math.ceil(tributeArray.length / 2), 2);
        let textDestinationX;
        let textDestinationY = avatarPaddingY - 15;

        for (let i = 0; i < districtCount; i++) {
            const districtText = `District ${i + 1}`;

            /* detecting if we are on our last iteration,
              and if the total length is odd, meaning there
               must be a district with one user. or if there
               is only 2 tributes.
            */

            if ((i === districtCount - 1 && tributeArray.length % 2 === 1) || tributeArray.length === 2) {
                console.log('center');
            } else {
                console.log('between');
            }

            /* After every 6 tributes, Y position is shifted down
               for the next row. The X position would need to be
               set to it's original position.
            */

            if ((i + 1) % 3 === 0) {
                textDestinationY += avatarSize + avatarSpacingY;
            }
        }
    }
about 4 years ago · Juan Pablo Isaza
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!