Overview
ThePointTable component renders a simple, compact table that displays the X and Y coordinates of data points or centroids. It provides a clear numerical view of point positions in the clustering space.
Props
Array of points to display. Each point must have
x and y coordinates.The title displayed above the table, typically “Points” or “Centroids” to indicate what data is being shown.
Point Type
The component uses the globalPoint type:
Usage
Displaying Data Points
Displaying Centroids
Data Source Transformation
The component transforms the point array into a table-friendly format:- key: Unique identifier for React rendering (string index)
- name: Human-readable label (“Point 1”, “Point 2”, etc.)
- x: X-coordinate formatted to 4 decimal places
- y: Y-coordinate formatted to 4 decimal places
Column Configuration
The table displays two columns:name field is generated but not displayed in columns. It’s available for potential expansion or use in row rendering.
Table Example
| X | Y |
|---|---|
| 45.2341 | 67.8901 |
| 12.3456 | 98.7654 |
| 78.9012 | 34.5678 |
Table Configuration
The component uses Ant Design’sTable with specific settings optimized for small datasets:
Configuration Properties
Renders a custom title as an H1 heading with semibold styling and large text
Disabled (
false) to show all points at once without pagination controlsEnables scrolling:
- Horizontal (
x: true) - ensures table is responsive on narrow screens - Vertical (
y: 150) - limits height to 150px to conserve screen space
Set to
'small' for compact row spacing, ideal for coordinate listsData Formatting
Coordinates are formatted to 4 decimal places for consistency:- Sufficient precision for clustering visualization
- Consistent column width
- Clean, readable display
- Alignment of decimal points
Responsive Behavior
Vertical Scrolling
The table height is limited to 150px:- Prevents excessive vertical space usage
- Useful when displaying many points
- Maintains visibility of other UI elements
- Automatic scrollbar appears when needed
Horizontal Scrolling
Enabled for narrow viewports:- Ensures the table remains usable on mobile devices
- Both columns remain accessible
- No content is hidden or truncated
Empty State
When the data array is empty (data.length === 0):
- The table renders with column headers
- No rows are displayed
- The title and structure remain intact
- Users can see where points will appear once added
Use Cases
Points Display
Display all data points being clustered:Centroids Display
Show the current cluster centers:Side-by-Side Comparison
Display both points and centroids for comparison:Styling
The component uses:- Tailwind CSS for title styling (
text-lg font-semibold) - Ant Design default table styling
- Small size variant for compact display
Performance
The component is optimized for small to medium datasets:- No pagination reduces complexity
- Simple transformation with
.map() - Fixed column count (always 2)
- Lightweight rendering
For very large datasets (1000+ points), consider adding pagination or virtualization to maintain performance.
Source Code
View the full implementation in the repository:src/components/PointTable.tsx