### Install React Heat Map
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
This command installs the necessary dependencies for the React Heat Map project. It is a prerequisite for running the project in development or building it for production.
```bash
npm install
```
--------------------------------
### Install @uiw/react-heat-map
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
Instructions for installing the react-heat-map package using npm. It also notes a potential dependency on `next-remove-imports` for Next.js projects to resolve specific issues.
```bash
# Not dependent on uiw.
npm install @uiw/react-heat-map --save
```
--------------------------------
### NPM Installation - Bash
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
Installs the @uiw/react-heat-map package using npm or yarn. No additional UIW dependencies are required. This command adds the package as a project dependency.
```bash
npm install @uiw/react-heat-map --save
# or
yarn add @uiw/react-heat-map
```
--------------------------------
### Run React Heat Map in Development Mode
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
This command starts the development server for the React Heat Map project. It allows you to see your changes in real-time as you develop and test the components.
```bash
npm run start
```
--------------------------------
### Next.js Configuration - Bash
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
Installs the next-remove-imports development dependency for Next.js projects. This package helps configure the build process to handle specific import scenarios within Next.js applications.
```bash
npm install next-remove-imports --save-dev
```
--------------------------------
### Basic Usage of React Heat Map
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
Demonstrates the basic implementation of the HeatMap component in React. It shows how to provide data, customize week labels, and set a start date for the heatmap visualization. Note the required date format `YYYY/MM/DD`.
```jsx
import React from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/01/12', count: 20 },
{ date: '2016/01/13', count: 10 },
...[...Array(17)].map((_, idx) => ({
date: `2016/02/${idx + 10}`, count: idx, content: ''
})),
{ date: '2016/04/11', count: 2 },
{ date: '2016/05/01', count: 5 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/04', count: 11 },
];
const Demo = () => {
return (
)
};
export default Demo
```
--------------------------------
### Advanced Heat Map Styling and Customization in React
Source: https://github.com/uiwjs/react-heat-map/blob/main/www/public/bundle.html
Showcases advanced customization options for the HeatMap component, including setting width, custom panel colors, and inline styles. This example requires 'react' and '@uiw/react-heat-map'. It illustrates how to control the visual appearance and color scheme of the heat map.
```javascript
import HeatMap from '@uiw/react-heat-map';
import React from 'react';
import ReactDOM from 'react-dom';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/01/12', count: 20 },
{ date: '2016/01/13', count: 10 },
...[...Array(17)].map((_, idx) => ({ date: `2016/02/${idx + 10}`, count: idx, content: '' })),
{ date: '2016/04/11', count: 2 },
{ date: '2016/05/01', count: 5 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/04', count: 11 },
];
const Demo = () => {
return (
);
};
ReactDOM.render(, document.getElementById('container'));
```
--------------------------------
### HeatMap Component with Custom Rect Styling (Border Radius)
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
Shows how to customize the styling of individual day rectangles in the `HeatMap` component, specifically by applying a border radius. This example uses a range slider to dynamically control the border-radius of the rectangles.
```jsx
import React, { useState } from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/01/12', count: 5 },
{ date: '2016/01/13', count: 8 },
{ date: '2016/02/10', count: 3 },
{ date: '2016/02/15', count: 12 },
{ date: '2016/04/12', count: 2 },
{ date: '2016/05/01', count: 5 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/03', count: 1 },
{ date: '2016/05/04', count: 11 },
{ date: '2016/05/08', count: 32 },
];
function RoundedRectHeatMap() {
const [range, setRange] = useState(5);
return (
setRange(e.target.value)}
/>
Border Radius: {range}}
rectProps={{
rx: range
}}
/>
);
}
export default RoundedRectHeatMap;
```
--------------------------------
### Implement Interactive Cell Selection in Heat Map
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
This example demonstrates how to enable interactive cell selection in a react-heat-map. It uses the `rectRender` prop to attach an `onClick` handler to each cell. Clicking a cell updates the `selected` state, and conditional styling (opacity) is applied to the selected cell and others based on the `selected` state. Clicking again deselects the cell.
```jsx
import React, { useState } from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/01/15', count: 6 },
{ date: '2016/02/12', count: 7 },
{ date: '2016/04/12', count: 2 },
{ date: '2016/05/01', count: 5 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/03', count: 1 },
{ date: '2016/05/04', count: 11 },
{ date: '2016/05/08', count: 32 },
];
function SelectableHeatMap() {
const [selected, setSelected] = useState('');
return (
);
}
export default SelectableHeatMap;
```
--------------------------------
### Basic HeatMap Component Rendering
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
Renders a basic calendar heatmap using the `HeatMap` component. It takes an array of value objects, each with a 'date' and 'count', and displays them on a calendar grid. Customizes week labels, start date, width, rectangle size, and spacing.
```jsx
import React from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/01/12', count: 20 },
{ date: '2016/01/13', count: 10 },
{ date: '2016/02/10', count: 5 },
{ date: '2016/02/11', count: 12 },
{ date: '2016/02/12', count: 15 },
{ date: '2016/04/11', count: 2 },
{ date: '2016/05/01', count: 5 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/04', count: 11 },
];
function App() {
return (
);
}
export default App;
```
--------------------------------
### Set Rect Style for React Heat Map
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
Customizes the appearance of individual rectangles in the heat map using the `rectProps` and `legendRender` props. This example shows how to set the border-radius (`rx`) dynamically based on user input, allowing for rounded corners on the heat map cells.
```jsx
import React, { useState } from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count:2 },
...[...Array(17)].map((_, idx) => ({ date: `2016/01/${idx + 10}`, count: idx })),
...[...Array(17)].map((_, idx) => ({ date: `2016/02/${idx + 10}`, count: idx })),
{ date: '2016/04/12', count:2 },
{ date: '2016/05/01', count:5 },
{ date: '2016/05/02', count:5 },
{ date: '2016/05/03', count:1 },
{ date: '2016/05/04', count:11 },
{ date: '2016/05/08', count:32 },
];
const Demo = () => {
const [range, setRange] = useState(5)
return (
setRange(e.target.value)}
/> {range}
}
rectProps={{
rx: range
}}
/>
)
};
export default Demo
```
--------------------------------
### Toggle Heat Map Legend Visibility
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
This example demonstrates how to dynamically toggle the visibility of the heat map legend. It uses the `legendCellSize` prop, setting it to a non-zero value when the legend should be visible and to `0` when it should be hidden. A checkbox controls the `showLegend` state, which in turn dictates the `legendCellSize`.
```jsx
import React, { useState } from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/01/20', count: 8 },
{ date: '2016/02/11', count: 5 },
{ date: '2016/04/12', count: 2 },
{ date: '2016/05/01', count: 5 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/03', count: 1 },
{ date: '2016/05/04', count: 11 },
{ date: '2016/05/08', count: 32 },
];
function LegendToggleHeatMap() {
const [showLegend, setShowLegend] = useState(true);
return (
);
}
export default LegendToggleHeatMap;
```
--------------------------------
### Build React Heat Map for Production
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
This command builds the React Heat Map project for production. It minifies the code and creates optimized files ready for deployment. The `npm run doc` command is also included, which likely generates documentation for the project.
```bash
npm run build
npm run doc
```
--------------------------------
### Basic Heat Map Implementation in React
Source: https://github.com/uiwjs/react-heat-map/blob/main/www/public/bundle.html
Demonstrates the fundamental usage of the HeatMap component. It requires the 'react' library and the '@uiw/react-heat-map' package. The component renders a heat map based on the provided 'value' and 'startDate' props.
```javascript
import HeatMap from '@uiw/react-heat-map';
import React from 'react';
import ReactDOM from 'react-dom';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/01/12', count: 20 },
{ date: '2016/01/13', count: 10 },
...[...Array(17)].map((_, idx) => ({ date: `2016/02/${idx + 10}`, count: idx, content: '' })),
{ date: '2016/04/11', count: 2 },
{ date: '2016/05/01', count: 5 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/04', count: 11 },
];
const Demo = () => {
return (
);
};
ReactDOM.render(, document.getElementById('container'));
```
--------------------------------
### TypeScript Usage - TypeScript
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
Demonstrates how to use the HeatMap component with TypeScript. It defines sample data and component props, including value, startDate, rectSize, space, and panelColors. Ensures type safety for component usage.
```typescript
import HeatMap, { HeatMapProps, HeatMapValue } from '@uiw/react-heat-map';
const data: HeatMapValue[] = [
{ date: '2016/01/11', count: 2, content: 'Custom content' },
{ date: '2016/01/12', count: 20 },
];
const MyComponent: React.FC = () => {
const props: HeatMapProps = {
value: data,
startDate: new Date('2016/01/01'),
rectSize: 11,
space: 2,
panelColors: ['#EBEDF0', '#C6E48B', '#7BC96F', '#239A3B', '#196127'],
};
return ;
};
```
--------------------------------
### Watch and Build React Heat Map Components
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
This command watches for changes in the component files and recompiles them, outputting the .js and .d.ts files. This is the first step in the development process, ensuring that the component code is up-to-date before running the development server.
```bash
npm run watch
```
--------------------------------
### HeatMap Component with Dynamic Color Schemes (Array)
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
Illustrates dynamic color schemes for the `HeatMap` component using array notation. The component automatically distributes colors based on the maximum value in the provided data, offering a simpler way to define color gradients.
```jsx
import React from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/04/12', count: 2 },
{ date: '2016/05/01', count: 17 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/03', count: 27 },
{ date: '2016/05/04', count: 11 },
{ date: '2016/05/08', count: 32 },
];
function DynamicColorHeatMap() {
return (
);
}
export default DynamicColorHeatMap;
```
--------------------------------
### Next.js Configuration - JavaScript
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
Configures the Next.js build process using next-remove-imports. This JavaScript code snippet shows how to integrate the 'removeImports' function into the 'next.config.js' file to manage imports.
```javascript
// next.config.js
const removeImports = require('next-remove-imports')();
module.exports = removeImports({
// your Next.js config
});
```
--------------------------------
### Set Color Theme for React Heat Map
Source: https://github.com/uiwjs/react-heat-map/blob/main/README.md
Demonstrates how to set the theme color for the heat map using the 'style' and 'panelColors' props. The 'style' prop applies a general color, while 'panelColors' allows for granular control over the color of different count ranges. This is useful for visualizing data intensity with distinct color schemes.
```jsx
import React from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count:2 },
{ date: '2016/04/12', count:2 },
{ date: '2016/05/01', count:17 },
{ date: '2016/05/02', count:5 },
{ date: '2016/05/03', count:27 },
{ date: '2016/05/04', count:11 },
{ date: '2016/05/08', count:32 },
];
const Demo = () => {
return (
)
};
export default Demo
```
--------------------------------
### Set Color Style for React Heat Map
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
Demonstrates how to set the theme color style for the heat map using the `style` and `panelColors` props. The `style` prop allows for inline CSS, and `panelColors` can define specific colors for different count ranges or be an array for dynamic coloring based on the maximum value.
```jsx
import React from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count:2 },
{ date: '2016/04/12', count:2 },
{ date: '2016/05/01', count:17 },
{ date: '2016/05/02', count:5 },
{ date: '2016/05/03', count:27 },
{ date: '2016/05/04', count:11 },
{ date: '2016/05/08', count:32 },
];
const Demo = () => {
return (
)
};
export default Demo
```
```jsx
import React from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count:2 },
{ date: '2016/04/12', count:2 },
{ date: '2016/05/01', count:17 },
{ date: '2016/05/02', count:5 },
{ date: '2016/05/03', count:27 },
{ date: '2016/05/04', count:11 },
{ date: '2016/05/08', count:32 },
];
const Demo = () => {
return (
)
};
export default Demo
```
--------------------------------
### HeatMap Component with Custom Color Schemes (Object Mapping)
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
Demonstrates custom color schemes for the `HeatMap` component using object mapping. Colors are assigned to specific count thresholds, allowing for detailed control over the heatmap's appearance. Supports defining custom CSS variables for styling.
```jsx
import React from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/04/12', count: 2 },
{ date: '2016/05/01', count: 17 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/03', count: 27 },
{ date: '2016/05/04', count: 11 },
{ date: '2016/05/08', count: 32 },
];
function CustomColorHeatMap() {
return (
);
}
export default CustomColorHeatMap;
```
--------------------------------
### Dynamic Color Based on Max Value for React Heat Map
Source: https://github.com/uiwjs/react-heat-map/blob/main/README.md
Shows how to dynamically set colors for the heat map based on the maximum value in the dataset. By providing an array of colors to 'panelColors', the component automatically maps these colors to different data intensity levels, simplifying color scale management.
```jsx
import React from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count:2 },
{ date: '2016/04/12', count:2 },
{ date: '2016/05/01', count:17 },
{ date: '2016/05/02', count:5 },
{ date: '2016/05/03', count:27 },
{ date: '2016/05/04', count:11 },
{ date: '2016/05/08', count:32 },
];
const Demo = () => {
return (
)
};
export default Demo
```
--------------------------------
### Format Heat Map Data Array to Object
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
The `formatData` utility function transforms an array of date-value objects into an object where keys are formatted dates and values are the original objects. This optimizes lookups by date. It handles date normalization, ensuring consistent date formats in the output object.
```typescript
import { formatData } from '@uiw/react-heat-map';
const rawData = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/01/12', count: 20 },
{ date: '2016-01-13', count: 10 }, // Invalid format, will be normalized
];
const formattedData = formatData(rawData);
// Result:
// {
// '2016/1/11': { date: '2016/1/11', count: 2 },
// '2016/1/12': { date: '2016/1/12', count: 20 },
// '2016/1/13': { date: '2016/1/13', count: 10 }
// }
```
--------------------------------
### Generate Dynamic Color Mapping for Heat Map
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
The `convertPanelColors` utility function creates a color mapping based on a provided array of colors and a maximum count. It divides the range from 0 to `maxCount` into segments and assigns a color to each segment's threshold. This is useful for dynamically setting the color scale of the heat map.
```typescript
import { convertPanelColors } from '@uiw/react-heat-map';
const colors = ['#f4decd', '#e4b293', '#d48462', '#c2533a', '#ad001d', '#6c0012'];
const maxCount = 35;
const panelColors = convertPanelColors(colors, maxCount);
// Result:
// {
// 0: '#f4decd',
// 7: '#e4b293',
// 14: '#d48462',
// 21: '#c2533a',
// 28: '#ad001d',
// 35: '#6c0012'
// }
```
--------------------------------
### Add Interactive Tooltips to Heat Map
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
This snippet shows how to add interactive tooltips to a react-heat-map. It utilizes the `rectRender` prop to wrap each cell with a Tooltip component from '@uiw/react-tooltip', displaying custom information on hover. The `Tooltip` component's `content` prop dynamically shows the date and count for each data point.
```jsx
import React from 'react';
import Tooltip from '@uiw/react-tooltip';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count: 2 },
{ date: '2016/01/12', count: 7 },
{ date: '2016/01/13', count: 9 },
{ date: '2016/02/10', count: 4 },
{ date: '2016/02/15', count: 13 },
{ date: '2016/04/12', count: 2 },
{ date: '2016/05/01', count: 5 },
{ date: '2016/05/02', count: 5 },
{ date: '2016/05/03', count: 1 },
{ date: '2016/05/04', count: 11 },
{ date: '2016/05/08', count: 32 },
];
function TooltipHeatMap() {
return (
{
return (
);
}}
/>
);
}
export default TooltipHeatMap;
```
--------------------------------
### Add Tooltip to React Heat Map Rectangles
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
Integrates a tooltip functionality for each rectangle in the heat map using the `@uiw/react-tooltip` component. The `rectRender` prop is used to wrap each `rect` element with a `Tooltip`, displaying the `count` data when hovered.
```jsx
import React from 'react';
import Tooltip from '@uiw/react-tooltip';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count:2 },
...[...Array(17)].map((_, idx) => ({ date: `2016/01/${idx + 10}`, count: idx, })),
...[...Array(17)].map((_, idx) => ({ date: `2016/02/${idx + 10}`, count: idx, })),
{ date: '2016/04/12', count:2 },
{ date: '2016/05/01', count:5 },
{ date: '2016/05/02', count:5 },
{ date: '2016/05/03', count:1 },
{ date: '2016/05/04', count:11 },
{ date: '2016/05/08', count:32 },
];
const Demo = () => {
return (
{
// if (!data.count) return ;
return (
);
}}
/>
)
};
export default Demo
```
--------------------------------
### Implement Selected Rectangle in React Heat Map
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
This snippet demonstrates how to highlight a selected rectangle in a React Heat Map. It uses the `rectRender` prop to customize the rendering of each day's rectangle. A `useState` hook manages the selected date, and the opacity of rectangles is adjusted based on whether they match the selected date. Clicking a rectangle toggles its selection.
```jsx
import React, { useState } from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count:2 },
...[...Array(17)].map((_, idx) => ({ date: `2016/01/${idx + 10}`, count: idx })),
...[...Array(17)].map((_, idx) => ({ date: `2016/02/${idx + 10}`, count: idx })),
{ date: '2016/04/12', count:2 },
{ date: '2016/05/01', count:5 },
{ date: '2016/05/02', count:5 },
{ date: '2016/05/03', count:1 },
{ date: '2016/05/04', count:11 },
{ date: '2016/05/08', count:32 },
];
const Demo = () => {
const [selected, setSelected] = useState('')
return (
)
};
export default Demo
```
--------------------------------
### Dynamic Heat Map Rect Style in React
Source: https://github.com/uiwjs/react-heat-map/blob/main/www/public/bundle.html
This snippet demonstrates how to dynamically update the style of rectangle elements within the HeatMap component using React state. It utilizes an input range slider to control the 'rx' (corner radius) property, affecting the appearance of the heat map cells. Dependencies include 'react' and '@uiw/react-heat-map'.
```javascript
import HeatMap from '@uiw/react-heat-map';
import React from 'react';
const SetRectStyle = () => {
const [range, setRange] = React.useState(5);
return (
);
};
// This component would typically be rendered within a parent component like 'Demo'.
// For standalone execution, you would need to integrate it with ReactDOM.render.
```
--------------------------------
### Determine Color for Count Value - TypeScript
Source: https://context7.com/uiwjs/react-heat-map/llms.txt
Finds the appropriate color for a given count based on a threshold mapping. It takes a count, an array of sorted threshold numbers, and an object mapping thresholds to colors. Returns the color corresponding to the range the count falls into. Dependencies: '@uiw/react-heat-map'.
```typescript
import { existColor, numberSort } from '@uiw/react-heat-map';
const panelColors = {
0: '#f4decd',
10: '#e4b293',
20: '#d48462',
30: '#c2533a',
};
const nums = numberSort(Object.keys(panelColors).map(k => parseInt(k, 10)));
const color = existColor(15, nums, panelColors);
// Result: '#e4b293' (threshold for 10-19 range)
```
--------------------------------
### Show/Hide Legend in React Heat Map
Source: https://github.com/uiwjs/react-heat-map/blob/main/core/README.md
Controls the visibility of the heat map legend using the `legendCellSize` prop. A checkbox is used to toggle the `legendCellSize` between 0 (hidden) and a default value (visible), allowing users to show or hide the legend dynamically.
```jsx
import React, { useState } from 'react';
import HeatMap from '@uiw/react-heat-map';
const value = [
{ date: '2016/01/11', count:2 },
...[...Array(17)].map((_, idx) => ({ date: `2016/01/${idx + 10}`, count: idx })),
...[...Array(17)].map((_, idx) => ({ date: `2016/02/${idx + 10}`, count: idx })),
{ date: '2016/04/12', count:2 },
{ date: '2016/05/01', count:5 },
{ date: '2016/05/02', count:5 },
{ date: '2016/05/03', count:1 },
{ date: '2016/05/04', count:11 },
{ date: '2016/05/08', count:32 },
];
const Demo = () => {
const [size, setSize] = useState(0)
return (
)
};
export default Demo
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.