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.7.1 to 1.0.0

.DS_Store

13

build/d3-geo-scale-bar.js

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

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

@@ -249,3 +249,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

// If a label has not been explicitly set, set it
labelText = labelText === null ? null : labelText || units.charAt(0).toUpperCase() + units.slice(1); // The position, width, and ticks of the scale bar
labelText = labelText === null ? null : labelText || units.charAt(0).toUpperCase() + units.slice(1); // The position and width of the scale bar

@@ -274,7 +274,3 @@ var width = extent[1][0] - extent[0][0],

barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);
if (barWidth >= minWidth) {
break;
}
if (barWidth >= minWidth) break;
barDistance = dist * 4;

@@ -285,4 +281,5 @@ barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);

}
}
} // The ticks and elements of the bar
var max = barDistance / zoomFactor,

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

{
"name": "d3-geo-scale-bar",
"version": "0.7.1",
"version": "1.0.0",
"description": "Displays automatic scale bars for projected geospatial data.",

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

# d3-geo-scale-bar
Like [d3-axis](https://github.com/d3/d3-axis) but for maps, this module displays automatic scale bars for projected geospatial data.
d3-geo-scale-bar is a JavaScript library and [D3.js](https://d3js.org/) plugin that makes it easy to add scale bars to maps created with [d3-geo](https://github.com/d3/d3-geo).
In cartography, scale bars help viewers understand the geographic extent of maps. Professional cartographers seldom omit them from published maps, yet scale bars are commonly missing from interactive maps published on the internet. d3-geo-scale-bar makes it easy to add scale bars to maps created with [d3-geo](https://github.com/d3/d3-geo).
## Installing

@@ -12,7 +10,7 @@

```html
<script src="https://unpkg.com/d3-geo-scale-bar@0.7.1/build/d3-geo-scale-bar.min.js"></script>
<script src="https://unpkg.com/d3-geo-scale-bar@1.0.0/build/d3-geo-scale-bar.min.js"></script>
<script>
const projection = d3.geoMercator()
.fitSize([width, height], geoJSON)
.fitSize(width, height], geoJSON);

@@ -32,3 +30,3 @@ const scaleBar = d3.geoScaleBar()

[Try d3-geo-scale-bar in your browser](https://npm.runkit.com/d3-geo-scale-bar).
[Try d3-geo-scale-bar in your browser](https://observablehq.com/d/e2a2c037f579d0c9).

@@ -46,34 +44,9 @@ ## API Reference

A scale bar's [default design](https://bl.ocks.org/HarryStevens/8c8d3a489aa1372e14b8084f94b32464) references the classic checkered design:
Scale bars help readers understand the geographic extent of maps. A scale bar's [default design](https://bl.ocks.org/HarryStevens/8c8d3a489aa1372e14b8084f94b32464) references the classic checkered design:
[<img alt="Scale Bar Design" src="https://raw.githubusercontent.com/HarryStevens/d3-geo-scale-bar/master/img/default.png">](https://bl.ocks.org/HarryStevens/8c8d3a489aa1372e14b8084f94b32464)
A scale bar consists of a [g element](https://www.w3.org/TR/SVG/struct.html#Groups) which, by default, contains one [path element](https://www.w3.org/TR/SVG/paths.html#PathElement) of class "domain", four [g elements](https://www.w3.org/TR/SVG/struct.html#Groups) of class "tick" representing each of the scale bar's ticks. Each tick has a [line element](https://www.w3.org/TR/SVG/shapes.html#LineElement) to draw the tick line, a [text element](https://www.w3.org/TR/SVG/text.html#TextElement) for the tick label, and a [rect element](https://www.w3.org/TR/SVG/shapes.html#RectElement) of alternating black and white fill. There is also another text element of class "label" sitting above the bar that denotes the units. All of these can be styled and manipulated like normal SVG elements.
By tweaking the scale bar's configuration and CSS, you can produce [several different scale bar designs](https://observablehq.com/d/e2a2c037f579d0c9#styling).
```svg
<g font-family="sans-serif" transform="translate(0,0)">
<path class="domain" fill="none" stroke="currentColor" d="M0,4 L0,0 L200,0 L200,4"></path>
<g class="tick" transform="translate(0)" opacity="1">
<line stroke="currentColor" y2="4"></line>
<text fill="currentColor" y="6" font-size="10" text-anchor="middle" dy="0.71em">0</text>
<rect fill="currentColor" stroke="currentColor" stroke-width="0.5" width="50" height="4"></rect>
</g>
<g class="tick" transform="translate(50)" opacity="1">
<line stroke="currentColor" y2="4"></line>
<text fill="currentColor" y="6" font-size="10" text-anchor="middle" dy="0.71em">25</text>
<rect fill="#fff" stroke="currentColor" stroke-width="0.5" width="50" height="4"></rect>
</g>
<g class="tick" transform="translate(100)" opacity="1">
<line stroke="currentColor" y2="4"></line>
<text fill="currentColor" y="6" font-size="10" text-anchor="middle" dy="0.71em">50</text>
<rect fill="currentColor" stroke="currentColor" stroke-width="0.5" width="100" height="4"></rect>
</g>
<g class="tick" transform="translate(200)" opacity="1">
<line stroke="currentColor" y2="4"></line>
<text fill="currentColor" y="6" font-size="10" text-anchor="middle" dy="0.71em">100</text>
<rect fill="#fff" stroke="currentColor" stroke-width="0.5" width="0" height="4"></rect>
</g>
<text class="label" fill="currentColor" font-size="12" dy="-0.32em" x="0" text-anchor="start">Kilometers</text>
</g>
```
A scale bar consists of a [path element](https://www.w3.org/TR/SVG/paths.html#PathElement) of class "domain", followed by four [g elements](https://www.w3.org/TR/SVG/struct.html#Groups) of class "tick" representing each of the scale bar's ticks. Each tick has a [line element](https://www.w3.org/TR/SVG/shapes.html#LineElement) to draw the tick line, a [text element](https://www.w3.org/TR/SVG/text.html#TextElement) for the tick label, and a [rect element](https://www.w3.org/TR/SVG/shapes.html#RectElement) of alternating black and white fill. There is also another text element of class "label" sitting above the bar that denotes the units.

@@ -86,3 +59,3 @@ <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)

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):
Renders the scale bar to the given <i>context</i>, which may be either a [selection](https://github.com/d3/d3-selection) of an SVG [g element](https://www.w3.org/TR/SVG/struct.html#Groups) or a corresponding [transition](https://observablehq.com/d/e2a2c037f579d0c9#transitions). Configure the scale bar with [<i>scaleBar</i>.projection](#scaleBar_projection) and [<i>scaleBar</i>.extent](#scaleBar_fitSize) before rendering. Generally, you will use this with <i>selection</i>.[call](https://github.com/d3/d3-selection#selection_call):

@@ -99,11 +72,11 @@ ```js

<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)
<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#L156 "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. 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.
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 is 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_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)
<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#L176 "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. A projection is required to render a scale bar.
If <i>projection</i> is specified, sets the [projection](https://github.com/d3/d3-geo#projections) and returns the scale bar. If <i>projection</i> 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L183 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBar)
<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#L184 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBar)

@@ -118,39 +91,39 @@ 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L167 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarPositioned)
<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#L168 "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, and returns the scale bar. If *left* is not specified, returns the current left position which defaults to 0.
If <i>left</i> is specified, sets the left position to the specified value which must be in the range [0, 1], where 0 is the leftmost side of the scale bar's extent and 1 is the rightmost, and returns the scale bar. If <i>left</i> 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L187 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarPositioned)
<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#L188 "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, and returns the scale bar. If *top* is not specified, returns the current top position which defaults to 0.
If <i>top</i> 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 <i>top</i> 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L151 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
<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#L152 "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 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.
If <i>distance</i> is specifed, sets the maximum distance of the scale bar and returns the scale bar. [Defaults](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L42) to the smallest exponent of 10 or 10x4 that will render the bar at least 60 pixels wide. 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L179 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarMoon)
<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#L180 "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 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.
If <i>radius</i> is specifed, sets the radius of the sphere on which the scale bar is placed 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](https://observablehq.com/d/e2a2c037f579d0c9#spaceBars). If <i>radius</i> is not specified, returns the current radius.
<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)
<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#L204 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
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).
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](https://github.com/HarryStevens/d3-geo-scale-bar#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).
If <i>units</i> is not specified, returns a string representing the current unit, e.g. "kilometers". The capitalized version of this string will be used for the [label](#scaleBar_label) if no label is specified.
<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")
<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>() · [Source](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.
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. This is the default setting.
<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")
<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>() · [Source](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")

@@ -161,15 +134,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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L159 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
<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#L160 "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 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.
If a <i>label</i> string is specified, sets 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 null, 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L163 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
<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#L164 "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.
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, and returns 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L171 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarTop)
<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#L172 "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).
If an <i>orientation</i> 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>() · [Source](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")

@@ -182,3 +155,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>() · [Source](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")

@@ -191,19 +164,19 @@ 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L191 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarPositioned)
<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#L192 "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.
If a <i>formatter</i> function is specified, each tick value 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L195 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
<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#L196 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarWapo)
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.
If a <i>size</i> number is specified, sets the vertical tick size of the scale bar in pixels and returns the scale bar. Defaults to 4. If <i>size</i> 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>]) · [Source](https://github.com/HarryStevens/d3-geo-scale-bar/blob/master/src/geoScaleBar.js#L199 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarBottom)
<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#L200 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#scaleBarBottom)
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.
If a <i>values</i> array is specified, sets the tick values to the specified values in the array rather than using the scale bar’s automatic tick generator, and returns the scale bar. Defaults to [0, kilometers / 4, kilometers / 2, kilometers]. Passing <i>null</i> removes the values and their associated ticks from the scale bar. If <i>values</i> is not specified, returns the current tick values.
### Zooming
<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)
<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#L208 "Source"), [Example](https://observablehq.com/d/e2a2c037f579d0c9#zooming)
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 <i>k</i> is specified, zooms the scale bar by the <i>k</i> [scale factor](https://github.com/d3/d3-zoom#zoomTransform) and returns the scale bar. This will commonly [be used](https://observablehq.com/d/e2a2c037f579d0c9#zooming) in conjunction with [d3-zoom](https://github.com/d3/d3-zoom):

@@ -224,2 +197,2 @@ ```js

If *k* is not specified, returns the current zoom factor.
If <i>k</i> is not specified, returns the current zoom factor.

@@ -25,3 +25,3 @@ import { default as geoDistance } from "./geo/distance";

// The position, width, and ticks of the scale bar
// The position and width of the scale bar
let width = extent[1][0] - extent[0][0],

@@ -46,3 +46,3 @@ height = extent[1][1] - extent[0][1],

barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);
if (barWidth >= minWidth) {break;}
if (barWidth >= minWidth) break;
barDistance = dist * 4;

@@ -55,2 +55,3 @@ barWidth = barDistance / (geoDistance(start, projection.invert([x + 1, y])) * radius);

// The ticks and elements of the bar
let max = barDistance / zoomFactor,

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

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc