0.0.5 • Published 3 months ago

rn-heatmap v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Heatmap Component - NPM Package

Overview

The rn-heatmap package provides a customizable activity heatmap similar to GitHub's contribution graph, built with react-native-svg.

Installation

npm install rn-heatmap

or with Yarn:

yarn add rn-heatmap

Peer Dependencies

Ensure you have react-native-svg installed:

npm install react-native-svg

Usage

Light Mode Component

import React from 'react';
import { View } from 'react-native';
import {Heatmap} from 'rn-heatmap';

const LightModeHeatmap = () => {
  return (
    <View>
      <Heatmap
        year={2024}
        activeDays={[
          {monthIndex: 0, dayIndex: 5, level: 2},
          {monthIndex: 2, dayIndex: 10, level: 3},
          {monthIndex: 5, dayIndex: 20, level: 1},
        ]}
        defaultCellColor="#808080"
        colorMap={{
          1: '#a3d9a5',
          2: '#57c84d',
          3: '#228b22',
        }}
        cellSize={12}
        dayGap={6}
        monthlyGap={30}
        textPadding={10}
        fontWeight="bold"
        getMonthAnnotation={monthIndex =>
          [
            'Jan',
            'Feb',
            'Mar',
            'Apr',
            'May',
            'Jun',
            'Jul',
            'Aug',
            'Sep',
            'Oct',
            'Nov',
            'Dec',
          ][monthIndex]
        }
        showMonthAnnotation={true}
        monthlyAnnotationFontSize={12}
        monthlyAnnotationColor="black"
        cellBorderRadius={4}
        paddingHorizontal={15}
        paddingVertical={5}
        bottomPadding={15}
        showCurrentFullYear={true}
        showScrollBar={true}
      />
    </View>
  );
};

export default LightModeHeatmap;

Alt text


Dark Mode Component

import React from 'react';
import { View } from 'react-native';
import {Heatmap} from 'rn-heatmap';

const DarkModeHeatmap = () => {
  return (
    <View>
      <Heatmap
        year={2024}
        activeDays={[
          {monthIndex: 0, dayIndex: 5, level: 2},
          {monthIndex: 2, dayIndex: 10, level: 3},
          {monthIndex: 5, dayIndex: 20, level: 1},
        ]}
        defaultCellColor="#161b22"
        colorMap={{
          1: '#0e4429',
          2: '#006d32',
          3: '#26a641',
        }}
        cellSize={14}
        dayGap={8}
        monthlyGap={35}
        textPadding={12}
        fontWeight="bold"
        getMonthAnnotation={monthIndex =>
          [
            'Jan',
            'Feb',
            'Mar',
            'Apr',
            'May',
            'Jun',
            'Jul',
            'Aug',
            'Sep',
            'Oct',
            'Nov',
            'Dec',
          ][monthIndex]
        }
        showMonthAnnotation={true}
        monthlyAnnotationFontSize={12}
        monthlyAnnotationColor="white"
        cellBorderRadius={4}
        paddingHorizontal={15}
        paddingVertical={5}
        bottomPadding={15}
        showCurrentFullYear={true}
        showScrollBar={true}
      />
    </View>
  );
};

export default DarkModeHeatmap;

Alt text


API Reference

Props

PropTypeDefaultDescription
yearnumberRequiredThe year for which the heatmap is generated.
activeDaysArray<Activity>[]List of active days with their month, day index, and activity level.
defaultCellColorstring#161b22The default background color for inactive days.
colorMap{[key: number]: string}{1: '#0e4429', 2: '#006d32', 3: '#26a641'}Color mapping for different activity levels.
cellSizenumber12The size of each cell representing a day.
dayGapnumber6The gap between each day's cell.
monthlyGapnumber30The gap between months.
textPaddingnumber10Padding for month annotations.
fontWeightFontWeight'normal'Font weight for month labels.
getMonthAnnotation(monthIndex: number) => stringgetMonthFromMonthIndexFunction to get month labels.
showMonthAnnotationbooleantrueWhether to display month labels.
monthlyAnnotationFontSizenumber10Font size for month labels.
monthlyAnnotationColorstring'white'Color of month labels.
cellBorderRadiusnumber2Border radius for day cells.
paddingHorizontalnumber10Horizontal padding for the component.
paddingVerticalnumber0Vertical padding for the component.
bottomPaddingnumber10Bottom padding for the heatmap.
showCurrentFullYearbooleanfalseWhether to show the entire current year or only past days.
showScrollBarbooleanfalseWhether to show the horizontal scrollbar.

Activity Object Structure

Each Activity object in activeDays should have the following structure:

interface Activity {
  monthIndex: number; // 0-based index (0 = January, 11 = December)
  dayIndex: number;   // 0-based index (0 = first day of the month)
  level: 1 | 2 | 3;   // Activity level, corresponding to `colorMap`
}

Contributing

  1. Fork the repository.
  2. Clone the repo: git clone https://github.com/yourusername/rn-heatmap.git
  3. Install dependencies: npm install
  4. Run project by : npm run android or npm run ios etc
  5. Make your changes.
  6. Submit a pull request.

License

MIT License

0.0.5

3 months ago

0.0.4

3 months ago

0.0.3

3 months ago

0.0.2

3 months ago

0.0.1

3 months ago