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

@antonio-goncalves/react-regional-data-display-test

v1.0.6

Published

React components based on [mapbox](https://www.mapbox.com/) used to display quantitative data of geographical regions with support for multiples data sets and dates.

Downloads

17

Readme

React Regional Data Display

React components based on mapbox used to display quantitative data of geographical regions with support for multiples data sets and dates.

Install

npm install @antonio-goncalves/react-regional-data-display

Usage

Usage example using data provided by Eurostats.

import * as React from "react";
import {ReactRegionalDataDisplay} from "@antonio-goncalves/react-regional-data-display";
import '@antonio-goncalves/react-regional-data-display/dist/main.css'

import useSWR from 'swr'
import axios from 'axios'


const center = {
    lng: 13.9612,
    lat: 57.1004,
    zoom: 2.36
}

const fetcher =( url:string )=> axios.get(url).then(res => res.data)

const MAPBOX_TOKEN="your-token";

export function DataDisplayWithData(){
    const { data:dataSets, error:dataSetsError } = useSWR('https://preview.antonio-goncalves.com/api/dataSets?ids=gdp,populationDensity', fetcher)
    const { data:regions, error:regionsError } = useSWR('https://preview.antonio-goncalves.com/api/regions/eurostatCountries10m?ids=BE,BG,CZ,DK,DE,EE,IE,EL,ES,FR,HR,IT,CY,LV,LT,LU,HU,MT,NL,AT,PL,PT,RO,SI,SK,FI,SE,IS,LI,NO,CH,UK,ME,MK,AL,RS,TR', fetcher)

    if(dataSetsError || regionsError){
        const errors = []
        if(dataSetsError){
            errors.push(<p style={{color:"red"}}>Error when fetching data sets: {dataSetsError.message}</p>)
        }
        if(regionsError){
            errors.push(<p style={{color:"red"}}>Error when fetching regions: {regionsError.message}</p>)
        }
        return <>
            {errors.map((el,i)=>(
                el
            ))}
        </>
    }

    return (
        <ReactRegionalDataDisplay
            dataSets={dataSets}
            regions={regions}
            mapBoxToken={MAPBOX_TOKEN}
            center={center}
        />
    )


}

Components

React component provided by this library.

ReactRegionalDataDisplay

Main component providing the map visualizer, data info, data set and date selection.

Properties

| Name | Type | Is Optional | Default Value | Description | |-----------------------|------------------|-------------|---------------------------|-----------------------------------------------------------------------------------------------------------------| | dataSets | DataSet[] | no | | Data sets available on the component. | | regions | Region[] | no | | GeoJSON data of regions available on the map. | | center | Center | yes | {   zoom:1,    lng:0,    lat:0} | Center position and zoom. | | mapBoxToken | string | no | | Access token required to use mapbox. | | mapHeight | string or number | yes | 500 | Height of the map, use a number of "px" or a sring for a css value. | | mapBoxOptions | object | yes | | Extra options passed to the mapbox constructor. | | onDataSetChange | (dataSetId:string)=>void| yes | | Fired when a new data set is selected. | | className | string | yes | | Custom class for the container. | | sliderClassName | string | yes | | Custom class for the slider element. | | dropdownClassName | string | yes | | Custom class for the dropdown element. | | placeholderClassName | string | yes | | Custom class for the placeholder text. | | mapContainerClassName | string | yes | | Custom class for map container. | | style | object | yes | | Custom style for the container. | | sliderStyle | object | yes | | Custom style for the slider element. | | dropdownStyle | object | yes | | Custom style for the dropdown element. | | placeholderStyle | object | yes | | Custom style for the placeholder text. | | mapContainerStyle | object | yes | | Custom style for map container. |

RegionsMap

Map component used on this project, can be used as a standalone component if date and data set selection is not required.

Properties

| Name | Type | Is Optional | Default Value | Description | |----------------|----------------------|--------|---------------|----------------------------------------------------------------------------------------------------------------| | regionsData | RegionData[] or null | no | | Data value for each region. | | regions | Region[] | no | | GeoJSON data of regions available on the map. | | center | Center | yes | {   zoom:1,    lng:0,    lat:0} | Center position and zoom. | | mapBoxToken | string | no | | Access token required to use mapbox. | | mapHeight | string or number | yes | 500 | Height of the map, use a number of "px" or a sring for a css value. | | mapBoxOptions | object | yes | | Extra options passed to the mapbox constructor. | | scale | Scale | no | | Scale used by the map. | | footnotes | Footnote[] | yes | | Footnotes texts available to be used by data points. | | unit | Unit | no | | Unit of the data showed on the map. | | dropdownClassName | string | yes | | Custom class for the dropdown element. | | mapContainerClassName | string | yes | | Custom class for the map container. | | mapContainerStyle | object | yes | | Custom style for the map container. |

Scale

Coloured scale used on the map

Properties

| Name | Type | Is Optional | Default Value | Description | |-------------|---------|--------|---------------|--------------------------------------| | value | DataScale | no | | Numeric intervals and colors. | | unit | Unit | no | | Unit showed on the label. | | onMouseOver | (value?: ScaleInterval)=>void | no | | Mouse over event for each scale area. |

Slider

Animated slider used for date selection.

Properties

| Name | Type | Is Optional | Default Value | Description | |-------------|-----------------------|-------------|---------------|------------------------------------------------------------| | value | number | no | | Current selection of the scale. | | values | SliderValue[] | no | | Available values. | | timeBetweenJumps | number | yes | 1000 | Time in ms between between selection when in animated mode is enabled. | | onChange | (value: number)=>void | no | | Event when fired when the value changes | | className | string | yes | | Custom class for the slider. | | style | object | yes | | Custom style for the slider. |

Structures

Data structures used on this project.

DataSet

Object describing a data set.

| Name | Type | Is Optional | Default Value | Description | |-------------|---------------|-------------|---------------|-----------------------------------------------------------------------| | id | string | no | | Id of the data set. | | name | string | no | | Name of the data set. | | description | string | no | | Description of the data set. | | center | Center | no | | Position and zoom of the map (overrides "center" property of the map). | | source | DataSetSource | no | | Source of the data. | | dates | DataSetDates | no | | Dates of the data set. | | unit | Unit | no | | Unit of the data set. | | scale | DataScale | no | | Scale info for the data set. | | data | RegionData[] or null | no | | Data values for each region. | | footnotes | Footnote[] | yes | | Footnotes texts available to be used by data points. |

Center

Object describing the center position and zoom on the map.

| Name | Type | Is Optional | Default Value | Description | |------|--------|-------------|----------------------|-----------------| | lat | number | no | | Latitude value. | | lng | number | no | | Longitude value. | | zoom | number | no | | Zoom level. |

DataSetSource

Object describing the source of the data

| Name | Type | Is Optional | Default Value | Description | |------|--------|-------------|----------------------|-----------------------------------------------------------------| | name | string | no | | Name of the source. | | url | string | no | | Url of the source. |

DataSetDates

Object describing the dates available on the data set

| Name | Type | Is Optional | Default Value | Description | |------------|----------|-------------|----------------------|------------------------------------------------------------------------------------------| | format | string | no | | Format on how to display the dates. | | timestamps | number[] | no | | Values of the timestamps in ms. |

Unit

Object describing the unit

| Name | Type | Is Optional | Default Value | Description | |--------|--------|-------------|----------------------|----------------------| | name | string | no | | Name of the unit. | | symbol | string | no | | Symbol of the unit. |

DataScale

Object describing the scale used on the map

| Name | Type | Is Optional | Default Value | Description | |------------|----------|-------------|----------------------|--------------------------| | startValue | number | no | | First value of the scale. | | steps | number[] | no | | Values for each step. | | colors | string[] | no | | Color of each step. |

RegionData

Object describing the data for each region

| Name | Type | Is Optional | Default Value | Description | |---------------|----------|-------------|----------------------|----------------------| | dateTimestamp | number | no | | Date of the data. | | id | string | no | | Id of the region. | | value | number | no | | Numeric value of the data. | | footnoteIds | string[] | yes | | Ids of the footnotes. |

Footnote

Object describing footnotes available

| Name | Type | Is Optional | Default Value | Description | |-------------|----------|-------------|----------------------|----------------------------| | id | string | no | | Id of the footnote. | | value | string | no | | Text value of the footnote. |

Region

Object containing the contours of a region

| Name | Type | Is Optional | Default Value | Description | |---------|---------|-------------|----------------------|---------------------------------------------------| | id | string | no | | Id of the region. | | name | string | no | | name of the region. | | geoJSON | GeoJSON | no | | Contours of the region, GeoJSON (type="Feature"). |

SliderValue

| Name | Type | Is Optional | Default Value | Description | |---------|---------|-------------|----------------------|------------------------| | label | string | no | | Label of the value. | | value | number | no | | Numeric value. |

ScaleInterval

| Name | Type | Is Optional | Default Value | Description | |----------|--------|-------------|----------------------|-------------------| | minValue | number | no | | Minimum value. | | maxValue | number | no | | Maximum value. | | color | string | no | | Color of the area. |