Socket
Socket
Sign inDemoInstall

d3-geo-scale-bar

Package Overview
Dependencies
1
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.3 to 0.5.5

41

build/d3-geo-scale-bar.js

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

// https://github.com/HarryStevens/d3-geo-scale-bar Version 0.5.3. Copyright 2020 Harry Stevens.
// https://github.com/HarryStevens/d3-geo-scale-bar Version 0.5.5. Copyright 2020 Harry Stevens.
(function (global, factory) {

@@ -246,17 +246,5 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

function capitalizeFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
function countDigits(num) {
return Math.floor(num).toString().length;
}
function inferDistance(extent, radius, divisor) {
return Math.pow(10, countDigits(geoDistance(projection.invert(extent[0]), projection.invert([extent[1][0], extent[0][1]])) * radius / divisor) - 1);
}
function scaleBar(context) {
// If a label has not been explicitly set, set it
labelText = labelText === null ? null : labelText || capitalizeFirstLetter(units); // The position, width, and ticks of the scale bar
labelText = labelText === null ? null : labelText || units.charAt(0).toUpperCase() + units.slice(1); // The position, width, and ticks of the scale bar

@@ -275,15 +263,24 @@ var width = extent[1][0] - extent[0][0],

barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);
} // Otherwise, make it an exponent of 10 with a minimum width of 40px
} // Otherwise, make it an exponent of 10 or 10 * 4 with a minimum width of 60px
else {
var divisor = 4,
minWidth = 40;
var dist = .01,
minWidth = 60,
iters = 0,
maxiters = 100;
while (barWidth < minWidth) {
barDistance = inferDistance(extent, radius, divisor);
while (barWidth < minWidth && iters < maxiters) {
barDistance = dist;
barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);
divisor -= 0.1;
if (barWidth >= minWidth) {
break;
}
barDistance = dist * 4;
barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);
dist *= 10;
iters++;
}
} // The values and elements of the scale bar
}
var max = barDistance / zoomFactor,

@@ -290,0 +287,0 @@ values = tickValues === null ? [] : tickValues ? tickValues : [0, max / 4, max / 2, max],

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

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.d3=t.d3||{})}(this,function(t){"use strict";function n(){this.reset()}function e(t,n,e){var r=t.s=n+e,o=r-n,i=r-o;t.t=n-i+(e-o)}function r(t,n){t&&M.hasOwnProperty(t.type)&&M[t.type](t,n)}function o(t,n,e){var r,o=-1,i=t.length-e;for(n.lineStart();++o<i;)r=t[o],n.point(r[0],r[1],r[2]);n.lineEnd()}function i(t,n){var e=-1,r=t.length;for(n.polygonStart();++e<r;)o(t[e],n,1);n.polygonEnd()}function a(t,n){t&&v.hasOwnProperty(t.type)?v[t.type](t,n):r(t,n)}function c(){x.point=l,x.lineEnd=u}function u(){x.point=x.lineEnd=function(t){}}function l(t,n){t*=Math.PI/180,n*=Math.PI/180,p=t,g=Math.sin(n),y=Math.cos(n),x.point=f}function f(t,n){t*=Math.PI/180,n*=Math.PI/180;var e=Math.sin(n),r=Math.cos(n),o=Math.abs(t-p),i=Math.cos(o),a=Math.sin(o),c=r*a,u=y*e-g*r*i,l=g*e+y*r*i;k.add(Math.atan2(Math.sqrt(c*c+u*u),l)),p=t,g=e,y=r}function s(t){return k.reset(),a(t,x),+k}function h(t,n){return P[0]=t,P[1]=n,s(S)}function d(){function t(t){return t.charAt(0).toUpperCase()+t.slice(1)}function n(t){return Math.floor(t).toString().length}function e(t,e,r){return Math.pow(10,n(h(o.invert(t[0]),o.invert([t[1][0],t[0][1]]))*e/r)-1)}function r(n){c=null===c?null:c||t(s);var r=u[1][0]-u[0][0],v=u[1][1]-u[0][1],M=u[0][0]+r*l,k=u[0][1]+v*f,x=o.invert([M,k]),P=0,S=0;if(i)P=i,S=P/(h(x,o.invert([M+1,k]))*d);else for(var C=4;S<40;)P=e(u,d,C),S=P/(h(x,o.invert([M+1,k]))*d),C-=.1;var b=P/m,w=null===a?[]:a||[0,b/4,b/2,b],E=function(t){return t*S/(P/m)},L=n.selection?n.selection():n,z=L.selectAll(".label").data([c]),A=L.selectAll(".domain").data([null]),O=L.selectAll(".tick").data(w,E).order(),j=O.exit(),F=O.enter().append("g").attr("class","tick"),I=O.select("line"),_=O.select("text"),q=O.select("rect");L.attr("font-family","sans-serif").attr("transform","translate(".concat([M,k],")")),A=A.merge(A.enter().insert("path",".tick").attr("class","domain").attr("fill","none").attr("stroke","currentColor")),O=O.merge(F),I=I.merge(F.append("line").attr("stroke","currentColor").attr("y2",g)),_=_.merge(F.append("text").attr("fill","currentColor").attr("y",g+2).attr("font-size",10).attr("text-anchor","middle").attr("dy","0.71em")),q=q.merge(F.append("rect").attr("fill",function(t,n){return n%2==0?"currentColor":"#fff"}).attr("stroke","currentColor").attr("stroke-width",.5).attr("width",function(t,n,e){return n===e.length-1?0:E(w[n+1]-t)}).attr("height",g)),n!==L&&(O=O.transition(n),A=A.transition(n),q=q.transition(n),j=j.transition(n).attr("opacity",1e-6).attr("transform",function(t){return"translate(".concat(E(t),")")}),F.attr("opacity",1e-6).attr("transform",function(t){return"translate(".concat(E(t),")")})),j.remove(),A.attr("d","M".concat(E(0),",").concat(g," L").concat(E(0),",0 L").concat(E(b),",0 L").concat(E(b),",").concat(g)),O.attr("transform",function(t){return"translate(".concat(E(t),")")}).attr("opacity",1),I.attr("y2",g),_.attr("y",g+2).text(p),q.attr("fill",function(t,n){return n%2==0?"currentColor":"#fff"}).attr("width",function(t,n,e){return n===e.length-1?0:E(w[n+1]-t)}).attr("height",g),null===z?z.remove():z.enter().append("text").attr("class","label").attr("fill","currentColor").attr("font-size",12).attr("dy","-0.32em").merge(z).attr("x","start"===y?0:E("middle"===y?b/2:b)).attr("text-anchor",y).text(function(t){return t})}var o,i,a,c,u=null,l=0,f=0,s="kilometers",d=6371,p=function(t){return Math.round(t)},g=4,y="start",m=1,v={miles:{radius:3959},kilometers:{radius:6371}};return r.extent=function(t){return arguments.length?(u=t,r):u},r.size=function(t){return arguments.length?(u=[[0,0],t],r):u[1]},r.projection=function(t){return arguments.length?(o=t,r):o},r.units=function(t){return arguments.length?(s=t,Object.keys(v).includes(t)&&(d=v[t].radius),r):s},r.left=function(t){return arguments.length?(l=+t>1?1:+t<0?0:+t,r):l},r.top=function(t){return arguments.length?(f=+t>1?1:+t<0?0:+t,r):f},r.distance=function(t){return arguments.length?(i=+t,r):i},r.radius=function(t){return arguments.length?(d=+t,r):d},r.tickValues=function(t){return arguments.length?(a=t,r):a},r.tickFormat=function(t){return arguments.length?(p=t,r):p},r.tickSize=function(t){return arguments.length?(g=+t,r):g},r.label=function(t){return arguments.length?(c=t,r):c},r.labelAnchor=function(t){return arguments.length?(y=t,r):y},r.zoomFactor=function(t){return arguments.length?(m=+t,r):m},r}n.prototype={constructor:n,reset:function(){this.s=this.t=0},add:function(t){e(m,t,this.t),e(this,m.s,this.s),this.s?this.t+=m.t:this.s=m.t},valueOf:function(){return this.s}};var p,g,y,m=new n,v={Feature:function(t,n){r(t.geometry,n)},FeatureCollection:function(t,n){for(var e=t.features,o=-1,i=e.length;++o<i;)r(e[o].geometry,n)}},M={Sphere:function(t,n){n.sphere()},Point:function(t,n){t=t.coordinates,n.point(t[0],t[1],t[2])},MultiPoint:function(t,n){for(var e=t.coordinates,r=-1,o=e.length;++r<o;)t=e[r],n.point(t[0],t[1],t[2])},LineString:function(t,n){o(t.coordinates,n,0)},MultiLineString:function(t,n){for(var e=t.coordinates,r=-1,i=e.length;++r<i;)o(e[r],n,0)},Polygon:function(t,n){i(t.coordinates,n)},MultiPolygon:function(t,n){for(var e=t.coordinates,r=-1,o=e.length;++r<o;)i(e[r],n)},GeometryCollection:function(t,n){for(var e=t.geometries,o=-1,i=e.length;++o<i;)r(e[o],n)}},k=function(){return new n}(),x={sphere:function(t){},point:function(t){},lineStart:c,lineEnd:function(t){},polygonStart:function(t){},polygonEnd:function(t){}},P=[null,null],S={type:"LineString",coordinates:P};t.geoScaleBar=d,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.d3=t.d3||{})}(this,function(t){"use strict";function n(){this.reset()}function e(t,n,e){var r=t.s=n+e,o=r-n,i=r-o;t.t=n-i+(e-o)}function r(t,n){t&&M.hasOwnProperty(t.type)&&M[t.type](t,n)}function o(t,n,e){var r,o=-1,i=t.length-e;for(n.lineStart();++o<i;)r=t[o],n.point(r[0],r[1],r[2]);n.lineEnd()}function i(t,n){var e=-1,r=t.length;for(n.polygonStart();++e<r;)o(t[e],n,1);n.polygonEnd()}function a(t,n){t&&v.hasOwnProperty(t.type)?v[t.type](t,n):r(t,n)}function c(){x.point=l,x.lineEnd=u}function u(){x.point=x.lineEnd=function(t){}}function l(t,n){t*=Math.PI/180,n*=Math.PI/180,p=t,g=Math.sin(n),y=Math.cos(n),x.point=s}function s(t,n){t*=Math.PI/180,n*=Math.PI/180;var e=Math.sin(n),r=Math.cos(n),o=Math.abs(t-p),i=Math.cos(o),a=Math.sin(o),c=r*a,u=y*e-g*r*i,l=g*e+y*r*i;k.add(Math.atan2(Math.sqrt(c*c+u*u),l)),p=t,g=e,y=r}function f(t){return k.reset(),a(t,x),+k}function h(t,n){return P[0]=t,P[1]=n,f(C)}function d(){function t(t){o=null===o?null:o||u.charAt(0).toUpperCase()+u.slice(1);var g=i[1][0]-i[0][0],y=i[1][1]-i[0][1],m=i[0][0]+g*a,v=i[0][1]+y*c,M=n.invert([m,v]),k=0,x=0;if(e)k=e,x=k/(h(M,n.invert([m+1,v]))*l);else for(var P=.01,C=0;x<60&&C<100&&(k=P,!((x=k/(h(M,n.invert([m+1,v]))*l))>=60));)k=4*P,x=k/(h(M,n.invert([m+1,v]))*l),P*=10,C++;var S=k/p,b=null===r?[]:r||[0,S/4,S/2,S],w=function(t){return t*x/(k/p)},E=t.selection?t.selection():t,L=E.selectAll(".label").data([o]),z=E.selectAll(".domain").data([null]),A=E.selectAll(".tick").data(b,w).order(),O=A.exit(),j=A.enter().append("g").attr("class","tick"),F=A.select("line"),I=A.select("text"),_=A.select("rect");E.attr("font-family","sans-serif").attr("transform","translate(".concat([m,v],")")),z=z.merge(z.enter().insert("path",".tick").attr("class","domain").attr("fill","none").attr("stroke","currentColor")),A=A.merge(j),F=F.merge(j.append("line").attr("stroke","currentColor").attr("y2",f)),I=I.merge(j.append("text").attr("fill","currentColor").attr("y",f+2).attr("font-size",10).attr("text-anchor","middle").attr("dy","0.71em")),_=_.merge(j.append("rect").attr("fill",function(t,n){return n%2==0?"currentColor":"#fff"}).attr("stroke","currentColor").attr("stroke-width",.5).attr("width",function(t,n,e){return n===e.length-1?0:w(b[n+1]-t)}).attr("height",f)),t!==E&&(A=A.transition(t),z=z.transition(t),_=_.transition(t),O=O.transition(t).attr("opacity",1e-6).attr("transform",function(t){return"translate(".concat(w(t),")")}),j.attr("opacity",1e-6).attr("transform",function(t){return"translate(".concat(w(t),")")})),O.remove(),z.attr("d","M".concat(w(0),",").concat(f," L").concat(w(0),",0 L").concat(w(S),",0 L").concat(w(S),",").concat(f)),A.attr("transform",function(t){return"translate(".concat(w(t),")")}).attr("opacity",1),F.attr("y2",f),I.attr("y",f+2).text(s),_.attr("fill",function(t,n){return n%2==0?"currentColor":"#fff"}).attr("width",function(t,n,e){return n===e.length-1?0:w(b[n+1]-t)}).attr("height",f),null===L?L.remove():L.enter().append("text").attr("class","label").attr("fill","currentColor").attr("font-size",12).attr("dy","-0.32em").merge(L).attr("x","start"===d?0:w("middle"===d?S/2:S)).attr("text-anchor",d).text(function(t){return t})}var n,e,r,o,i=null,a=0,c=0,u="kilometers",l=6371,s=function(t){return Math.round(t)},f=4,d="start",p=1,g={miles:{radius:3959},kilometers:{radius:6371}};return t.extent=function(n){return arguments.length?(i=n,t):i},t.size=function(n){return arguments.length?(i=[[0,0],n],t):i[1]},t.projection=function(e){return arguments.length?(n=e,t):n},t.units=function(n){return arguments.length?(u=n,Object.keys(g).includes(n)&&(l=g[n].radius),t):u},t.left=function(n){return arguments.length?(a=+n>1?1:+n<0?0:+n,t):a},t.top=function(n){return arguments.length?(c=+n>1?1:+n<0?0:+n,t):c},t.distance=function(n){return arguments.length?(e=+n,t):e},t.radius=function(n){return arguments.length?(l=+n,t):l},t.tickValues=function(n){return arguments.length?(r=n,t):r},t.tickFormat=function(n){return arguments.length?(s=n,t):s},t.tickSize=function(n){return arguments.length?(f=+n,t):f},t.label=function(n){return arguments.length?(o=n,t):o},t.labelAnchor=function(n){return arguments.length?(d=n,t):d},t.zoomFactor=function(n){return arguments.length?(p=+n,t):p},t}n.prototype={constructor:n,reset:function(){this.s=this.t=0},add:function(t){e(m,t,this.t),e(this,m.s,this.s),this.s?this.t+=m.t:this.s=m.t},valueOf:function(){return this.s}};var p,g,y,m=new n,v={Feature:function(t,n){r(t.geometry,n)},FeatureCollection:function(t,n){for(var e=t.features,o=-1,i=e.length;++o<i;)r(e[o].geometry,n)}},M={Sphere:function(t,n){n.sphere()},Point:function(t,n){t=t.coordinates,n.point(t[0],t[1],t[2])},MultiPoint:function(t,n){for(var e=t.coordinates,r=-1,o=e.length;++r<o;)t=e[r],n.point(t[0],t[1],t[2])},LineString:function(t,n){o(t.coordinates,n,0)},MultiLineString:function(t,n){for(var e=t.coordinates,r=-1,i=e.length;++r<i;)o(e[r],n,0)},Polygon:function(t,n){i(t.coordinates,n)},MultiPolygon:function(t,n){for(var e=t.coordinates,r=-1,o=e.length;++r<o;)i(e[r],n)},GeometryCollection:function(t,n){for(var e=t.geometries,o=-1,i=e.length;++o<i;)r(e[o],n)}},k=function(){return new n}(),x={sphere:function(t){},point:function(t){},lineStart:c,lineEnd:function(t){},polygonStart:function(t){},polygonEnd:function(t){}},P=[null,null],C={type:"LineString",coordinates:P};t.geoScaleBar=d,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "d3-geo-scale-bar",
"version": "0.5.3",
"version": "0.5.5",
"description": "Displays automatic scale bars for projected geospatial data.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -14,3 +14,3 @@ # d3-geo-scale-bar

```html
<script src="https://unpkg.com/d3-geo-scale-bar@0.5.3/build/d3-geo-scale-bar.min.js"></script>
<script src="https://unpkg.com/d3-geo-scale-bar@0.5.5/build/d3-geo-scale-bar.min.js"></script>
<script>

@@ -17,0 +17,0 @@

@@ -27,17 +27,5 @@ import { default as geoDistance } from "./geo/distance";

function capitalizeFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
function countDigits(num){
return Math.floor(num).toString().length;
}
function inferDistance(extent, radius, divisor){
return Math.pow(10, countDigits(geoDistance(projection.invert(extent[0]), projection.invert([extent[1][0], extent[0][1]])) * radius / divisor) - 1);
}
function scaleBar(context){
// If a label has not been explicitly set, set it
labelText = labelText === null ? null : labelText || capitalizeFirstLetter(units);
labelText = labelText === null ? null : labelText || units.charAt(0).toUpperCase() + units.slice(1);

@@ -57,14 +45,17 @@ // The position, width, and ticks of the scale bar

}
// Otherwise, make it an exponent of 10 with a minimum width of 40px
// Otherwise, make it an exponent of 10 or 10 * 4 with a minimum width of 60px
else {
let divisor = 4, minWidth = 40;
let dist = .01, minWidth = 60, iters = 0, maxiters = 100;
while (barWidth < minWidth){
barDistance = inferDistance(extent, radius, divisor);
barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);
divisor -= 0.1;
}
while (barWidth < minWidth && iters < maxiters){
barDistance = dist;
barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);
if (barWidth >= minWidth) {break;}
barDistance = dist * 4;
barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);
dist *= 10;
iters++;
}
}
// The values and elements of the scale bar
let max = barDistance / zoomFactor,

@@ -71,0 +62,0 @@ values = tickValues === null ? [] : tickValues ? tickValues : [0, max / 4, max / 2, max],

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc