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

us-state-map

v1.3.9

Published

React component for displaying colors on a US state map

Downloads

80

Readme

usStateMap

React component for displaying colors on a US state map. Available on npm as us-state-map.

See the included app for usage, or see stateElectionMap for another example.

Note: You must copy the files in public/data to your app's public/data directory. (issue #2 is looking for a better way to handle this)

The main components are:

USStateMap

The main map component. It has props:

  • stateColors: Map<string, string | ColorGradient> Map of stateCode (i.e. 'AL', 'DC', 'TX', etc.) to what color it should be. Any CSS color should work (examples: 'red', '#123456', 'rgb(100, 200, 0)', etc.) Instead of a string, you can specify a ColorGradient.
  • stateTitles?: Map<string, string> Optional map of stateCode (i.e. 'AL', 'DC', 'TX', etc.) to the label on the tooltip.
  • stateSelectedCallback?: (stateCode: string) => void Optional callback when a state is tapped. Argument passed is the stateCode (i.e. 'AL', 'DC', 'TX', etc.)
  • stateClearedCallback?: () => void Optional callback when a part of the map that is not a state is tapped.
  • isCartogram: boolean Whether the map is a cartogram (state sizes roughly proportional to population) or not.
  • x?: number Optional offset in the x direction for the map. Defaults to 0.
  • y?: number Optional offset in the y direction for the map. Defaults to 0.
  • width: number Width of the map. 900 seems like a good value.
  • height: number Height of the map. 500 seems like a good value.
  • onError: (error: any) => void Callback that is called when there's an error loading data.

DateSlider

A slider that can display months or years. It has props:

  • ticksPerYear?: number The number of ticks per year, if a year is made up of multiple ticks. If this is defined it should be divisible by 12 (i.e. 1, 2, 3, 4, 6, or 12) Exactly one of this and yearsPerTick should be defined (the other should be undefined)
  • yearsPerTick?: number The number of years per tick, if a tick covers multiple years. Exactly one of this and ticksPerYear should be defined (the other should be undefined)
  • startTickDateRange: TickDateRange The TickDateRange of the first tick of the slider.
  • endTickDateRange: TickDateRange The TickDateRange of the last tick of the slider.
  • currentTickDateRange: TickDateRange The TickDateRange of the current tick.
  • onTickDateRangeChange: (tickDateRange: TickDateRange) => void Callback called when the tick changes (whether the user changes it or it automatically advances because it's playing)
  • hidePlay?: boolean Whether to hide the Play/Stop button and speed controls. Default is to show them.
  • initialSpeed?: DateSpeedSliderEnum The initial speed of the slider. Default is Normal
  • cssProps?: React.CSSProperties CSS properties to apply to the div containing the slider. Default is {width: 500}

TickDateRange

Represents a date range of a tick on the slider. The year and month represent the end of the range, while the beginning of the range can be calculated by looking at ticksPerYear or yearsPerTick, although I expect most applications will set these to be constants so your code can assume what they are. It has properties:

  • endYear: number The ending year that this date range represents.
  • endMonth: number The ending month that this date range represents. Note that this is 0-indexed, so 0=January and 11=December.