Skip to content

Commit 2aee4bb

Browse files
author
Dylan Huang
committed
works
1 parent 58d8409 commit 2aee4bb

File tree

13 files changed

+692
-99
lines changed

13 files changed

+692
-99
lines changed

vite-app/CHART_EXPORT_README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Chart Export Functionality
2+
3+
This document describes the new Chart Export feature that allows users to export pivot table data as interactive charts and save them as high-resolution PNG images.
4+
5+
## Overview
6+
7+
The Chart Export component (`ChartExport.tsx`) integrates with Chart.js to provide visualization capabilities for pivot table data. Users can:
8+
9+
- Choose from multiple chart types (Bar, Line, Doughnut, Pie)
10+
- View real-time chart updates as pivot table configuration changes
11+
- Export charts as high-resolution PNG images
12+
- Customize chart appearance and data representation
13+
14+
## Features
15+
16+
### Chart Types
17+
18+
1. **Bar Chart**: Best for comparing values across categories
19+
2. **Line Chart**: Ideal for showing trends over time or sequences
20+
3. **Doughnut Chart**: Good for showing proportions of a whole
21+
4. **Pie Chart**: Similar to doughnut but shows complete proportions
22+
23+
### Data Visualization
24+
25+
- **Row-based grouping**: Row fields become chart labels
26+
- **Column-based datasets**: Each column field combination becomes a separate dataset
27+
- **Totals integration**: Row totals can be included as an additional dataset
28+
- **Dynamic coloring**: Automatic color generation for different datasets
29+
- **Responsive design**: Charts adapt to container size
30+
31+
### Export Capabilities
32+
33+
- **High-resolution output**: 2x scale for crisp images
34+
- **PNG format**: Lossless image format suitable for presentations and reports
35+
- **Automatic naming**: Files include chart type and timestamp
36+
- **Background handling**: Clean white background for professional appearance
37+
38+
## Technical Implementation
39+
40+
### Dependencies
41+
42+
- `chart.js` (v4.5.0): Core charting library
43+
- `react-chartjs-2` (v5.3.0): React wrapper for Chart.js
44+
- `html2canvas` (v1.4.1): HTML to canvas conversion for image export
45+
46+
### Component Structure
47+
48+
```tsx
49+
<ChartExport
50+
pivotData={pivotComputationResult}
51+
rowFields={selectedRowFields}
52+
columnFields={selectedColumnFields}
53+
valueField={selectedValueField}
54+
aggregator={selectedAggregator}
55+
chartType="bar"
56+
showRowTotals={true}
57+
showColumnTotals={true}
58+
/>
59+
```
60+
61+
### Data Flow
62+
63+
1. **Pivot Data**: Raw pivot table computation results
64+
2. **Chart Conversion**: Data transformation for Chart.js format
65+
3. **Rendering**: Chart display using react-chartjs-2
66+
4. **Export**: HTML to canvas conversion and PNG download
67+
68+
## Usage
69+
70+
### Basic Setup
71+
72+
1. Ensure pivot table has both row and column fields selected
73+
2. The Chart Export component will automatically appear above the pivot table
74+
3. Select desired chart type from the dropdown
75+
4. Click "Export as Image" to download the chart
76+
77+
### Chart Type Selection
78+
79+
- **Bar/Line**: Best for comparing multiple categories with multiple datasets
80+
- **Pie/Doughnut**: Best for showing proportions when you have one main dimension
81+
82+
### Export Process
83+
84+
1. Click "Export as Image" button
85+
2. Wait for processing (button shows "Exporting...")
86+
3. Browser automatically downloads PNG file
87+
4. File is named: `pivot-chart-{type}-{timestamp}.png`
88+
89+
## Integration
90+
91+
The component is automatically integrated into the PivotTab and only appears when:
92+
- At least one row field is selected
93+
- At least one column field is selected
94+
- Valid pivot data exists
95+
96+
## Styling
97+
98+
- Follows the existing design system with minimal, clean appearance
99+
- Uses Tailwind CSS classes for consistent styling
100+
- Responsive design that works on different screen sizes
101+
- Colorblind-friendly color generation using HSL color space
102+
103+
## Performance Considerations
104+
105+
- Charts are rendered only when pivot data changes
106+
- Export process uses `html2canvas` for reliable image generation
107+
- Chart data is memoized to prevent unnecessary re-renders
108+
- Responsive design maintains good performance on various devices
109+
110+
## Browser Compatibility
111+
112+
- Modern browsers with ES6+ support
113+
- Canvas API support required for image export
114+
- File download API support required for automatic downloads
115+
116+
## Troubleshooting
117+
118+
### Common Issues
119+
120+
1. **Chart not appearing**: Ensure both row and column fields are selected
121+
2. **Export fails**: Check browser console for errors, ensure canvas is properly rendered
122+
3. **Poor image quality**: Export uses 2x scale by default for high resolution
123+
4. **Chart data missing**: Verify pivot table configuration and data availability
124+
125+
### Debug Information
126+
127+
- Check browser console for any JavaScript errors
128+
- Verify pivot data structure matches expected format
129+
- Ensure all required dependencies are properly installed
130+
131+
## Future Enhancements
132+
133+
Potential improvements for future versions:
134+
- Additional chart types (scatter, radar, etc.)
135+
- Custom color schemes
136+
- Chart configuration options (axes, legends, etc.)
137+
- Multiple export formats (SVG, PDF)
138+
- Chart templates and presets
139+
- Batch export capabilities

vite-app/dist/assets/index-CvsKHhRd.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite-app/dist/assets/index-D1ErODUS.js

Lines changed: 0 additions & 93 deletions
This file was deleted.

vite-app/dist/assets/index-D1ErODUS.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

vite-app/dist/assets/index-D5KxcfFQ.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

vite-app/dist/assets/index-Dc1lntzy.js

Lines changed: 131 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite-app/dist/assets/index-Dc1lntzy.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite-app/dist/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>EP | Log Viewer</title>
77
<link rel="icon" href="/assets/favicon-BkAAWQga.png" />
8-
<script type="module" crossorigin src="/assets/index-D1ErODUS.js"></script>
9-
<link rel="stylesheet" crossorigin href="/assets/index-D5KxcfFQ.css">
8+
<script type="module" crossorigin src="/assets/index-Dc1lntzy.js"></script>
9+
<link rel="stylesheet" crossorigin href="/assets/index-CvsKHhRd.css">
1010
</head>
1111
<body>
1212
<div id="root"></div>
1313
</body>
14-
</html>
14+
</html>

vite-app/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
"test:coverage": "vitest run --coverage"
1414
},
1515
"dependencies": {
16+
"chart.js": "^4.5.0",
17+
"html2canvas-oklch": "1.5.0-alpha.0",
1618
"mobx": "^6.13.7",
1719
"mobx-react": "^9.2.0",
1820
"react": "^19.1.0",
21+
"react-chartjs-2": "^5.3.0",
1922
"react-dom": "^19.1.0",
2023
"react-router-dom": "^7.7.1",
2124
"zod": "^4.0.14"

vite-app/pnpm-lock.yaml

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)