Comments (2)
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:
Line 130 in 5e9ee8a
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.
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)
- Release d3-array v2 compatible version? HOT 2
- hole issue in contour HOT 5
- Arrows using elevation value for any point(x, y) in contour chart HOT 5
- GeoJSON Geometry which is generated by d3.contour displays wrong HOT 3
- output data has index which is not exist in input data HOT 2
- Feature request: contour labels HOT 2
- smoothing removes line segements HOT 1
- Buggy input check in density size setter.
- Improve slow computations for large images HOT 2
- Handle Null values in grid HOT 9
- Dependencies HOT 3
- Some contour polygon is reverse. HOT 5
- Support fractional bandwidths. HOT 2
- [feature]: cellSize(0.5) would work well in d3.contourDensity() HOT 1
- Support curvilinear grids HOT 11
- Sometimes the lowest threshold is missing
- Bug HOT 2
- isobands?
- Donβt round the corners HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-contour.