Gathering detailed insights and metrics for d3-weighted-voronoi
Gathering detailed insights and metrics for d3-weighted-voronoi
Gathering detailed insights and metrics for d3-weighted-voronoi
Gathering detailed insights and metrics for d3-weighted-voronoi
d3-voronoi-treemap
D3 plugin which computes a treemap based on Voronoi tesselation
d3-voronoi
Compute the Voronoi diagram of a set of two-dimensional points.
d3-voronoi-map
D3 plugin which computes a map (one-level treemap), based on Voronoi tesselation
@types/d3-voronoi
TypeScript definitions for d3-voronoi
npm install d3-weighted-voronoi
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
63 Stars
112 Commits
12 Forks
5 Watching
2 Branches
1 Contributors
Updated on 27 Sept 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-11.6%
11,946
Compared to previous day
Last week
2%
65,631
Compared to previous week
Last month
13.5%
282,982
Compared to previous month
Last year
420.8%
2,669,498
Compared to previous year
2
This d3 plugin produces a weighted Voronoi diagram. It tessellates/partitions the plane given a set of weighted two-dimensional sites.
Because a picture is worth a thousand words:
<== default / weighted ==>
Available only for d3 v4, d3 v5 and d3 v6.
This plugin is at the root of:
Compared to the default Voronoï diagram, it adds the capability to assign a particular weight to each site. The higher is the weight of a site, the more this site influences its environment, and the larger is its surrounding area.
Weighted Voronoï diagrams come in severall flavours (additive/multiplicative, powered/not-powered, 2D/3D and higher dimensions, ..., cf. Wikipedia). This plugin focuses on the 2D additive weighted power diagram, which provides a tessellation made of convex hole-free polygons/cells with straight borders, as the default Voronoï diagram does.
Nonetheless, weighted Voronoï diagrams may have weird properties compared to default Voronoï diagrams:
These situations arise when some sites are overweighted by others. You can experiment it in Voronoï playground : interactive weighted Voronoï study.
If you use NPM, npm install d3-weighted-voronoi
. Otherwise, load https://rawcdn.githack.com/Kcnarf/d3-weighted-voronoi/v1.1.3/build/d3-weighted-voronoi.js
(or its d3-weighted-voronoi.min.js
version) to make it available in AMD, CommonJS, or vanilla environments. In vanilla, a d3 global is exported:
1<script src="https://d3js.org/d3.v6.min.js"></script> 2<script src="https://rawcdn.githack.com/Kcnarf/d3-weighted-voronoi/v1.1.3/build/d3-weighted-voronoi.js"></script> 3<script> 4 var weightedVoronoi = d3.weightedVoronoi(); 5</script>
If you're interested in the latest developments, you can use the master build, available throught:
1<script src="https://raw.githack.com/Kcnarf/d3-weighted-voronoi/master/build/d3-weighted-voronoi.js"></script>
In your javascript, in order to define the tessellation:
1var weightedVoronoi = d3.weightedVoronoi() 2 .x(function(d){ return xScale(d); } // set the x coordinate accessor 3 .y(function(d){ return yScale(d); } // set the y coordinate accessor 4 .weight(function(d){ return weightScale(d); } // set the weight accessor 5 .clip([[0,0], [0,height], [width, height], [width,0]]) // set the clipping polygon 6 7var cells = weightedVoronoi(data); // compute the weighted Voronoi tessellation
Then, later in your javascript, in order to draw cells:
1d3.selectAll('path') 2 .data(cells) 3 .enter() 4 .append('path') 5 .attr('d', function (d) { 6 return cellLiner(d) + 'z'; 7 });
# d3.weightedVoronoi()
Creates a new weightedVoronoi with the default x-, y-, weight- accessors, and clip, extent, size configuration values.
# weightedVoronoi(data)
Computes the weighted Voronoi diagram for the specified data points.
Returns a sparse array of polygons clipped to the clip polygon, one for each cell (each unique input point) in the diagram. Each polygon is represented as an array of points [x, y] where x and y are the point coordinates, a site field that refers to its site (ie. with x, y and weight retrieved from the original data), and a site.originalObject field that refers to the corresponding element in data. Polygons are open: they do not contain a closing point that duplicates the first point; a triangle, for example, is an array of three points. Polygons are also counterclockwise (assuming the origin ⟨0,0⟩ is in the top-left corner).
Note that weighted Voronoï diagrams may have weird properties compared to default Voronoï diagrams:
These situations arise when some sites are overweighted by others. You can experiment it in Voronoï playground : interactive weighted Voronoï study.
# weightedVoronoi.x([x])
If x is specified, sets the x-coordinate accessor. If x is not specified, returns the current x-coordinate accessor, which defaults to:
1function x(d) { 2 return d.x; 3}
# weightedVoronoi.y([y])
If y is specified, sets the y-coordinate accessor. If y is not specified, returns the current y-coordinate accessor, which defaults to:
1function y(d) { 2 return d.y; 3}
# weightedVoronoi.weight([weight])
If weight is specified, sets the weight accessor. If weight is not specified, returns the current weight accessor, which defaults to:
1function weight(d) { 2 return d.weight; 3}
# weightedVoronoi.clip([clip])
If clip is specified, sets the clipping polygon, compute the adequate extent and size, and returns this layout. clip must define a hole-free concave polygon, and must be specified as an array of 2D points [x, y], which must be (i) open (no duplication of the first D2 point) and (ii) counterclockwise (assuming the origin ⟨0,0⟩ is in the top-left corner). If clip is not specified, returns the current clipping polygon, which defaults to:
1[ 2 [0, 0], 3 [0, 1], 4 [1, 1], 5 [1, 0], 6];
# weightedVoronoi.extent([extent])
If extent is specified, it is a convenient way to define the clipping polygon as a rectangle. It sets the extent, computes the adequate clipping polygon and size, and returns this layout. extent must be a two-element array of 2D points [x, y], which defines the clipping polygon as a rectangle with the top-left and bottom-right corners respectively set to the first and second points (assuming the origin ⟨0,0⟩ is in the top-left corner on the screen). If extent is not specified, returns the current extent, which is [[minX, minY], [maxX, maxY]]
of current clipping polygon, and which defaults to:
1[ 2 [0, 0], 3 [1, 1], 4];
# weightedVoronoi.size([size])
If size is specified, it is a convenient way to define the clipping polygon as a rectangle. It sets the size, computes the adequate clipping polygon and extent, and returns this layout. size must be a two-element array of numbers [width, height]
, which defines the clipping polygon as a rectangle with the top-left corner set to [0, 0]
and the bottom-right corner set to [width, height]
(assuming the origin ⟨0,0⟩ is in the top-left corner on the screen). If size is not specified, returns the current size, which is [maxX-minX, maxY-minY]
of current clipping polygon, and which defaults to:
1[1, 1];
d3-weighted-voronoi attempts to follow semantic versioning and bump major version only when backwards incompatible changes are released.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
Found 1/19 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More