Files
ITAM/src/views/Dashboard/HwDashboard.ts
Taehoon 587e92a7da feat: 서버 탭 전환 시 뷰 모드 유지 및 대시보드/맵 에디터 스타일 표준화
- 서버 탭 복귀 시 최근 선택한 뷰 모드(목록/위치) 상태 유지 및 currentViewMode 상태 일원화

- 개인PC 대시보드 및 맵 에디터의 인라인 CSS 스타일을 공통 CSS 및 변수 클래스로 분리 및 가독성 개선

- Vite 멀티페이지 빌드 설정(vite.config.ts) 추가
2026-06-19 14:55:25 +09:00

990 lines
50 KiB
TypeScript

import { state } from '../../core/state';
import { openHwModal } from '../../components/Modal/HWModal';
import { calculatePcScoreDeductive, getPcGrade, calculateAssetAge, isWindows11Incompatible } from '../../core/utils';
import { ASSET_SCHEMA } from '../../core/schema';
import { createIcons, Laptop, Cpu, Shield, Zap, Monitor, AlertTriangle, ChevronRight, HelpCircle } from 'lucide';
declare var Chart: any;
let donutChartInstance: any = null;
export function renderHwDashboard(container: HTMLElement) {
// 전역 툴팁 헬퍼 함수 등록
(window as any).showSpecTooltip = function(event: MouseEvent, element: HTMLElement, type: string, count: number) {
const container = element.closest('.spec-bar-container');
if (!container) return;
const tooltip = container.querySelector('.spec-tooltip') as HTMLElement;
if (!tooltip) return;
const textSpan = tooltip.querySelector('.tooltip-text') as HTMLElement;
if (textSpan) {
let color = '';
let label = '';
if (type === 'under') {
color = '#EF4444';
label = '부족';
} else if (type === 'normal') {
color = '#10B981';
label = '적정';
} else if (type === 'over') {
color = '#F59E0B';
label = '오버';
} else if (type === 'win11') {
color = '#7928ca';
label = '윈도우 11 불가';
}
textSpan.innerHTML = `<span style="color: ${color}; font-weight: 800;">${label} ${count}대</span>`;
}
tooltip.style.left = event.clientX + 'px';
tooltip.style.top = event.clientY + 'px';
tooltip.style.opacity = '1';
};
(window as any).updateSpecTooltipPos = function(event: MouseEvent, element: HTMLElement) {
const container = element.closest('.spec-bar-container');
if (!container) return;
const tooltip = container.querySelector('.spec-tooltip') as HTMLElement;
if (tooltip) {
tooltip.style.left = event.clientX + 'px';
tooltip.style.top = event.clientY + 'px';
}
};
(window as any).hideSpecTooltip = function(element: HTMLElement) {
const container = element.closest('.spec-bar-container');
if (!container) return;
const tooltip = container.querySelector('.spec-tooltip') as HTMLElement;
if (tooltip) {
tooltip.style.opacity = '0';
}
};
// 1. 개인용 PC 데이터 추출 (유형이 '개인PC'이거나 상태가 '재고' 또는 '대기' 상태인 PC 집계)
const pcs = (state.masterData.pc || []).filter((a: any) =>
a.asset_type === '개인PC' ||
((a.hw_status === '재고' || a.hw_status === '대기') && a.category === 'PC')
);
// 2. 1페이지 매거진 리포트(제목바 제거, '| 제목' 미니멀리즘 스타일) HTML 빌드
container.innerHTML = `
<div class="view-container" style="overflow: hidden; padding: 0; background-color: var(--canvas); height: calc(100vh - var(--header-height) - 48px); box-sizing: border-box; display: flex; flex-direction: column; gap: 0; color: var(--text-main);">
<!-- 대시보드 타이틀 및 사용조직 필터 -->
<div style="display: flex; justify-content: space-between; align-items: flex-end; flex-shrink: 0; padding-bottom: 0.4rem;">
<div>
</div>
<!-- 사용조직 필터 (브랜드 그린 매칭 칩 디자인) -->
<div class="flex items-center gap-3">
<div id="dashboard-dept-buttons" class="flex gap-1 p-1 bg-canvas-soft border border-hairline rounded-lg">
<button class="dept-filter-btn active" data-dept="">전체</button>
<button class="dept-filter-btn" data-dept="한맥">한맥</button>
<button class="dept-filter-btn" data-dept="삼안">삼안</button>
<button class="dept-filter-btn" data-dept="장헌">장헌</button>
<button class="dept-filter-btn" data-dept="한라">한라</button>
<button class="dept-filter-btn" data-dept="기술개발센터">기술개발센터</button>
<button class="dept-filter-btn" data-dept="총괄기획실">총괄기획실</button>
</div>
</div>
</div>
<!-- 상단 섹션 (전체 높이의 약 35% 차지, stat-card와 donut/aging 나열) -->
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 0; height: 33%; min-height: 0; flex-shrink: 0; padding: 0.5rem 0;">
<!-- 상단 좌측: 핵심 지표 4개 격자 그리드 -->
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 0; height: 100%;">
<!-- 1. 보유 자산 수량 -->
<div id="metric-card-total" class="stat-card">
<div style="display: flex; align-items: center; z-index: 1; height: 1.4rem;">
<span class="stat-card-label">보유 자산 수량</span>
</div>
<div id="metric-total-pcs" class="stat-card-value">0대</div>
</div>
<!-- 2. 사양 부족 -->
<div id="card-under-spec" class="stat-card">
<div style="display: flex; align-items: center; z-index: 1; height: 1.4rem;">
<span class="stat-card-label">사양 부족</span>
</div>
<div id="metric-under-spec" class="stat-card-value">0대</div>
</div>
<!-- 3. 오버 스펙 -->
<div id="card-over-spec" class="stat-card">
<div style="display: flex; align-items: center; z-index: 1; height: 1.4rem;">
<span class="stat-card-label">오버 스펙</span>
</div>
<div id="metric-over-spec" class="stat-card-value">0대</div>
</div>
<!-- 4. 윈도우 11 불가 PC -->
<div id="card-win11-incompatible" class="stat-card">
<div style="display: flex; align-items: center; z-index: 1; height: 1.4rem;">
<span class="stat-card-label">윈도우 11 불가</span>
</div>
<div id="metric-win11-incompatible" class="stat-card-value">0대</div>
</div>
</div>
<!-- 상단 우측: 등급별 보유 비율 도넛 & 연도별 PC 노후도 통합 배치 (두 개의 개별 레이아웃으로 배치) -->
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 0; min-height: 0; height: 100%;">
<!-- 1열: 조직별 사용 비율 도넛 영역 -->
<div style="background: var(--canvas); padding: 1.5rem; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 0.3rem; min-height: 0; height: 100%;">
<!-- 서브 제목 -->
<div style="width: 100%; margin-bottom: 0.15rem; display: flex; align-items: center; line-height: 1; flex-shrink: 0; height: 1.4rem;">
<span class="dashboard-subtitle">조직별 사용 비율</span>
</div>
<!-- 도넛 그래프 -->
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; width: 100%; min-height: 0;">
<div style="width: 170px; height: 170px; position: relative;">
<canvas id="chart-overall-donut"></canvas>
</div>
<!-- 커스텀 범례 -->
<div style="display: flex; flex-wrap: wrap; gap: 0.15rem 0.35rem; justify-content: center; align-items: center; margin-top: 6px; font-size: var(--fs-xs); font-weight: 800; color: var(--text-muted); width: 100%;">
<div style="display: flex; align-items: center; gap: 3px;">
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #D02121;"></span>
<span>한맥</span>
</div>
<div style="display: flex; align-items: center; gap: 3px;">
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #F58120;"></span>
<span>삼안</span>
</div>
<div style="display: flex; align-items: center; gap: 3px;">
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #3889C7;"></span>
<span>장헌</span>
</div>
<div style="display: flex; align-items: center; gap: 3px;">
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #79B2D9;"></span>
<span>한라</span>
</div>
<div style="display: flex; align-items: center; gap: 3px;">
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #10B981;"></span>
<span>기술개발센터</span>
</div>
<div style="display: flex; align-items: center; gap: 3px;">
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #133D84;"></span>
<span>총괄기획실</span>
</div>
<div style="display: flex; align-items: center; gap: 3px;">
<span style="display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #94A3B8;"></span>
<span>기타</span>
</div>
</div>
</div>
</div>
<!-- 2열: PC 노후도 영역 (표 잘림 방지를 위해 아래 패딩을 줄이고 overflow auto 설정) -->
<div style="background: var(--canvas); padding: 1.5rem 1.5rem 0.5rem 1.5rem; display: flex; flex-direction: column; min-height: 0; height: 100%;">
<div style="margin-bottom: 0.35rem; display: flex; align-items: center; line-height: 1; flex-shrink: 0; height: 1.4rem;">
<span class="dashboard-subtitle" style="white-space: nowrap;">PC 노후도</span>
</div>
<div style="flex: 1; overflow-y: auto; min-height: 0; padding-right: 0.1rem;">
<table style="width: 100%; border-collapse: collapse; text-align: left; font-size: var(--fs-base);">
<thead style="position: sticky; top: 0; background: var(--canvas); z-index: 5;">
<tr class="table-header-row" style="background: var(--canvas);">
<th style="padding: 6px 8px; width: 70%; font-size: var(--fs-base); background: var(--canvas);">구분 (연한)</th>
<th style="padding: 6px 8px; text-align: center; width: 30%; font-size: var(--fs-base); background: var(--canvas);">보유</th>
</tr>
</thead>
<tbody id="pc-aging-tbody">
<!-- Dynamic Aging Contents -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- 하단 섹션 (등급별 자산 종합 현황 및 사양 적정성 분석 영역 - 높이 비율 65%로 확대) -->
<div style="background: var(--canvas); padding: 1.5rem 0; display: flex; flex-direction: column; height: 65%; min-height: 0;">
<div style="display: flex; flex-direction: column; gap: 0.6rem; justify-content: flex-start; height: 100%;">
<!-- 메인 제목 -->
<div style="margin-bottom: 0.1rem; display: flex; align-items: center; line-height: 1; height: 1.6rem; flex-shrink: 0;">
<span class="dashboard-subtitle">등급별 자산 종합현황</span>
</div>
<!-- 종합 매트릭스 테이블 -->
<div style="width: 100%; overflow-y: hidden; flex: 1; border-radius: 0;">
<table style="width: 100%; border-collapse: collapse; text-align: left; font-size: var(--fs-base);">
<thead style="position: sticky; top: 0; background: var(--canvas-soft); z-index: 10;">
<tr class="table-header-row" style="background: var(--canvas-soft);">
<th style="padding: 16px 10px; width: 18%; font-size: var(--fs-base); background: var(--canvas-soft); border-bottom: 2px solid var(--border-color);">구분 (등급)</th>
<th style="padding: 16px 10px; text-align: center; width: 8%; font-size: var(--fs-base); background: var(--canvas-soft); border-bottom: 2px solid var(--border-color);">보유량</th>
<th style="padding: 16px 10px; text-align: center; width: 8%; font-size: var(--fs-base); background: var(--canvas-soft); border-bottom: 2px solid var(--border-color);">운영중</th>
<th style="padding: 16px 10px; text-align: center; width: 8%; font-size: var(--fs-base); background: var(--canvas-soft); border-bottom: 2px solid var(--border-color);">재고</th>
<th style="padding: 16px 10px; text-align: center; width: 8%; color: var(--danger); font-size: var(--fs-base); background: var(--canvas-soft); border-bottom: 2px solid var(--border-color);">부족분</th>
<th style="padding: 16px 10px; text-align: center; width: 50%; font-size: var(--fs-base); background: var(--canvas-soft); border-bottom: 2px solid var(--border-color);">사양 적정성</th>
</tr>
</thead>
<tbody id="pc-grade-matrix-tbody">
<!-- Dynamic Matrix Contents -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<style>
.dept-filter-btn { padding: 6px 14px; font-size: var(--fs-sm); font-weight: 700; border-radius: 6px; border: none; background: transparent; color: var(--mute); cursor: pointer; transition: all 0.2s; }
.dept-filter-btn.active { background: var(--primary); color: var(--on-primary); }
.donut-text-overlay { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -46%); font-size: var(--fs-md); font-weight: 700; color: var(--primary); pointer-events: none; white-space: nowrap; }
.stat-card { background: var(--canvas); padding: 1.5rem; display: flex; flex-direction: row; justify-content: space-between; align-items: flex-start; position: relative; overflow: hidden; transition: background-color 0.15s ease; cursor: pointer; }
#metric-card-total { cursor: default; }
#metric-card-total:hover { background-color: var(--canvas-soft); }
#card-under-spec:hover { background-color: #FEF2F2; }
#card-over-spec:hover { background-color: #FFFBEB; }
#card-win11-incompatible:hover { background-color: #F5F3FF; }
.stat-card-label { font-size: var(--fs-md); font-weight: 600; color: var(--text-main); letter-spacing: -0.3px; }
.stat-card-value { font-size: var(--fs-xl); font-weight: 700; line-height: 1.1; z-index: 1; margin-right: 2rem; margin-top: 1.8rem; }
#metric-total-pcs { color: var(--primary); }
#metric-under-spec { color: var(--danger); }
#metric-over-spec { color: var(--color-orange); }
#metric-win11-incompatible { color: var(--color-violet); }
.dashboard-subtitle { font-size: var(--fs-md); font-weight: 600; color: var(--text-main); }
.table-header-row { border-bottom: 2px solid var(--border-color); color: var(--text-muted); font-weight: 600; }
.matrix-cell { transition: background-color 0.2s; cursor: pointer; }
.matrix-cell:hover { background-color: var(--canvas-soft-2); }
.aging-row { transition: background-color 0.2s; cursor: pointer; }
.aging-row:hover { background-color: var(--canvas-soft); }
.mini-modal-row { transition: background-color 0.2s; cursor: pointer; }
.mini-modal-row:hover { background-color: var(--canvas-soft); }
#btn-close-mini-modal { transition: background-color 0.2s, color 0.2s; }
#btn-close-mini-modal:hover { background-color: var(--canvas-soft); color: var(--primary); }
#btn-confirm-mini-modal { transition: opacity 0.2s; }
#btn-confirm-mini-modal:hover { opacity: 0.9; }
</style>
`;
// 3. Lucide 아이콘 초기화
createIcons({
icons: { Laptop, Cpu, Shield, Zap, Monitor, AlertTriangle, ChevronRight, HelpCircle }
});
// 4. 사용조직 버튼 그룹 필터 이벤트 연동
const btnGroup = container.querySelector('#dashboard-dept-buttons') as HTMLElement;
btnGroup.addEventListener('click', (e) => {
const btn = (e.target as HTMLElement).closest('.dept-filter-btn') as HTMLButtonElement;
if (!btn) return;
btnGroup.querySelectorAll('.dept-filter-btn').forEach(b => {
const button = b as HTMLButtonElement;
button.classList.remove('active');
button.style.background = 'transparent';
button.style.color = 'var(--text-muted)';
});
btn.classList.add('active');
const dept = btn.getAttribute('data-dept') || '';
let bgColor = '#1E5149';
if (dept === '한맥') bgColor = '#D02121';
else if (dept === '삼안') bgColor = '#F58120';
else if (dept === '장헌') bgColor = '#3889C7';
else if (dept === '한라') bgColor = '#79B2D9';
else if (dept === '기술개발센터') bgColor = '#10B981';
else if (dept === '총괄기획실') bgColor = '#133D84';
btn.style.background = bgColor;
btn.style.color = 'white';
const selectedDept = btn.getAttribute('data-dept') || '';
updateDashboardData(pcs, selectedDept);
});
// 5. 첫 로딩 시 전체 부서 대상 통계 로드
updateDashboardData(pcs, '');
}
/**
* 대시보드 데이터 수치 및 차트, 테이블 실시간 갱신
*/
function updateDashboardData(pcs: any[], selectedDept: string) {
// 1. 선택 부서 필터 적용
const filtered = selectedDept
? pcs.filter((p: any) => String(p[ASSET_SCHEMA.CURRENT_DEPT.key] || '').trim().includes(selectedDept))
: pcs;
// 2. 개별 PC의 성능 감점식 점수 실시간 재연산
filtered.forEach((p: any) => {
p._pc_score = calculatePcScoreDeductive(p.cpu, p.ram, p.gpu, p.purchase_date);
});
// 3. DB 기준 사양 데이터 맵핑 (state.masterData.jobSpecs 이용)
const jobSpecsMap: Record<string, string> = {};
if (state.masterData.jobSpecs) {
state.masterData.jobSpecs.forEach((s: any) => {
jobSpecsMap[s.job_name] = s.required_grade || '중급';
});
}
// 사용자 이름 → 세부 직무 맵 생성 (system_users.position 기준, 더 정확한 직무 구분)
const userPositionMap: Record<string, string> = {};
if (state.masterData.users) {
state.masterData.users.forEach((u: any) => {
if (u.user_name && u.position) {
userPositionMap[u.user_name.trim()] = u.position.trim();
}
});
}
const GRADE_RANK: Record<string, number> = {
'premium': 4, '최상급': 4,
'high': 3, '상급': 3,
'normal': 2, '중급': 2,
'entry': 1, '보급': 1,
'replace': 0, '교체 대상': 0
};
const jobScores: Record<string, { totalScore: number; count: number; avg: number }> = {};
pcs.forEach((p: any) => {
const score = calculatePcScoreDeductive(p.cpu, p.ram, p.gpu, p.purchase_date);
const job = p[ASSET_SCHEMA.USER_POSITION.key] || '미분류';
if (!jobScores[job]) jobScores[job] = { totalScore: 0, count: 0, avg: 0 };
jobScores[job].totalScore += score;
jobScores[job].count += 1;
});
Object.keys(jobScores).forEach(job => {
jobScores[job].avg = jobScores[job].count > 0 ? jobScores[job].totalScore / jobScores[job].count : 0;
});
// 4. 등급 집계 (보유량 vs 실제 할당량 vs 유효 재고량 vs 사양 부족량)
const isStock = (p: any) => {
return p.hw_status === '재고' ||
p.hw_status === '대기' ||
!(p.user_current || '').trim();
};
const matrix = {
premium: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] },
high: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] },
normal: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] },
entry: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] },
replace: { total: 0, active: 0, stock: 0, under: 0, pcs: [] as any[], activePcs: [] as any[], stockPcs: [] as any[], underPcs: [] as any[] }
};
let scoreSum = 0;
let underSpecCount = 0;
let overSpecCount = 0;
let win11IncompatibleCount = 0;
const criticalList: any[] = [];
filtered.forEach((p: any) => {
const score = p._pc_score;
scoreSum += score;
const stockYn = isStock(p);
const win11Incompatible = isWindows11Incompatible(p.cpu, p.ram);
// 1. 현재 물리적 자산 등급 판정
let currentGradeKey: keyof typeof matrix;
if (score >= 85) {
currentGradeKey = 'premium';
} else if (score >= 70) {
currentGradeKey = 'high';
} else if (score >= 40) {
currentGradeKey = 'normal';
} else if (score >= 20) {
currentGradeKey = 'entry';
} else {
currentGradeKey = 'replace';
}
const currentTarget = matrix[currentGradeKey];
currentTarget.pcs.push(p);
currentTarget.total++;
if (stockYn) {
currentTarget.stock++;
currentTarget.stockPcs.push(p);
} else {
currentTarget.active++;
currentTarget.activePcs.push(p);
// 직무 적정성 계산: system_users.position 우선 조회 → asset_core.user_position fallback
const userName = (p[ASSET_SCHEMA.CURRENT_USER.key] || '').trim();
const job = userPositionMap[userName] || p[ASSET_SCHEMA.USER_POSITION.key] || '미분류';
const requiredGrade = jobSpecsMap[job] || jobSpecsMap[p[ASSET_SCHEMA.USER_POSITION.key]] || '중급'; // 세부 직무 우선, 없으면 일반 직무, 없으면 기본 중급
// 미니 모달 표시용으로 해석된 세부 직무명 저장
p._resolved_position = job;
const actualGrade = currentGradeKey; // premium, high, normal, entry, replace 중 하나
const reqRank = GRADE_RANK[requiredGrade] !== undefined ? GRADE_RANK[requiredGrade] : 2; // '중급' rank
const actRank = GRADE_RANK[actualGrade] !== undefined ? GRADE_RANK[actualGrade] : 0;
let isUnder = false;
if (job !== '재고PC') {
if (win11Incompatible) {
isUnder = true;
p._spec_status = '사양 부족';
} else if (actRank < reqRank) {
isUnder = true;
p._spec_status = '사양 부족';
} else if (actRank > reqRank) {
p._spec_status = '오버스펙';
criticalList.push(p);
overSpecCount++;
} else {
p._spec_status = '적정';
}
} else {
if (win11Incompatible) {
isUnder = true;
p._spec_status = '사양 부족';
} else {
p._spec_status = '적정';
}
}
if (isUnder) {
criticalList.push(p);
underSpecCount++;
// 2. 사양 부족 시 교체받아야 할 직무별 권장 목표 등급 판정
let targetGradeKey: keyof typeof matrix = 'normal';
if (requiredGrade === '최상급') targetGradeKey = 'premium';
else if (requiredGrade === '상급') targetGradeKey = 'high';
else if (requiredGrade === '중급') targetGradeKey = 'normal';
else if (requiredGrade === '보급') targetGradeKey = 'entry';
const targetGrade = matrix[targetGradeKey];
targetGrade.under++;
targetGrade.underPcs.push(p);
}
}
// Windows 11 업그레이드 지원 불가 검사
if (isWindows11Incompatible(p.cpu, p.ram)) {
win11IncompatibleCount++;
}
});
// 5. 핵심 텍스트형 요약 지표 갱신
document.getElementById('metric-total-pcs')!.textContent = `${filtered.length}`;
document.getElementById('metric-under-spec')!.textContent = `${underSpecCount}`;
document.getElementById('metric-over-spec')!.textContent = `${overSpecCount}`;
document.getElementById('metric-win11-incompatible')!.textContent = `${win11IncompatibleCount}`;
// 6. 종합 매트릭스 테이블 렌더링 및 바인딩
const matrixTbody = document.getElementById('pc-grade-matrix-tbody')!;
const getSpecStatusCounts = (activePcsList: any[]) => {
let win11 = 0;
let under = 0;
let normal = 0;
let over = 0;
activePcsList.forEach(p => {
if (isWindows11Incompatible(p.cpu, p.ram)) win11++;
else if (p._spec_status === '사양 부족') under++;
else if (p._spec_status === '오버스펙') over++;
else normal++;
});
return { win11, under, normal, over };
};
const maxTotal = Math.max(
matrix.premium.total,
matrix.high.total,
matrix.normal.total,
matrix.entry.total,
matrix.replace.total
);
const renderMatrixRow = (gradeKey: keyof typeof matrix, label: string, color: string, shortage: number) => {
const data = matrix[gradeKey];
const totalRate = filtered.length > 0 ? Math.round((data.total / filtered.length) * 100) : 0;
const cellStyle = `padding: 22px 8px; text-align: center; font-weight: 700; font-size: var(--fs-base);`;
// 사양 적정성 분석 데이터 계산 (운영중인 자산만)
const { win11, under, normal, over } = getSpecStatusCounts(data.activePcs);
const activeCount = data.active;
const win11Pct = activeCount > 0 ? (win11 / activeCount) * 100 : 0;
const underPct = activeCount > 0 ? (under / activeCount) * 100 : 0;
const normalPct = activeCount > 0 ? (normal / activeCount) * 100 : 0;
const overPct = activeCount > 0 ? (over / activeCount) * 100 : 0;
const rowTotal = data.total;
const barWidthPct = maxTotal > 0 ? (rowTotal / maxTotal) * 100 : 0;
let barGraphHtml = '';
if (activeCount > 0) {
barGraphHtml = `
<div style="position: relative; display: inline-block; width: 100%; max-width: 100%; text-align: left;" class="spec-bar-container">
<!-- 게이지 바 (보유량 비례) -->
<div class="spec-bar-wrapper" style="display: flex; height: 16px; border-radius: 8px; overflow: hidden; background: var(--canvas-soft-2); width: ${barWidthPct}%; min-width: 15px; box-shadow: inset 0 1px 2px rgba(0,0,0,0.06); cursor: pointer;">
${win11 > 0 ? `<div style="width: ${win11Pct}%; background: var(--color-violet); border-right: 2px solid var(--canvas); cursor: pointer; transition: opacity 0.15s;" title="윈도우 11 불가: ${win11}대" class="spec-segment-btn" data-grade="${gradeKey}" data-spec-status="윈도우 11 불가" onmouseover="showSpecTooltip(event, this, 'win11', ${win11}); this.style.opacity='0.85';" onmousemove="updateSpecTooltipPos(event, this);" onmouseout="hideSpecTooltip(this); this.style.opacity='1';"></div>` : ''}
${under > 0 ? `<div style="width: ${underPct}%; background: var(--danger); border-right: 2px solid var(--canvas); cursor: pointer; transition: opacity 0.15s;" title="사양 부족: ${under}대" class="spec-segment-btn" data-grade="${gradeKey}" data-spec-status="사양 부족" onmouseover="showSpecTooltip(event, this, 'under', ${under}); this.style.opacity='0.85';" onmousemove="updateSpecTooltipPos(event, this);" onmouseout="hideSpecTooltip(this); this.style.opacity='1';"></div>` : ''}
${normal > 0 ? `<div style="width: ${normalPct}%; background: var(--primary); border-right: 2px solid var(--canvas); cursor: pointer; transition: opacity 0.15s;" title="적정 사양: ${normal}대" class="spec-segment-btn" data-grade="${gradeKey}" data-spec-status="적정" onmouseover="showSpecTooltip(event, this, 'normal', ${normal}); this.style.opacity='0.85';" onmousemove="updateSpecTooltipPos(event, this);" onmouseout="hideSpecTooltip(this); this.style.opacity='1';"></div>` : ''}
${over > 0 ? `<div style="width: ${overPct}%; background: var(--color-orange); cursor: pointer; transition: opacity 0.15s;" title="오버 스펙: ${over}대" class="spec-segment-btn" data-grade="${gradeKey}" data-spec-status="오버스펙" onmouseover="showSpecTooltip(event, this, 'over', ${over}); this.style.opacity='0.85';" onmousemove="updateSpecTooltipPos(event, this);" onmouseout="hideSpecTooltip(this); this.style.opacity='1';"></div>` : ''}
</div>
<!-- 마우스 오버 시 나타날 커스텀 말풍선 툴팁 -->
<div class="spec-tooltip" style="position: fixed; transform: translate(-50%, -100%); margin-top: -10px; background: var(--primary); color: var(--on-primary); padding: 6px 10px; border-radius: 6px; font-size: 11px; white-space: nowrap; box-shadow: 0 4px 6px rgba(0,0,0,0.15); opacity: 0; pointer-events: none; transition: opacity 0.15s; z-index: 9999; display: flex; gap: 8px; align-items: center;">
<span class="tooltip-text"></span>
<div style="position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 5px solid transparent; border-top-color: var(--primary);"></div>
</div>
</div>
`;
} else {
barGraphHtml = `<span style="font-size: var(--fs-xs); color: var(--mute); font-weight: 550;">운영중 자산 없음</span>`;
}
return `
<tr style="border-bottom: 1px solid var(--border-color);">
<td style="padding: 22px 10px; font-weight: 600; color: ${color}; font-size: var(--fs-base);">${label}</td>
<td class="matrix-cell" data-grade="${gradeKey}" data-type="total" style="${cellStyle}">${data.total}대 <span style="font-size:var(--fs-xs); color:var(--text-muted); font-weight:500;">(${totalRate}%)</span></td>
<td class="matrix-cell" data-grade="${gradeKey}" data-type="active" style="${cellStyle}">${data.active}대</td>
<td class="matrix-cell" data-grade="${gradeKey}" data-type="stock" style="${cellStyle}">${data.stock}대</td>
<td class="matrix-cell" data-grade="${gradeKey}" data-type="under" style="${cellStyle} color: var(--danger);">${shortage}대</td>
<td style="padding: 22px 8px; text-align: center; font-weight: 700; font-size: var(--fs-base); vertical-align: middle;">
${barGraphHtml}
</td>
</tr>
`;
};
const totalPcs = filtered.length;
const totalActive = matrix.premium.active + matrix.high.active + matrix.normal.active + matrix.entry.active + matrix.replace.active;
const totalStock = matrix.premium.stock + matrix.high.stock + matrix.normal.stock + matrix.entry.stock + matrix.replace.stock;
const premiumShortage = Math.max(0, matrix.premium.under - matrix.premium.stock);
const highShortage = Math.max(0, matrix.high.under - matrix.high.stock);
const normalShortage = Math.max(0, matrix.normal.under - matrix.normal.stock);
// 보급 PC 구매 필요 = 보급 under - 보급 stock
const entryShortage = Math.max(0, matrix.entry.under - matrix.entry.stock);
// 교체 대상 PC 자체는 새로 구매하는 기종이 아니므로 구매 필요 0대
const replaceShortage = 0;
const totalShortage = premiumShortage + highShortage + normalShortage + entryShortage + replaceShortage;
const totalActivePcs = filtered.filter(p => !isStock(p));
const { win11: totWin11, under: totUnder, normal: totNormal, over: totOver } = getSpecStatusCounts(totalActivePcs);
const totUnderPct = totalActive > 0 ? (totUnder / totalActive) * 100 : 0;
const totNormalPct = totalActive > 0 ? (totNormal / totalActive) * 100 : 0;
const totOverPct = totalActive > 0 ? (totOver / totalActive) * 100 : 0;
let totBarGraphHtml = '';
if (totalActive > 0) {
totBarGraphHtml = `
<div style="position: relative; display: inline-block; width: 100%; max-width: 100%; text-align: left;" class="spec-bar-container">
<!-- 게이지 바 (합계는 100% 너비) -->
<div class="spec-bar-wrapper" style="display: flex; height: 16px; border-radius: 8px; overflow: hidden; background: var(--canvas-soft-2); width: 100%; box-shadow: inset 0 1px 2px rgba(0,0,0,0.06); cursor: pointer;">
${totUnder > 0 ? `<div style="width: ${totUnderPct}%; background: var(--danger); border-right: 2px solid var(--canvas); cursor: pointer; transition: opacity 0.15s;" title="사양 부족: ${totUnder}대" class="spec-segment-btn" data-grade="all" data-spec-status="사양 부족" onmouseover="showSpecTooltip(event, this, 'under', ${totUnder}); this.style.opacity='0.85';" onmousemove="updateSpecTooltipPos(event, this);" onmouseout="hideSpecTooltip(this); this.style.opacity='1';"></div>` : ''}
${totNormal > 0 ? `<div style="width: ${totNormalPct}%; background: var(--primary); border-right: 2px solid var(--canvas); cursor: pointer; transition: opacity 0.15s;" title="적정 사양: ${totNormal}대" class="spec-segment-btn" data-grade="all" data-spec-status="적정" onmouseover="showSpecTooltip(event, this, 'normal', ${totNormal}); this.style.opacity='0.85';" onmousemove="updateSpecTooltipPos(event, this);" onmouseout="hideSpecTooltip(this); this.style.opacity='1';"></div>` : ''}
${totOver > 0 ? `<div style="width: ${totOverPct}%; background: var(--color-orange); cursor: pointer; transition: opacity 0.15s;" title="오버 스펙: ${totOver}대" class="spec-segment-btn" data-grade="all" data-spec-status="오버스펙" onmouseover="showSpecTooltip(event, this, 'over', ${totOver}); this.style.opacity='0.85';" onmousemove="updateSpecTooltipPos(event, this);" onmouseout="hideSpecTooltip(this); this.style.opacity='1';"></div>` : ''}
</div>
<!-- 마우스 오버 시 나타날 커스텀 말풍선 툴팁 -->
<div class="spec-tooltip" style="position: fixed; transform: translate(-50%, -100%); margin-top: -10px; background: var(--primary); color: var(--on-primary); padding: 6px 10px; border-radius: 6px; font-size: 11px; white-space: nowrap; box-shadow: 0 4px 6px rgba(0,0,0,0.15); opacity: 0; pointer-events: none; transition: opacity 0.15s; z-index: 9999; display: flex; gap: 8px; align-items: center;">
<span class="tooltip-text"></span>
<div style="position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 5px solid transparent; border-top-color: var(--primary);"></div>
</div>
</div>
`;
} else {
totBarGraphHtml = `<span style="font-size: var(--fs-xs); color: var(--text-sub); font-weight: 500;">운영중 자산 없음</span>`;
}
matrixTbody.innerHTML = `
${renderMatrixRow('premium', '최상급 PC (85점 이상)', '#11302B', premiumShortage)}
${renderMatrixRow('high', '상급 PC (70점 ~ 85점)', '#1E8E7C', highShortage)}
${renderMatrixRow('normal', '중급 PC (40점 ~ 70점)', '#10B981', normalShortage)}
${renderMatrixRow('entry', '보급 PC (20점 ~ 40점)', 'var(--color-orange)', entryShortage)}
${renderMatrixRow('replace', '교체 대상 PC (20점 미만)', 'var(--danger)', replaceShortage)}
`;
// 셀별 동적 클릭 리스너 바인딩
matrixTbody.querySelectorAll('.matrix-cell').forEach(cell => {
cell.addEventListener('click', () => {
const grade = cell.getAttribute('data-grade')!;
const type = cell.getAttribute('data-type')!;
let targetList: any[] = [];
let title = '';
const getGradeLabel = (g: string) => {
if (g === 'premium') return '최상급 PC';
if (g === 'high') return '상급 PC';
if (g === 'normal') return '중급 PC';
if (g === 'entry') return '보급 PC';
if (g === 'replace') return '교체 대상 PC';
return '전체 PC';
};
const getTypeLabel = (t: string) => {
if (t === 'total') return '보유';
if (t === 'active') return '운영중';
if (t === 'stock') return '재고';
if (t === 'under') return '부족분';
return '';
};
if (grade === 'all') {
if (type === 'total') {
targetList = filtered;
} else if (type === 'active') {
targetList = filtered.filter(p => !isStock(p));
} else if (type === 'stock') {
targetList = filtered.filter(p => isStock(p));
} else if (type === 'under') {
targetList = criticalList.filter(p => p._spec_status === '사양 부족');
}
} else {
const data = matrix[grade as keyof typeof matrix];
if (type === 'total') {
targetList = data.pcs;
} else if (type === 'active') {
targetList = data.activePcs;
} else if (type === 'stock') {
targetList = data.stockPcs;
} else if (type === 'under') {
targetList = data.underPcs;
}
}
title = `${getGradeLabel(grade)} - ${getTypeLabel(type)} 자산 목록`;
showMiniListModal(title, targetList);
});
});
// 바그래프 세그먼트 또는 텍스트 클릭 리스너 설정
const handleSpecClick = (e: Event) => {
e.stopPropagation();
const target = e.currentTarget as HTMLElement;
const grade = target.getAttribute('data-grade')!;
const status = target.getAttribute('data-spec-status')!;
let targetPcs: any[] = [];
const filterFn = (p: any) => {
if (status === '윈도우 11 불가') {
return isWindows11Incompatible(p.cpu, p.ram);
} else if (status === '사양 부족') {
return !isWindows11Incompatible(p.cpu, p.ram) && p._spec_status === '사양 부족';
} else {
return p._spec_status === status;
}
};
if (grade === 'all') {
targetPcs = filtered.filter(p => !isStock(p) && filterFn(p));
} else {
const data = matrix[grade as keyof typeof matrix];
targetPcs = data.activePcs.filter(filterFn);
}
const getGradeLabel = (g: string) => {
if (g === 'premium') return '최상급 PC';
if (g === 'high') return '상급 PC';
if (g === 'normal') return '중급 PC';
if (g === 'entry') return '보급 PC';
if (g === 'replace') return '교체 대상 PC';
return '전체 PC';
};
const title = `${getGradeLabel(grade)} - ${status} 자산 목록`;
showMiniListModal(title, targetPcs);
};
matrixTbody.querySelectorAll('.spec-segment-btn, .spec-text-btn').forEach(btn => {
btn.addEventListener('click', handleSpecClick);
});
// 7. 연도별 PC 노후도 집계 및 렌더링
const agingCounts = {
immediate: [] as any[], // 7년 이상
review: [] as any[], // 3년 이상 7년 미만
normal: [] as any[], // 1년 이상 3년 미만
fresh: [] as any[] // 1년 미만
};
filtered.forEach((p: any) => {
const age = calculateAssetAge(p.purchase_date);
if (age >= 7.0) {
agingCounts.immediate.push(p);
} else if (age >= 3.0) {
agingCounts.review.push(p);
} else if (age >= 1.0) {
agingCounts.normal.push(p);
} else {
agingCounts.fresh.push(p);
}
});
const agingTbody = document.getElementById('pc-aging-tbody')!;
const renderAgingRow = (label: string, list: any[], ageGroupKey: string) => {
return `
<tr style="border-bottom:1px solid var(--border-color);" class="aging-row" data-group="${ageGroupKey}">
<td style="padding:5px 8px; font-weight:700; color:var(--text-main); font-size: var(--fs-base);">${label}</td>
<td style="padding:5px 8px; text-align:center; font-weight:700; color:var(--text-main); font-size: var(--fs-base);">${list.length}대</td>
</tr>
`;
};
agingTbody.innerHTML = `
${renderAgingRow('즉시 교체 (7년 이상)', agingCounts.immediate, 'immediate')}
${renderAgingRow('교체 검토 (3년 ~ 7년)', agingCounts.review, 'review')}
${renderAgingRow('정상 운용 (1년 ~ 3년)', agingCounts.normal, 'normal')}
${renderAgingRow('최신 도입 (1년 미만)', agingCounts.fresh, 'fresh')}
`;
agingTbody.querySelectorAll('.aging-row').forEach(row => {
row.addEventListener('click', () => {
const groupKey = row.getAttribute('data-group') as any;
const groupList = agingCounts[groupKey as keyof typeof agingCounts];
const groupLabels = {
immediate: '즉시 교체 대상 (7년 이상)',
review: '교체 검토 대상 (3년 ~ 7년)',
normal: '정상 운용 장비 (1년 ~ 3년)',
fresh: '최신 도입 장비 (1년 미만)'
};
showMiniListModal(groupLabels[groupKey as keyof typeof groupLabels], groupList);
});
});
// 8. 요약 지표 카드 클릭 리스너 설정
const bindCardClick = (id: string, gradeTitle: string, filterFn: (p: any) => boolean) => {
const card = document.getElementById(id)!;
if (!card) return;
card.onclick = () => {
const pcsInGrade = filtered.filter(filterFn);
showMiniListModal(gradeTitle, pcsInGrade);
};
};
// 사양 부족 / 오버 스펙 / 윈도우 11 불가 클릭 리스너 설정
bindCardClick('card-under-spec', '사양 부족 대상', p => p._spec_status === '사양 부족');
bindCardClick('card-over-spec', '오버 스펙 대상', p => p._spec_status === '오버스펙');
bindCardClick('card-win11-incompatible', '윈도우 11 업그레이드 불가 PC', p => isWindows11Incompatible(p.cpu, p.ram));
// 9. 조직별 사용 비율 집계 (전체 개인용 PC 기준)
const deptCounts: Record<string, number> = {
'한맥': 0,
'삼안': 0,
'장헌': 0,
'한라': 0,
'기술개발센터': 0,
'총괄기획실': 0,
'기타': 0
};
pcs.forEach((p: any) => {
const dept = String(p[ASSET_SCHEMA.CURRENT_DEPT.key] || '').trim();
let matched = false;
for (const key of Object.keys(deptCounts)) {
if (key !== '기타' && dept.includes(key)) {
deptCounts[key]++;
matched = true;
break;
}
}
if (!matched) {
deptCounts['기타']++;
}
});
const deptChartData = [
{ label: '한맥', count: deptCounts['한맥'], color: '#D02121' },
{ label: '삼안', count: deptCounts['삼안'], color: '#F58120' },
{ label: '장헌', count: deptCounts['장헌'], color: '#3889C7' },
{ label: '한라', count: deptCounts['한라'], color: '#79B2D9' },
{ label: '기술개발센터', count: deptCounts['기술개발센터'], color: '#10B981' },
{ label: '총괄기획실', count: deptCounts['총괄기획실'], color: '#133D84' },
{ label: '기타', count: deptCounts['기타'], color: '#94A3B8' }
];
// 10. 도넛 차트 렌더링 호출
renderDonutChart(deptChartData);
// 전역 상태 등록
state.activeCharts = [donutChartInstance];
}
/**
* 등급 클릭 시 열리는 심플 미니 리스트 모달 (라이트 글래스 헤더 적용)
*/
function showMiniListModal(title: string, list: any[]) {
const oldModal = document.getElementById('dashboard-mini-modal');
if (oldModal) oldModal.remove();
const modal = document.createElement('div');
modal.id = 'dashboard-mini-modal';
modal.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(15, 23, 42, 0.4);
backdrop-filter: blur(4px);
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
color: var(--text-main);
`;
modal.innerHTML = `
<div style="background: var(--canvas); border-radius: 12px; width: 800px; max-width: 95%; max-height: 80%; display: flex; flex-direction: column; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15); overflow: hidden; border: 1px solid var(--border-color); animation: modalFadeIn 0.2s ease-out; color: var(--text-main);">
<div style="padding: 1.25rem 1.75rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: var(--canvas-soft);">
<h3 style="margin: 0; font-size: var(--fs-md); font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 0.5rem;">
<span style="display:inline-block; width:8px; height:8px; border-radius:50%; background:var(--primary);"></span>
${title} 자산 목록
<span style="font-size: var(--fs-xs); font-weight: 700; color: white; background: var(--primary); padding: 2px 8px; border-radius: 9999px; margin-left: 0.25rem;">${list.length}대</span>
</h3>
<button id="btn-close-mini-modal" style="background: none; border: none; font-size: 1.25rem; color: var(--text-sub); cursor: pointer; display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 6px;">
&times;
</button>
</div>
<div style="padding: 0 1.75rem 1rem 1.75rem; overflow-y: auto; flex: 1;">
<table style="width: 100%; border-collapse: collapse; text-align: left; font-size: var(--fs-base); table-layout: fixed;">
<thead style="position: sticky; top: 0; background: var(--canvas); z-index: 10;">
<tr class="table-header-row" style="background: var(--canvas);">
<th style="padding: 10px 4px; width: 14%; background: var(--canvas);">사용자</th>
<th style="padding: 10px 4px; width: 25%; background: var(--canvas);">조직 (직무)</th>
<th style="padding: 10px 4px; width: 28%; background: var(--canvas);">주요 사양</th>
<th style="padding: 10px 4px; width: 18%; text-align: center; background: var(--canvas);">등급 (점수)</th>
<th style="padding: 10px 4px; text-align: center; background: var(--canvas);">자산코드</th>
</tr>
</thead>
<tbody>
${list.length === 0
? `<tr><td colspan="5" style="text-align:center; padding:3rem; color:var(--mute); font-weight:500;">해당 등급의 자산이 없습니다.</td></tr>`
: list.map(pc => {
const spec = `${pc.cpu || ''} / ${pc.ram || ''} / ${pc.gpu || '-'}`;
const user = pc.user_current || '(재고)';
const score = pc._pc_score !== undefined ? pc._pc_score : calculatePcScoreDeductive(pc.cpu, pc.ram, pc.gpu, pc.purchase_date);
const win11Incompatible = isWindows11Incompatible(pc.cpu, pc.ram);
const grade = getPcGrade(score, win11Incompatible);
const badgeHTML = `<span class="badge ${grade.class}" style="font-size: 11px; padding: 2px 6px;">${grade.name}</span>`;
const scoreHTML = `<strong style="color: ${grade.color}; font-size: 13px; margin-left: 4px;">${score}점</strong>`;
return `
<tr style="border-bottom: 1px solid var(--border-color);" class="mini-modal-row" data-id="${pc.id}">
<td style="padding: 12px 4px; font-weight: 700; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="${user}">${user}</td>
<td style="padding: 12px 4px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="${pc.current_dept || '-'} (${pc._resolved_position || pc.user_position || '-'})">${pc.current_dept || '-'} (${pc._resolved_position || pc.user_position || '-'})</td>
<td style="padding: 12px 4px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="${spec}">${spec}</td>
<td style="padding: 12px 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">${badgeHTML}${scoreHTML}</td>
<td style="padding: 12px 4px; font-family: monospace; color: var(--text-muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="${pc.asset_code || '-'}">${pc.asset_code || '-'}</td>
</tr>
`;
}).join('')
}
</tbody>
</table>
</div>
<div style="padding: 1rem 1.75rem; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; background: var(--canvas-soft);">
<button id="btn-confirm-mini-modal" style="padding: 6px 20px; font-size: var(--fs-base); font-weight: 700; background: var(--primary); color: white; border: none; border-radius: 6px; cursor: pointer;">
확인
</button>
</div>
</div>
`;
const style = document.createElement('style');
style.innerHTML = `
@keyframes modalFadeIn {
from { transform: scale(0.96); opacity: 0; }
to { transform: scale(1); opacity: 1; }
}
`;
modal.appendChild(style);
document.body.appendChild(modal);
const closeModal = () => { modal.remove(); };
modal.addEventListener('click', (e) => {
if (e.target === modal) closeModal();
});
document.getElementById('btn-close-mini-modal')?.addEventListener('click', closeModal);
document.getElementById('btn-confirm-mini-modal')?.addEventListener('click', closeModal);
modal.querySelectorAll('.mini-modal-row').forEach(row => {
row.addEventListener('click', () => {
const id = row.getAttribute('data-id');
const asset = list.find(p => String(p.id) === String(id));
if (asset) {
closeModal();
openHwModal(asset, 'view');
}
});
});
}
/**
* 실시간 사양 적정률 원형 도넛 그래프 (Active Spec Rate)
*/
function renderDonutChart(deptData: { label: string; count: number; color: string }[]) {
const ctx = document.getElementById('chart-overall-donut') as HTMLCanvasElement;
if (!ctx || typeof Chart === 'undefined') return;
if (donutChartInstance) {
donutChartInstance.destroy();
donutChartInstance = null;
}
const total = deptData.reduce((sum, d) => sum + d.count, 0);
donutChartInstance = new Chart(ctx, {
type: 'doughnut',
data: {
labels: deptData.map(d => d.label),
datasets: [{
data: deptData.map(d => d.count),
backgroundColor: deptData.map(d => d.color),
borderColor: '#ffffff',
borderWidth: 2
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
cutout: '70%',
plugins: {
legend: { display: false },
tooltip: {
titleFont: { family: 'Pretendard', size: 12 },
bodyFont: { family: 'Pretendard', size: 12 },
callbacks: {
label: (context: any) => `${context.label}: ${context.raw}`
}
}
}
}
});
// 도넛 차트 중앙에 총 자산 대수 텍스트 오버레이 배치
const parent = ctx.parentElement!;
let textOverlay = parent.querySelector('.donut-text-overlay') as HTMLElement;
if (!textOverlay) {
textOverlay = document.createElement('div');
textOverlay.className = 'donut-text-overlay';
textOverlay.style.cssText = `
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -46%);
font-size: var(--fs-lg);
font-weight: 900;
color: var(--primary);
pointer-events: none;
white-space: nowrap;
`;
parent.appendChild(textOverlay);
}
textOverlay.textContent = `${total}`;
}