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

218
Visualizações
D3js get d in a call inside a event (click)

When I click on a rectangle, ellipses are created. On drag I want to do something. The problem is, I need the data (d) of the rectangle, on which I clicked, also in my drag functions, connectStart, connectDrag and connectEnd. At the last 3 lines I tried to add data to my Ellipse, to access d from these 3 functions, but in the dragfunctions d is always the first value of my self.data and not the d of the rect I clicked on. So its not working. When I completely cut the last 3 lines out, I get 'd not defined' in my drag functions. How can I do this?

drawLine = d3.drag()
            .on('start', connectStart)
            .on('drag', connectDrag)
            .on('end', connectEnd);
...
rects = itemRects.selectAll('rect')
            .data(self.data)
            .attr('x', function (d) { return newXscale(d.start); })
            .attr('y', function (d) {
                return yScale(d.lane) + ((getMarginHeight() / (self.lanesLength || 1)) * 0.2);
            })
            .attr('width', function (d) { return (newXscale(d.end) - newXscale(d.start)); })
            .attr('height', itemHeight)
            .attr('rx', 10)
            .attr('ry', 10)
            .attr('class', function (d) { return d.class + ' main'; })
            .attr('id', function (d) { return 'rect_' + d.id; })
            .attr('opacity', 0.5)
            .attr('fill', '#0091dc')
            .call(drag)
            .on('click', function (i, d) {
                console.log('PARENTNODE', this.parentNode);
                console.log('Node', this);
                d3.selectAll('g > ellipse').remove();

                d3.select(this)
                    .attr('class', function (d) { return d.class + ' task-selected'; })
                    .attr('stroke-width', '3')
                    .attr('stroke', '#000088');

                d3.select(this.parentNode)
                    .append('ellipse')
                    .attr('cx', newXscale(d.end) + 1)
                    .attr('cy', yScale(d.lane + d.lane + 1) / 2)
                    .attr('rx', 3)
                    .attr('ry', 6)
                    .attr('stroke-width', '2')
                    .attr('stroke', '#0091dc')
                    .attr('fill', '#0091dc')
                    .attr('class', 'dependencieStart')
                    .attr('opacity', '1');

                d3.selectAll('ellipse.dependencieStart')
                    .data(self.data)
                    .call(drawLine);
                    ...
about 4 years ago · Juan Pablo Isaza
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