Git Product home page Git Product logo

Comments (7)

lapidus avatar lapidus commented on July 29, 2024

👍 I don't mind working on a pull request if anyone can hint about a possible cause.

from topogram.

shawnbot avatar shawnbot commented on July 29, 2024

The problem seems to be that v3's projection functions work differently than v2's. @mbostock, can you provide a hint?

from topogram.

mbostock avatar mbostock commented on July 29, 2024

https://github.com/mbostock/d3/wiki/3.0
https://github.com/mbostock/d3/wiki/Upgrading-to-3.0

from topogram.

lapidus avatar lapidus commented on July 29, 2024

Thanks for the hints. Every 32nd point (with a few exceptions), the algorithm seems to insert a diagonally offset coordinate:

Point 1: M738.6410891318739,288.6117802470147
18.64099944406587,-71.38842446507579
18.640909754354652,-71.38862917712373
[...]
-1.089590636644175,-84.48670347140757
-1.090580345942044,-84.48688700598365
Point 33: 718.9084298790658,275.5129294610754
-1.0919136122784039,-84.48703876147886
-1.0922570996749528,-84.48700698383607
[...]
Point 65: 702.9690598895354,277.89646070245584
-17.030943323429927,-82.10357075652627
-17.030946536420732,-82.1036022155083
[...]
Point 97: 702.6845670620858,275.83483610874566

I haven't been able to find the solution yet but will look deeper into the mapping of arcs to screen space:

Row 38: // project the arcs into screen space
      var tf = transformer(topology.transform),
          projectedArcs = topology.arcs.map(function(arc) {
            var x = 0, y = 0;
            return arc.map(function(coord) {
              coord[0] = (x += coord[0]);
              coord[1] = (y += coord[1]);
              return projection(tf(coord));
            });
          });

@shawnbot: What do you think?

texas

from topogram.

mbostock avatar mbostock commented on July 29, 2024

I would probably use the browser's debugger to step through the code as it is running to understand what is happening. There could be many reasons why this isn't working, and without being familiar with the code it's difficult for me to say what the problem is.

I suspect it might be caused by d3.geo's adaptive resampling of the projection, which detects areas of distortion. When you pass in a bare function as the projection to d3.geo.path, it gets wrapped in a resampling projection stream (see d3_geo_pathProjectStream); an instance of d3.geo.projection in contrast adds rotation and clipping, in addition to resampling, to the projection stream.

Adaptive resampling requires that the geometry being transform is expressed in spherical coordinates, so if you pass in Cartesian coordinates, you're going to have a bad time. If you want to use the identity projection (i.e., pass projected Cartesian coordinates to d3.geo.path and disable resampling), then in V3 you should set path.projection(null) rather than passing in the identity function. Otherwise the adaptive resampling will introduce intermediate points in your geometry using great-arc interpolation, because it assumes each polygonal segment is a great arc.

from topogram.

lapidus avatar lapidus commented on July 29, 2024

Thanks @mbostock! Passing null instead of the identity was all it took. Have submitted the fix.

from topogram.

mbostock avatar mbostock commented on July 29, 2024

💥

from topogram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.