Files
verifikator/resources/views/jurnal/index.blade.php
T
2026-08-07 10:47:09 +07:00

2157 lines
99 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard Statistik Jurnal — UNTAN</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700;800&display=swap');
body {
font-family: 'Inter', sans-serif;
background-color: #f8fafc;
}
.glass-card {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border: 1px solid rgba(226, 232, 240, 0.8);
}
.gradient-text {
background: linear-gradient(135deg, #1e40af, #3b82f6);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.badge-fraction {
background: #eff6ff;
border: 1px solid #dbeafe;
color: #1e40af;
}
.badge-faculty {
background: #f0fdf4;
border: 1px solid #bbf7d0;
color: #166534;
}
#loader {
transition: opacity 0.5s ease-out;
}
.period-btn {
transition: all 0.2s ease;
}
.period-btn.active {
background: #1e40af;
color: white;
box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
transform: translateY(-1px);
}
.period-btn:not(.active):hover {
background: #e0e7ff;
color: #3730a3;
}
.fade-in {
animation: fadeIn 0.4s ease-out;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.positive {
color: #16a34a;
font-weight: 700;
}
.negative {
color: #dc2626;
font-weight: 700;
}
.neutral {
color: #6b7280;
font-weight: 600;
}
.tab-btn {
transition: all 0.2s;
}
.tab-btn.active {
border-bottom: 3px solid #3b82f6;
color: #1e40af;
font-weight: 700;
}
</style>
</head>
<body class="p-4 md:p-8">
<!-- Loading Screen -->
<div id="loader" class="fixed inset-0 z-50 flex flex-col items-center justify-center bg-white">
<div class="w-16 h-16 border-4 border-blue-200 border-t-blue-600 rounded-full animate-spin mb-4"></div>
<p class="text-slate-500 font-medium animate-pulse" id="loadingText">Memuat data dari API...</p>
<p class="text-xs text-slate-400 mt-2" id="loadingProgress"></p>
</div>
<div class="max-w-7xl mx-auto opacity-0" id="mainContent">
<!-- Header -->
<header class="mb-6 text-center">
<h1 class="text-4xl font-extrabold mb-2 gradient-text">📊 Dashboard Statistik Jurnal</h1>
<p class="text-slate-500">Analisis Komprehensif Publikasi, Fakultas, dan Kontribusi Penulis — UNTAN</p>
</header>
<!-- TAB NAVIGATION -->
<div class="glass-card rounded-2xl shadow-sm mb-6 overflow-hidden">
<div class="flex border-b border-slate-200">
<button
class="tab-btn active flex-1 py-4 px-6 text-center text-sm font-semibold text-slate-500 hover:text-blue-600"
onclick="switchTab('dashboard')">
📊 Dashboard Per Periode
</button>
<button
class="tab-btn flex-1 py-4 px-6 text-center text-sm font-semibold text-slate-500 hover:text-blue-600"
onclick="switchTab('growth')">
📈 Pertumbuhan Antar Tahun
</button>
</div>
</div>
<!-- ============================================================ -->
<!-- TAB 1: DASHBOARD PER PERIODE -->
<!-- ============================================================ -->
<div id="tabDashboard">
<!-- Period Selector -->
<div class="glass-card rounded-2xl shadow-sm p-4 mb-8">
<div class="flex flex-col items-center gap-3">
<h3 class="text-sm font-bold text-slate-500 uppercase tracking-wider">Pilih Periode</h3>
<div class="flex flex-wrap justify-center gap-2" id="periodSelector"></div>
<p class="text-xs text-slate-400" id="periodInfo"></p>
</div>
</div>
<!-- Stat Summary Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8" id="summaryCards"></div>
<!-- Charts Section -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-10">
<div class="glass-card p-6 rounded-2xl shadow-sm">
<h3 class="text-lg font-semibold mb-6 text-slate-700 text-center">Distribusi Jurnal (Jumlah)</h3>
<div class="h-[300px]"><canvas id="categoryBarChart"></canvas></div>
</div>
<div class="glass-card p-6 rounded-2xl shadow-sm">
<h3 class="text-lg font-semibold mb-6 text-slate-700 text-center">Proporsi Jurnal (Jumlah)</h3>
<div class="h-[300px]"><canvas id="categoryPieChart"></canvas></div>
</div>
<div class="glass-card p-6 rounded-2xl shadow-sm">
<h3 class="text-lg font-semibold mb-6 text-slate-700 text-center">Proporsi Jurnal (Persentase)</h3>
<div class="h-[300px]"><canvas id="categoryPercentChart"></canvas></div>
</div>
</div>
<!-- Section: Analisis Fakultas -->
<div class="mb-10">
<div class="flex flex-col md:flex-row justify-between items-end mb-4">
<div>
<h3 class="text-xl font-bold text-slate-800 flex items-center gap-2"><span>🏛️</span> Analisis
Kontribusi per Fakultas</h3>
<p class="text-sm text-slate-500 mt-1">Data fakultas diambil dari field <code>unit</code> pada
data penulis di API</p>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
<div class="glass-card p-6 rounded-2xl shadow-sm">
<h4 class="text-sm font-bold text-slate-500 uppercase mb-4 text-center">Total Artikel per
Fakultas</h4>
<div class="h-[400px]"><canvas id="facultyChart"></canvas></div>
</div>
<div class="glass-card p-6 rounded-2xl shadow-sm">
<h4 class="text-sm font-bold text-slate-500 uppercase mb-4 text-center">Persentase Kontribusi
terhadap Total Univ</h4>
<div class="h-[400px]"><canvas id="facultyPieChart"></canvas></div>
</div>
</div>
<div class="glass-card rounded-2xl shadow-sm overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-left">
<thead class="bg-green-50 border-b border-green-200">
<tr>
<th class="px-6 py-4 text-xs font-bold text-green-800 uppercase tracking-wider">
Fakultas</th>
<th class="px-6 py-4 text-xs font-bold text-green-800 uppercase tracking-wider">
Detail Kontribusi per Kategori<br><span
class="text-[10px] font-normal normal-case">(Tebal: Jml Artikel | Kecil: Jml
Penulis)</span></th>
<th
class="px-6 py-4 text-xs font-bold text-green-800 uppercase tracking-wider text-center">
Total Artikel</th>
<th
class="px-6 py-4 text-xs font-bold text-green-800 uppercase tracking-wider text-center">
Total Penulis</th>
</tr>
</thead>
<tbody id="facultyTableBody" class="divide-y divide-slate-100 text-sm"></tbody>
</table>
</div>
</div>
</div>
<!-- Section: Champions -->
<div class="mb-10">
<h3 class="text-xl font-bold text-slate-800 mb-4 flex items-center gap-2"><span>🏆</span> Juara Per
Kategori</h3>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6" id="championsContainer"></div>
</div>
<!-- Category Table -->
<div class="glass-card rounded-2xl shadow-sm overflow-hidden mb-10">
<div class="p-6 border-b border-slate-100">
<h3 class="text-xl font-bold text-slate-800">Ringkasan per Kategori</h3>
</div>
<div class="overflow-x-auto">
<table class="w-full text-left">
<thead class="bg-slate-50 border-b border-slate-200">
<tr>
<th class="px-6 py-4 text-sm font-semibold text-slate-600">Nama Kategori</th>
<th class="px-6 py-4 text-sm font-semibold text-slate-600 text-center">Total Jurnal</th>
<th class="px-6 py-4 text-sm font-semibold text-slate-600 text-center">Persentase (%)
</th>
</tr>
</thead>
<tbody id="categoryTableBody" class="divide-y divide-slate-100"></tbody>
</table>
</div>
</div>
<!-- Author Analysis -->
<div class="glass-card rounded-2xl shadow-sm overflow-hidden mb-10 border-blue-100 border-2">
<div
class="p-6 border-b border-slate-100 flex flex-col md:flex-row md:items-center justify-between gap-4 bg-blue-50/50">
<div>
<h3 class="text-xl font-bold text-blue-900">Analisis Kontribusi Penulis</h3>
<p class="text-sm text-blue-600">Rasio karya penulis dibanding total karya di Universitas</p>
</div>
<div class="relative">
<input type="text" id="authorSearch" placeholder="Cari Nama atau NIP..."
class="pl-10 pr-4 py-2 border rounded-xl w-64 focus:ring-2 focus:ring-blue-400 outline-none">
<span class="absolute left-3 top-2.5 opacity-40">🔍</span>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full text-left">
<thead class="bg-blue-100/50 border-b border-blue-200">
<tr>
<th class="px-6 py-4 text-xs font-bold text-blue-800 uppercase">Penulis (NIP)</th>
<th class="px-6 py-4 text-xs font-bold text-blue-800 uppercase">Kontribusi per Kategori
</th>
<th class="px-6 py-4 text-xs font-bold text-blue-800 uppercase text-center">Total Karya
</th>
<th class="px-6 py-4 text-xs font-bold text-blue-800 uppercase text-center">% Thd Total
</th>
</tr>
</thead>
<tbody id="authorTableBody" class="divide-y divide-slate-100 text-sm"></tbody>
</table>
</div>
</div>
</div>
<!-- ============================================================ -->
<!-- TAB 2: PERTUMBUHAN ANTAR TAHUN -->
<!-- ============================================================ -->
<div id="tabGrowth" class="hidden">
<!-- YoY Summary Cards: satu card per transisi -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8" id="yoySummaryCards"></div>
<!-- Policy Note (jika ada) -->
<div id="policyNoteContainer" class="mb-8"></div>
<!-- Trend Chart: All Years -->
<div class="glass-card p-6 rounded-2xl shadow-sm mb-10">
<h3 class="text-lg font-semibold mb-4 text-slate-700 text-center">📈 Tren Total Jurnal per Tahun</h3>
<p class="text-xs text-slate-400 text-center mb-4">Adjusted = tanpa kategori S3–S6 yang dihentikan
karena kebijakan</p>
<div class="h-[350px]"><canvas id="trendLineChart"></canvas></div>
</div>
<!-- YoY Stacked Bar Chart per Kategori -->
<div class="glass-card p-6 rounded-2xl shadow-sm mb-10">
<h3 class="text-lg font-semibold mb-4 text-slate-700 text-center">Jumlah Jurnal per Kategori per Tahun
</h3>
<div class="h-[420px]"><canvas id="yoyCategoryChart"></canvas></div>
</div>
<!-- Pertumbuhan Internasional Q1-Q4 per Tahun -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-10">
<div class="glass-card p-6 rounded-2xl shadow-sm">
<h3 class="text-lg font-semibold mb-2 text-slate-700 text-center">📘 Pertumbuhan Internasional
Q1–Q4 per Tahun</h3>
<p class="text-xs text-slate-400 text-center mb-4">Tren jumlah artikel jurnal internasional
berkualitas</p>
<div class="h-[380px]"><canvas id="intlQ1Q4Chart"></canvas></div>
</div>
<div class="glass-card p-6 rounded-2xl shadow-sm">
<h3 class="text-lg font-semibold mb-2 text-slate-700 text-center">📗 Pertumbuhan Nasional S1 & S2
per Tahun</h3>
<p class="text-xs text-slate-400 text-center mb-4">Tren jumlah artikel jurnal nasional
terakreditasi</p>
<div class="h-[380px]"><canvas id="natlS1S2Chart"></canvas></div>
</div>
</div>
<!-- Master Table: semua tahun + semua transisi YoY -->
<div class="glass-card rounded-2xl shadow-sm overflow-hidden mb-10">
<div class="p-6 border-b border-slate-100">
<h3 class="text-xl font-bold text-slate-800">Breakdown Lengkap per Kategori & Tahun</h3>
<p class="text-sm text-slate-500 mt-1">Kategori S3–S6 yang dihentikan di-flag sebagai perubahan
kebijakan, bukan penurunan.</p>
</div>
<div class="overflow-x-auto">
<table class="w-full text-left text-sm">
<thead id="growthTableHead" class="bg-purple-50 border-b border-purple-200"></thead>
<tbody id="growthTableBody" class="divide-y divide-slate-100"></tbody>
</table>
</div>
</div>
<!-- Detail per transisi YoY -->
<div class="glass-card rounded-2xl shadow-sm overflow-hidden mb-10">
<div class="p-6 border-b border-slate-100">
<h3 class="text-xl font-bold text-slate-800">Detail Perbandingan per Transisi</h3>
<div class="flex flex-wrap gap-2 mt-3" id="yoyDetailButtons"></div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 p-6">
<div class="h-[380px]"><canvas id="yoyDetailCompare"></canvas></div>
<div class="h-[380px]"><canvas id="yoyDetailDiff"></canvas></div>
</div>
</div>
<!-- ============================================================ -->
<!-- PETA KONTRIBUSI FAKULTAS: NASIONAL vs INTERNASIONAL -->
<!-- ============================================================ -->
<div class="glass-card rounded-2xl shadow-sm overflow-hidden mb-10">
<div class="p-6 border-b border-slate-100">
<h3 class="text-xl font-bold text-slate-800">🏛️ Kontribusi Fakultas — Jurnal Internasional per
Tahun</h3>
<p class="text-sm text-slate-500 mt-1">Jumlah artikel di jurnal internasional (Q1–Q4 + Tidak
Terakreditasi) per fakultas per tahun</p>
</div>
<div class="p-6">
<div class="h-[420px]"><canvas id="facultyIntlChart"></canvas></div>
</div>
</div>
<div class="glass-card rounded-2xl shadow-sm overflow-hidden mb-10">
<div class="p-6 border-b border-slate-100">
<h3 class="text-xl font-bold text-slate-800">🏛️ Kontribusi Fakultas — Jurnal Nasional (Adjusted)
per Tahun</h3>
<p class="text-sm text-slate-500 mt-1">Jumlah artikel di jurnal nasional (S1 & S2, tanpa S3–S6) per
fakultas per tahun</p>
</div>
<div class="p-6">
<div class="h-[420px]"><canvas id="facultyNatlChart"></canvas></div>
</div>
</div>
<!-- Summary Table Fakultas -->
<div class="glass-card rounded-2xl shadow-sm overflow-hidden mb-10">
<div class="p-6 border-b border-slate-100">
<h3 class="text-xl font-bold text-slate-800">Tabel Kontribusi Fakultas per Tahun</h3>
<p class="text-sm text-slate-500 mt-1">Ringkasan jumlah artikel internasional & nasional (adjusted)
per fakultas</p>
</div>
<div class="overflow-x-auto">
<table class="w-full text-left text-sm">
<thead id="facultyGrowthHead" class="bg-emerald-50 border-b border-emerald-200"></thead>
<tbody id="facultyGrowthBody" class="divide-y divide-slate-100"></tbody>
</table>
</div>
</div>
<!-- ============================================================ -->
<!-- KONTRIBUSI PENGUSUL PER TAHUN -->
<!-- ============================================================ -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-10">
<div class="glass-card p-6 rounded-2xl shadow-sm">
<h3 class="text-lg font-semibold mb-2 text-slate-700 text-center">👤 Jumlah Pengusul Unik per Tahun
</h3>
<p class="text-xs text-slate-400 text-center mb-4">Total penulis unik yang berkontribusi setiap
tahun</p>
<div class="h-[350px]"><canvas id="pengusulCountChart"></canvas></div>
</div>
<div class="glass-card p-6 rounded-2xl shadow-sm">
<h3 class="text-lg font-semibold mb-2 text-slate-700 text-center">📊 Rata-rata Artikel per Pengusul
</h3>
<p class="text-xs text-slate-400 text-center mb-4">Produktivitas: total artikel (adjusted) ÷ jumlah
pengusul unik</p>
<div class="h-[350px]"><canvas id="pengusulAvgChart"></canvas></div>
</div>
</div>
<div class="glass-card p-6 rounded-2xl shadow-sm mb-10">
<h3 class="text-lg font-semibold mb-2 text-slate-700 text-center">👤 Pengusul: Internasional vs
Nasional per Tahun</h3>
<p class="text-xs text-slate-400 text-center mb-4">Jumlah pengusul unik yang publish di jurnal
internasional vs nasional (adjusted)</p>
<div class="h-[400px]"><canvas id="pengusulIntlNatlChart"></canvas></div>
</div>
</div>
</div>
<script>
// =====================================================
// KONFIGURASI PERIODE
// =====================================================
const PERIODES = [{
id: 377,
apiLabel: '2021/2022',
label: '2022 Ganjil',
year: 2022,
semester: 'Ganjil'
},
{
id: 380,
apiLabel: '2022/2023',
label: '2022 Genap',
year: 2022,
semester: 'Genap'
},
{
id: 383,
apiLabel: '2022/2023',
label: '2023 Ganjil',
year: 2023,
semester: 'Ganjil'
},
{
id: 386,
apiLabel: '2023/2024',
label: '2023 Genap',
year: 2023,
semester: 'Genap'
},
{
id: 389,
apiLabel: '2023/2024',
label: '2024 Ganjil',
year: 2024,
semester: 'Ganjil'
},
{
id: 392,
apiLabel: '2024/2025',
label: '2024 Genap',
year: 2024,
semester: 'Genap'
},
{
id: 395,
apiLabel: '2024/2025',
label: '2025 Ganjil',
year: 2025,
semester: 'Ganjil'
},
{
id: 398,
apiLabel: '2025/2026',
label: '2025 Genap',
year: 2025,
semester: 'Genap'
},
];
const API_BASE = 'https://insentif.jurnal.untan.ac.id/api/v1/jurnal-count/';
const YEARS = [...new Set(PERIODES.map(p => p.year))].sort();
let allPeriodeData = {};
let dashboardData = null;
let currentPeriode = 'all';
const chartColors = [
'#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6',
'#ec4899', '#6366f1', '#14b8a6', '#f97316', '#06b6d4',
'#84cc16', '#0ea5e9'
];
// Kategori yang dihentikan karena perubahan kebijakan peningkatan kualitas
// Jika kategori ini ada di tahun awal tapi hilang di tahun akhir,
// TIDAK dihitung sebagai penurunan, tapi di-flag sebagai perubahan kebijakan
// Matching fleksibel: "Nasional S3", "Nasional - S3", "nasional s3", dll.
function isDiscontinued(catName) {
const normalized = catName.toLowerCase().replace(/[\s\-_]+/g, '');
// Harus DIMULAI dengan "nasional" (bukan "internasional") dan diakhiri s3/s4/s5/s6
return /^nasional.*s[3-6]$/.test(normalized);
}
// =====================================================
// TAB SWITCHING
// =====================================================
function switchTab(tab) {
document.querySelectorAll('.tab-btn').forEach((btn, i) => {
btn.classList.toggle('active', (i === 0 && tab === 'dashboard') || (i === 1 && tab === 'growth'));
});
document.getElementById('tabDashboard').classList.toggle('hidden', tab !== 'dashboard');
document.getElementById('tabGrowth').classList.toggle('hidden', tab !== 'growth');
if (tab === 'growth') renderGrowthTab();
}
// =====================================================
// FETCH SEMUA PERIODE
// =====================================================
async function fetchAllPeriodes() {
const loadingText = document.getElementById('loadingText');
const loadingProgress = document.getElementById('loadingProgress');
let loaded = 0;
const promises = PERIODES.map(async (p) => {
try {
const response = await fetch(API_BASE + p.id);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
allPeriodeData[p.id] = data;
} catch (err) {
console.warn(`Gagal memuat periode ${p.id} (${p.label}):`, err);
} finally {
loaded++;
loadingProgress.innerText = `${loaded} / ${PERIODES.length} periode dimuat...`;
}
});
loadingText.innerText = 'Memuat data dari API...';
await Promise.all(promises);
}
// =====================================================
// PERIOD SELECTOR
// =====================================================
function renderPeriodSelector() {
const container = document.getElementById('periodSelector');
let html =
`<button class="period-btn px-4 py-2 rounded-xl text-sm font-semibold border border-slate-200 bg-white text-slate-600 active" data-period="all" onclick="selectPeriod('all')">📊 Semua Periode</button>`;
PERIODES.forEach(p => {
const hasData = allPeriodeData[p.id] !== undefined;
const cls = hasData ? '' : 'opacity-40 cursor-not-allowed';
const dis = hasData ? '' : 'disabled';
html +=
`<button class="period-btn px-4 py-2 rounded-xl text-sm font-semibold border border-slate-200 bg-white text-slate-600 ${cls}" data-period="${p.id}" onclick="selectPeriod(${p.id})" ${dis}>${p.label}</button>`;
});
container.innerHTML = html;
updatePeriodInfo('all');
}
function selectPeriod(periodeId) {
currentPeriode = periodeId;
document.querySelectorAll('.period-btn').forEach(btn => {
btn.classList.toggle('active', btn.dataset.period == periodeId);
});
updatePeriodInfo(periodeId);
rebuildDashboard();
}
function updatePeriodInfo(periodeId) {
const infoEl = document.getElementById('periodInfo');
if (periodeId === 'all') {
infoEl.innerText = `Menampilkan gabungan dari ${Object.keys(allPeriodeData).length} periode`;
} else {
const p = PERIODES.find(x => x.id === periodeId);
if (p) infoEl.innerText = `Periode: ${p.label} (TA ${p.apiLabel}) — ID: ${p.id}`;
}
}
// =====================================================
// RENDER GROWTH TAB — Full YoY Chain
// =====================================================
let currentYoyDetail = null; // track which transition is selected for detail charts
function renderGrowthTab() {
// 1. Hitung data per tahun
const yearData = {};
YEARS.forEach(y => {
yearData[y] = getCategoryCountsForYear(y);
});
// 2. Kumpulkan SEMUA kategori dari semua tahun
const allCatsSet = new Set();
YEARS.forEach(y => Object.keys(yearData[y]).forEach(c => allCatsSet.add(c)));
const allCats = [...allCatsSet].sort();
// 3. Hitung total per tahun (raw & adjusted)
const yearTotals = {};
const yearTotalsAdj = {};
YEARS.forEach(y => {
yearTotals[y] = Object.values(yearData[y]).reduce((a, b) => a + b, 0);
// Adjusted: buang kategori discontinued yg sudah hilang di tahun terakhir
let adj = 0;
allCats.forEach(cat => {
const val = yearData[y][cat] || 0;
// Cek apakah kategori ini discontinued & sudah hilang di tahun-tahun selanjutnya
const isDisc = isDiscontinued(cat);
const lastYear = YEARS[YEARS.length - 1];
const goneInLatest = (yearData[lastYear][cat] || 0) === 0;
if (isDisc && goneInLatest) {
// skip — ini kategori kebijakan
} else {
adj += val;
}
});
yearTotalsAdj[y] = adj;
});
// 4. Hitung transisi YoY
const transitions = [];
for (let i = 0; i < YEARS.length - 1; i++) {
const yFrom = YEARS[i],
yTo = YEARS[i + 1];
const tFrom = yearTotals[yFrom],
tTo = yearTotals[yTo];
const aFrom = yearTotalsAdj[yFrom],
aTo = yearTotalsAdj[yTo];
// Cari kategori discontinued dalam transisi ini
let discCount = 0,
discJurnals = 0,
discNames = [];
allCats.forEach(cat => {
const vFrom = yearData[yFrom][cat] || 0;
const vTo = yearData[yTo][cat] || 0;
if (isDiscontinued(cat) && vFrom > 0 && vTo === 0) {
discCount++;
discJurnals += vFrom;
discNames.push(cat);
}
});
transitions.push({
from: yFrom,
to: yTo,
totalFrom: tFrom,
totalTo: tTo,
selisih: tTo - tFrom,
pertumbuhan: tFrom > 0 ? ((tTo - tFrom) / tFrom * 100) : 0,
adjFrom: aFrom,
adjTo: aTo,
adjSelisih: aTo - aFrom,
adjPertumbuhan: aFrom > 0 ? ((aTo - aFrom) / aFrom * 100) : 0,
discCount,
discJurnals,
discNames
});
}
// ===== RENDER YoY SUMMARY CARDS =====
const cardsEl = document.getElementById('yoySummaryCards');
// Hitung rata-rata pertumbuhan adjusted
const avgAdjPertumbuhan = transitions.length > 0 ?
transitions.reduce((sum, t) => sum + t.adjPertumbuhan, 0) / transitions.length : 0;
const avgAdjSelisih = transitions.length > 0 ?
Math.round(transitions.reduce((sum, t) => sum + t.adjSelisih, 0) / transitions.length) : 0;
const avgColor = avgAdjPertumbuhan >= 0 ? 'emerald' : 'red';
const avgIcon = avgAdjPertumbuhan >= 0 ? '📈' : '📉';
// Total keseluruhan (tahun pertama vs terakhir)
const firstYear = YEARS[0],
lastYear = YEARS[YEARS.length - 1];
const overallAdjSel = yearTotalsAdj[lastYear] - yearTotalsAdj[firstYear];
const overallAdjPert = yearTotalsAdj[firstYear] > 0 ? ((overallAdjSel) / yearTotalsAdj[firstYear] * 100) : 0;
let cardsHtml = '';
// Card 1: Total per tahun
cardsHtml += `<div class="glass-card p-5 rounded-2xl shadow-sm border-l-4 border-blue-500 fade-in">
<p class="text-[10px] font-bold text-slate-500 uppercase mb-3">Total Jurnal per Tahun (Adjusted)</p>
<div class="space-y-1.5">
${YEARS.map(y => `<div class="flex justify-between items-center"><span class="text-sm font-semibold text-slate-600">${y}</span><span class="text-lg font-extrabold text-slate-800">${yearTotalsAdj[y].toLocaleString()}</span></div>`).join('')}
</div>
</div>`;
// Card 2: Rata-rata pertumbuhan per tahun
cardsHtml += `<div class="glass-card p-5 rounded-2xl shadow-sm border-l-4 border-${avgColor}-500 fade-in">
<div class="flex items-center justify-between mb-2">
<p class="text-[10px] font-bold text-slate-500 uppercase">Rata-rata Pertumbuhan / Tahun</p>
<span class="text-xl">${avgIcon}</span>
</div>
<div class="flex items-baseline gap-2">
<span class="text-3xl font-extrabold ${avgAdjPertumbuhan >= 0 ? 'text-green-600' : 'text-red-600'}">${avgAdjPertumbuhan >= 0 ? '+' : ''}${avgAdjPertumbuhan.toFixed(1)}%</span>
</div>
<p class="text-xs text-slate-500 mt-1">Rata-rata ${avgAdjSelisih >= 0 ? '+' : ''}${avgAdjSelisih} jurnal/tahun</p>
<div class="mt-3 pt-3 border-t border-slate-100 space-y-1">
${transitions.map(t => {
const c = t.adjPertumbuhan >= 0 ? 'text-green-600' : 'text-red-600';
return `<div class="flex justify-between items-center text-xs"><span class="text-slate-500">${t.from}→${t.to}</span><span class="font-bold ${c}">${t.adjPertumbuhan >= 0 ? '+' : ''}${t.adjPertumbuhan.toFixed(1)}% <span class="text-slate-400 font-normal">(${t.adjSelisih >= 0 ? '+' : ''}${t.adjSelisih})</span></span></div>`;
}).join('')}
</div>
</div>`;
// Card 3: Pertumbuhan kumulatif (tahun pertama → terakhir)
const kumColor = overallAdjPert >= 0 ? 'purple' : 'red';
cardsHtml += `<div class="glass-card p-5 rounded-2xl shadow-sm border-l-4 border-${kumColor}-500 fade-in">
<div class="flex items-center justify-between mb-2">
<p class="text-[10px] font-bold text-slate-500 uppercase">Kumulatif ${firstYear} → ${lastYear}</p>
<span class="text-xl">🎯</span>
</div>
<div class="flex items-baseline gap-2">
<span class="text-3xl font-extrabold ${overallAdjPert >= 0 ? 'text-purple-600' : 'text-red-600'}">${overallAdjPert >= 0 ? '+' : ''}${overallAdjPert.toFixed(1)}%</span>
</div>
<p class="text-xs text-slate-500 mt-1">${yearTotalsAdj[firstYear]} → ${yearTotalsAdj[lastYear]} (${overallAdjSel >= 0 ? '+' : ''}${overallAdjSel} jurnal)</p>
<p class="text-[9px] text-slate-400 mt-2">${allCats.length} kategori dari ${YEARS.length} tahun</p>
</div>`;
cardsEl.innerHTML = cardsHtml;
// ===== POLICY NOTE =====
const policyContainer = document.getElementById('policyNoteContainer');
// Collect all unique discontinued categories across all transitions
const allDiscNames = [...new Set(transitions.flatMap(t => t.discNames))];
const allDiscJurnals = {};
transitions.forEach(t => {
t.discNames.forEach((name, idx) => {
// find jurnal count for this name in this transition
const cat = name;
const vFrom = yearData[t.from][cat] || 0;
if (!allDiscJurnals[cat]) allDiscJurnals[cat] = {
firstYear: t.from,
count: vFrom
};
});
});
if (allDiscNames.length > 0) {
policyContainer.innerHTML = `<div class="glass-card p-4 rounded-2xl shadow-sm border-l-4 border-amber-400 fade-in bg-amber-50/50">
<div class="flex items-start gap-3">
<span class="text-2xl mt-0.5">📋</span>
<div>
<p class="text-sm font-bold text-amber-800">Catatan Perubahan Kebijakan</p>
<p class="text-xs text-amber-700 mt-1">Kategori <strong>${allDiscNames.join(', ')}</strong> dihentikan pada tahun-tahun berikutnya. Ini merupakan <strong>perubahan kebijakan untuk peningkatan kualitas artikel</strong>, bukan penurunan performa. Kategori tersebut <strong>tidak dihitung</strong> dalam angka pertumbuhan adjusted.</p>
</div>
</div>
</div>`;
} else {
policyContainer.innerHTML = '';
}
// ===== DESTROY OLD CHARTS =====
['trendLineChart', 'yoyCategoryChart', 'yoyDetailCompare', 'yoyDetailDiff', 'facultyIntlChart',
'facultyNatlChart', 'pengusulCountChart', 'pengusulAvgChart', 'pengusulIntlNatlChart', 'intlQ1Q4Chart',
'natlS1S2Chart'
].forEach(id => {
const c = Chart.getChart(id);
if (c) c.destroy();
});
// ===== TREND LINE CHART =====
new Chart(document.getElementById('trendLineChart'), {
type: 'line',
data: {
labels: YEARS.map(String),
datasets: [{
label: 'Total (Raw)',
data: YEARS.map(y => yearTotals[y]),
borderColor: '#94a3b8',
backgroundColor: 'rgba(148,163,184,0.05)',
borderDash: [5, 5],
fill: false,
tension: 0.3,
pointBackgroundColor: '#94a3b8',
pointRadius: 5,
borderWidth: 2
},
{
label: 'Total (Adjusted)',
data: YEARS.map(y => yearTotalsAdj[y]),
borderColor: '#7c3aed',
backgroundColor: 'rgba(124,58,237,0.1)',
fill: true,
tension: 0.3,
pointBackgroundColor: '#7c3aed',
pointRadius: 6,
pointHoverRadius: 9,
borderWidth: 3
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top'
},
tooltip: {
callbacks: {
label: ctx => ctx.dataset.label + ': ' + ctx.parsed.y + ' jurnal'
}
}
},
scales: {
y: {
beginAtZero: true
}
}
}
});
// ===== GROUPED BAR CHART: Kategori x Tahun =====
const yearColors = ['#3b82f6', '#22c55e', '#f59e0b', '#ef4444', '#8b5cf6'];
const datasets = YEARS.map((y, yi) => ({
label: String(y),
data: allCats.map(c => yearData[y][c] || 0),
backgroundColor: yearColors[yi % yearColors.length],
borderRadius: 4
}));
new Chart(document.getElementById('yoyCategoryChart'), {
type: 'bar',
data: {
labels: allCats,
datasets
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top'
}
},
scales: {
y: {
beginAtZero: true
},
x: {
ticks: {
maxRotation: 45,
minRotation: 20,
font: {
size: 10
}
}
}
}
}
});
// ===== INTL Q1-Q4 LINE CHART =====
const intlCats = ['Internasional Q1', 'Internasional Q2', 'Internasional Q3', 'Internasional Q4'];
const intlColors = ['#1e40af', '#3b82f6', '#60a5fa', '#93c5fd'];
const intlDatasets = intlCats.map((cat, ci) => ({
label: cat.replace('Internasional ', ''),
data: YEARS.map(y => yearData[y][cat] || 0),
borderColor: intlColors[ci],
backgroundColor: intlColors[ci] + '15',
fill: false,
tension: 0.3,
pointBackgroundColor: intlColors[ci],
pointRadius: 6,
pointHoverRadius: 9,
borderWidth: 3
}));
// Add total line
intlDatasets.push({
label: 'Total Q1–Q4',
data: YEARS.map(y => intlCats.reduce((sum, cat) => sum + (yearData[y][cat] || 0), 0)),
borderColor: '#0f172a',
backgroundColor: 'rgba(15,23,42,0.05)',
fill: false,
tension: 0.3,
borderWidth: 3,
borderDash: [6, 3],
pointBackgroundColor: '#0f172a',
pointRadius: 6,
pointHoverRadius: 9
});
new Chart(document.getElementById('intlQ1Q4Chart'), {
type: 'line',
data: {
labels: YEARS.map(String),
datasets: intlDatasets
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom',
labels: {
boxWidth: 12,
font: {
size: 10
}
}
},
tooltip: {
callbacks: {
label: ctx => ctx.dataset.label + ': ' + ctx.parsed.y + ' jurnal'
}
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Jumlah Artikel'
}
}
}
}
});
// ===== NATL S1-S2 LINE CHART =====
const natlCats = ['Nasional S1', 'Nasional S2'];
const natlColors = ['#16a34a', '#4ade80'];
const natlLineDatasets = natlCats.map((cat, ci) => ({
label: cat.replace('Nasional ', ''),
data: YEARS.map(y => yearData[y][cat] || 0),
borderColor: natlColors[ci],
backgroundColor: natlColors[ci] + '15',
fill: false,
tension: 0.3,
pointBackgroundColor: natlColors[ci],
pointRadius: 6,
pointHoverRadius: 9,
borderWidth: 3
}));
// Add total line
natlLineDatasets.push({
label: 'Total S1+S2',
data: YEARS.map(y => natlCats.reduce((sum, cat) => sum + (yearData[y][cat] || 0), 0)),
borderColor: '#0f172a',
backgroundColor: 'rgba(15,23,42,0.05)',
fill: false,
tension: 0.3,
borderWidth: 3,
borderDash: [6, 3],
pointBackgroundColor: '#0f172a',
pointRadius: 6,
pointHoverRadius: 9
});
new Chart(document.getElementById('natlS1S2Chart'), {
type: 'line',
data: {
labels: YEARS.map(String),
datasets: natlLineDatasets
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom',
labels: {
boxWidth: 12,
font: {
size: 10
}
}
},
tooltip: {
callbacks: {
label: ctx => ctx.dataset.label + ': ' + ctx.parsed.y + ' jurnal'
}
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Jumlah Artikel'
}
}
}
}
});
// ===== MASTER TABLE =====
const thead = document.getElementById('growthTableHead');
let headHtml =
'<tr><th class="px-4 py-3 text-xs font-bold text-purple-800 uppercase sticky left-0 bg-purple-50">Kategori</th>';
YEARS.forEach(y => {
headHtml +=
`<th class="px-3 py-3 text-xs font-bold text-purple-800 uppercase text-center">${y}</th>`;
});
transitions.forEach(t => {
headHtml +=
`<th class="px-3 py-3 text-xs font-bold text-purple-800 uppercase text-center bg-purple-100/50">${t.from}→${t.to}</th>`;
});
headHtml += '</tr>';
thead.innerHTML = headHtml;
const tbody = document.getElementById('growthTableBody');
tbody.innerHTML = '';
allCats.forEach(cat => {
const isDisc = isDiscontinued(cat);
let rowHtml =
`<td class="px-4 py-3 font-semibold text-slate-700 sticky left-0 bg-white whitespace-nowrap">${cat}`;
// Check if this cat was discontinued in any transition
let wasDiscontinued = false;
transitions.forEach(t => {
const vF = yearData[t.from][cat] || 0;
const vT = yearData[t.to][cat] || 0;
if (isDisc && vF > 0 && vT === 0) wasDiscontinued = true;
});
if (wasDiscontinued) rowHtml +=
'<div class="text-[9px] text-amber-600">Kebijakan peningkatan kualitas</div>';
rowHtml += '</td>';
// Year columns
YEARS.forEach(y => {
const v = yearData[y][cat] || 0;
rowHtml +=
`<td class="px-3 py-3 text-center">${v > 0 ? v : '<span class="text-slate-300">—</span>'}</td>`;
});
// Transition columns
transitions.forEach(t => {
const vF = yearData[t.from][cat] || 0;
const vT = yearData[t.to][cat] || 0;
const sel = vT - vF;
if (isDisc && vF > 0 && vT === 0) {
rowHtml +=
`<td class="px-3 py-3 text-center bg-amber-50"><span class="text-[10px] bg-amber-100 text-amber-800 px-2 py-0.5 rounded-full font-bold">📋</span></td>`;
} else if (vF === 0 && vT > 0) {
rowHtml +=
`<td class="px-3 py-3 text-center bg-green-50"><span class="text-[10px] bg-green-100 text-green-700 px-1.5 py-0.5 rounded-full font-bold">+${vT}</span></td>`;
} else if (vF > 0 && vT === 0) {
rowHtml +=
`<td class="px-3 py-3 text-center bg-red-50"><span class="text-[10px] bg-red-100 text-red-700 px-1.5 py-0.5 rounded-full font-bold">${sel}</span></td>`;
} else if (vF === 0 && vT === 0) {
rowHtml += `<td class="px-3 py-3 text-center text-slate-300">—</td>`;
} else {
const cls = sel > 0 ? 'positive' : sel < 0 ? 'negative' : 'neutral';
const pct = vF > 0 ? ((sel / vF) * 100).toFixed(1) : '0.0';
rowHtml +=
`<td class="px-3 py-3 text-center"><span class="${cls} text-xs">${sel >= 0 ? '+' : ''}${sel}</span><br><span class="text-[9px] ${cls}">${sel >= 0 ? '+' : ''}${pct}%</span></td>`;
}
});
const rowBg = wasDiscontinued ? 'bg-amber-50/30' : '';
tbody.innerHTML += `<tr class="hover:bg-purple-50/30 transition-colors ${rowBg}">${rowHtml}</tr>`;
});
// Total rows
// Raw total
let totalRowHtml = '<td class="px-4 py-3 font-bold text-slate-700 sticky left-0 bg-slate-50">TOTAL (Raw)</td>';
YEARS.forEach(y => {
totalRowHtml += `<td class="px-3 py-3 text-center font-bold bg-slate-50">${yearTotals[y]}</td>`;
});
transitions.forEach(t => {
const sel = t.selisih;
const cls = sel >= 0 ? 'positive' : 'negative';
totalRowHtml +=
`<td class="px-3 py-3 text-center bg-slate-100"><span class="${cls} text-xs font-bold">${sel >= 0 ? '+' : ''}${sel}</span><br><span class="text-[9px] ${cls}">${t.pertumbuhan >= 0 ? '+' : ''}${t.pertumbuhan.toFixed(1)}%</span></td>`;
});
tbody.innerHTML += `<tr class="border-t-2 border-slate-300">${totalRowHtml}</tr>`;
// Adjusted total
let adjRowHtml =
'<td class="px-4 py-3 font-bold text-purple-800 sticky left-0 bg-purple-50">TOTAL (Adjusted)<div class="text-[9px] font-normal text-purple-500">Tanpa kategori kebijakan</div></td>';
YEARS.forEach(y => {
adjRowHtml +=
`<td class="px-3 py-3 text-center font-bold bg-purple-50 text-purple-800">${yearTotalsAdj[y]}</td>`;
});
transitions.forEach(t => {
const cls = t.adjSelisih >= 0 ? 'positive' : 'negative';
adjRowHtml +=
`<td class="px-3 py-3 text-center bg-purple-100/50"><span class="${cls} text-xs font-bold">${t.adjSelisih >= 0 ? '+' : ''}${t.adjSelisih}</span><br><span class="text-[9px] ${cls}">${t.adjPertumbuhan >= 0 ? '+' : ''}${t.adjPertumbuhan.toFixed(1)}%</span></td>`;
});
tbody.innerHTML += `<tr class="border-t-2 border-purple-300">${adjRowHtml}</tr>`;
// ===== DETAIL BUTTONS =====
const btnContainer = document.getElementById('yoyDetailButtons');
btnContainer.innerHTML = transitions.map((t, i) =>
`<button class="period-btn px-4 py-2 rounded-xl text-sm font-semibold border border-purple-200 bg-white text-purple-600 ${i === 0 ? 'active' : ''}" onclick="renderYoyDetail(${i})" data-yoy="${i}">${t.from} → ${t.to}</button>`
).join('');
// Render first detail
if (!currentYoyDetail || currentYoyDetail >= transitions.length) currentYoyDetail = 0;
renderYoyDetail(currentYoyDetail);
// ===== RENDER FACULTY CONTRIBUTION: INTL vs NATL =====
renderFacultyContribCharts();
renderPengusulCharts();
}
function renderYoyDetail(idx) {
currentYoyDetail = idx;
// Update active button
document.querySelectorAll('#yoyDetailButtons .period-btn').forEach((btn, i) => {
btn.classList.toggle('active', i === idx);
});
const yearFrom = YEARS[idx],
yearTo = YEARS[idx + 1];
const countsFrom = getCategoryCountsForYear(yearFrom);
const countsTo = getCategoryCountsForYear(yearTo);
const allCats = [...new Set([...Object.keys(countsFrom), ...Object.keys(countsTo)])].sort();
const dataFrom = allCats.map(c => countsFrom[c] || 0);
const dataTo = allCats.map(c => countsTo[c] || 0);
const dataSelisih = allCats.map((_, i) => dataTo[i] - dataFrom[i]);
// Color selisih bars: amber for discontinued policy, green/red for others
const selisihColors = allCats.map((cat, i) => {
const isDisc = isDiscontinued(cat);
if (isDisc && dataFrom[i] > 0 && dataTo[i] === 0) return '#f59e0b'; // amber for policy
return dataSelisih[i] >= 0 ? '#22c55e' : '#ef4444';
});
['yoyDetailCompare', 'yoyDetailDiff'].forEach(id => {
const c = Chart.getChart(id);
if (c) c.destroy();
});
new Chart(document.getElementById('yoyDetailCompare'), {
type: 'bar',
data: {
labels: allCats,
datasets: [{
label: String(yearFrom),
data: dataFrom,
backgroundColor: '#3b82f6',
borderRadius: 6
},
{
label: String(yearTo),
data: dataTo,
backgroundColor: '#22c55e',
borderRadius: 6
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top'
},
title: {
display: true,
text: `Perbandingan ${yearFrom} vs ${yearTo}`
}
},
scales: {
y: {
beginAtZero: true
},
x: {
ticks: {
maxRotation: 45,
minRotation: 20,
font: {
size: 10
}
}
}
}
}
});
new Chart(document.getElementById('yoyDetailDiff'), {
type: 'bar',
data: {
labels: allCats,
datasets: [{
label: 'Selisih',
data: dataSelisih,
backgroundColor: selisihColors,
borderRadius: 6
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
},
title: {
display: true,
text: `Selisih ${yearFrom} → ${yearTo} (kuning = kebijakan)`
}
},
scales: {
y: {
grid: {
color: 'rgba(0,0,0,0.05)'
}
},
x: {
ticks: {
maxRotation: 45,
minRotation: 20,
font: {
size: 10
}
}
}
}
}
});
}
// =====================================================
// FACULTY CONTRIB: INTL vs NATL per Year
// =====================================================
function isInternational(catName) {
return String(catName).toLowerCase().startsWith('internasional');
}
function isNationalAdj(catName) {
const n = String(catName).toLowerCase();
return n.startsWith('nasional') && !isDiscontinued(catName);
}
function getFacultyIntlNatlForYear(year) {
const periodeIds = PERIODES.filter(p => p.year === year).map(p => p.id);
const facData = {}; // { facultyName: { intl: count, natl: count } }
periodeIds.forEach(id => {
if (!allPeriodeData[id]) return;
const items = extractKategoriItems(allPeriodeData[id]);
items.forEach(item => {
if (!item.kategori || !Array.isArray(item.kategori)) return;
item.kategori.forEach(cat => {
const catName = cat.kategori || "Tanpa Kategori";
const catIsIntl = isInternational(catName);
const catIsNatl = isNationalAdj(catName);
if (!catIsIntl && !catIsNatl) return; // skip S3-S6
if (cat.jurnals && Array.isArray(cat.jurnals)) {
cat.jurnals.forEach(jurnal => {
const uniqueFac = new Set();
if (jurnal.authors && Array.isArray(jurnal.authors)) {
jurnal.authors.forEach(author => {
if (!author.nip) return;
const fac = detectFaculty(author);
uniqueFac.add(fac);
});
}
uniqueFac.forEach(fac => {
if (!facData[fac]) facData[fac] = {
intl: 0,
natl: 0
};
if (catIsIntl) facData[fac].intl++;
if (catIsNatl) facData[fac].natl++;
});
});
}
});
});
});
return facData;
}
function renderFacultyContribCharts() {
// Collect data per year
const yearFacData = {};
YEARS.forEach(y => {
yearFacData[y] = getFacultyIntlNatlForYear(y);
});
// All faculties across all years
const allFacs = new Set();
YEARS.forEach(y => Object.keys(yearFacData[y]).forEach(f => allFacs.add(f)));
// Sort by total intl+natl descending
const facTotals = {};
allFacs.forEach(f => {
facTotals[f] = 0;
YEARS.forEach(y => {
const d = yearFacData[y][f];
if (d) facTotals[f] += d.intl + d.natl;
});
});
const sortedFacs = [...allFacs].sort((a, b) => facTotals[b] - facTotals[a]);
// Top 12 to keep charts readable
const topFacs = sortedFacs.slice(0, 12);
const yearColors = ['#3b82f6', '#22c55e', '#f59e0b', '#ef4444', '#8b5cf6'];
// ===== INTL Chart =====
const intlDatasets = YEARS.map((y, yi) => ({
label: String(y),
data: topFacs.map(f => (yearFacData[y][f] ? yearFacData[y][f].intl : 0)),
backgroundColor: yearColors[yi % yearColors.length],
borderRadius: 4
}));
new Chart(document.getElementById('facultyIntlChart'), {
type: 'bar',
data: {
labels: topFacs.map(f => f.length > 25 ? f.substring(0, 23) + '…' : f),
datasets: intlDatasets
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top'
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Jumlah Artikel'
}
},
x: {
ticks: {
maxRotation: 45,
minRotation: 20,
font: {
size: 9
}
}
}
}
}
});
// ===== NATL Chart =====
const natlDatasets = YEARS.map((y, yi) => ({
label: String(y),
data: topFacs.map(f => (yearFacData[y][f] ? yearFacData[y][f].natl : 0)),
backgroundColor: yearColors[yi % yearColors.length],
borderRadius: 4
}));
new Chart(document.getElementById('facultyNatlChart'), {
type: 'bar',
data: {
labels: topFacs.map(f => f.length > 25 ? f.substring(0, 23) + '…' : f),
datasets: natlDatasets
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top'
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Jumlah Artikel'
}
},
x: {
ticks: {
maxRotation: 45,
minRotation: 20,
font: {
size: 9
}
}
}
}
}
});
// ===== FACULTY TABLE =====
const thead = document.getElementById('facultyGrowthHead');
let headHtml =
'<tr><th class="px-4 py-3 text-xs font-bold text-emerald-800 uppercase sticky left-0 bg-emerald-50" rowspan="2">Fakultas</th>';
YEARS.forEach(y => {
headHtml +=
`<th class="px-3 py-3 text-xs font-bold text-emerald-800 uppercase text-center border-l border-emerald-200" colspan="2">${y}</th>`;
});
headHtml +=
'<th class="px-3 py-3 text-xs font-bold text-emerald-800 uppercase text-center border-l border-emerald-200" colspan="2">Total</th></tr><tr>';
YEARS.forEach(() => {
headHtml +=
'<th class="px-2 py-2 text-[10px] font-bold text-blue-600 text-center">Intl</th><th class="px-2 py-2 text-[10px] font-bold text-green-600 text-center">Natl</th>';
});
headHtml +=
'<th class="px-2 py-2 text-[10px] font-bold text-blue-600 text-center border-l border-emerald-200">Intl</th><th class="px-2 py-2 text-[10px] font-bold text-green-600 text-center">Natl</th></tr>';
thead.innerHTML = headHtml;
const tbody = document.getElementById('facultyGrowthBody');
let bodyHtml = '';
let totIntlPerYear = {},
totNatlPerYear = {};
YEARS.forEach(y => {
totIntlPerYear[y] = 0;
totNatlPerYear[y] = 0;
});
let grandIntl = 0,
grandNatl = 0;
sortedFacs.forEach(fac => {
let rowIntl = 0,
rowNatl = 0;
let cells =
`<td class="px-4 py-3 font-semibold text-slate-700 sticky left-0 bg-white whitespace-nowrap text-xs">${fac}</td>`;
YEARS.forEach(y => {
const d = yearFacData[y][fac] || {
intl: 0,
natl: 0
};
cells +=
`<td class="px-2 py-3 text-center text-xs border-l border-slate-50">${d.intl || '<span class="text-slate-300">—</span>'}</td>`;
cells +=
`<td class="px-2 py-3 text-center text-xs">${d.natl || '<span class="text-slate-300">—</span>'}</td>`;
rowIntl += d.intl;
rowNatl += d.natl;
totIntlPerYear[y] += d.intl;
totNatlPerYear[y] += d.natl;
});
grandIntl += rowIntl;
grandNatl += rowNatl;
cells +=
`<td class="px-2 py-3 text-center text-xs font-bold text-blue-700 border-l border-emerald-200">${rowIntl}</td>`;
cells += `<td class="px-2 py-3 text-center text-xs font-bold text-green-700">${rowNatl}</td>`;
bodyHtml += `<tr class="hover:bg-emerald-50/30 transition-colors">${cells}</tr>`;
});
// Total row
let totCells = '<td class="px-4 py-3 font-bold text-slate-700 sticky left-0 bg-slate-50 text-xs">TOTAL</td>';
YEARS.forEach(y => {
totCells +=
`<td class="px-2 py-3 text-center text-xs font-bold bg-slate-50 border-l border-slate-100">${totIntlPerYear[y]}</td>`;
totCells +=
`<td class="px-2 py-3 text-center text-xs font-bold bg-slate-50">${totNatlPerYear[y]}</td>`;
});
totCells +=
`<td class="px-2 py-3 text-center text-xs font-extrabold text-blue-800 bg-slate-50 border-l border-emerald-200">${grandIntl}</td>`;
totCells +=
`<td class="px-2 py-3 text-center text-xs font-extrabold text-green-800 bg-slate-50">${grandNatl}</td>`;
bodyHtml += `<tr class="border-t-2 border-slate-300">${totCells}</tr>`;
tbody.innerHTML = bodyHtml;
}
// =====================================================
// PENGUSUL CHARTS: Unik, Produktivitas, Intl vs Natl
// =====================================================
function getPengusulDataForYear(year) {
const periodeIds = PERIODES.filter(p => p.year === year).map(p => p.id);
const allNips = new Set();
const intlNips = new Set();
const natlNips = new Set();
periodeIds.forEach(id => {
if (!allPeriodeData[id]) return;
const items = extractKategoriItems(allPeriodeData[id]);
items.forEach(item => {
if (!item.kategori || !Array.isArray(item.kategori)) return;
item.kategori.forEach(cat => {
const catName = cat.kategori || "Tanpa Kategori";
const catIsIntl = isInternational(catName);
const catIsNatl = isNationalAdj(catName);
// skip discontinued S3-S6
if (!catIsIntl && !catIsNatl) return;
if (cat.jurnals && Array.isArray(cat.jurnals)) {
cat.jurnals.forEach(jurnal => {
if (jurnal.authors && Array.isArray(jurnal.authors)) {
jurnal.authors.forEach(author => {
if (!author.nip) return;
allNips.add(author.nip);
if (catIsIntl) intlNips.add(author.nip);
if (catIsNatl) natlNips.add(author.nip);
});
}
});
}
});
});
});
return {
total: allNips.size,
intl: intlNips.size,
natl: natlNips.size
};
}
function renderPengusulCharts() {
const pengusulPerYear = {};
YEARS.forEach(y => {
pengusulPerYear[y] = getPengusulDataForYear(y);
});
// Adjusted totals per year (reuse from yearTotalsAdj in parent scope — recalculate here)
const yearData = {};
YEARS.forEach(y => {
yearData[y] = getCategoryCountsForYear(y);
});
const allCatsSet = new Set();
YEARS.forEach(y => Object.keys(yearData[y]).forEach(c => allCatsSet.add(c)));
const allCats = [...allCatsSet];
const yearTotalsAdj = {};
YEARS.forEach(y => {
let adj = 0;
allCats.forEach(cat => {
const val = yearData[y][cat] || 0;
const isDisc = isDiscontinued(cat);
const lastYear = YEARS[YEARS.length - 1];
const goneInLatest = (yearData[lastYear][cat] || 0) === 0;
if (isDisc && goneInLatest) {
/* skip */ } else {
adj += val;
}
});
yearTotalsAdj[y] = adj;
});
const counts = YEARS.map(y => pengusulPerYear[y].total);
const avgs = YEARS.map(y => pengusulPerYear[y].total > 0 ? (yearTotalsAdj[y] / pengusulPerYear[y].total) : 0);
const intls = YEARS.map(y => pengusulPerYear[y].intl);
const natls = YEARS.map(y => pengusulPerYear[y].natl);
// Chart 1: Jumlah Pengusul Unik
new Chart(document.getElementById('pengusulCountChart'), {
type: 'bar',
data: {
labels: YEARS.map(String),
datasets: [{
label: 'Pengusul Unik',
data: counts,
backgroundColor: '#8b5cf6',
borderRadius: 8
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
},
tooltip: {
callbacks: {
label: ctx => ctx.parsed.y + ' pengusul'
}
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Jumlah Pengusul'
}
}
}
}
});
// Chart 2: Rata-rata Artikel per Pengusul
new Chart(document.getElementById('pengusulAvgChart'), {
type: 'line',
data: {
labels: YEARS.map(String),
datasets: [{
label: 'Rata-rata Artikel/Pengusul',
data: avgs,
borderColor: '#f59e0b',
backgroundColor: 'rgba(245,158,11,0.1)',
fill: true,
tension: 0.3,
pointBackgroundColor: '#f59e0b',
pointRadius: 7,
pointHoverRadius: 10,
borderWidth: 3
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
},
tooltip: {
callbacks: {
label: ctx => ctx.parsed.y.toFixed(2) + ' artikel/pengusul'
}
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Rata-rata Artikel'
}
}
}
}
});
// Chart 3: Pengusul Intl vs Natl
new Chart(document.getElementById('pengusulIntlNatlChart'), {
type: 'bar',
data: {
labels: YEARS.map(String),
datasets: [{
label: 'Internasional',
data: intls,
backgroundColor: '#3b82f6',
borderRadius: 6
},
{
label: 'Nasional (S1+S2)',
data: natls,
backgroundColor: '#22c55e',
borderRadius: 6
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top'
},
tooltip: {
callbacks: {
label: ctx => ctx.dataset.label + ': ' + ctx.parsed.y + ' pengusul'
}
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Jumlah Pengusul Unik'
}
}
}
}
});
}
// =====================================================
// HELPER: Extract kategori dari raw data
// =====================================================
function extractKategoriItems(rawData) {
let items = [];
if (Array.isArray(rawData)) {
items = rawData;
} else if (rawData && rawData.kategori && Array.isArray(rawData.kategori)) {
items = [rawData];
} else if (rawData && rawData.data) {
if (Array.isArray(rawData.data)) items = rawData.data;
else if (rawData.data.kategori) items = [rawData.data];
}
return items;
}
// Hitung jumlah per kategori untuk satu tahun
function getCategoryCountsForYear(year) {
const periodeIds = PERIODES.filter(p => p.year === year).map(p => p.id);
const catCount = {};
periodeIds.forEach(id => {
if (!allPeriodeData[id]) return;
const items = extractKategoriItems(allPeriodeData[id]);
items.forEach(item => {
if (!item.kategori || !Array.isArray(item.kategori)) return;
item.kategori.forEach(cat => {
const name = cat.kategori || "Tanpa Kategori";
const count = parseInt(cat.total_jurnal) || 0;
catCount[name] = (catCount[name] || 0) + count;
});
});
});
return catCount;
}
// =====================================================
// DETEKSI FAKULTAS
// =====================================================
function detectFaculty(author) {
return (author.unit && author.unit.trim()) ? author.unit.trim() : 'Lainnya / Tidak Terdata';
}
// =====================================================
// PROSES DATA (Dashboard Tab)
// =====================================================
function getSelectedRawData() {
if (currentPeriode === 'all') return Object.values(allPeriodeData);
const data = allPeriodeData[currentPeriode];
return data ? [data] : [];
}
function processData(rawDataArray) {
let dataToProcess = [];
rawDataArray.forEach(rawData => {
const items = extractKategoriItems(rawData);
dataToProcess.push(...items);
});
if (dataToProcess.length === 0) throw new Error("Data kosong atau format tidak dikenali.");
const authorMap = {},
globalCatCount = {},
facultyStats = {};
let globalTotal = 0;
dataToProcess.forEach(periode => {
if (!periode.kategori || !Array.isArray(periode.kategori)) return;
periode.kategori.forEach(cat => {
const catName = cat.kategori || "Tanpa Kategori";
const catTotal = parseInt(cat.total_jurnal) || 0;
globalCatCount[catName] = (globalCatCount[catName] || 0) + catTotal;
globalTotal += catTotal;
if (cat.jurnals && Array.isArray(cat.jurnals)) {
cat.jurnals.forEach(jurnal => {
const uniqueFac = new Set();
if (jurnal.authors && Array.isArray(jurnal.authors)) {
jurnal.authors.forEach(author => {
if (!author.nip) return;
const faculty = detectFaculty(author);
uniqueFac.add(faculty);
if (!facultyStats[faculty]) facultyStats[faculty] = {
name: faculty,
totalArticles: 0,
totalAuthors: 0,
categories: {}
};
if (!facultyStats[faculty].categories[catName])
facultyStats[faculty].categories[catName] = {
articles: 0,
authors: 0
};
facultyStats[faculty].categories[catName].authors++;
facultyStats[faculty].totalAuthors++;
if (!authorMap[author.nip]) authorMap[author.nip] = {
nip: author.nip,
nama: author.nama || "Tanpa Nama",
faculty,
counts: {},
total: 0
};
authorMap[author.nip].counts[catName] = (authorMap[
author.nip].counts[catName] || 0) + 1;
authorMap[author.nip].total++;
});
}
uniqueFac.forEach(faculty => {
if (!facultyStats[faculty]) facultyStats[faculty] = {
name: faculty,
totalArticles: 0,
totalAuthors: 0,
categories: {}
};
if (!facultyStats[faculty].categories[catName])
facultyStats[faculty].categories[catName] = {
articles: 0,
authors: 0
};
facultyStats[faculty].categories[catName].articles++;
facultyStats[faculty].totalArticles++;
});
});
}
});
});
const categories = Object.keys(globalCatCount).map(key => ({
kategori: key,
total_jurnal: globalCatCount[key]
})).sort((a, b) => b.total_jurnal - a.total_jurnal);
const sortedFacultyStats = Object.values(facultyStats).sort((a, b) => b.totalArticles - a.totalArticles);
return {
categories,
globalTotal,
authorMap,
globalCatCount,
facultyStats: sortedFacultyStats
};
}
// =====================================================
// REBUILD DASHBOARD (Tab 1)
// =====================================================
function rebuildDashboard() {
try {
const rawDataArray = getSelectedRawData();
if (rawDataArray.length === 0) return;
dashboardData = processData(rawDataArray);
renderSummaryCards();
renderCategoryTable();
renderFacultyAnalysis();
renderChampions();
renderAuthorTable();
renderCharts();
} catch (err) {
console.error(err);
}
}
// =====================================================
// DASHBOARD RENDER FUNCTIONS (Tab 1)
// =====================================================
function renderSummaryCards() {
const el = document.getElementById('summaryCards');
if (!el) return;
const stats = [{
label: 'Total Jurnal',
value: dashboardData.globalTotal,
icon: '📚',
color: 'blue'
},
{
label: 'Fakultas Terdata',
value: dashboardData.facultyStats.length,
icon: '🏛️',
color: 'emerald'
},
{
label: 'Total Penulis',
value: Object.keys(dashboardData.authorMap).length,
icon: '👥',
color: 'amber'
},
{
label: 'Top Kategori',
value: dashboardData.categories[0]?.kategori || '-',
icon: '🏆',
color: 'purple'
}
];
el.innerHTML = stats.map(s =>
`<div class="glass-card p-6 rounded-2xl shadow-sm border-l-4 border-${s.color}-500 fade-in"><div class="flex items-center justify-between"><div><p class="text-[10px] font-bold text-slate-500 uppercase tracking-wider">${s.label}</p><h4 class="text-xl font-bold text-slate-800">${s.value}</h4></div><span class="text-2xl">${s.icon}</span></div></div>`
).join('');
}
function renderCategoryTable() {
const el = document.getElementById('categoryTableBody');
el.innerHTML = '';
dashboardData.categories.forEach(cat => {
const pct = dashboardData.globalTotal > 0 ? ((cat.total_jurnal / dashboardData.globalTotal) * 100)
.toFixed(1) : 0;
el.innerHTML +=
`<tr><td class="px-6 py-4 font-semibold text-slate-700">${cat.kategori}</td><td class="px-6 py-4 text-center font-bold">${cat.total_jurnal}</td><td class="px-6 py-4"><div class="flex items-center justify-center gap-3"><div class="w-32 h-2 bg-slate-100 rounded-full overflow-hidden"><div class="h-full bg-blue-500" style="width: ${pct}%"></div></div><span class="text-xs font-bold text-slate-600">${pct}%</span></div></td></tr>`;
});
}
function renderFacultyAnalysis() {
const tbody = document.getElementById('facultyTableBody');
tbody.innerHTML = '';
dashboardData.facultyStats.forEach(fac => {
let bh = '<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">';
Object.keys(fac.categories).sort().forEach(cn => {
const s = fac.categories[cn];
const tc = dashboardData.globalCatCount[cn] || 1;
const pc = ((s.articles / tc) * 100).toFixed(1);
bh +=
`<div class="badge-faculty p-2 rounded-lg"><div class="text-[10px] font-bold uppercase opacity-70 mb-1">${cn}</div><div class="flex items-end justify-between"><div><span class="font-bold text-lg leading-none">${s.articles}</span><span class="text-[10px] text-green-600">Art.</span><span class="text-xs text-slate-400 mx-0.5">/</span><span class="text-sm font-medium text-slate-600">${s.authors}</span><span class="text-[10px] text-slate-400">Org</span></div><span class="text-[10px] bg-green-200 px-1.5 py-0.5 rounded font-bold text-green-800">${pc}%</span></div></div>`;
});
bh += '</div>';
tbody.innerHTML +=
`<tr class="hover:bg-green-50/30 transition-colors"><td class="px-6 py-4 font-bold text-slate-800 align-top">${fac.name}</td><td class="px-6 py-4 align-top">${bh}</td><td class="px-6 py-4 text-center align-top"><div class="font-bold text-lg text-green-700">${fac.totalArticles}</div><div class="text-[10px] text-slate-500 uppercase">Artikel</div></td><td class="px-6 py-4 text-center align-top"><div class="font-bold text-lg text-slate-600">${fac.totalAuthors}</div><div class="text-[10px] text-slate-400 uppercase">Penulis</div></td></tr>`;
});
const ctx = document.getElementById('facultyChart');
if (ctx) {
const c = Chart.getChart(ctx);
if (c) c.destroy();
new Chart(ctx, {
type: 'bar',
data: {
labels: dashboardData.facultyStats.map(f => f.name),
datasets: [{
label: 'Total Artikel',
data: dashboardData.facultyStats.map(f => f.totalArticles),
backgroundColor: '#10b981',
borderRadius: 6
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
}
},
scales: {
y: {
beginAtZero: true
}
}
}
});
}
const ctxP = document.getElementById('facultyPieChart');
if (ctxP) {
const c = Chart.getChart(ctxP);
if (c) c.destroy();
const pd = dashboardData.facultyStats.map(f => ((f.totalArticles / dashboardData.globalTotal) * 100)
.toFixed(1));
new Chart(ctxP, {
type: 'doughnut',
data: {
labels: dashboardData.facultyStats.map(f => f.name),
datasets: [{
data: pd,
backgroundColor: chartColors,
borderWidth: 2
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom',
labels: {
boxWidth: 12,
font: {
size: 10
}
}
},
tooltip: {
callbacks: {
label: ctx => ctx.label + ': ' + ctx.parsed + '%'
}
}
}
}
});
}
}
function renderChampions() {
const el = document.getElementById('championsContainer');
el.innerHTML = '';
dashboardData.categories.forEach(ci => {
const cn = ci.kategori,
tc = ci.total_jurnal;
let ta = null,
mac = 0;
Object.values(dashboardData.authorMap).forEach(a => {
const c = a.counts[cn] || 0;
if (c > mac) {
mac = c;
ta = a;
}
});
let tf = null,
mfc = 0;
dashboardData.facultyStats.forEach(f => {
const cs = f.categories[cn];
if (cs && cs.articles > mfc) {
mfc = cs.articles;
tf = f;
}
});
if (ta || tf) {
let ah = '',
fh = '';
if (ta) {
const ap = tc > 0 ? ((mac / tc) * 100).toFixed(1) : 0;
ah =
`<div class="mb-4 border-b border-slate-100 pb-3"><div class="flex items-center justify-between mb-1"><span class="text-[10px] font-bold text-slate-400 uppercase">Penulis Terbanyak</span><span class="text-xs font-bold text-blue-600 bg-blue-50 px-2 py-0.5 rounded-full">${mac} Artikel</span></div><div class="flex items-start gap-3"><div class="mt-1">🥇</div><div><p class="text-sm font-bold text-slate-800">${ta.nama}</p><p class="text-[10px] text-slate-400 font-mono">${ta.faculty}</p><div class="w-24 bg-slate-100 rounded-full h-1 mt-2"><div class="bg-yellow-400 h-1 rounded-full" style="width:${ap}%"></div></div><p class="text-[9px] text-slate-400 mt-0.5">${ap}%</p></div></div></div>`;
}
if (tf) {
const fp = tc > 0 ? ((mfc / tc) * 100).toFixed(1) : 0;
fh =
`<div class="pt-2"><div class="flex items-center justify-between mb-1"><span class="text-[10px] font-bold text-slate-400 uppercase">Fakultas Terbanyak</span><span class="text-xs font-bold text-green-600 bg-green-50 px-2 py-0.5 rounded-full">${mfc} Artikel</span></div><div class="flex items-start gap-3"><div class="mt-1 text-lg">🏛️</div><div class="flex-1"><p class="text-sm font-bold text-slate-800">${tf.name}</p><div class="w-full bg-slate-100 rounded-full h-1 mt-2"><div class="bg-green-500 h-1 rounded-full" style="width:${fp}%"></div></div><p class="text-[9px] text-slate-400 mt-0.5">${fp}%</p></div></div></div>`;
}
el.innerHTML +=
`<div class="glass-card p-5 rounded-2xl border-t-4 border-indigo-500 shadow-sm hover:shadow-md transition-all fade-in"><div class="flex justify-between items-center mb-4"><h4 class="text-sm font-black text-indigo-700 uppercase tracking-widest">${cn}</h4><span class="text-[10px] font-bold bg-slate-100 text-slate-500 px-2 py-1 rounded-lg">Total: ${tc}</span></div>${ah}${fh}</div>`;
}
});
}
function renderAuthorTable(filter = '') {
const el = document.getElementById('authorTableBody');
el.innerHTML = '';
const authors = Object.values(dashboardData.authorMap).filter(a => a.nama.toLowerCase().includes(filter
.toLowerCase()) || a.nip.includes(filter)).sort((a, b) => b.total - a.total);
if (!authors.length) {
el.innerHTML =
`<tr><td colspan="4" class="px-6 py-10 text-center text-slate-400 italic">Tidak ada penulis ditemukan...</td></tr>`;
return;
}
authors.slice(0, 100).forEach(a => {
const gp = dashboardData.globalTotal > 0 ? ((a.total / dashboardData.globalTotal) * 100).toFixed(
2) : 0;
let bh = '<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">';
Object.keys(a.counts).sort().forEach(cn => {
const ac = a.counts[cn],
tc = dashboardData.globalCatCount[cn] || 0,
pc = tc > 0 ? ((ac / tc) * 100).toFixed(1) : 0;
bh +=
`<div class="badge-fraction p-2 rounded-lg flex flex-col"><span class="text-[10px] font-bold uppercase text-blue-800 opacity-70">${cn}</span><div class="flex items-baseline gap-1"><span class="text-lg font-black">${ac}</span><span class="text-xs text-blue-400 font-bold">/ ${tc}</span><span class="ml-auto text-[10px] bg-blue-100 text-blue-700 px-1.5 py-0.5 rounded font-bold">${pc}%</span></div></div>`;
});
bh += '</div>';
el.innerHTML +=
`<tr class="hover:bg-blue-50/50 transition-colors border-b border-slate-50"><td class="px-6 py-4 align-top"><div class="font-bold text-slate-800">${a.nama}</div><div class="flex flex-wrap gap-2 mt-1"><span class="text-[10px] font-mono text-slate-400 bg-slate-100 px-1 rounded">${a.nip}</span><span class="text-[10px] font-bold text-green-700 bg-green-100 px-1 rounded">${a.faculty}</span></div></td><td class="px-6 py-4 align-top">${bh}</td><td class="px-6 py-4 text-center align-top"><div class="text-xl font-black text-slate-700">${a.total}</div><div class="text-[10px] text-slate-400 uppercase font-bold">Karya</div></td><td class="px-6 py-4 text-center align-top"><div class="inline-block bg-blue-600 text-white px-3 py-1 rounded-full text-xs font-black shadow-sm">${gp}%</div></td></tr>`;
});
}
function renderCharts() {
const labels = dashboardData.categories.map(k => k.kategori);
const vals = dashboardData.categories.map(k => k.total_jurnal);
const tot = dashboardData.globalTotal;
const pcts = vals.map(v => ((v / tot) * 100).toFixed(1));
['categoryBarChart', 'categoryPieChart', 'categoryPercentChart'].forEach(id => {
const c = Chart.getChart(id);
if (c) c.destroy();
});
new Chart(document.getElementById('categoryBarChart'), {
type: 'bar',
data: {
labels,
datasets: [{
label: 'Jumlah Jurnal',
data: vals,
backgroundColor: '#3b82f6',
borderRadius: 6
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
}
},
scales: {
y: {
beginAtZero: true
},
x: {
ticks: {
maxRotation: 45,
minRotation: 20,
font: {
size: 10
}
}
}
}
}
});
new Chart(document.getElementById('categoryPieChart'), {
type: 'doughnut',
data: {
labels,
datasets: [{
data: vals,
backgroundColor: chartColors,
borderWidth: 2
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom',
labels: {
boxWidth: 12,
font: {
size: 10
}
}
}
}
}
});
new Chart(document.getElementById('categoryPercentChart'), {
type: 'doughnut',
data: {
labels,
datasets: [{
data: pcts,
backgroundColor: chartColors,
borderWidth: 2
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom',
labels: {
boxWidth: 12,
font: {
size: 10
}
}
},
tooltip: {
callbacks: {
label: ctx => ctx.label + ': ' + ctx.parsed + '%'
}
}
}
}
});
}
function showError(msg) {
document.getElementById('loader').innerHTML =
`<div class="text-center p-8 bg-red-50 rounded-2xl border border-red-200 max-w-sm mx-4"><p class="text-red-600 font-bold mb-2">Terjadi Kesalahan</p><p class="text-red-500 text-sm mb-4">${msg}</p><button onclick="window.location.reload()" class="bg-red-600 text-white px-6 py-2 rounded-lg text-sm font-bold hover:bg-red-700">Coba Lagi</button></div>`;
}
// =====================================================
// START
// =====================================================
async function startApp() {
try {
await fetchAllPeriodes();
if (Object.keys(allPeriodeData).length === 0) {
showError('Gagal memuat semua data dari API.');
return;
}
renderPeriodSelector();
rebuildDashboard();
document.getElementById('loader').style.display = 'none';
document.getElementById('mainContent').classList.remove('opacity-0');
document.getElementById('mainContent').classList.add('transition-opacity', 'duration-500',
'opacity-100');
} catch (err) {
showError(err.message);
}
}
document.getElementById('authorSearch').addEventListener('input', e => {
if (dashboardData) renderAuthorTable(e.target.value);
});
startApp();
</script>
</body>
</html>