Socket
Socket
Sign inDemoInstall

d3-geo-scale-bar

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-geo-scale-bar - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

10

build/d3-geo-scale-bar.js

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

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

@@ -385,6 +385,2 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

scaleBar.tickValues = function (_) {
return arguments.length ? (tickValues = _, scaleBar) : tickValues;
};
scaleBar.tickFormat = function (_) {

@@ -398,2 +394,6 @@ return arguments.length ? (tickFormat = _, scaleBar) : tickFormat;

scaleBar.tickValues = function (_) {
return arguments.length ? (tickValues = _, scaleBar) : tickValues;
};
scaleBar.units = function (_) {

@@ -400,0 +400,0 @@ var _ref;

@@ -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&&x.hasOwnProperty(t.type)&&x[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&&S.hasOwnProperty(t.type)?S[t.type](t,n):r(t,n)}function c(){P.point=l,P.lineEnd=u}function u(){P.point=P.lineEnd=function(t){}}function l(t,n){t*=Math.PI/180,n*=Math.PI/180,m=t,y=Math.sin(n),v=Math.cos(n),P.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-m),i=Math.cos(o),a=Math.sin(o),c=r*a,u=v*e-y*r*i,l=y*e+v*r*i;k.add(Math.atan2(Math.sqrt(c*c+u*u),l)),m=t,y=e,v=r}function f(t){return k.reset(),a(t,P),+k}function h(t,n){return C[0]=t,C[1]=n,f(b)}function d(){return 1}function g(){function t(t){o=null===o?null:o||u.charAt(0).toUpperCase()+u.slice(1);var d=i[1][0]-i[0][0],y=i[1][1]-i[0][1],v=i[0][0]+d*a,M=i[0][1]+y*c,S=n.invert([v,M]),x=0,k=0;if(e)x=e,k=x/(h(S,n.invert([v+1,M]))*l);else for(var P=.01,C=0;k<60&&C<100&&(x=P,!((k=x/(h(S,n.invert([v+1,M]))*l))>=60));)x=4*P,k=x/(h(S,n.invert([v+1,M]))*l),P*=10,C++;var b=x/p,w=null===r?[]:r||[0,b/4,b/2,b],E=function(t){return t*k/(x/p)},L=t.selection?t.selection():t,z=L.selectAll(".label").data([o]),A=L.selectAll(".domain").data([null]),F=L.selectAll(".tick").data(w,E).order(),I=F.exit(),O=F.enter().append("g").attr("class","tick"),j=F.select("line"),B=F.select("text"),_=F.select("rect");L.attr("font-family","sans-serif").attr("transform","translate(".concat([v,M],")")),A=A.merge(A.enter().insert("path",".tick").attr("class","domain").attr("fill","none").attr("stroke","currentColor")),F=F.merge(O),j=j.merge(O.append("line").attr("stroke","currentColor").attr("y2",f*m)),B=B.merge(O.append("text").attr("fill","currentColor").attr("y",f*m+2).attr("font-size",10).attr("text-anchor","middle").attr("dy","".concat(1===m?.71:-.35,"em"))),_=_.merge(O.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("y",1===m?0:-f).attr("height",f)),t!==L&&(F=F.transition(t),A=A.transition(t),_=_.transition(t),I=I.transition(t).attr("opacity",1e-6).attr("transform",function(t){return"translate(".concat(E(t),")")}),O.attr("opacity",1e-6).attr("transform",function(t){return"translate(".concat(E(t),")")})),I.remove(),A.attr("d","M".concat(E(0),",").concat(f*m," L").concat(E(0),",0 L").concat(E(b),",0 L").concat(E(b),",").concat(f*m)),F.attr("transform",function(t){return"translate(".concat(E(t),")")}).attr("opacity",1),j.attr("y2",f*m),B.attr("y",f*m+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:E(w[n+1]-t)}).attr("y",1===m?0:-f).attr("height",f),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"===g?0:E("middle"===g?b/2:b)).attr("y",1===m?0:"1.3em").attr("text-anchor",g).text(function(t){return t})}var n,e,r,o,i=null,a=0,c=0,u=w.units,l=w.radius,s=function(t){return Math.round(t)},f=4,g="start",p=1,m=d();return t.distance=function(n){return arguments.length?(e=+n,t):e},t.extent=function(n){return arguments.length?(i=n,t):i},t.label=function(n){return arguments.length?(o=n,t):o},t.labelAnchor=function(n){return arguments.length?(g=n,t):g},t.left=function(n){return arguments.length?(a=+n>1?1:+n<0?0:+n,t):a},t.orient=function(n){return arguments.length?(m=n(),t):1===m?"bottom":"top"},t.projection=function(e){return arguments.length?(n=e,t):n},t.radius=function(n){return arguments.length?(l=+n,t):l},t.size=function(n){return arguments.length?(i=[[0,0],n],t):i[1]},t.top=function(n){return arguments.length?(c=+n>1?1:+n<0?0:+n,t):c},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.units=function(n){var e;return arguments.length?(e=n,u=e.units,l=e.radius,t):u},t.zoomFactor=function(n){return arguments.length?(p=+n,t):p},t}function p(){return-1}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 m,y,v,M=new n,S={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)}},x={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}(),P={sphere:function(t){},point:function(t){},lineStart:c,lineEnd:function(t){},polygonStart:function(t){},polygonEnd:function(t){}},C=[null,null],b={type:"LineString",coordinates:C},w={units:"kilometers",radius:6371.0088},E={units:"feet",radius:20902259.664},L={units:"meters",radius:6371008.8},z={units:"miles",radius:3958.7613};t.geoScaleBar=g,t.geoScaleBottom=d,t.geoScaleTop=p,t.geoScaleFeet=E,t.geoScaleKilometers=w,t.geoScaleMeters=L,t.geoScaleMiles=z,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&&x.hasOwnProperty(t.type)&&x[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&&S.hasOwnProperty(t.type)?S[t.type](t,n):r(t,n)}function c(){P.point=l,P.lineEnd=u}function u(){P.point=P.lineEnd=function(t){}}function l(t,n){t*=Math.PI/180,n*=Math.PI/180,m=t,y=Math.sin(n),v=Math.cos(n),P.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-m),i=Math.cos(o),a=Math.sin(o),c=r*a,u=v*e-y*r*i,l=y*e+v*r*i;k.add(Math.atan2(Math.sqrt(c*c+u*u),l)),m=t,y=e,v=r}function f(t){return k.reset(),a(t,P),+k}function h(t,n){return C[0]=t,C[1]=n,f(b)}function d(){return 1}function g(){function t(t){o=null===o?null:o||u.charAt(0).toUpperCase()+u.slice(1);var d=i[1][0]-i[0][0],y=i[1][1]-i[0][1],v=i[0][0]+d*a,M=i[0][1]+y*c,S=n.invert([v,M]),x=0,k=0;if(e)x=e,k=x/(h(S,n.invert([v+1,M]))*l);else for(var P=.01,C=0;k<60&&C<100&&(x=P,!((k=x/(h(S,n.invert([v+1,M]))*l))>=60));)x=4*P,k=x/(h(S,n.invert([v+1,M]))*l),P*=10,C++;var b=x/p,w=null===r?[]:r||[0,b/4,b/2,b],E=function(t){return t*k/(x/p)},L=t.selection?t.selection():t,z=L.selectAll(".label").data([o]),A=L.selectAll(".domain").data([null]),F=L.selectAll(".tick").data(w,E).order(),I=F.exit(),O=F.enter().append("g").attr("class","tick"),j=F.select("line"),B=F.select("text"),_=F.select("rect");L.attr("font-family","sans-serif").attr("transform","translate(".concat([v,M],")")),A=A.merge(A.enter().insert("path",".tick").attr("class","domain").attr("fill","none").attr("stroke","currentColor")),F=F.merge(O),j=j.merge(O.append("line").attr("stroke","currentColor").attr("y2",f*m)),B=B.merge(O.append("text").attr("fill","currentColor").attr("y",f*m+2).attr("font-size",10).attr("text-anchor","middle").attr("dy","".concat(1===m?.71:-.35,"em"))),_=_.merge(O.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("y",1===m?0:-f).attr("height",f)),t!==L&&(F=F.transition(t),A=A.transition(t),_=_.transition(t),I=I.transition(t).attr("opacity",1e-6).attr("transform",function(t){return"translate(".concat(E(t),")")}),O.attr("opacity",1e-6).attr("transform",function(t){return"translate(".concat(E(t),")")})),I.remove(),A.attr("d","M".concat(E(0),",").concat(f*m," L").concat(E(0),",0 L").concat(E(b),",0 L").concat(E(b),",").concat(f*m)),F.attr("transform",function(t){return"translate(".concat(E(t),")")}).attr("opacity",1),j.attr("y2",f*m),B.attr("y",f*m+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:E(w[n+1]-t)}).attr("y",1===m?0:-f).attr("height",f),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"===g?0:E("middle"===g?b/2:b)).attr("y",1===m?0:"1.3em").attr("text-anchor",g).text(function(t){return t})}var n,e,r,o,i=null,a=0,c=0,u=w.units,l=w.radius,s=function(t){return Math.round(t)},f=4,g="start",p=1,m=d();return t.distance=function(n){return arguments.length?(e=+n,t):e},t.extent=function(n){return arguments.length?(i=n,t):i},t.label=function(n){return arguments.length?(o=n,t):o},t.labelAnchor=function(n){return arguments.length?(g=n,t):g},t.left=function(n){return arguments.length?(a=+n>1?1:+n<0?0:+n,t):a},t.orient=function(n){return arguments.length?(m=n(),t):1===m?"bottom":"top"},t.projection=function(e){return arguments.length?(n=e,t):n},t.radius=function(n){return arguments.length?(l=+n,t):l},t.size=function(n){return arguments.length?(i=[[0,0],n],t):i[1]},t.top=function(n){return arguments.length?(c=+n>1?1:+n<0?0:+n,t):c},t.tickFormat=function(n){return arguments.length?(s=n,t):s},t.tickSize=function(n){return arguments.length?(f=+n,t):f},t.tickValues=function(n){return arguments.length?(r=n,t):r},t.units=function(n){var e;return arguments.length?(e=n,u=e.units,l=e.radius,t):u},t.zoomFactor=function(n){return arguments.length?(p=+n,t):p},t}function p(){return-1}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 m,y,v,M=new n,S={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)}},x={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}(),P={sphere:function(t){},point:function(t){},lineStart:c,lineEnd:function(t){},polygonStart:function(t){},polygonEnd:function(t){}},C=[null,null],b={type:"LineString",coordinates:C},w={units:"kilometers",radius:6371.0088},E={units:"feet",radius:20902259.664},L={units:"meters",radius:6371008.8},z={units:"miles",radius:3958.7613};t.geoScaleBar=g,t.geoScaleBottom=d,t.geoScaleTop=p,t.geoScaleFeet=E,t.geoScaleKilometers=w,t.geoScaleMeters=L,t.geoScaleMiles=z,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "d3-geo-scale-bar",
"version": "0.7.0",
"version": "0.7.1",
"description": "Displays automatic scale bars for projected geospatial data.",

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

@@ -7,4 +7,2 @@ # d3-geo-scale-bar

[See it in action](https://bl.ocks.org/HarryStevens/8c8d3a489aa1372e14b8084f94b32464).
## Installing

@@ -15,3 +13,3 @@

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

@@ -81,7 +79,7 @@

<a name="geoScaleBar" href="#geoScaleBar">#</a> d3.<b>geoScaleBar</b>() [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L5 "Source")
<a name="geoScaleBar" href="#geoScaleBar">#</a> d3.<b>geoScaleBar</b>() · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L5 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9)
Constructs a new scale bar generator with the default settings.
<a name="_scaleBar" href="#_scaleBar">#</a> <i>scaleBar</i>(<i>context</i>) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L27 "Source")
<a name="_scaleBar" href="#_scaleBar">#</a> <i>scaleBar</i>(<i>context</i>) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L21 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#basicUsage)

@@ -100,11 +98,11 @@ Render the scale bar to the given *context*, which may be either a [selection](https://github.com/d3/d3-selection) of SVG containers (either SVG or G elements) or a corresponding [transition](https://github.com/d3/d3-transition). Configure the scale bar with [*scaleBar*.projection](#scaleBar_projection) and [*scaleBar*.extent](#scaleBar_fitSize) before rendering. Generally, you will use this with <i>selection</i>.[call](https://github.com/d3/d3-selection#selection_call):

<a name="scaleBar_projection" href="#scaleBar_projection">#</a> <i>scaleBar</i>.<b>projection</b>([<i>projection</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L95 "Source")
<a name="scaleBar_extent" href="#scaleBar_extent">#</a> <i>scaleBar</i>.<b>extent</b>([<i>extent</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L155 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBar)
If *projection* is specified, sets the [projection](https://github.com/d3/d3-geo#projections) and returns the scale bar. If *projection* is not specified, returns the current projection.
If <i>extent</i> is specified, sets the extent of the scale bar generator to the specified bounds and returns the scale bar. The extent bounds are specified as an array [[<i>x0</i>, <i>y0</i>], [<i>x1</i>, <i>y1</i>]], where <i>x0</i> is the left side of the extent, <i>y0</i> is the top, <i>x1</i> is the right and <i>y1</i> is the bottom. If extent is not specified, returns the current extent which defaults to null. An extent is required to render a scale bar.
<a name="scaleBar_extent" href="#scaleBar_extent">#</a> <i>scaleBar</i>.<b>extent</b>([<i>extent</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L91 "Source")
<a name="scaleBar_projection" href="#scaleBar_projection">#</a> <i>scaleBar</i>.<b>projection</b>([<i>projection</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L175 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBar)
If <i>extent</i> is specified, sets the extent of the scale bar generator to the specified bounds and returns the scale bar generator. The extent bounds are specified as an array [[<i>x0</i>, <i>y0</i>], [<i>x1</i>, <i>y1</i>]], where <i>x0</i> is the left side of the extent, <i>y0</i> is the top, <i>x1</i> is the right and <i>y1</i> is the bottom. If extent is not specified, returns the current extent which defaults to null. An extent is required.
If *projection* is specified, sets the [projection](https://github.com/d3/d3-geo#projections) and returns the scale bar. If *projection* is not specified, returns the current projection. A projection is required to render a scale bar.
<a name="scaleBar_size" href="#scaleBar_size">#</a> <i>scaleBar</i>.<b>size</b>([<i>size</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L91 "Source")
<a name="scaleBar_size" href="#scaleBar_size">#</a> <i>scaleBar</i>.<b>size</b>([<i>size</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L183 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBar)

@@ -119,21 +117,21 @@ An alias for [<i>scaleBar</i>.extent](#scaleBar_extent) where the minimum x and y of the extent are ⟨0,0⟩. Equivalent to:

<a name="scaleBar_left" href="#scaleBar_left">#</a> <i>scaleBar</i>.<b>left</b>([<i>left</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L134 "Source")
<a name="scaleBar_left" href="#scaleBar_left">#</a> <i>scaleBar</i>.<b>left</b>([<i>left</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L167 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarPositioned)
If *left* is specified, sets the left position to the specified value which must be in the range [0, 1], where 0 is the left-most side of the scale bar's extent and 1 is the right-most. If *left* is not specified, returns the current left position which defaults to 0.
If *left* is specified, sets the left position to the specified value which must be in the range [0, 1], where 0 is the left-most side of the scale bar's extent and 1 is the right-most, and returns the scale bar. If *left* is not specified, returns the current left position which defaults to 0.
<a name="scaleBar_top" href="#scaleBar_top">#</a> <i>scaleBar</i>.<b>top</b>([<i>top</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L138 "Source")
<a name="scaleBar_top" href="#scaleBar_top">#</a> <i>scaleBar</i>.<b>top</b>([<i>top</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L187 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarPositioned)
If *top* is specified, sets the top position to the specified value which must be in the range [0, 1], where 0 is the top-most side of the scale bar's extent and 1 is the bottom-most. If *top* is not specified, returns the current top position which defaults to 0.
If *top* is specified, sets the top position to the specified value which must be in the range [0, 1], where 0 is the top-most side of the scale bar's extent and 1 is the bottom-most, and returns the scale bar. If *top* is not specified, returns the current top position which defaults to 0.
### Sizing
<a name="scaleBar_distance" href="#scaleBar_distance">#</a> <i>scaleBar</i>.<b>distance</b>([<i>distance</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L114 "Source")
<a name="scaleBar_distance" href="#scaleBar_distance">#</a> <i>scaleBar</i>.<b>distance</b>([<i>distance</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L151 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
If <i>distance</i> is specifed, sets the maxiumum distance of the scale bar in the scale bar's units. Defaults to the largest exponent of 10 that will fit on the map. If <i>distance</i> is not specified, returns the current maximum distance of the scale bar.
If <i>distance</i> is specifed, sets the maxiumum distance of the scale bar in the scale bar's units and returns the scale bar. Defaults to the largest exponent of 10 that will fit on the map. If <i>distance</i> is not specified, returns the current maximum distance of the scale bar.
<a name="scaleBar_radius" href="#scaleBar_radius">#</a> <i>scaleBar</i>.<b>radius</b>([<i>radius</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L118 "Source")
<a name="scaleBar_radius" href="#scaleBar_radius">#</a> <i>scaleBar</i>.<b>radius</b>([<i>radius</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L179 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarMoon)
If <i>radius</i> is specifed, sets the radius of the sphere on which the geospatial data is projected. Defaults to 6371.0088, [the mean radius of Earth in kilometers](https://en.wikipedia.org/wiki/Earth_radius#Mean_radius). If you set [<i>units</i>](#scaleBar_units) to d3.geoScaleMiles, the <i>radius</i> will also update to 3958.7613, [the mean radius of Earth in miles](https://en.wikipedia.org/wiki/Earth_radius#Mean_radius). You can set the *radius* to any number you like, useful for mapping planets other than Earth. If *radius* is not specified, returns the current radius.
If <i>radius</i> is specifed, sets the radius of the sphere on which the geospatial data is projected and returns the scale bar. Defaults to 6371.0088, [the mean radius of Earth in kilometers](https://en.wikipedia.org/wiki/Earth_radius#Mean_radius). If you set [<i>units</i>](#scaleBar_units) to d3.[geoScaleMiles](#geoScaleMiles), the <i>radius</i> will also update to 3958.7613, [the mean radius of Earth in miles](https://en.wikipedia.org/wiki/Earth_radius#Mean_radius). You can set the *radius* to any number you like, useful for mapping planets other than Earth. If *radius* is not specified, returns the current radius.
<a name="scaleBar_units" href="#scaleBar_units">#</a> <i>scaleBar</i>.<b>units</b>([<i>units</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L99 "Source")
<a name="scaleBar_units" href="#scaleBar_units">#</a> <i>scaleBar</i>.<b>units</b>([<i>units</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L203 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)

@@ -144,15 +142,15 @@ If <i>units</i> is specifed, sets the [radius](#scaleBar_radius) of the scale bar to the corresponding units and returns the scale bar. Defaults to d3.geoScaleKilometers, which sets the label to "Kilometers" and the radius to 6371.0088, [the mean radius of Earth in kilometers](https://en.wikipedia.org/wiki/Earth_radius#Mean_radius). Note that the Earth's radius varies depending upon latitude, so if extremely high precision matters, you can [perform your own calculation of the radius](https://web.archive.org/web/20200118181437/https://rechneronline.de/earth-radius/) and pass the output to <i>scaleBar</i>.[radius](#scaleBar_radius).

<a name="geoScaleFeet" href="#geoScaleFeet">#</a> d3.<b>geoScaleFeet</b>() [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/units/feet.js "Source")
<a name="geoScaleFeet" href="#geoScaleFeet">#</a> d3.<b>geoScaleFeet</b>() · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/units/feet.js "Source")
When passed to <i>scaleBar</i>.[units](#scaleBar_units), sets the [radius](scaleBar_radius) to 20902259.664, the mean radius of Earth in feet. The [label](#scaleBar_label) will be set to "Feet" if no label is specified.
<a name="geoScaleKilometers" href="#geoScaleKilometers">#</a> d3.<b>geoScaleKilometers</b>() [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/units/kilometers.js "Source")
<a name="geoScaleKilometers" href="#geoScaleKilometers">#</a> d3.<b>geoScaleKilometers</b>() · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/units/kilometers.js "Source")
When passed to <i>scaleBar</i>.[units](#scaleBar_units), sets the [radius](scaleBar_radius) to 6371.0088, the mean radius of Earth in kilometers. The [label](#scaleBar_label) will be set to "Kilometers" if no label is specified.
<a name="geoScaleMeters" href="#geoScaleMeters">#</a> d3.<b>geoScaleMeters</b>() [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/units/meters.js "Source")
<a name="geoScaleMeters" href="#geoScaleMeters">#</a> d3.<b>geoScaleMeters</b>() · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/units/meters.js "Source")
When passed to <i>scaleBar</i>.[units](#scaleBar_units), sets the [radius](scaleBar_radius) to 6371008.8, the mean radius of Earth in meters. The [label](#scaleBar_label) will be set to "Meters" if no label is specified.
<a name="geoScaleMiles" href="#geoScaleMiles">#</a> d3.<b>geoScaleMiles</b>() [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/units/miles.js "Source")
<a name="geoScaleMiles" href="#geoScaleMiles">#</a> d3.<b>geoScaleMiles</b>() · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/units/miles.js "Source")

@@ -163,15 +161,15 @@ When passed to <i>scaleBar</i>.[units](#scaleBar_units), sets the [radius](scaleBar_radius) to 3958.7613, the mean radius of Earth in miles. The [label](#scaleBar_label) will be set to "Miles" if no label is specified.

<a name="scaleBar_label" href="#scaleBar_label">#</a> <i>scaleBar</i>.<b>label</b>([<i>label</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L126 "Source")
<a name="scaleBar_label" href="#scaleBar_label">#</a> <i>scaleBar</i>.<b>label</b>([<i>label</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L159 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
If a <i>label</i> string is specified, updates the text in the scale bar's label to the specified string. Defaults to the capitalized unit, e.g. "Kilometers". If label is specified as <i>null</i>, removes the label. If <i>label</i> is not specified, returns the current label.
If a <i>label</i> string is specified, updates the text in the scale bar's label to the specified string and returns the scale bar. Defaults to the capitalized unit, e.g. "Kilometers". If label is specified as <i>null</i>, removes the label. If <i>label</i> is not specified, returns the current label.
<a name="scaleBar_labelAnchor" href="#scaleBar_labelAnchor">#</a> <i>scaleBar</i>.<b>labelAnchor</b>([<i>anchor</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L126 "Source")
<a name="scaleBar_labelAnchor" href="#scaleBar_labelAnchor">#</a> <i>scaleBar</i>.<b>labelAnchor</b>([<i>anchor</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L163 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
If an <i>anchor</i> string is specified, aligns the scale bar's label such that it is either at the "start" of the scale bar, the "middle" of the scale bar, or the "end" of the scale bar. Defaults to "start". If an <i>anchor</i> string is not specified, returns the current anchor.
<a name="scaleBar_orient" href="#scaleBar_orient">#</a> <i>scaleBar</i>.<b>orient</b>([<i>orientation</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L126 "Source")
<a name="scaleBar_orient" href="#scaleBar_orient">#</a> <i>scaleBar</i>.<b>orient</b>([<i>orientation</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L171 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarTop)
If an [<i>orientation</i>](#geoScaleBottom) is specified, styles the bar according to the specified orientation and returns the scale bar. If an <i>orientation</i> is not specified, returns the current orientation as a string, either "top" or "bottom". Defaults to [d3.geoScaleBottom](#geoScaleBottom).
<a name="geoScaleBottom" href="#geoScaleBottom">#</a> d3.<b>geoScaleBottom</b>() [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/orient/bottom.js "Source")
<a name="geoScaleBottom" href="#geoScaleBottom">#</a> d3.<b>geoScaleBottom</b>() · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/orient/bottom.js "Source")

@@ -184,3 +182,3 @@ When passed to <i>scaleBar</i>.[orient](#scaleBar_orient), orients the scale bar so that the label is on the top and the ticks are on bottom. This is the default orientation.

<a name="geoScaleTop" href="#geoScaleTop">#</a> d3.<b>geoScaleTop</b>() [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/orient/top.js "Source")
<a name="geoScaleTop" href="#geoScaleTop">#</a> d3.<b>geoScaleTop</b>() · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/orient/top.js "Source")

@@ -193,11 +191,11 @@ When passed to <i>scaleBar</i>.[orient](#scaleBar_orient), orients the scale bar so that the label is on the bottom and the ticks are on top.

<a name="scaleBar_tickFormat" href="#scaleBar_tickFormat">#</a> <i>scaleBar</i>.<b>tickFormat</b>([<i>formatter</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L122 "Source")
<a name="scaleBar_tickFormat" href="#scaleBar_tickFormat">#</a> <i>scaleBar</i>.<b>tickFormat</b>([<i>formatter</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L191 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarPositioned)
If a <i>formatter</i> function is specified, each tick is passed through the formatter before being displayed. Defaults to (d, i, e) => Math.round(d), where d is the tick number, i is the tick index, and e is an array of all tick data. If a <i>formatter</i> is not specified, returns the current formatter.
<a name="scaleBar_tickSize" href="#scaleBar_tickSize">#</a> <i>scaleBar</i>.<b>tickSize</b>([<i>size</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L130 "Source")
<a name="scaleBar_tickSize" href="#scaleBar_tickSize">#</a> <i>scaleBar</i>.<b>tickSize</b>([<i>size</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L195 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
If *size* is specified, sets the vertical tick size of the scale bar in pixels. Defaults to 4. If *size* is not specified, returns the current tick size of the scale bar.
If *size* is specified, sets the vertical tick size of the scale bar in pixels and returns the scale bar. Defaults to 4. If *size* is not specified, returns the current tick size of the scale bar.
<a name="scaleBar_tickValues" href="#scaleBar_tickValues">#</a> <i>scaleBar</i>.<b>tickValues</b>([<i>values</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L122 "Source")
<a name="scaleBar_tickValues" href="#scaleBar_tickValues">#</a> <i>scaleBar</i>.<b>tickValues</b>([<i>values</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L199 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarBottom)

@@ -208,3 +206,3 @@ If a <i>values</i> array is specified, the specified values are used for ticks rather than using the scale bar’s automatic tick generator. Defaults to [0, kilometers / 4, kilometers / 2, kilometers]. Passing <i>null</i> removes the values from the scale bar. If <i>values</i> is not specified, returns the current tick values.

<a name="scaleBar_zoomFactor" href="#scaleBar_zoomFactor">#</a> <i>scaleBar</i>.<b>zoomFactor</b>([<i>k</i>]) [<>](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L142 "Source")
<a name="scaleBar_zoomFactor" href="#scaleBar_zoomFactor">#</a> <i>scaleBar</i>.<b>zoomFactor</b>([<i>k</i>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L207 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#zooming)

@@ -227,2 +225,2 @@ If *k* is specified, zooms the scale bar by the *k* zoom factor. This will commonly [be used](https://bl.ocks.org/HarryStevens/64fc5f1a4489abe78433b7d19510f864) in conjunction with [d3-zoom](https://github.com/d3/d3-zoom):

If *k* is not specified, returns the current scale factor.
If *k* is not specified, returns the current zoom factor.

@@ -190,6 +190,2 @@ import { default as geoDistance } from "./geo/distance";

}
scaleBar.tickValues = function(_) {
return arguments.length ? (tickValues = _, scaleBar) : tickValues;
}

@@ -203,2 +199,6 @@ scaleBar.tickFormat = function(_) {

}
scaleBar.tickValues = function(_) {
return arguments.length ? (tickValues = _, scaleBar) : tickValues;
}

@@ -205,0 +205,0 @@ scaleBar.units = function(_) {

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