@@ -602,24 +602,29 @@ <h3 class="font-bold text-base leading-tight" x-text="item.name"></h3>
602602 const isDark = this . darkMode ;
603603 const gridColor = isDark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.06)' ;
604604 const labelColor = isDark ? '#9ca3af' : '#6b7280' ;
605+ const accent = this . activeTab === 'datasets' ? '#22c55e' : '#6366f1' ;
606+
607+ // 탭에 따라 표시할 데이터 선택
608+ const items = this . activeTab === 'datasets' ? this . datasets : this . models ;
605609
606610 // --- Timeline chart ---
607- const allItems = [ ...this . models , ...this . datasets ] ;
608611 const yearCounts = { } ;
609- allItems . forEach ( i => { yearCounts [ i . year ] = ( yearCounts [ i . year ] || 0 ) + 1 ; } ) ;
612+ items . forEach ( i => { yearCounts [ i . year ] = ( yearCounts [ i . year ] || 0 ) + 1 ; } ) ;
610613 const years = Object . keys ( yearCounts ) . sort ( ) ;
611614 const counts = years . map ( y => yearCounts [ y ] ) ;
612615
613- const tlCtx = document . getElementById ( 'timelineChart' ) . getContext ( '2d' ) ;
614- if ( this . timelineChart ) this . timelineChart . destroy ( ) ;
615- this . timelineChart = new Chart ( tlCtx , {
616+ // Chart.js 4.x 권장: getChart()으로 기존 인스턴스 안전하게 제거
617+ const tlCanvas = document . getElementById ( 'timelineChart' ) ;
618+ const existingTl = Chart . getChart ( tlCanvas ) ;
619+ if ( existingTl ) existingTl . destroy ( ) ;
620+ new Chart ( tlCanvas , {
616621 type : 'bar' ,
617622 data : {
618623 labels : years ,
619624 datasets : [ {
620625 data : counts ,
621- backgroundColor : '#6366f1cc ',
622- borderColor : '#6366f1' ,
626+ backgroundColor : accent + 'cc ',
627+ borderColor : accent ,
623628 borderWidth : 1 ,
624629 borderRadius : 4 ,
625630 } ]
@@ -636,14 +641,15 @@ <h3 class="font-bold text-base leading-tight" x-text="item.name"></h3>
636641
637642 // --- Category donut ---
638643 const catCounts = { } ;
639- allItems . forEach ( i => ( i . categories || [ ] ) . forEach ( c => { catCounts [ c ] = ( catCounts [ c ] || 0 ) + 1 ; } ) ) ;
644+ items . forEach ( i => ( i . categories || [ ] ) . forEach ( c => { catCounts [ c ] = ( catCounts [ c ] || 0 ) + 1 ; } ) ) ;
640645 const cats = Object . keys ( catCounts ) . sort ( ( a , b ) => catCounts [ b ] - catCounts [ a ] ) ;
641646 const catValues = cats . map ( c => catCounts [ c ] ) ;
642647 const palette = [ '#6366f1' , '#a855f7' , '#ec4899' , '#f97316' , '#eab308' , '#22c55e' , '#14b8a6' , '#3b82f6' ] ;
643648
644- const catCtx = document . getElementById ( 'categoryChart' ) . getContext ( '2d' ) ;
645- if ( this . categoryChart ) this . categoryChart . destroy ( ) ;
646- this . categoryChart = new Chart ( catCtx , {
649+ const catCanvas = document . getElementById ( 'categoryChart' ) ;
650+ const existingCat = Chart . getChart ( catCanvas ) ;
651+ if ( existingCat ) existingCat . destroy ( ) ;
652+ new Chart ( catCanvas , {
647653 type : 'doughnut' ,
648654 data : {
649655 labels : cats ,
@@ -665,12 +671,6 @@ <h3 class="font-bold text-base leading-tight" x-text="item.name"></h3>
665671 } ) ;
666672 } ,
667673
668- updateCharts ( ) {
669- if ( this . timelineChart ) this . timelineChart . destroy ( ) ;
670- if ( this . categoryChart ) this . categoryChart . destroy ( ) ;
671- this . buildCharts ( ) ;
672- } ,
673-
674674 // ── Init ──
675675 async init ( ) {
676676 this . darkMode = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
0 commit comments