0.1.5 • Published 8 months ago

@dkkoval/react-ua-map v0.1.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

@dkkoval/react-ua-map

A React component for visualizing data on a map of Ukraine by oblast. This package makes it easy to present regional data visually, providing a choropleth map representation of Ukrainian oblasts (regions).

Features

  • Display a map of Ukraine with individual oblasts colored based on provided data.
  • Supports tooltip interactions to display additional information about each oblast.
  • Easy integration with responsive container components to make the map adjust to the size of the parent.

Installation

To install the package, use npm or yarn:

npm install @dkkoval/react-ua-map

or

yarn add @dkkoval/react-ua-map

Usage

Here is an example of how to use the UAMap component in a React application.

Example

import { ParentSize } from '@visx/responsive';
import './App.css';
import populationJson from './data/population.json';
import UAMap, { getOblastCode, OblastCode } from '@dkkoval/react-ua-map';

interface MapData {
  title: string;
  valueName: string;
  data: {
    [region: string]: number;
  };
}

// Helper function to convert region names to oblast codes
function transformDataKeys(data: Record<string, number>): Record<OblastCode, number> {
  const transformedData: Partial<Record<OblastCode, number>> = {};

  Object.entries(data).forEach(([key, value]) => {
    const code = getOblastCode(key);
    if (code) {
      transformedData[code] = value;
    }
  });

  return transformedData as Record<OblastCode, number>;
}

function App() {
  const { data: rawData, title, valueName }: MapData = populationJson;

  const data = transformDataKeys(rawData);

  return (
    <div className='App' style={{
      width: '90vw',
      height: '90vh',
      border: '1px solid #eee',
      display: 'flex',
      justifyContent: 'center',
      alignItems: 'center',
      margin: '24px',
    }}>
      <ParentSize>
        {({ width, height }) => (
          <UAMap
            {...{ width, height }}
            title={title}
            valueName={valueName}
            data={data}
          />
        )}
      </ParentSize>
    </div>
  );
}

export default App;

Props

  • width: The width of the map (number).
  • height: The height of the map (number).
  • title: A string to display as the map title.
  • valueName: The unit or type of data being visualized (e.g., "Population").
  • data: An object representing the values to display for each oblast, where the keys are oblast codes and values are numerical data.

Oblast Codes

The data prop should use oblast codenames as keys to identify different regions. The oblast codes used are:

Oblast NameCode
Черкаська областьCK
Чернігівська областьCH
Чернівецька областьCV
Автономна республіка КримKR
Дніпропетровська областьDP
Донецька областьDT
Івано-Франківська областьIF
Харківська областьKK
Херсонська областьKS
Хмельницька областьKM
Київська областьKV
КиївKC
Кіровоградська областьKH
Луганська областьLH
Львівська областьLV
Миколаївська областьMY
Одеська областьOD
Полтавська областьPL
Рівненська областьRV
СевастопольSC
Сумська областьSM
Тернопільська областьTP
Закарпатська областьZK
Вінницька областьVI
Волинська областьVO
Запорізька областьZP
Житомирська областьZT

Helper Functions

  • getOblastCode(name: string): OblastCode | undefined: Converts a string representing the oblast name into the corresponding oblast code. This function is useful for transforming user-provided or external data to match the required format.

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 any suggestions or improvements.

Contact

Created by Dmytro Koval. You can reach out via GitHub for any questions or feedback.

0.1.5

8 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago