@moontra/moonui-pro 2.4.3 → 2.4.5
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/dist/index.d.ts +22 -4
- package/dist/index.mjs +1046 -235
- package/package.json +1 -2
- package/src/components/advanced-chart/index.tsx +962 -142
- package/src/components/data-table/data-table-column-toggle.tsx +7 -4
- package/src/components/data-table/data-table-filter-drawer.tsx +48 -42
- package/src/components/data-table/index.tsx +104 -38
- package/src/styles/advanced-chart.css +239 -0
- package/src/styles/index.css +2 -1
- package/src/utils/chart-helpers.ts +100 -0
|
@@ -255,3 +255,103 @@ export function exportChartAsImage(
|
|
|
255
255
|
// Implementation would go here
|
|
256
256
|
// This is a placeholder for the actual export functionality
|
|
257
257
|
}
|
|
258
|
+
|
|
259
|
+
export function exportChartData(
|
|
260
|
+
data: ChartDataPoint[],
|
|
261
|
+
filename: string = 'chart-data',
|
|
262
|
+
format: 'json' | 'csv' = 'json'
|
|
263
|
+
): void {
|
|
264
|
+
let content: string
|
|
265
|
+
let mimeType: string
|
|
266
|
+
|
|
267
|
+
if (format === 'json') {
|
|
268
|
+
content = JSON.stringify(data, null, 2)
|
|
269
|
+
mimeType = 'application/json'
|
|
270
|
+
} else {
|
|
271
|
+
// CSV export
|
|
272
|
+
const headers = Object.keys(data[0] || {})
|
|
273
|
+
const csvRows = [
|
|
274
|
+
headers.join(','),
|
|
275
|
+
...data.map(row =>
|
|
276
|
+
headers.map(header => {
|
|
277
|
+
const value = row[header]
|
|
278
|
+
return typeof value === 'string' && value.includes(',')
|
|
279
|
+
? `"${value}"`
|
|
280
|
+
: value
|
|
281
|
+
}).join(',')
|
|
282
|
+
)
|
|
283
|
+
]
|
|
284
|
+
content = csvRows.join('\n')
|
|
285
|
+
mimeType = 'text/csv'
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const blob = new Blob([content], { type: mimeType })
|
|
289
|
+
const url = window.URL.createObjectURL(blob)
|
|
290
|
+
const link = document.createElement('a')
|
|
291
|
+
link.href = url
|
|
292
|
+
link.download = `${filename}.${format}`
|
|
293
|
+
document.body.appendChild(link)
|
|
294
|
+
link.click()
|
|
295
|
+
document.body.removeChild(link)
|
|
296
|
+
window.URL.revokeObjectURL(url)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Gradient color generator
|
|
300
|
+
export function generateGradientColors(baseColor: string, count: number = 5): string[] {
|
|
301
|
+
const colors: string[] = []
|
|
302
|
+
const rgb = hexToRgb(baseColor)
|
|
303
|
+
|
|
304
|
+
if (!rgb) return [baseColor]
|
|
305
|
+
|
|
306
|
+
for (let i = 0; i < count; i++) {
|
|
307
|
+
const factor = i / (count - 1)
|
|
308
|
+
const r = Math.round(rgb.r + (255 - rgb.r) * factor * 0.5)
|
|
309
|
+
const g = Math.round(rgb.g + (255 - rgb.g) * factor * 0.5)
|
|
310
|
+
const b = Math.round(rgb.b + (255 - rgb.b) * factor * 0.5)
|
|
311
|
+
colors.push(`rgb(${r}, ${g}, ${b})`)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return colors
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function hexToRgb(hex: string): { r: number; g: number; b: number } | null {
|
|
318
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
|
319
|
+
return result ? {
|
|
320
|
+
r: parseInt(result[1], 16),
|
|
321
|
+
g: parseInt(result[2], 16),
|
|
322
|
+
b: parseInt(result[3], 16)
|
|
323
|
+
} : null
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Performance optimization helpers
|
|
327
|
+
export function throttleChartData(data: ChartDataPoint[], maxPoints: number = 1000): ChartDataPoint[] {
|
|
328
|
+
if (data.length <= maxPoints) return data
|
|
329
|
+
|
|
330
|
+
const step = Math.ceil(data.length / maxPoints)
|
|
331
|
+
return data.filter((_, index) => index % step === 0)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Format large numbers
|
|
335
|
+
export function formatChartValue(value: number): string {
|
|
336
|
+
if (value >= 1e9) return `${(value / 1e9).toFixed(1)}B`
|
|
337
|
+
if (value >= 1e6) return `${(value / 1e6).toFixed(1)}M`
|
|
338
|
+
if (value >= 1e3) return `${(value / 1e3).toFixed(1)}K`
|
|
339
|
+
return value.toString()
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Calculate chart statistics
|
|
343
|
+
export function calculateChartStats(data: ChartDataPoint[], keys: string[]): Record<string, { min: number; max: number; avg: number; total: number }> {
|
|
344
|
+
const stats: Record<string, { min: number; max: number; avg: number; total: number }> = {}
|
|
345
|
+
|
|
346
|
+
keys.forEach(key => {
|
|
347
|
+
const values = data.map(point => Number(point[key]) || 0)
|
|
348
|
+
stats[key] = {
|
|
349
|
+
min: Math.min(...values),
|
|
350
|
+
max: Math.max(...values),
|
|
351
|
+
avg: values.reduce((sum, val) => sum + val, 0) / values.length,
|
|
352
|
+
total: values.reduce((sum, val) => sum + val, 0)
|
|
353
|
+
}
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
return stats
|
|
357
|
+
}
|