UNPKG

d3-morton

Version:

D3 layout to visualize distance variables using a continuous Morton (Z-order) space-filling space.

3 lines (2 loc) 1.52 kB
// Version 1.1.2 d3-morton - https://github.com/vasturiano/d3-morton-order !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{})}(this,(function(t){"use strict";t.zOrder=function(){var t={point2Distance:function(t,n){var e=[1431655765,858993459,252645135,16711935],r=[1,2,4,8];return(t=((t=((t=((t=(t|t<<r[3])&e[3])|t<<r[2])&e[2])|t<<r[1])&e[1])|t<<r[0])&e[0])|(n=((n=((n=((n=(n|n<<r[3])&e[3])|n<<r[2])&e[2])|n<<r[1])&e[1])|n<<r[0])&e[0])<<1},distance2Point:function(t){return[n(t),n(t>>1)];function n(t){return t=65535&((t=16711935&((t=252645135&((t=858993459&((t&=1431655765)|t>>1))|t>>2))|t>>4))|t>>8)}}},n={},e=1,r=4,i=!0;return n.canvasWidth=function(t){return arguments.length?(e=+t,n):e},n.order=function(t){return arguments.length?(r=+t,n):r},n.simplifyCurves=function(t){return arguments.length?(i=t,n):i},n.layout=function(o){var u=function(n,e,r,i,o){if(o){for(;!Number.isInteger(n)||!Number.isInteger(e);)n*=4,e*=4,r+=1;for(;!(n%4)&&!(e%4)&&r>0;)n/=4,e/=4,r-=1}var u=Math.pow(4,r);n=Math.min(n,u),e=Math.min(e,u-n);for(var f=Math.pow(2,r),a=i/f,c=[],s=0;s<e;s++)c.push(t.distance2Point(n+s));return{cellWidth:a,pathVertices:c}}(o.start,o.length,r,e,i);return o.cellWidth=u.cellWidth,o.pathVertices=u.pathVertices,n},n.getValAtXY=function(n,i){var o=Math.pow(2,r),u=[n,i].map((function(t){return Math.floor(t*o/e)}));return t.point2Distance(u[0],u[1])},n}}));