Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!