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

@dkkoval/react-stats-map

v0.1.3

Published

A React component for visualizing data on a map of Ukraine by oblast.

Downloads

476

Readme

@dkkoval/react-stats-map

A React component for visualizing data on geographic maps by region. This package provides a flexible way to present regional data visually, creating a choropleth map representation where each region is colored based on its data value.

Features

  • Display a custom map with regions colored based on provided data.
  • Supports tooltip interactions to display additional information about each region.
  • Easily integrates with responsive containers to automatically adjust to the size of the parent component.
  • Compatible with custom maps using TopoJSON data.

Installation

Install the package with npm or yarn:

npm install @dkkoval/react-stats-map

or

yarn add @dkkoval/react-stats-map

Usage

Here’s an example of how to use the StatsMap component in a React application with a custom map file.

import * as topojson from 'topojson-client';
import StatsMap, { MapStyle, ThresholdColor } from '@dkkoval/react-stats-map';

// Example TopoJSON data and types
import topology from './assets/maps/regions.json';
import { RegionCode } from './types'; // 'CODE1' | 'CODE2' | 'CODE3'

// Extract features from TopoJSON
const { features } = topojson.feature(
  topology,
  topology.objects.regions
) as topojson.FeatureCollection;

export interface CustomMapProps {
  width: number;
  height: number;
  data: Record<RegionCode, number>;
  valueName: string;
  title: string;
  hideLegend?: boolean;
  hideTitle?: boolean;
  mapStyle?: MapStyle;
  thresholdColors?: ThresholdColor[];
}

// Custom Map Component using StatsMap
export function CustomMap(props: CustomMapProps) {
  return (
    <StatsMap
      {...props}
      topojsonFeatures={features}
      nameAccessor={(f) => f.properties.NAME}  // Accessor for region names
      codeAccessor={(f) => f.id}               // Accessor for region codes
    />
  );
}

Explanation

In this example, we create a CustomMap component using StatsMap:

  • topojsonFeatures: The map data, extracted from a TopoJSON file, defines the shapes and boundaries of each region.
  • nameAccessor: Specifies how to retrieve each region's name, which is used for tooltips and labels.
  • codeAccessor: Defines how to retrieve each region's unique code, which is used to match data values to specific regions.

Props for StatsMap

  • width: Width of the map (number).
  • height: Height of the map (number).
  • data: Object containing data values for each region, where keys are region codes.
  • valueName: The label for the type of data being visualized (e.g., "population density").
  • title: Title displayed above the map.
  • hideLegend: Boolean to hide the legend (optional).
  • hideTitle: Boolean to hide the title (optional).
  • mapStyle: Style options for customizing map appearance (optional).
  • thresholdColors: Array of colors to define the range for choropleth visualization (optional).

License

This project is licensed under the Apache-2.0 License. See the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.

Contact

Created by Dmytro Koval. Reach out via GitHub for any questions or feedback.