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

svelte-geo

v0.3.0

Published

A small map component, suitable for building choropleths amongst other things, for Svelte.

Downloads

151

Readme

svelte-geo

A tiny library for making maps, intended for use in data visualisation projects. Svelte-geo uses d3-geo to plot .geojson polygon data as svg.

svelte-geo in action

Two components

  <BaseMap
    projection={a_d3-geo_projection}
    margin = {{left:10,right:10,top:10,bottom:10} }
    background = {any_valid_html_color}
    bind:zoomReset = {resetter}
  >
    <FeatureLayer
      geojson={geojson_object}
      styleAccessor = {(feature, selected) => style_object}
      idAccessor = {feature => feature_uid}
      selectMode = {integer >=0 || Infinity}
      bind:selection = {selection}
      on:click={event_handler}
      on:mousemove = {event_handler}
      on:mouseenter = {event_handler}
      on:mouseleave = {event_handler}
      on:mount = {event_handler}
      on:destroy = {event_handler}
      let:hoveredFeature
    >
      <text>{hoveredFeature.someAttribute}</text>
    </FeatureLayer>
  <\BaseMap>

BaseMap sets up things which are common to all feature layers e.g. the map projection and the margin to allow around the layers.

BaseMap

props

projection : a D3-geo projection
margin : a margin object of the form {left:10,right:10,top:10,bottom:10}. Measurements are in px.
background : sets the background color of the <svg> element.
zoomReset : exports a reset function for the map zoom.

slot

<FeatureLayer> elements go in a slot in <BaseMap>. <FeatureLayer> plots and styles the features from a geojson object. You may use multiple <FeatureLayer>s in a map.

FeatureLayer

props

geojson : a geojson object. Required
styleAccessor : a function that takes a feature from your geojson object, and a selection status (boolean), and returns a style object for an svg path.
idAccessor : a function that takes a feature from your geojson object, and returns a unique identifier for the feature. This is what will be stored in selection.
selectMode : defines the number of features that may be selected. May be an integer >=0, or Infinity.
selection : an array containing the uid's of the current selection. Bind to selection to control the selection programmatically.

events

mount
destroy

Mount and destroy events are dispatched when the <FeatureLayer> element is created or destroyed.

click
mousemove
mouseenter
mouseleave
Mouse events are dispatched when the <svg> elements in the <Featurelayer> are interacted with. e.detail contains the originating event and the feature.

slot

Any SVG elements placed inside the <FeatureLayer> element will be rendered as a tooltip with its origin at the position of the mouse pointer. Slot prop hoveredFeature is provided and contains the feature.