@dhiraj0720/report1chart 2.2.1 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,417 @@
1
+ import React, { useState } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ TouchableOpacity,
7
+ ScrollView,
8
+ ActivityIndicator,
9
+ } from 'react-native';
10
+ import { ApiFetcher } from '../api/fetcher';
11
+ import ReportList from '../components/ReportList';
12
+ import {
13
+ renderTable,
14
+ renderCompactTable,
15
+ renderFreezeTable
16
+ } from '../components/TableRenderer';
17
+ import {
18
+ renderLineChart,
19
+ renderBarChart,
20
+ renderPieChart,
21
+ getColor
22
+ } from '../components/ChartRenderer';
23
+
24
+ const ReportScreen = ({
25
+ onReportSelect,
26
+ onClose,
27
+ reports = []
28
+ }) => {
29
+ const [selectedReport, setSelectedReport] = useState(null);
30
+ const [reportData, setReportData] = useState(null);
31
+ const [loading, setLoading] = useState(false);
32
+ const [error, setError] = useState(null);
33
+ const [viewType, setViewType] = useState('default');
34
+
35
+ const handleReportClick = async (report) => {
36
+ setLoading(true);
37
+ setError(null);
38
+ setReportData(null);
39
+ setSelectedReport(report);
40
+ setViewType('default');
41
+
42
+ try {
43
+ // Fetch data using ApiFetcher from npm package
44
+ const data = await ApiFetcher.fetchReportData(report);
45
+ setReportData(data);
46
+
47
+ if (onReportSelect) {
48
+ onReportSelect(report.name);
49
+ }
50
+ } catch (err) {
51
+ setError(err.message || 'Failed to fetch report data');
52
+ } finally {
53
+ setLoading(false);
54
+ }
55
+ };
56
+
57
+ const renderChart = () => {
58
+ if (!reportData || !reportData.data) {
59
+ return (
60
+ <View style={styles.noDataContainer}>
61
+ <Text style={styles.noDataText}>No data available for this report</Text>
62
+ </View>
63
+ );
64
+ }
65
+
66
+ const { type, data, title } = reportData;
67
+
68
+ // For performance reports
69
+ if (type === 'table' && selectedReport &&
70
+ (selectedReport.id === 1 || selectedReport.id === 1.1 || selectedReport.id === 1.2)) {
71
+ switch (viewType) {
72
+ case 'compact':
73
+ return renderCompactTable(data);
74
+ case 'freeze':
75
+ return renderFreezeTable(data);
76
+ case 'default':
77
+ default:
78
+ return renderTable(data);
79
+ }
80
+ }
81
+
82
+ // For other table reports
83
+ if (type === 'table') {
84
+ return renderTable(data);
85
+ }
86
+
87
+ // For chart reports
88
+ switch (type) {
89
+ case 'line':
90
+ return renderLineChart(data, title);
91
+ case 'bar':
92
+ return renderBarChart(data, title);
93
+ case 'pie':
94
+ return renderPieChart(data, title);
95
+ default:
96
+ return renderBarChart(data, title);
97
+ }
98
+ };
99
+
100
+ // ========== RENDER SELECTED REPORT VIEW ==========
101
+ if (selectedReport) {
102
+ return (
103
+ <View style={styles.container}>
104
+ <View style={styles.header}>
105
+ <TouchableOpacity
106
+ style={styles.backButton}
107
+ onPress={() => {
108
+ setSelectedReport(null);
109
+ setReportData(null);
110
+ setViewType('default');
111
+ }}
112
+ >
113
+ <Text style={styles.backText}>‹</Text>
114
+ <Text style={styles.backButtonText}>Back</Text>
115
+ </TouchableOpacity>
116
+ <Text style={styles.headerTitle} numberOfLines={1}>
117
+ {selectedReport.title || selectedReport.name}
118
+ </Text>
119
+ <TouchableOpacity onPress={onClose} style={styles.closeButton}>
120
+ <Text style={styles.closeText}>×</Text>
121
+ </TouchableOpacity>
122
+ </View>
123
+
124
+ {loading ? (
125
+ <View style={styles.loadingContainer}>
126
+ <ActivityIndicator size="large" color="#4CAF50" />
127
+ <Text style={styles.loadingText}>Loading report data...</Text>
128
+ </View>
129
+ ) : error ? (
130
+ <View style={styles.errorContainer}>
131
+ <Text style={styles.errorText}>Error: {error}</Text>
132
+ <TouchableOpacity
133
+ style={styles.retryButton}
134
+ onPress={() => handleReportClick(selectedReport)}
135
+ >
136
+ <Text style={styles.retryText}>Retry</Text>
137
+ </TouchableOpacity>
138
+ </View>
139
+ ) : (
140
+ <ScrollView style={styles.chartView}>
141
+ {/* View Type Selector for Performance Reports */}
142
+ {selectedReport &&
143
+ (selectedReport.id === 1 || selectedReport.id === 1.1 || selectedReport.id === 1.2) &&
144
+ reportData && (
145
+ <View style={styles.viewTypeSelector}>
146
+ <TouchableOpacity
147
+ style={[
148
+ styles.viewTypeButton,
149
+ viewType === 'default' && styles.activeViewType
150
+ ]}
151
+ onPress={() => setViewType('default')}
152
+ >
153
+ <Text style={[
154
+ styles.viewTypeText,
155
+ viewType === 'default' && styles.activeViewTypeText
156
+ ]}>Varsayılan</Text>
157
+ </TouchableOpacity>
158
+
159
+ <TouchableOpacity
160
+ style={[
161
+ styles.viewTypeButton,
162
+ viewType === 'compact' && styles.activeViewType
163
+ ]}
164
+ onPress={() => setViewType('compact')}
165
+ >
166
+ <Text style={[
167
+ styles.viewTypeText,
168
+ viewType === 'compact' && styles.activeViewTypeText
169
+ ]}>Kompakt</Text>
170
+ </TouchableOpacity>
171
+
172
+ <TouchableOpacity
173
+ style={[
174
+ styles.viewTypeButton,
175
+ viewType === 'freeze' && styles.activeViewType
176
+ ]}
177
+ onPress={() => setViewType('freeze')}
178
+ >
179
+ <Text style={[
180
+ styles.viewTypeText,
181
+ viewType === 'freeze' && styles.activeViewTypeText
182
+ ]}>Sabit Kolon</Text>
183
+ </TouchableOpacity>
184
+ </View>
185
+ )}
186
+
187
+ <View style={styles.chartContainer}>
188
+ <Text style={styles.chartTitle}>{reportData?.title || selectedReport.title}</Text>
189
+ {selectedReport.id === 1 || selectedReport.id === 1.1 || selectedReport.id === 1.2 ? (
190
+ <Text style={styles.reportSubtitle}>
191
+ {viewType === 'default' ? 'Varsayılan Görünüm' :
192
+ viewType === 'compact' ? 'Kompakt Görünüm' :
193
+ 'Sabit Kolonlu Görünüm'}
194
+ </Text>
195
+ ) : null}
196
+ {renderChart()}
197
+ </View>
198
+
199
+ {reportData && reportData.data && (
200
+ <View style={styles.dataInfo}>
201
+ <Text style={styles.infoTitle}>Report Information</Text>
202
+ <Text style={styles.infoText}>
203
+ {selectedReport.description || 'Detailed analysis report'}
204
+ </Text>
205
+ <Text style={styles.dataSource}>
206
+ Data points: {Array.isArray(reportData.data) ? reportData.data.length :
207
+ reportData.data.values?.length || reportData.data.labels?.length || 'N/A'}
208
+ </Text>
209
+ </View>
210
+ )}
211
+ </ScrollView>
212
+ )}
213
+ </View>
214
+ );
215
+ }
216
+
217
+ // ========== RENDER REPORT LIST VIEW ==========
218
+ return (
219
+ <View style={styles.container}>
220
+ <View style={styles.header}>
221
+ <Text style={styles.headerTitle}>Reports Dashboard</Text>
222
+ <TouchableOpacity onPress={onClose} style={styles.closeButton}>
223
+ <Text style={styles.closeText}>×</Text>
224
+ </TouchableOpacity>
225
+ </View>
226
+
227
+ <ReportList
228
+ reports={reports}
229
+ onReportClick={handleReportClick}
230
+ getColor={getColor}
231
+ />
232
+ </View>
233
+ );
234
+ };
235
+
236
+ const styles = StyleSheet.create({
237
+ container: {
238
+ flex: 1,
239
+ backgroundColor: '#f8f9fa',
240
+ },
241
+ header: {
242
+ flexDirection: 'row',
243
+ alignItems: 'center',
244
+ justifyContent: 'space-between',
245
+ backgroundColor: '#fff',
246
+ paddingHorizontal: 16,
247
+ paddingVertical: 12,
248
+ borderBottomWidth: 1,
249
+ borderBottomColor: '#e0e0e0',
250
+ },
251
+ headerTitle: {
252
+ fontSize: 18,
253
+ fontWeight: '700',
254
+ color: '#000',
255
+ flex: 1,
256
+ textAlign: 'center',
257
+ },
258
+ backButton: {
259
+ flexDirection: 'row',
260
+ alignItems: 'center',
261
+ padding: 8,
262
+ },
263
+ backText: {
264
+ fontSize: 24,
265
+ color: '#4CAF50',
266
+ marginRight: 4,
267
+ },
268
+ backButtonText: {
269
+ fontSize: 16,
270
+ color: '#4CAF50',
271
+ fontWeight: '600',
272
+ },
273
+ closeButton: {
274
+ width: 32,
275
+ height: 32,
276
+ borderRadius: 16,
277
+ backgroundColor: '#f0f0f0',
278
+ justifyContent: 'center',
279
+ alignItems: 'center',
280
+ },
281
+ closeText: {
282
+ fontSize: 20,
283
+ color: '#666',
284
+ fontWeight: '300',
285
+ },
286
+ chartView: {
287
+ flex: 1,
288
+ padding: 16,
289
+ },
290
+ chartContainer: {
291
+ backgroundColor: '#fff',
292
+ borderRadius: 12,
293
+ padding: 16,
294
+ marginBottom: 16,
295
+ borderWidth: 1,
296
+ borderColor: '#e8e8e8',
297
+ shadowColor: '#000',
298
+ shadowOffset: { width: 0, height: 1 },
299
+ shadowOpacity: 0.05,
300
+ shadowRadius: 2,
301
+ elevation: 2,
302
+ },
303
+ chartTitle: {
304
+ fontSize: 18,
305
+ fontWeight: '700',
306
+ color: '#000',
307
+ marginBottom: 20,
308
+ textAlign: 'center',
309
+ },
310
+ dataInfo: {
311
+ backgroundColor: '#e8f5e9',
312
+ borderRadius: 12,
313
+ padding: 16,
314
+ marginTop: 8,
315
+ },
316
+ infoTitle: {
317
+ fontSize: 16,
318
+ fontWeight: '700',
319
+ color: '#2e7d32',
320
+ marginBottom: 8,
321
+ },
322
+ infoText: {
323
+ fontSize: 14,
324
+ color: '#555',
325
+ lineHeight: 20,
326
+ marginBottom: 8,
327
+ },
328
+ dataSource: {
329
+ fontSize: 13,
330
+ color: '#777',
331
+ fontStyle: 'italic',
332
+ },
333
+ loadingContainer: {
334
+ flex: 1,
335
+ justifyContent: 'center',
336
+ alignItems: 'center',
337
+ padding: 40,
338
+ },
339
+ loadingText: {
340
+ marginTop: 16,
341
+ fontSize: 16,
342
+ color: '#666',
343
+ },
344
+ errorContainer: {
345
+ flex: 1,
346
+ justifyContent: 'center',
347
+ alignItems: 'center',
348
+ padding: 40,
349
+ },
350
+ errorText: {
351
+ fontSize: 16,
352
+ color: '#d32f2f',
353
+ textAlign: 'center',
354
+ marginBottom: 20,
355
+ },
356
+ retryButton: {
357
+ backgroundColor: '#4CAF50',
358
+ paddingHorizontal: 24,
359
+ paddingVertical: 12,
360
+ borderRadius: 8,
361
+ },
362
+ retryText: {
363
+ color: '#fff',
364
+ fontSize: 16,
365
+ fontWeight: '600',
366
+ },
367
+ noDataContainer: {
368
+ padding: 40,
369
+ alignItems: 'center',
370
+ },
371
+ noDataText: {
372
+ fontSize: 16,
373
+ color: '#999',
374
+ textAlign: 'center',
375
+ },
376
+ viewTypeSelector: {
377
+ flexDirection: 'row',
378
+ backgroundColor: '#f0f0f0',
379
+ borderRadius: 8,
380
+ padding: 4,
381
+ marginBottom: 16,
382
+ alignSelf: 'center',
383
+ },
384
+ viewTypeButton: {
385
+ paddingHorizontal: 16,
386
+ paddingVertical: 8,
387
+ borderRadius: 6,
388
+ marginHorizontal: 2,
389
+ },
390
+ activeViewType: {
391
+ backgroundColor: '#fff',
392
+ shadowColor: '#000',
393
+ shadowOffset: { width: 0, height: 1 },
394
+ shadowOpacity: 0.1,
395
+ shadowRadius: 2,
396
+ elevation: 2,
397
+ },
398
+ viewTypeText: {
399
+ fontSize: 13,
400
+ fontWeight: '500',
401
+ color: '#666',
402
+ },
403
+ activeViewTypeText: {
404
+ color: '#4CAF50',
405
+ fontWeight: '600',
406
+ },
407
+ reportSubtitle: {
408
+ fontSize: 14,
409
+ fontWeight: '600',
410
+ color: '#4CAF50',
411
+ textAlign: 'center',
412
+ marginBottom: 16,
413
+ fontStyle: 'italic',
414
+ },
415
+ });
416
+
417
+ export default ReportScreen;
@@ -1,162 +0,0 @@
1
- import axios from 'axios';
2
-
3
- class ApiService {
4
- constructor() {
5
- this.api = axios.create({
6
- timeout: 15000,
7
- headers: {
8
- 'Content-Type': 'application/json',
9
- 'Accept': 'application/json'
10
- }
11
- });
12
- }
13
-
14
- async fetchReportData(apiConfig) {
15
- try {
16
- const config = {
17
- url: apiConfig.url,
18
- method: apiConfig.method || 'GET',
19
- timeout: apiConfig.timeout || 15000,
20
- headers: {
21
- 'Content-Type': 'application/json',
22
- 'Accept': 'application/json'
23
- }
24
- };
25
-
26
- if (apiConfig.token) {
27
- config.headers.Authorization = `Bearer ${apiConfig.token}`;
28
- }
29
-
30
- const response = await this.api(config);
31
- return this.transformData(response.data, apiConfig.url);
32
-
33
- } catch (error) {
34
- console.error('API Error:', error.message);
35
- return this.getFallbackData(apiConfig.url);
36
- }
37
- }
38
-
39
- transformData(data, url) {
40
- if (url.includes('cumulative-operating-profit')) {
41
- return this.transformPerformanceData(data);
42
- } else if (url.includes('revenue-by-mode')) {
43
- return this.transformRevenueByMode(data);
44
- } else if (url.includes('shipment-by-direction')) {
45
- return this.transformShipmentByDirection(data);
46
- } else if (url.includes('revenue-trend')) {
47
- return this.transformRevenueTrend(data);
48
- }
49
-
50
- return data;
51
- }
52
-
53
- transformPerformanceData(data) {
54
- if (!data || !data.data) return this.getPerformanceFallbackData();
55
-
56
- return data.data.map(item => ({
57
- name: item.name || 'Unknown',
58
- actual2024: item.actual2024 || 0,
59
- actual2025: item.actual2025 || 0,
60
- budget2025: item.budget2025 || 0,
61
- yoYChangePercent: this.calculatePercentageChange(item.actual2024 || 0, item.actual2025 || 0),
62
- budgetVariancePercent: this.calculatePercentageChange(item.budget2025 || 0, item.actual2025 || 0),
63
- grossMarginPercent: item.grossMarginPercent || 0,
64
- isTotal: item.isTotal || false
65
- }));
66
- }
67
-
68
- transformRevenueByMode(data) {
69
- if (Array.isArray(data)) {
70
- return data.map(item => ({
71
- mode: item.mode || 'Unknown',
72
- revenue: item.revenue || 0
73
- }));
74
- }
75
-
76
- if (data.data && Array.isArray(data.data)) {
77
- return data.data;
78
- }
79
-
80
- return this.getRevenueByModeFallbackData();
81
- }
82
-
83
- transformShipmentByDirection(data) {
84
- if (Array.isArray(data)) {
85
- return data.map(item => ({
86
- direction: item.direction || 'Unknown',
87
- shipments: item.shipments || 0
88
- }));
89
- }
90
-
91
- if (data.data && Array.isArray(data.data)) {
92
- return data.data;
93
- }
94
-
95
- return this.getShipmentFallbackData();
96
- }
97
-
98
- transformRevenueTrend(data) {
99
- if (data.labels && data.values) {
100
- return {
101
- labels: data.labels,
102
- values: data.values
103
- };
104
- }
105
-
106
- return this.getRevenueTrendFallbackData();
107
- }
108
-
109
- calculatePercentageChange(oldValue, newValue) {
110
- if (!oldValue || oldValue === 0) return 0;
111
- return Number(((newValue - oldValue) / Math.abs(oldValue)) * 100).toFixed(1);
112
- }
113
-
114
- getFallbackData(url) {
115
- if (url.includes('cumulative-operating-profit')) {
116
- return this.getPerformanceFallbackData();
117
- } else if (url.includes('revenue-by-mode')) {
118
- return this.getRevenueByModeFallbackData();
119
- } else if (url.includes('shipment-by-direction')) {
120
- return this.getShipmentFallbackData();
121
- } else if (url.includes('revenue-trend')) {
122
- return this.getRevenueTrendFallbackData();
123
- }
124
-
125
- return [];
126
- }
127
-
128
- getPerformanceFallbackData() {
129
- return [
130
- { name: "Ocean Transportation", actual2024: 45000000, actual2025: 52000000, budget2025: 50000000, grossMarginPercent: 25, isTotal: false },
131
- { name: "Air Freight", actual2024: 18000000, actual2025: 21000000, budget2025: 20000000, grossMarginPercent: 22, isTotal: false },
132
- { name: "Road Logistics", actual2024: 32000000, actual2025: 38000000, budget2025: 35000000, grossMarginPercent: 28, isTotal: false },
133
- { name: "Warehousing", actual2024: 12000000, actual2025: 15000000, budget2025: 14000000, grossMarginPercent: 35, isTotal: false },
134
- { name: "Customs Clearance", actual2024: 8000000, actual2025: 9500000, budget2025: 9000000, grossMarginPercent: 40, isTotal: false },
135
- { name: "TOTAL", actual2024: 115000000, actual2025: 135500000, budget2025: 128000000, grossMarginPercent: 28, isTotal: true }
136
- ];
137
- }
138
-
139
- getRevenueByModeFallbackData() {
140
- return [
141
- { mode: "Ocean", revenue: 101951456 },
142
- { mode: "Road", revenue: 89158437 },
143
- { mode: "Air", revenue: 40171032 }
144
- ];
145
- }
146
-
147
- getShipmentFallbackData() {
148
- return [
149
- { direction: "Export", shipments: 568 },
150
- { direction: "Import", shipments: 546 }
151
- ];
152
- }
153
-
154
- getRevenueTrendFallbackData() {
155
- return {
156
- labels: ["01-2025", "02-2025", "03-2025", "04-2025", "05-2025", "06-2025"],
157
- values: [16011213, 13368072, 17004674, 19065790, 19978378, 20766951]
158
- };
159
- }
160
- }
161
-
162
- export default new ApiService();
@@ -1,116 +0,0 @@
1
- import React from 'react';
2
- import {
3
- View,
4
- Text,
5
- ScrollView,
6
- StyleSheet,
7
- } from 'react-native';
8
-
9
- const BarChart = ({ data, title }) => {
10
- const formatNumber = (num) => {
11
- return num.toLocaleString();
12
- };
13
-
14
- const getColor = (index) => {
15
- const colors = ['#4CAF50', '#2196F3', '#FF9800', '#E91E63', '#9C27B0'];
16
- return colors[index % colors.length];
17
- };
18
-
19
- if (!Array.isArray(data) || data.length === 0) {
20
- return (
21
- <View style={styles.noDataContainer}>
22
- <Text style={styles.noDataText}>No data available</Text>
23
- </View>
24
- );
25
- }
26
-
27
- const values = data.map(d => d.revenue || d.value || 0);
28
- const labels = data.map(d => d.mode || d.label || '');
29
-
30
- const maxValue = Math.max(...values, 1);
31
- const chartHeight = 200;
32
-
33
- return (
34
- <View style={styles.container}>
35
- {title && <Text style={styles.title}>{title}</Text>}
36
- <ScrollView
37
- horizontal
38
- showsHorizontalScrollIndicator={true}
39
- >
40
- <View style={[styles.chart, { height: chartHeight }]}>
41
- {values.map((value, index) => {
42
- const height = (value / maxValue) * chartHeight;
43
- const label = labels[index] || `Item ${index + 1}`;
44
-
45
- return (
46
- <View key={index} style={styles.barWrapper}>
47
- <View style={[styles.bar, {
48
- height,
49
- backgroundColor: getColor(index)
50
- }]} />
51
- <Text style={styles.barLabel} numberOfLines={1}>{label}</Text>
52
- <Text style={styles.valueText}>{formatNumber(value)}</Text>
53
- </View>
54
- );
55
- })}
56
- </View>
57
- </ScrollView>
58
- </View>
59
- );
60
- };
61
-
62
- const styles = StyleSheet.create({
63
- container: {
64
- backgroundColor: '#fff',
65
- borderRadius: 12,
66
- padding: 16,
67
- marginBottom: 16,
68
- borderWidth: 1,
69
- borderColor: '#e8e8e8',
70
- },
71
- title: {
72
- fontSize: 18,
73
- fontWeight: '700',
74
- color: '#000',
75
- marginBottom: 20,
76
- textAlign: 'center',
77
- },
78
- chart: {
79
- flexDirection: 'row',
80
- alignItems: 'flex-end',
81
- paddingHorizontal: 8,
82
- minWidth: 400,
83
- },
84
- barWrapper: {
85
- alignItems: 'center',
86
- marginHorizontal: 12,
87
- },
88
- bar: {
89
- width: 40,
90
- borderRadius: 4,
91
- },
92
- barLabel: {
93
- marginTop: 8,
94
- fontSize: 12,
95
- color: '#666',
96
- textAlign: 'center',
97
- width: 60,
98
- },
99
- valueText: {
100
- fontSize: 11,
101
- color: '#999',
102
- marginTop: 4,
103
- fontWeight: '500',
104
- },
105
- noDataContainer: {
106
- padding: 40,
107
- alignItems: 'center',
108
- },
109
- noDataText: {
110
- fontSize: 16,
111
- color: '#999',
112
- textAlign: 'center',
113
- },
114
- });
115
-
116
- export default BarChart;