// Get elements var tasks = document.getElementById('chart_tasks').getContext('2d'); var points = document.getElementById('chart_points').getContext('2d'); let fields = { earnings_tot1: document.getElementById('earnings_tot1'), earnings_tot2: document.getElementById('earnings_tot2'), earnings_tot3: document.getElementById('earnings_tot3'), p1_piecerate: document.getElementById('p1_piecerate'), p1_tasks_tot: document.getElementById('p1_tasks_tot'), p1_tasks_share: document.getElementById('p1_tasks_share'), p1_commit_tot: document.getElementById('p1_commit_tot'), p1_commit_share: document.getElementById('p1_commit_share'), p1_earnings_tot: document.getElementById('p1_earnings_tot'), p1_earnings_share: document.getElementById('p1_earnings_share'), p1_allocation_tot: document.getElementById('p1_allocation_tot'), p1_allocation_share: document.getElementById('p1_allocation_share'), p2_piecerate: document.getElementById('p2_piecerate'), p2_tasks_tot: document.getElementById('p2_tasks_tot'), p2_tasks_share: document.getElementById('p2_tasks_share'), p2_commit_tot: document.getElementById('p2_commit_tot'), p2_commit_share: document.getElementById('p2_commit_share'), p2_earnings_tot: document.getElementById('p2_earnings_tot'), p2_earnings_share: document.getElementById('p2_earnings_share'), p2_allocation_tot: document.getElementById('p2_allocation_tot'), p2_allocation_share: document.getElementById('p2_allocation_share'), } function tasks_share() { let task1= parseInt(p1_tasks_tot.textContent); let task2= parseInt(p2_tasks_tot.textContent); let total= task1+task2 p1_tasks_share.textContent = (100*(task1/total)).toFixed(0); p2_tasks_share.textContent = (100*(task2/total)).toFixed(0); } function earnings_share() { let earning1= parseInt(p1_earnings_tot.textContent); let earning2= parseInt(p2_earnings_tot.textContent); let total= earning1+earning2 p1_earnings_share.textContent = (100*(earning1/total)).toFixed(0); p2_earnings_share.textContent = (100*(earning2/total)).toFixed(0); } function graphs() { let task1= parseInt(p1_tasks_tot.textContent); let task2= parseInt(p2_tasks_tot.textContent); let earning1= parseInt(p1_earnings_tot.textContent); let earning2= parseInt(p2_earnings_tot.textContent); var ChartTasks = new Chart(tasks, { type: 'pie', data: { datasets: [{ data: [task2, task1], backgroundColor: ['#5f96de', '#de5f6c'], }] }, options: { maintainAspectRatio: false, responsive: true, width: 50, height: 50, }, }); var ChartPoints = new Chart(points, { type: 'pie', data: { datasets: [{ data: [earning2, earning1], backgroundColor: ['#5f96de', '#de5f6c'], }] }, options: { maintainAspectRatio: false, responsive: true, width: 50, height: 50, }, }); } function comm_graph() { var comm = document.getElementById('chart_comm').getContext('2d'); let comm1= parseInt(p1_comm_tot.textContent); let comm2= parseInt(p2_comm_tot.textContent); var ChartComm = new Chart(comm, { type: 'pie', data: { datasets: [{ data: [comm2, comm1], backgroundColor: ['#5f96de', '#de5f6c'], }] }, options: { maintainAspectRatio: false, responsive: true, width: 50, height: 50, }, }); } function totals() { let earning1= parseInt(p1_earnings_tot.textContent); let earning2= parseInt(p2_earnings_tot.textContent); earnings_tot1.textContent = earning1+earning2; earnings_tot2.textContent = earnings_tot1.textContent; } function allocation_integer1() { const input = p1_allocation_tot.value; const regex = /^\d*$/; // Regular expression to match only digits if (!regex.test(input)) { // If the input is not a valid integer, remove non-digit characters p1_allocation_tot.value = input.replace(/[^\d]/g, ""); } } function allocation_integer2() { const input = p2_allocation_tot.value; const regex = /^\d*$/; // Regular expression to match only digits if (!regex.test(input)) { // If the input is not a valid integer, remove non-digit characters p2_allocation_tot.value = input.replace(/[^\d]/g, ""); } } function allocation_autocomplete1() { let allocation1= parseInt(p1_allocation_tot.value); let allocation2= parseInt(p2_allocation_tot.value); let totals = parseInt(p1_earnings_tot.textContent)+parseInt(p2_earnings_tot.textContent); if (p1_allocation_tot.value.trim() !== '') { if (allocation1 <= totals) { p2_allocation_tot.value = totals-allocation1; } else { p2_allocation_tot.value = ''; } } else { p2_allocation_tot.value = ''; } } function allocation_autocomplete2() { let allocation1= parseInt(p1_allocation_tot.value); let allocation2= parseInt(p2_allocation_tot.value); let totals = parseInt(p1_earnings_tot.textContent)+parseInt(p2_earnings_tot.textContent); if (p2_allocation_tot.value.trim() !== '') { if (allocation2 <= totals) { p1_allocation_tot.value = totals-allocation2; } else { p1_allocation_tot.value = ''; } } else { p1_allocation_tot.value = ''; } } function allocation_share() { let total; if (p1_allocation_tot.value.trim() !== '' && p2_allocation_tot.value.trim() !== '') { total = parseInt(p1_allocation_tot.value) + parseInt(p2_allocation_tot.value); p1_allocation_share.textContent = parseFloat((100*(parseFloat(p1_allocation_tot.value)/total)).toFixed(0)); p2_allocation_share.textContent = parseFloat((100*(parseFloat(p2_allocation_tot.value)/total)).toFixed(0)); } else { p1_allocation_share.textContent = '...'; p2_allocation_share.textContent = '...'; } } function p1_input() { allocation_integer1() allocation_autocomplete1() allocation_share() } function p2_input() { allocation_integer2() allocation_autocomplete2() allocation_share() } function commit() { commit_share() commit_graph() }