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

85
Vistas
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
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