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 🙏

© 2024 – Pkg Stats / Ryan Hefner

solaris-js

v0.1.2

Published

A reusable component for interactive visualization of the Solar System

Downloads

5

Readme

Solaris.js

A reusable component for interactive visualization of the Solar System.

  • WebGL-based: uses three.js for rendering
  • Mobile-friendly: mouse and touch controls supported
  • Framework-agnostic: no dependency on jQuery or other major libraries apart from three.js
  • Customizable styles for the rendering of planets, moons, orbits, etc

The goal is to have something like a Google Maps or Cesium for the Solar System, making it easier to build apps and games depicting it.

This is a work in progress: the basics are there but many areas, especially satellites, still need a lot of work.

Corrections and bug reports are welcome.

Model / custom rendering: all astronomical data and orbital calculations are encapsulated in the solaris-model module. You can use it directly if you'd like to implement your own rendering of the Solar System.

Install

From npm

npm install solaris-js

CommonJS:

let Solaris = require('solaris-js')

It's also available as an ES6 module (using pkg.module):

import Solaris from 'solaris-js'

The CSS is declared in pkg.style, so you can get it from npm too:

@import "solaris-js";

To use the default assets (planet textures etc), serve the folder node_modules/solaris/dist, by copying it to your public root or mounting it in your application. Ex.:

cp node_modules/solaris/dist public/solaris

Or mounting it in express:

app.use('/solaris', express.static(__dirname + '/node_modules/solaris/dist'))

Manual installation

If you prefer to install it the old-fashioned way, download the tarball and copy the dist folder to your public root, renaming it solaris.

<link rel="stylesheet" href="solaris/solaris.css">
<script src="solaris/solaris.min.js"></script> <!-- sets window.Solaris -->

Custom path for assets

Using either method above, if you wish to put the assets in a path other than the default solaris, just pass your custom path during initialization:

let solaris = new Solaris(element, {root: 'path/to/wisdom'})

Usage

Just give it an element id and you'll get a Solar System view with the default settings and theme:

let solaris = new Solaris('elementId')

You can also pass it an element reference:

let solaris = new Solaris(document.querySelector('.solaris'))

#setTime

By default, the date/time used for the calculation of positions will be the system's local.

To set a specific date/time, you can either give it a date string:

solaris.setTime('1961-04-12') // will be parsed to 1961-04-12T12:00:00Z (UTC)

Or a javascript Date object:

solaris.setTime(new Date('1969-07-20T20:17:43Z'))

#center

Sets the center of camera and controls.

solaris.center('mars')

#reset

Resets the scene to the default perspective (centered on the sun).

solaris.reset()

Styles

You can customize the appearance of celestial bodies and orbits by using the styles param:

let solaris = new Solaris(elementId, {
  styles: {
    types: {
      planet: {color: 0xFFFFFF, orbit: 0xFFFFFF},
      dwarfPlanet: {color: 0x666666, orbit: 0x666666},
      moon: {color: 0x666666, orbit: 0x666666},
      spacecraft: {color: 0x666666, orbit: 0x666666}
    }

    bodies: {
      sun: {color: 0xFFFFFF, light: 0xFFFFFF},
      mercury: {texture: true, orbit: 0xD2D0D3},
      venus: {color: 0xFFFFFF, orbit: 0xFFFF99},
      earth: {texture: true, orbit: 0x659EC1},
      moon: {texture: true},
      iss: {orbit: 0x0000FF},
      mars: {texture: true, orbit: 0xCC0000},
      ceres: {texture: true}
    }
  }
})

By default, each celestial body will be rendered according to the styles defined for their type (star, planet, dwarfPlanet, moon or spacecraft).

These can be selectively overriden by the individually-targeted styles defined in the bodies section.

To get the complete list of objects you can style:

Object.keys(solaris.model.bodies)
// => ["sun", "mercury", "venus", "earth", "moon", "iss", "mars", "phobos", "deimos", "ceres", "jupiter", "io", "europa", "ganymede", "callisto", "saturn", "mimas", "enceladus", "tethys", "dione", "rhea", "titan", "hyperion", "iapetus", "phoebe", "uranus", "titania", "neptune", "triton", "pluto", "eris", "sedna"]

Styleable properties

color

The sphere's surface color, as a number. Ex.: 0xFFFFFF.

texture

Instead of a color, use a texture for the sphere's surface.

If set to true, the corresponding image will be expected at {root}/img/{bodyKey}.jpg.

If given a string, it will be interpreted as the full relative path to the image.

light

Color of the emitted light, only used for orbiters of type star.

orbit

Color of the line showing the orbit's path.

Other options

fastclickElement

The FastClick library is used to eliminate tap delay on touch-based devices, and by default it is restricted to the element you supplied Solaris with.

You can use this option to attach FastClick to a different element, for example if you wish it to apply to the whole document:

let solaris = new Solaris('elementId', {fastClickElement: document.body})

To-do list

  • Camera positioning and direction

  • Emit events: onLoad, onBodyClicked, etc

  • Show message when WebGL is not available

  • Add Electron-based tests.

  • The milky way should be inclined 63 degrees to the plane of the ecliptic.

  • Add a "classic" theme (yellow sun, infrared venus). The current one depicts celestial bodies as close as possible to what they would look like to the human eye in space (white sun, white venus).

Check solaris-model for issues not related to presentation.

License

MIT