Overview
TheDataChart component renders an interactive scatter plot that visualizes data points, cluster centroids, and membership relationships using Chart.js. Points are dynamically colored based on their membership values to show cluster affinity.
Props
Array of data points to visualize. Each point must have
x and y coordinates.Array of cluster centroids. These are displayed with distinctive styling to differentiate them from regular data points.
A 2D array where
membershipMatrix[i][j] represents the membership degree of point j in cluster i. Values range from 0 to 1. An empty array indicates no clustering has been performed.Usage
Color Coding System
The component uses a sophisticated color system to represent cluster membership:Predefined Color Palette
The chart uses 8 distinct hues that cycle for multiple clusters:Point Color Calculation
Points are colored based on their dominant cluster membership:How Membership Affects Point Colors
The color intensity reflects the strength of cluster membership:- Dominant Cluster Selection - The algorithm identifies which cluster has the highest membership value for each point
- Color Base - The point adopts the hue of its dominant cluster
-
Intensity Modulation - Higher membership values result in:
- Higher saturation (55% to 83%)
- Lower lightness (82% down to 52%) - darker colors
- Higher alpha (0.45 to 0.9) - more opaque
-
Unclustered Points - When the membership matrix is empty, points appear in neutral gray:
- Background:
rgba(107, 114, 128, 0.55) - Border:
rgba(75, 85, 99, 0.9)
- Background:
- Strong membership (close to 1.0) = bold, saturated, opaque colors
- Weak membership (close to 0.0) = pale, desaturated, transparent colors
- No clustering = neutral gray
Centroid Colors
Centroids are displayed with bold, distinctive colors:- Background - Highly saturated color at 75% saturation
- Area - Semi-transparent ring around the centroid (radius 20)
- Border - Dark border for definition
Chart Configuration
The component renders three datasets:1. Points Dataset
2. Centroids Dataset
3. Centroids Area Dataset
Creates a larger, semi-transparent circle around each centroid to show the cluster influence area:Visual Hierarchy
The component creates clear visual distinction:| Element | Radius | Border Width | Purpose |
|---|---|---|---|
| Points | 4px | 1px | Show data distribution |
| Centroids | 5px | 2px | Mark cluster centers |
| Centroid Areas | 20px | 1px | Show cluster influence zones |
Chart Options
The scatter plot includes axis configuration:Performance Considerations
- Colors are computed once per render using
.map() - The membership matrix is traversed to find dominant clusters
- HSL color space allows smooth color interpolation
- The component uses React-ChartJS-2 for efficient chart updates
Source Code
View the full implementation in the repository:src/components/DataChart.tsx