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

267
Visualizações
d3 datapoint disappearing Error: <circle> attribute cx: Expected length, "NaN"

I'm trying to map several points on an interactive 3D globe using d3. The points show up at first, but after trying to rotate the globe, they disappear until the page is reloaded. This problem does not occur when I only use a pan/zoom feature.

Here's the code for adding the points:

d3.csv("cities.csv").then(function(data) {
    svg.selectAll("circle").data(data)
       .enter()
       .append("circle")
       .attr("class", "cities")
       .attr("r", 3)
       .attr("cx", d => projection([d.lon,d.lat])[0])
       .attr("cy", d => projection([d.lon,d.lat])[1])
})

Here's the code for rotating:

var mapZoom = d3.zoom()
     .on("zoom", zoomed);

var zoomSettings = d3.zoomIdentity
                     .translate(0, 0)
                     .scale(120);
var rotateScale = d3.scaleLinear()
                    .domain([-500, 0, 500])
                    .range([-180, 0, 180]);

d3.select("svg").call(mapZoom).call(mapZoom.transform, zoomSettings);

function zoomed() {
   var e = d3.event;
   var currentRotate = rotateScale(e.transform.x) % 360
   projection.rotate([currentRotate, 0])
             .scale(e.transform.k)

   d3.selectAll("path.graticule").attr("d", path);
   d3.selectAll("path.countries").attr("d", path)
     .style("fill", d => newFeatureColor(d3.geoArea(d)))
     .style("stroke", d =>   d3.rgb(newFeatureColor(d3.geoArea(d))).darker())

   d3.selectAll("circle.cities").each(function (d, i) {
      var projectedPoint = projection([d.x,d.y])
      var x = parseInt(d.x)
      var display = x + currentRotate < 90 && x + currentRotate > -90
               || (x + currentRotate < -270 && x + currentRotate > -450)
               || (x + currentRotate > 270 && x + currentRotate < 450)
        ? "block" : "none"
      d3.select(this)
        .attr("cx", projectedPoint[0])
        .attr("cy", projectedPoint[1])
        .style("display", display)
    })
}

This is the format of the projection used with the cx and cy coordinates:

var projection = d3.geoOrthographic() .scale(200) .translate([width/2, height/2]) .center([0,0])

Any help would be appreciated!

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