Code Monkey home page Code Monkey logo

Comments (4)

mbostock avatar mbostock commented on April 28, 2024
Screenshot 2023-10-28 at 8 49 37 AM

You’re probably using an old version of D3?

from d3.

mbostock avatar mbostock commented on April 28, 2024

As for the other cases, this:

d3.min(['5', '10', null, '2'], (d) => +d)

is equivalent to this:

d3.min(['5', '10', null, '2'].map((d) => +d))

is equivalent to this:

d3.min([5, 10, 0, 2])

hence it returns zero.

And likewise for d3.least, it doesn’t care that the element is null, it cares whether the return value of the given accessor is null. So if you coerce null to zero in your accessor, and zero is the least value, then d3.least will return the corresponding element which is null.

from d3.

helderdarocha avatar helderdarocha commented on April 28, 2024

Yes. Thank you. I know this is the expected behavior. The problem is that the accessor is not really being used to access anything, but to coerce and change values in the dataset, which can lead to cryptic code. Mislead by an example of mine where I used +d to coerce strings, my student spent a day trying to fix a bug and fixed it after removing nulls from her dataset. She had understood that extent should ignore nulls, but wasn't aware that they were being coerced.

from d3.

mbostock avatar mbostock commented on April 28, 2024

Yes, I recommend that you apply type coercion as early as possible — ideally when the data is loaded, say by using d3.autoType in conjunction with d3.csv, or Observable’s FileAttachment helper with typed: true. If you defer type coercion until later, there is much more surface area for these problems.

from d3.

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.