Code Monkey home page Code Monkey logo

Comments (3)

mbostock avatar mbostock commented on July 21, 2024

d3.voronoi does not mutate the input data. Internally, it wraps each element in the input data array in a new object called a site (a two-element array [x, y]). The site also stores a reference to the original data element as the data property.

function voronoi(data) {
return new Diagram(data.map(function(d, i) {
var s = [Math.round(x(d, i, data) / epsilon) * epsilon, Math.round(y(d, i, data) / epsilon) * epsilon];
s.index = i;
s.data = d;
return s;
}), extent);
}

Some of the voronoi methods expose the site objects. Others return the original elements from the input data array, such as voronoi.triangles.

from d3-voronoi.

DDDgfx avatar DDDgfx commented on July 21, 2024

For some reason, I was seeing these site arrays, and the data object when I logged my original data. Also was experiencing this:

    var cells = dataLr.selectAll(".data-bub").data(d3.voronoi()
            .extent([
                [-100, -100],
                [svgWidth, svgHeight]
            ])
            .x(function(d) {
                //console.log(d);
                return d.x;
            })
            .y(function(d) {
                return d.y;
            })
            .polygons(fData),
            function(d) {
                console.log(d); //my properties are logged
                console(d.data.id); //the property itself returns undefined
            })
        .enter().append("g");

But now I'm not seeing that, and I have decided not to try to key the diagram. Thank you for explainig.

from d3-voronoi.

DDDgfx avatar DDDgfx commented on July 21, 2024

Overall, trying to learn what d3 modules do to my data by logging it to the console seems to be a very bad idea as the console is logging the end state no matter where in the code the command is.

from d3-voronoi.

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.