@dhiraj0720/report1chart 1.0.3 → 1.0.4
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.
- package/package.json +1 -1
- package/src/index.jsx +233 -20
package/package.json
CHANGED
package/src/index.jsx
CHANGED
|
@@ -77,28 +77,44 @@ const ReportChart = ({
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
+
// Add currency formatter
|
|
81
|
+
const formatCurrency = (value) => {
|
|
82
|
+
const num = Number(value);
|
|
83
|
+
if (isNaN(num)) return '0';
|
|
84
|
+
|
|
85
|
+
if (num >= 1000000) {
|
|
86
|
+
return `${(num / 1000000).toFixed(1)}M`;
|
|
87
|
+
} else if (num >= 1000) {
|
|
88
|
+
return `${(num / 1000).toFixed(1)}K`;
|
|
89
|
+
}
|
|
90
|
+
return num.toString();
|
|
91
|
+
};
|
|
92
|
+
|
|
80
93
|
const renderChart = () => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
if (!reportData || !reportData.data) {
|
|
95
|
+
return (
|
|
96
|
+
<View style={styles.noDataContainer}>
|
|
97
|
+
<Text style={styles.noDataText}>No data available for this report</Text>
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const { type, data } = reportData;
|
|
103
|
+
|
|
104
|
+
switch (type) {
|
|
105
|
+
case 'table':
|
|
106
|
+
return renderTable(data);
|
|
107
|
+
case 'line':
|
|
108
|
+
return renderLineChart(data);
|
|
109
|
+
case 'bar':
|
|
110
|
+
return renderBarChart(data);
|
|
111
|
+
case 'pie':
|
|
112
|
+
return renderPieChart(data);
|
|
113
|
+
default:
|
|
114
|
+
return renderBarChart(data);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
88
117
|
|
|
89
|
-
const { type, data } = reportData;
|
|
90
|
-
|
|
91
|
-
switch (type) {
|
|
92
|
-
case 'line':
|
|
93
|
-
return renderLineChart(data);
|
|
94
|
-
case 'bar':
|
|
95
|
-
return renderBarChart(data);
|
|
96
|
-
case 'pie':
|
|
97
|
-
return renderPieChart(data);
|
|
98
|
-
default:
|
|
99
|
-
return renderBarChart(data);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
118
|
|
|
103
119
|
const renderLineChart = (data) => {
|
|
104
120
|
// Handle both formats: { labels, values } or array format
|
|
@@ -175,6 +191,112 @@ const ReportChart = ({
|
|
|
175
191
|
);
|
|
176
192
|
};
|
|
177
193
|
|
|
194
|
+
const renderTable = (data) => {
|
|
195
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
196
|
+
return (
|
|
197
|
+
<View style={styles.noDataContainer}>
|
|
198
|
+
<Text style={styles.noDataText}>No data available for this report</Text>
|
|
199
|
+
</View>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<ScrollView horizontal showsHorizontalScrollIndicator={true}>
|
|
205
|
+
<View style={styles.table}>
|
|
206
|
+
{/* Table Header */}
|
|
207
|
+
<View style={styles.tableHeader}>
|
|
208
|
+
<View style={[styles.headerCell, styles.firstColumn]}>
|
|
209
|
+
<Text style={styles.headerText}>FALİYET KAR/ZARAR</Text>
|
|
210
|
+
</View>
|
|
211
|
+
<View style={styles.headerCell}>
|
|
212
|
+
<Text style={styles.headerText}>2024 Fiili</Text>
|
|
213
|
+
</View>
|
|
214
|
+
<View style={styles.headerCell}>
|
|
215
|
+
<Text style={styles.headerText}>2025 Fiili</Text>
|
|
216
|
+
</View>
|
|
217
|
+
<View style={styles.headerCell}>
|
|
218
|
+
<Text style={styles.headerText}>Fiili Artış %</Text>
|
|
219
|
+
</View>
|
|
220
|
+
<View style={styles.headerCell}>
|
|
221
|
+
<Text style={styles.headerText}>2025 Bütçe</Text>
|
|
222
|
+
</View>
|
|
223
|
+
<View style={styles.headerCell}>
|
|
224
|
+
<Text style={styles.headerText}>Sapma %</Text>
|
|
225
|
+
</View>
|
|
226
|
+
<View style={styles.headerCell}>
|
|
227
|
+
<Text style={styles.headerText}>FALİYET GİD.</Text>
|
|
228
|
+
<Text style={styles.headerText}>/ BRÜT KAR %</Text>
|
|
229
|
+
</View>
|
|
230
|
+
</View>
|
|
231
|
+
|
|
232
|
+
{/* Table Rows */}
|
|
233
|
+
{data.map((item, index) => (
|
|
234
|
+
<View
|
|
235
|
+
key={index}
|
|
236
|
+
style={[
|
|
237
|
+
styles.tableRow,
|
|
238
|
+
item.isTotal ? styles.totalRow : (index % 2 === 0 ? styles.evenRow : styles.oddRow)
|
|
239
|
+
]}
|
|
240
|
+
>
|
|
241
|
+
<View style={[styles.cell, styles.firstColumn]}>
|
|
242
|
+
<Text style={item.isTotal ? styles.totalText : styles.cellText}>
|
|
243
|
+
{item.name}
|
|
244
|
+
</Text>
|
|
245
|
+
</View>
|
|
246
|
+
|
|
247
|
+
<View style={styles.cell}>
|
|
248
|
+
<Text style={styles.numberText}>
|
|
249
|
+
{formatCurrency(item.actual2024)}
|
|
250
|
+
</Text>
|
|
251
|
+
</View>
|
|
252
|
+
|
|
253
|
+
<View style={styles.cell}>
|
|
254
|
+
<Text style={styles.numberText}>
|
|
255
|
+
{formatCurrency(item.actual2025)}
|
|
256
|
+
</Text>
|
|
257
|
+
</View>
|
|
258
|
+
|
|
259
|
+
<View style={styles.cell}>
|
|
260
|
+
<Text style={[
|
|
261
|
+
styles.percentText,
|
|
262
|
+
item.yoYChangePercent >= 0 ? styles.positive : styles.negative
|
|
263
|
+
]}>
|
|
264
|
+
{item.yoYChangePercent >= 0 ? '↑' : '↓'} {Math.abs(item.yoYChangePercent)}%
|
|
265
|
+
</Text>
|
|
266
|
+
</View>
|
|
267
|
+
|
|
268
|
+
<View style={styles.cell}>
|
|
269
|
+
<Text style={styles.numberText}>
|
|
270
|
+
{formatCurrency(item.budget2025)}
|
|
271
|
+
</Text>
|
|
272
|
+
</View>
|
|
273
|
+
|
|
274
|
+
<View style={styles.cell}>
|
|
275
|
+
<Text style={[
|
|
276
|
+
styles.percentText,
|
|
277
|
+
item.budgetVariancePercent >= 0 ? styles.positive : styles.negative
|
|
278
|
+
]}>
|
|
279
|
+
{item.budgetVariancePercent >= 0 ? '↑' : '↓'} {Math.abs(item.budgetVariancePercent)}%
|
|
280
|
+
</Text>
|
|
281
|
+
</View>
|
|
282
|
+
|
|
283
|
+
<View style={styles.cell}>
|
|
284
|
+
<Text style={[
|
|
285
|
+
styles.percentText,
|
|
286
|
+
styles.grossMargin
|
|
287
|
+
]}>
|
|
288
|
+
{item.grossMarginPercent}%
|
|
289
|
+
</Text>
|
|
290
|
+
</View>
|
|
291
|
+
</View>
|
|
292
|
+
))}
|
|
293
|
+
</View>
|
|
294
|
+
</ScrollView>
|
|
295
|
+
);
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
178
300
|
const renderPieChart = (data) => {
|
|
179
301
|
// Data should be array of objects with label and value
|
|
180
302
|
const total = data.reduce((sum, item) => sum + (item.shipments || item.revenue || item.value || 0), 0);
|
|
@@ -595,6 +717,97 @@ const styles = StyleSheet.create({
|
|
|
595
717
|
color: '#999',
|
|
596
718
|
textAlign: 'center',
|
|
597
719
|
},
|
|
720
|
+
|
|
721
|
+
// Table Styles
|
|
722
|
+
table: {
|
|
723
|
+
minWidth: 700,
|
|
724
|
+
marginBottom: 20,
|
|
725
|
+
},
|
|
726
|
+
tableHeader: {
|
|
727
|
+
flexDirection: 'row',
|
|
728
|
+
backgroundColor: '#2c3e50',
|
|
729
|
+
borderBottomWidth: 1,
|
|
730
|
+
borderBottomColor: '#ddd',
|
|
731
|
+
},
|
|
732
|
+
headerCell: {
|
|
733
|
+
flex: 1,
|
|
734
|
+
padding: 10,
|
|
735
|
+
minWidth: 100,
|
|
736
|
+
justifyContent: 'center',
|
|
737
|
+
alignItems: 'center',
|
|
738
|
+
borderRightWidth: 1,
|
|
739
|
+
borderRightColor: '#444',
|
|
740
|
+
},
|
|
741
|
+
firstColumn: {
|
|
742
|
+
flex: 1.5,
|
|
743
|
+
minWidth: 180,
|
|
744
|
+
},
|
|
745
|
+
headerText: {
|
|
746
|
+
color: '#fff',
|
|
747
|
+
fontWeight: '600',
|
|
748
|
+
fontSize: 11,
|
|
749
|
+
textAlign: 'center',
|
|
750
|
+
},
|
|
751
|
+
tableRow: {
|
|
752
|
+
flexDirection: 'row',
|
|
753
|
+
borderBottomWidth: 1,
|
|
754
|
+
borderBottomColor: '#eee',
|
|
755
|
+
minHeight: 40,
|
|
756
|
+
},
|
|
757
|
+
evenRow: {
|
|
758
|
+
backgroundColor: '#fff',
|
|
759
|
+
},
|
|
760
|
+
oddRow: {
|
|
761
|
+
backgroundColor: '#f9f9f9',
|
|
762
|
+
},
|
|
763
|
+
totalRow: {
|
|
764
|
+
backgroundColor: '#e8f5e9',
|
|
765
|
+
borderTopWidth: 2,
|
|
766
|
+
borderTopColor: '#4CAF50',
|
|
767
|
+
borderBottomWidth: 2,
|
|
768
|
+
borderBottomColor: '#4CAF50',
|
|
769
|
+
},
|
|
770
|
+
cell: {
|
|
771
|
+
flex: 1,
|
|
772
|
+
padding: 8,
|
|
773
|
+
minWidth: 100,
|
|
774
|
+
justifyContent: 'center',
|
|
775
|
+
alignItems: 'center',
|
|
776
|
+
borderRightWidth: 1,
|
|
777
|
+
borderRightColor: '#eee',
|
|
778
|
+
},
|
|
779
|
+
cellText: {
|
|
780
|
+
fontSize: 12,
|
|
781
|
+
color: '#333',
|
|
782
|
+
textAlign: 'center',
|
|
783
|
+
},
|
|
784
|
+
totalText: {
|
|
785
|
+
fontSize: 12,
|
|
786
|
+
fontWeight: '700',
|
|
787
|
+
color: '#2c3e50',
|
|
788
|
+
textAlign: 'center',
|
|
789
|
+
},
|
|
790
|
+
numberText: {
|
|
791
|
+
fontSize: 11,
|
|
792
|
+
fontWeight: '500',
|
|
793
|
+
fontFamily: 'monospace',
|
|
794
|
+
color: '#333',
|
|
795
|
+
},
|
|
796
|
+
percentText: {
|
|
797
|
+
fontSize: 12,
|
|
798
|
+
fontWeight: '600',
|
|
799
|
+
fontFamily: 'monospace',
|
|
800
|
+
},
|
|
801
|
+
positive: {
|
|
802
|
+
color: '#27ae60',
|
|
803
|
+
},
|
|
804
|
+
negative: {
|
|
805
|
+
color: '#e74c3c',
|
|
806
|
+
},
|
|
807
|
+
grossMargin: {
|
|
808
|
+
color: '#2c3e50',
|
|
809
|
+
fontWeight: '700',
|
|
810
|
+
},
|
|
598
811
|
});
|
|
599
812
|
|
|
600
813
|
export default ReportChart;
|