One Hat Cyber Team
Your IP :
216.73.216.55
Server IP :
5.189.175.239
Server :
Linux panel.gemx-ai.com 5.14.0-570.19.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 4 04:00:24 EDT 2025 x86_64
Server Software :
LiteSpeed
PHP Version :
8.2.28
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
farmersapp
/
store.farmersapp.store
/
public
/
js
/
Edit File:
chart.js
// Simple chart library for shadcn-laravel const ShadcnChart = { // Line chart createLineChart(ctx, data, options = {}) { const canvas = document.getElementById(ctx); if (!canvas) return; const context = canvas.getContext('2d'); const width = canvas.width; const height = canvas.height; // Clear canvas context.clearRect(0, 0, width, height); // Set default options const defaultOptions = { padding: 20, lineColor: '#000', pointColor: '#000', lineWidth: 2, pointRadius: 4, gridColor: '#eee', showGrid: true, showAxis: true, axisColor: '#888', labelColor: '#888', labelFont: '12px sans-serif', animate: true }; const chartOptions = { ...defaultOptions, ...options }; // Find min and max values let minX = Infinity; let maxX = -Infinity; let minY = Infinity; let maxY = -Infinity; data.forEach(point => { minX = Math.min(minX, point.x); maxX = Math.max(maxX, point.x); minY = Math.min(minY, point.y); maxY = Math.max(maxY, point.y); }); // Add padding to min/max const rangeX = maxX - minX; const rangeY = maxY - minY; minX = minX - rangeX * 0.05; maxX = maxX + rangeX * 0.05; minY = minY - rangeY * 0.05; maxY = maxY + rangeY * 0.05; // Scale function to convert data coordinates to canvas coordinates const scaleX = (x) => { return chartOptions.padding + (x - minX) / (maxX - minX) * (width - 2 * chartOptions.padding); }; const scaleY = (y) => { return height - chartOptions.padding - (y - minY) / (maxY - minY) * (height - 2 * chartOptions.padding); }; // Draw grid if (chartOptions.showGrid) { context.strokeStyle = chartOptions.gridColor; context.lineWidth = 0.5; // Vertical grid lines for (let i = 0; i <= 10; i++) { const x = chartOptions.padding + i * (width - 2 * chartOptions.padding) / 10; context.beginPath(); context.moveTo(x, chartOptions.padding); context.lineTo(x, height - chartOptions.padding); context.stroke(); } // Horizontal grid lines for (let i = 0; i <= 10; i++) { const y = chartOptions.padding + i * (height - 2 * chartOptions.padding) / 10; context.beginPath(); context.moveTo(chartOptions.padding, y); context.lineTo(width - chartOptions.padding, y); context.stroke(); } } // Draw axes if (chartOptions.showAxis) { context.strokeStyle = chartOptions.axisColor; context.lineWidth = 1; // X-axis context.beginPath(); context.moveTo(chartOptions.padding, height - chartOptions.padding); context.lineTo(width - chartOptions.padding, height - chartOptions.padding); context.stroke(); // Y-axis context.beginPath(); context.moveTo(chartOptions.padding, chartOptions.padding); context.lineTo(chartOptions.padding, height - chartOptions.padding); context.stroke(); // X-axis labels context.fillStyle = chartOptions.labelColor; context.font = chartOptions.labelFont; context.textAlign = 'center'; for (let i = 0; i <= 5; i++) { const value = minX + i * (maxX - minX) / 5; const x = scaleX(value); context.fillText(value.toFixed(1), x, height - chartOptions.padding / 2); } // Y-axis labels context.textAlign = 'right'; context.textBaseline = 'middle'; for (let i = 0; i <= 5; i++) { const value = minY + i * (maxY - minY) / 5; const y = scaleY(value); context.fillText(value.toFixed(1), chartOptions.padding - 5, y); } } // Draw line context.strokeStyle = chartOptions.lineColor; context.lineWidth = chartOptions.lineWidth; context.beginPath(); // Animation function const animate = (progress) => { context.clearRect(0, 0, width, height); // Redraw grid and axes if (chartOptions.showGrid) { context.strokeStyle = chartOptions.gridColor; context.lineWidth = 0.5; for (let i = 0; i <= 10; i++) { const x = chartOptions.padding + i * (width - 2 * chartOptions.padding) / 10; context.beginPath(); context.moveTo(x, chartOptions.padding); context.lineTo(x, height - chartOptions.padding); context.stroke(); } for (let i = 0; i <= 10; i++) { const y = chartOptions.padding + i * (height - 2 * chartOptions.padding) / 10; context.beginPath(); context.moveTo(chartOptions.padding, y); context.lineTo(width - chartOptions.padding, y); context.stroke(); } } if (chartOptions.showAxis) { context.strokeStyle = chartOptions.axisColor; context.lineWidth = 1; context.beginPath(); context.moveTo(chartOptions.padding, height - chartOptions.padding); context.lineTo(width - chartOptions.padding, height - chartOptions.padding); context.stroke(); context.beginPath(); context.moveTo(chartOptions.padding, chartOptions.padding); context.lineTo(chartOptions.padding, height - chartOptions.padding); context.stroke(); context.fillStyle = chartOptions.labelColor; context.font = chartOptions.labelFont; context.textAlign = 'center'; for (let i = 0; i <= 5; i++) { const value = minX + i * (maxX - minX) / 5; const x = scaleX(value); context.fillText(value.toFixed(1), x, height - chartOptions.padding / 2); } context.textAlign = 'right'; context.textBaseline = 'middle'; for (let i = 0; i <= 5; i++) { const value = minY + i * (maxY - minY) / 5; const y = scaleY(value); context.fillText(value.toFixed(1), chartOptions.padding - 5, y); } } // Draw line with animation context.strokeStyle = chartOptions.lineColor; context.lineWidth = chartOptions.lineWidth; context.beginPath(); const pointsToDraw = Math.floor(data.length * progress); for (let i = 0; i < pointsToDraw; i++) { const point = data[i]; const x = scaleX(point.x); const y = scaleY(point.y); if (i === 0) { context.moveTo(x, y); } else { context.lineTo(x, y); } } context.stroke(); // Draw points context.fillStyle = chartOptions.pointColor; for (let i = 0; i < pointsToDraw; i++) { const point = data[i]; const x = scaleX(point.x); const y = scaleY(point.y); context.beginPath(); context.arc(x, y, chartOptions.pointRadius, 0, 2 * Math.PI); context.fill(); } if (progress < 1) { requestAnimationFrame(() => animate(Math.min(progress + 0.05, 1))); } }; // Start animation or draw immediately if (chartOptions.animate) { animate(0); } else { // Draw line without animation for (let i = 0; i < data.length; i++) { const point = data[i]; const x = scaleX(point.x); const y = scaleY(point.y); if (i === 0) { context.moveTo(x, y); } else { context.lineTo(x, y); } } context.stroke(); // Draw points context.fillStyle = chartOptions.pointColor; for (let i = 0; i < data.length; i++) { const point = data[i]; const x = scaleX(point.x); const y = scaleY(point.y); context.beginPath(); context.arc(x, y, chartOptions.pointRadius, 0, 2 * Math.PI); context.fill(); } } }, // Bar chart createBarChart(ctx, data, options = {}) { const canvas = document.getElementById(ctx); if (!canvas) return; const context = canvas.getContext('2d'); const width = canvas.width; const height = canvas.height; // Clear canvas context.clearRect(0, 0, width, height); // Set default options const defaultOptions = { padding: 40, barColor: '#3b82f6', barWidth: 0.6, // Percentage of available space (0-1) gridColor: '#eee', showGrid: true, showAxis: true, axisColor: '#888', labelColor: '#888', labelFont: '12px sans-serif', animate: true }; const chartOptions = { ...defaultOptions, ...options }; // Find max value let maxValue = -Infinity; data.forEach(item => { maxValue = Math.max(maxValue, item.value); }); // Add padding to max maxValue = maxValue * 1.1; // Calculate bar width and spacing const barSpacing = (width - 2 * chartOptions.padding) / data.length; const barWidth = barSpacing * chartOptions.barWidth; // Draw grid if (chartOptions.showGrid) { context.strokeStyle = chartOptions.gridColor; context.lineWidth = 0.5; // Horizontal grid lines for (let i = 0; i <= 10; i++) { const y = chartOptions.padding + i * (height - 2 * chartOptions.padding) / 10; context.beginPath(); context.moveTo(chartOptions.padding, y); context.lineTo(width - chartOptions.padding, y); context.stroke(); } } // Draw axes if (chartOptions.showAxis) { context.strokeStyle = chartOptions.axisColor; context.lineWidth = 1; // X-axis context.beginPath(); context.moveTo(chartOptions.padding, height - chartOptions.padding); context.lineTo(width - chartOptions.padding, height - chartOptions.padding); context.stroke(); // Y-axis context.beginPath(); context.moveTo(chartOptions.padding, chartOptions.padding); context.lineTo(chartOptions.padding, height - chartOptions.padding); context.stroke(); // X-axis labels context.fillStyle = chartOptions.labelColor; context.font = chartOptions.labelFont; context.textAlign = 'center'; context.textBaseline = 'top'; data.forEach((item, index) => { const x = chartOptions.padding + barSpacing * index + barSpacing / 2; context.fillText(item.label, x, height - chartOptions.padding + 5); }); // Y-axis labels context.textAlign = 'right'; context.textBaseline = 'middle'; for (let i = 0; i <= 5; i++) { const value = i * maxValue / 5; const y = height - chartOptions.padding - (value / maxValue) * (height - 2 * chartOptions.padding); context.fillText(value.toFixed(0), chartOptions.padding - 5, y); } } // Animation function const animate = (progress) => { // Clear only the bar area context.clearRect(chartOptions.padding, chartOptions.padding, width - 2 * chartOptions.padding, height - 2 * chartOptions.padding); // Redraw grid if (chartOptions.showGrid) { context.strokeStyle = chartOptions.gridColor; context.lineWidth = 0.5; for (let i = 0; i <= 10; i++) { const y = chartOptions.padding + i * (height - 2 * chartOptions.padding) / 10; context.beginPath(); context.moveTo(chartOptions.padding, y); context.lineTo(width - chartOptions.padding, y); context.stroke(); } } // Draw bars with animation context.fillStyle = chartOptions.barColor; data.forEach((item, index) => { const x = chartOptions.padding + barSpacing * index + (barSpacing - barWidth) / 2; const barHeight = (item.value / maxValue) * (height - 2 * chartOptions.padding) * progress; const y = height - chartOptions.padding - barHeight; context.fillRect(x, y, barWidth, barHeight); }); if (progress < 1) { requestAnimationFrame(() => animate(Math.min(progress + 0.05, 1))); } }; // Start animation or draw immediately if (chartOptions.animate) { animate(0); } else { // Draw bars without animation context.fillStyle = chartOptions.barColor; data.forEach((item, index) => { const x = chartOptions.padding + barSpacing * index + (barSpacing - barWidth) / 2; const barHeight = (item.value / maxValue) * (height - 2 * chartOptions.padding); const y = height - chartOptions.padding - barHeight; context.fillRect(x, y, barWidth, barHeight); }); } }, // Pie chart createPieChart(ctx, data, options = {}) { const canvas = document.getElementById(ctx); if (!canvas) return; const context = canvas.getContext('2d'); const width = canvas.width; const height = canvas.height; // Clear canvas context.clearRect(0, 0, width, height); // Set default options const defaultOptions = { colors: ['#3b82f6', '#ef4444', '#10b981', '#f59e0b', '#8b5cf6', '#ec4899'], donut: false, donutRatio: 0.5, showLabels: true, labelColor: '#fff', labelFont: '12px sans-serif', animate: true }; const chartOptions = { ...defaultOptions, ...options }; // Calculate total const total = data.reduce((sum, item) => sum + item.value, 0); // Calculate center and radius const centerX = width / 2; const centerY = height / 2; const radius = Math.min(width, height) / 2 - 10; // Animation function const animate = (progress) => { context.clearRect(0, 0, width, height); let startAngle = -Math.PI / 2; data.forEach((item, index) => { const sliceAngle = (item.value / total) * Math.PI * 2 * progress; context.beginPath(); context.moveTo(centerX, centerY); context.arc(centerX, centerY, radius, startAngle, startAngle + sliceAngle); context.closePath(); context.fillStyle = chartOptions.colors[index % chartOptions.colors.length]; context.fill(); // Add labels if enabled and progress is complete if (chartOptions.showLabels && progress === 1) { const midAngle = startAngle + sliceAngle / 2; const labelRadius = radius * 0.7; const labelX = centerX + Math.cos(midAngle) * labelRadius; const labelY = centerY + Math.sin(midAngle) * labelRadius; context.fillStyle = chartOptions.labelColor; context.font = chartOptions.labelFont; context.textAlign = 'center'; context.textBaseline = 'middle'; const percentage = Math.round((item.value / total) * 100); context.fillText(`${percentage}%`, labelX, labelY); } startAngle += sliceAngle; }); // Draw donut hole if enabled if (chartOptions.donut) { context.beginPath(); context.moveTo(centerX, centerY); context.arc(centerX, centerY, radius * chartOptions.donutRatio, 0, Math.PI * 2); context.fillStyle = '#fff'; context.fill(); } if (progress < 1) { requestAnimationFrame(() => animate(Math.min(progress + 0.05, 1))); } }; // Start animation or draw immediately if (chartOptions.animate) { animate(0); } else { animate(1); } } }; // Make it available globally window.ShadcnChart = ShadcnChart;
Simpan