Giter Site home page Giter Site logo

Comments (2)

NataliaM5 avatar NataliaM5 commented on April 28, 2024 1

Hi, @Fil !
Thank you for the response. Faced the same issue.
After diving deep into d3-contour source code, I found that k depends on cellSize provided value:

return k = Math.floor(Math.log(_) / Math.LN2), resize();

So, to get a correct results, seems like we need to use the following formula when using cellSize method:

k = Math.floor(Math.log(cellSizeValue) / Math.LN2)

const thresholds = [0, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01]; // old style
const contours = d3_302
  .contourDensity()
  .cellSize(cellSizeValue)
  .thresholds(thresholds.map(d => d/ Math.pow(2, 2 * k))) // convert to new style
    (data)

from d3-contour.

Fil avatar Fil commented on April 28, 2024

This notebook: https://observablehq.com/@fil/density-thresholds-70

Suppose you wanted to pass the following thresholds in d3-contour 3.0.1:

const contours = d3301
  .contourDensity()
  .thresholds([0, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01])
    (data)

this would return contours with values:

contours.map((d) => d.value) // [0, 0.0000625, 0.000125, 0.0001875, 0.00025, 0.0003125, 0.000375, 0.0004375, 0.0005, 0.0005625, 0.000625]

This was inconsistent (you ask for 1, you get 1/16). #57 fixes the inconsistency, so starting with 3.0.2, you would pass this instead:

const thresholds = [0, 0.0000625, 0.000125, 0.0001875, 0.00025, 0.0003125, 0.000375, 0.0004375, 0.0005, 0.0005625, 0.000625];
const contours = d3_301
  .contourDensity()
  .thresholds(thresholds)
    (data)

and get the same contours (with the same values).

The relationship between the two is this ratio 2**k with k the cellSize which defaults to 4; in other words you should find the same contours as before if you did:

const thresholds = [0, 0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01]; // old style
const contours = d3_302
  .contourDensity()
  .thresholds(thresholds.map(d => d/16)) // convert to new style
    (data)

from d3-contour.

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.