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

92
Views
d3 best practise for css sprite

I am working on a project that need to do visualize a graph relation using d3, each icons has size 64 * 64 and all icons are stored in one png file 823 * 832 pixes.

The data.json is like:

[
   { "color": "#FFFFFF", "id": "XXXX", "position": "0px 0px" },
...
]

My current code is :

node.append("svg")
    .attr("class", "item")
    .attr('width', 64)
    .attr('height', 64)
    .attr("x", -70)
    .attr("y", -20)
    .append("image")
    .attr('xlink:href', logoSprite)
    .attr('id', (d) => (d.data as TreeNode).item.id)
    .attr('width', 832)
    .attr('height', 832)
    .attr("transform", (d) => {
        const pos = (d.data as TreeNode).item.icon.position.split(" ");
        const x = pos[0].substring(0, pos[0].length - 2);
        const y = pos[1].substring(0, pos[1].length - 2);
        return "translate(" + x + "," + y + ")";
    })

I am wondering if there is a better practices for this. Meanwhile, there are some use cases that a lots (few) of node in the diagram, and I am current struggling with dynamically resizing the icons, any help is appreciated.

Thanks in advance.

about 4 years ago · Santiago Trujillo
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!