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

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