Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-hexbin

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-hexbin - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

193

build/d3-hexbin.js

@@ -0,120 +1,121 @@

// https://github.com/d3/d3-hexbin Version 0.2.1. Copyright 2017 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3_hexbin = global.d3_hexbin || {})));
}(this, function (exports) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3 = global.d3 || {})));
}(this, (function (exports) { 'use strict';
var version = "0.2.0";
var thirdPi = Math.PI / 3;
var angles = [0, thirdPi, 2 * thirdPi, 3 * thirdPi, 4 * thirdPi, 5 * thirdPi];
var thirdPi = Math.PI / 3;
var angles = [0, thirdPi, 2 * thirdPi, 3 * thirdPi, 4 * thirdPi, 5 * thirdPi];
function pointX(d) {
return d[0];
}
function pointX(d) {
return d[0];
}
function pointY(d) {
return d[1];
}
function pointY(d) {
return d[1];
}
function hexbin() {
var x0 = 0,
y0 = 0,
x1 = 1,
y1 = 1,
x = pointX,
y = pointY,
r,
dx,
dy;
var hexbin = function() {
var x0 = 0,
y0 = 0,
x1 = 1,
y1 = 1,
x = pointX,
y = pointY,
r,
dx,
dy;
function hexbin(points) {
var binsById = {}, bins = [], i, n = points.length;
function hexbin(points) {
var binsById = {}, bins = [], i, n = points.length;
for (i = 0; i < n; ++i) {
if (isNaN(px = +x.call(null, point = points[i], i, points))
|| isNaN(py = +y.call(null, point, i, points))) continue;
for (i = 0; i < n; ++i) {
if (isNaN(px = +x.call(null, point = points[i], i, points))
|| isNaN(py = +y.call(null, point, i, points))) continue;
var point,
px,
py,
pj = Math.round(py = py / dy),
pi = Math.round(px = px / dx - (pj & 1) / 2),
py1 = py - pj;
var point,
px,
py,
pj = Math.round(py = py / dy),
pi = Math.round(px = px / dx - (pj & 1) / 2),
py1 = py - pj;
if (Math.abs(py1) * 3 > 1) {
var px1 = px - pi,
pi2 = pi + (px < pi ? -1 : 1) / 2,
pj2 = pj + (py < pj ? -1 : 1),
px2 = px - pi2,
py2 = py - pj2;
if (px1 * px1 + py1 * py1 > px2 * px2 + py2 * py2) pi = pi2 + (pj & 1 ? 1 : -1) / 2, pj = pj2;
}
if (Math.abs(py1) * 3 > 1) {
var px1 = px - pi,
pi2 = pi + (px < pi ? -1 : 1) / 2,
pj2 = pj + (py < pj ? -1 : 1),
px2 = px - pi2,
py2 = py - pj2;
if (px1 * px1 + py1 * py1 > px2 * px2 + py2 * py2) pi = pi2 + (pj & 1 ? 1 : -1) / 2, pj = pj2;
}
var id = pi + "-" + pj, bin = binsById[id];
if (bin) bin.push(point);
else {
bins.push(bin = binsById[id] = [point]);
bin.x = (pi + (pj & 1) / 2) * dx;
bin.y = pj * dy;
}
var id = pi + "-" + pj, bin = binsById[id];
if (bin) bin.push(point);
else {
bins.push(bin = binsById[id] = [point]);
bin.x = (pi + (pj & 1) / 2) * dx;
bin.y = pj * dy;
}
return bins;
}
function hexagon(radius) {
var x0 = 0, y0 = 0;
return angles.map(function(angle) {
var x1 = Math.sin(angle) * radius,
y1 = -Math.cos(angle) * radius,
dx = x1 - x0,
dy = y1 - y0;
x0 = x1, y0 = y1;
return [dx, dy];
});
}
return bins;
}
hexbin.hexagon = function(radius) {
return "m" + hexagon(radius == null ? r : +radius).join("l") + "z";
};
function hexagon(radius) {
var x0 = 0, y0 = 0;
return angles.map(function(angle) {
var x1 = Math.sin(angle) * radius,
y1 = -Math.cos(angle) * radius,
dx = x1 - x0,
dy = y1 - y0;
x0 = x1, y0 = y1;
return [dx, dy];
});
}
hexbin.centers = function() {
var centers = [],
j = Math.round(y0 / dy),
i = Math.round(x0 / dx);
for (var y = j * dy; y < y1 + r; y += dy, ++j) {
for (var x = i * dx + (j & 1) * dx / 2; x < x1 + dx / 2; x += dx) {
centers.push([x, y]);
}
hexbin.hexagon = function(radius) {
return "m" + hexagon(radius == null ? r : +radius).join("l") + "z";
};
hexbin.centers = function() {
var centers = [],
j = Math.round(y0 / dy),
i = Math.round(x0 / dx);
for (var y = j * dy; y < y1 + r; y += dy, ++j) {
for (var x = i * dx + (j & 1) * dx / 2; x < x1 + dx / 2; x += dx) {
centers.push([x, y]);
}
return centers;
};
}
return centers;
};
hexbin.mesh = function() {
var fragment = hexagon(r).slice(0, 4).join("l");
return hexbin.centers().map(function(p) { return "M" + p + "m" + fragment; }).join("");
};
hexbin.mesh = function() {
var fragment = hexagon(r).slice(0, 4).join("l");
return hexbin.centers().map(function(p) { return "M" + p + "m" + fragment; }).join("");
};
hexbin.x = function(_) {
return arguments.length ? (x = _, hexbin) : x;
};
hexbin.x = function(_) {
return arguments.length ? (x = _, hexbin) : x;
};
hexbin.y = function(_) {
return arguments.length ? (y = _, hexbin) : y;
};
hexbin.y = function(_) {
return arguments.length ? (y = _, hexbin) : y;
};
hexbin.radius = function(_) {
return arguments.length ? (r = +_, dx = r * 2 * Math.sin(thirdPi), dy = r * 1.5, hexbin) : r;
};
hexbin.radius = function(_) {
return arguments.length ? (r = +_, dx = r * 2 * Math.sin(thirdPi), dy = r * 1.5, hexbin) : r;
};
hexbin.extent = function(_) {
return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], hexbin) : [[x0, y0], [x1, y1]];
};
hexbin.extent = function(_) {
return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], hexbin) : [[x0, y0], [x1, y1]];
};
return hexbin.radius(1);
}
return hexbin.radius(1);
};
exports.version = version;
exports.hexbin = hexbin;
exports.hexbin = hexbin;
}));
Object.defineProperty(exports, '__esModule', { value: true });
})));

@@ -1,1 +0,2 @@

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.d3_hexbin=n.d3_hexbin||{})}(this,function(n){"use strict";function t(n){return n[0]}function r(n){return n[1]}function e(){function n(n){var t,r={},e=[],u=n.length;for(t=0;u>t;++t)if(!isNaN(o=+d.call(null,i=n[t],t,n))&&!isNaN(c=+v.call(null,i,t,n))){var i,o,c,h=Math.round(c/=f),s=Math.round(o=o/a-(1&h)/2),l=c-h;if(3*Math.abs(l)>1){var p=o-s,x=s+(s>o?-1:1)/2,M=h+(h>c?-1:1),m=o-x,g=c-M;p*p+l*l>m*m+g*g&&(s=x+(1&h?1:-1)/2,h=M)}var b=s+"-"+h,y=r[b];y?y.push(i):(e.push(y=r[b]=[i]),y.x=(s+(1&h)/2)*a,y.y=h*f)}return e}function e(n){var t=0,r=0;return o.map(function(e){var u=Math.sin(e)*n,i=-Math.cos(e)*n,o=u-t,a=i-r;return t=u,r=i,[o,a]})}var u,a,f,c=0,h=0,s=1,l=1,d=t,v=r;return n.hexagon=function(n){return"m"+e(null==n?u:+n).join("l")+"z"},n.centers=function(){for(var n=[],t=Math.round(h/f),r=Math.round(c/a),e=t*f;l+u>e;e+=f,++t)for(var i=r*a+(1&t)*a/2;s+a/2>i;i+=a)n.push([i,e]);return n},n.mesh=function(){var t=e(u).slice(0,4).join("l");return n.centers().map(function(n){return"M"+n+"m"+t}).join("")},n.x=function(t){return arguments.length?(d=t,n):d},n.y=function(t){return arguments.length?(v=t,n):v},n.radius=function(t){return arguments.length?(u=+t,a=2*u*Math.sin(i),f=1.5*u,n):u},n.extent=function(t){return arguments.length?(c=+t[0][0],h=+t[0][1],s=+t[1][0],l=+t[1][1],n):[[c,h],[s,l]]},n.radius(1)}var u="0.2.0",i=Math.PI/3,o=[0,i,2*i,3*i,4*i,5*i];n.version=u,n.hexbin=e});
// https://github.com/d3/d3-hexbin Version 0.2.1. Copyright 2017 Mike Bostock.
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.d3=n.d3||{})}(this,function(n){"use strict";function t(n){return n[0]}function r(n){return n[1]}var e=Math.PI/3,u=[0,e,2*e,3*e,4*e,5*e],o=function(){function n(n){var t,r={},e=[],u=n.length;for(t=0;t<u;++t)if(!isNaN(i=+d.call(null,o=n[t],t,n))&&!isNaN(c=+p.call(null,o,t,n))){var o,i,c,s=Math.round(c/=f),h=Math.round(i=i/a-(1&s)/2),l=c-s;if(3*Math.abs(l)>1){var v=i-h,M=h+(i<h?-1:1)/2,x=s+(c<s?-1:1),m=i-M,g=c-x;v*v+l*l>m*m+g*g&&(h=M+(1&s?1:-1)/2,s=x)}var y=h+"-"+s,j=r[y];j?j.push(o):(e.push(j=r[y]=[o]),j.x=(h+(1&s)/2)*a,j.y=s*f)}return e}function o(n){var t=0,r=0;return u.map(function(e){var u=Math.sin(e)*n,o=-Math.cos(e)*n,i=u-t,a=o-r;return t=u,r=o,[i,a]})}var i,a,f,c=0,s=0,h=1,l=1,d=t,p=r;return n.hexagon=function(n){return"m"+o(null==n?i:+n).join("l")+"z"},n.centers=function(){for(var n=[],t=Math.round(s/f),r=Math.round(c/a),e=t*f;e<l+i;e+=f,++t)for(var u=r*a+(1&t)*a/2;u<h+a/2;u+=a)n.push([u,e]);return n},n.mesh=function(){var t=o(i).slice(0,4).join("l");return n.centers().map(function(n){return"M"+n+"m"+t}).join("")},n.x=function(t){return arguments.length?(d=t,n):d},n.y=function(t){return arguments.length?(p=t,n):p},n.radius=function(t){return arguments.length?(i=+t,a=2*i*Math.sin(e),f=1.5*i,n):i},n.extent=function(t){return arguments.length?(c=+t[0][0],s=+t[0][1],h=+t[1][0],l=+t[1][1],n):[[c,s],[h,l]]},n.radius(1)};n.hexbin=o,Object.defineProperty(n,"__esModule",{value:!0})});

@@ -1,2 +0,1 @@

export {version} from "./build/package";
export {default as hexbin} from "./src/hexbin";
{
"name": "d3-hexbin",
"version": "0.2.0",
"version": "0.2.1",
"description": "Group two-dimensional points into hexagonal bins.",
"keywords": [
"d3",
"d3-module",
"hexbin",

@@ -18,2 +19,3 @@ "hexagonal",

"main": "build/d3-hexbin.js",
"module": "index",
"jsnext:main": "index",

@@ -25,10 +27,11 @@ "repository": {

"scripts": {
"pretest": "rm -rf build && mkdir build && json2module package.json > build/package.js && rollup -f umd -n d3_hexbin -o build/d3-hexbin.js -- index.js",
"pretest": "rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -f umd -n d3 -o build/d3-hexbin.js -- index.js",
"test": "tape 'test/**/*-test.js' && eslint index.js src",
"prepublish": "npm run test && uglifyjs build/d3-hexbin.js -c -m -o build/d3-hexbin.min.js",
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-hexbin.js ../d3.github.com/d3-hexbin.v0.2.js && cp build/d3-hexbin.min.js ../d3.github.com/d3-hexbin.v0.2.min.js && cd ../d3.github.com && git add d3-hexbin.v0.2.js d3-hexbin.v0.2.min.js && git commit -m \"d3-hexbin ${VERSION}\" && git push && cd - && zip -j build/d3-hexbin.zip -- LICENSE README.md build/d3-hexbin.js build/d3-hexbin.min.js"
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-hexbin.js -c -m -o build/d3-hexbin.min.js",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../d3-hexbin/build/d3-hexbin.js d3-hexbin.v1.js && cp ../d3-hexbin/build/d3-hexbin.min.js d3-hexbin.v1.min.js && git add d3-hexbin.v1.js d3-hexbin.v1.min.js && git commit -m \"d3-hexbin ${npm_package_version}\" && git push && cd - && zip -j build/d3-hexbin.zip -- LICENSE README.md build/d3-hexbin.js build/d3-hexbin.min.js"
},
"devDependencies": {
"json2module": "0.0",
"rollup": "0.25",
"eslint": "3",
"package-preamble": "0.0",
"rollup": "0.41",
"tape": "4",

@@ -35,0 +38,0 @@ "uglify-js": "2"

@@ -5,5 +5,7 @@ # d3-hexbin

[<img alt="Hexbin Random Distributions" src="https://cloud.githubusercontent.com/assets/156229/18386150/d162fb32-7649-11e6-97e0-36c1b459c61e.png" width="420" />](http://bl.ocks.org/syntagmatic/748b02519c942c5291f302e060315ad6)
## Installing
If you use NPM, `npm install d3-hexbin`. Otherwise, download the [latest release](https://github.com/d3/d3-hexbin/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-hexbin.v0.2.min.js) or as part of [D3 4.0 alpha](https://github.com/mbostock/d3/tree/4). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_hexbin` global is exported:
If you use NPM, `npm install d3-hexbin`. Otherwise, download the [latest release](https://github.com/d3/d3-hexbin/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-hexbin.v0.2.min.js). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3_hexbin` global is exported:

@@ -40,3 +42,3 @@ ```html

svg.selectAll("path")
.data(hexbin(points))
.data(hexbin(points))
.enter().append("path")

@@ -50,3 +52,3 @@ .attr("d", function(d) { return "M" + d.x + "," + d.y + hexbin.hexagon(); });

svg.selectAll("path")
.data(hexbin(points))
.data(hexbin(points))
.enter().append("path")

@@ -53,0 +55,0 @@ .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc