npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

d3orthozoom

v0.3.0

Published

Scale and rotate orthographic projections while preserving a bidirectional azimuth.

Readme

D3OrthoZoom

An implementation of d3.zoom() for the d3.geoOrthographic() projection that zooms to the cursor/pointer. Performing rotations rather than panning minimizes distortions. In other implementations, this approach causes a loss of northing because certain points simply cannot be reached without rotating all axes. At least not without increasing scaling above the user's input. Understanding the minimum scaling was crucial to figure out the right rotation.

<svg v-scope v-effect="d3orthozoom($el, $data)">
  <path :d="d('Sphere')" fill="lightblue"></path>
  <path :d="d('Graticule')" stroke="black" fill="none"></path>
</svg>

<script src="https://unpkg.com/d3orthozoom"></script>
<script src="https://unpkg.com/@jogemu/petite-vue" defer init></script>

Use v-scope to define or fetch data. Hide with v-if or modify with @click.

<div v-scope="{visible: true, world: geoJSON, point: [0, 0]}">
  <svg v-effect="d3orthozoom($el, $data)">
    <path :d="d({type: 'Sphere'})" fill="lightblue"></path>
    <path :d="d(world)" fill="teal" v-if="visible"></path>
    <path :d="d({type: 'Graticule', stepMinor: [10, 10], stepMajor: [90, 360]})" stroke="black" fill="none"></path>
    <path :d="d({type: 'Circle', center: [0, 0], radius: 10})" fill="tomato"></path>
    <path :d="d(point)" v-effect="drag($el, point)" fill="purple"></path>
  </svg>
  <button @click="rotate=[0,0,0];scale=1">Reset Projection</button>
  <input type="checkbox" v-model="visible"> Hide layer
</div>

<script>var geoJSON = fetch('TODO.json').then(o => o.json()).catch(e => 'TODO handle error')</script>
<script src="https://unpkg.com/d3orthozoom"></script>
<script src="https://unpkg.com/@jogemu/petite-vue" defer init></script>

Calculation

An orthographic projection with a scale of 1, a translation of [0, 0] and rotation of [0, 0, 0] is projected onto the unit circle. To obtain the equivalent coordinates x and y for all other projections, scale, translation and rotation are inverted. The inverse projection of these coordinates returns the longitude and latitude that is projected to that point.

In this calculation, [lon, lat] refers to the start position, while [x, y] refers to intermediate positions. The objective is to determine the two-axis rotation where the projection of [lon, lat] equals [x, y]. If [x, y] equals [0, 0] then the rotation is [-lon, -lat, ].

The North Pole and South Pole are always along the angle determined by the fixed rotation axis. Hence, no two-axis rotation can move the poles to a position [x, y] that is not aligned with the rotation axis. More broadly, any point's pole distance (x) cannot exceed the cosine of its latitude. Conceptually rotate the nearest pole in the center to see why.

Any movement of x perpendicular to the axis reduces possible movement within the unit circle parallel to the axis. Going back to the start (center) has the length of the radius (hypotenuse = 1), which is already everything needed for the Pythagorean theorem.

reachX = max(cosd(lat), epsilon)
reachY = sqrt(1 - x*x)

The projection is increased above user input if necessary.

projection.scale(max(
  event.transform.k,  // user input
  sqrt(x*x + y*y),    // to prevent leaving globe
  abs(x) / reachX     // to prevent pole too far
))

The asind will go from [-180, 180] depending on how close the relative x value is to the maximum x value (pole too far). Fortunately, this also puts it on a vertical line with the cursor.

r0 = asind(x / reachX) - lon

In an intermediate step, the latitude of a point is calculated that is on the same height as the pointer and on the centered line that goes south from the North Pole.

A second step calculates the latitude of the pointer and adds or subtracts the previous value based on the hemisphere. Both steps must take into account the limitations imposed by the reach.

lat_ = -90 + asind(cosd(lat) * cosd(lon + r0) / reachY)
r1 = -asind(y / reachY) + lat_ * sign(lat)