Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
Right to Left Icicle Tree

How can I mirror the d3 tree? I have use these code https://observablehq.com/@d3/zoomable-icicle but I can't put the father at right. I think is the attr("transform", d => translate(${d.y0},${d.x0})) and I tried function

positions(d){
      console.log(d.depth)
      if (d.depth == 0){
          d = d.children[0].children[0].children[0];
          return (d.x0);
      }
      else if(d.depth == 1){
          d = d.children[0];
          return (d.x0);
      }
      else if(d.depth == 2){
          d = d.parent;
          return (d.x0);
      }
      else{
        return 0;
      }
  }

But it does not work.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here's an example.

We can define a function to get the mirrored horizontal position:

function getFlippedPosition(d) {
  return width - ((d.depth + 1) * (d.y1 - d.y0));
}

Then creating the groups becomes

  const cell = svg
    .selectAll("g")
    .data(root.descendants())
    .join("g")
      .attr("transform", d => `translate(${getFlippedPosition(d)},${d.x0})`)

Similarly, the clicked function can be updated as follows:

function clicked(event, p) {
  focus = focus === p ? p = p.parent : p;

  root.each(d => d.target = {
    x0: (d.x0 - p.x0) / (p.x1 - p.x0) * height,
    x1: (d.x1 - p.x0) / (p.x1 - p.x0) * height,
    y0: d.y0 - p.y0,
    y1: d.y1 - p.y0,
    // this line is new:
    depth: d.depth - p.depth,
  });

  const t = cell.transition().duration(750)
      // this line is updated:
      .attr("transform", d => `translate(${getFlippedPosition(d.target)},${d.target.x0})`)

  rect.transition(t).attr("height", d => rectHeight(d.target));
  text.transition(t).attr("fill-opacity", d => +labelVisible(d.target));
  tspan.transition(t).attr("fill-opacity", d => labelVisible(d.target) * 0.7);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda