[]
        
(Showing Draft Content)

점진적 계산

SpreadJS는 Workbook 클래스의 incrementalCalculation 옵션을 true로 설정하여 실행 중 전체 계산을 여러 세그먼트로 나누는 점진적 계산(incremental calculation)을 지원합니다. 이 기능을 통해 계산 작업이 매우 클 경우에도 사용자 작업에 대한 응답성을 유지할 수 있습니다.

셀을 점진적으로 계산하고 UI 이벤트에 반응할 수 있습니다. 이 기능은 통합 문서에 많은 수식이 포함되어 있을 때 UI가 멈추는 것을 방지합니다. 계산 대기 중인 셀이 있는 동안 셀이 업데이트되면, 해당 업데이트된 셀과 그에 의존하는 셀이 계산 작업에 추가됩니다. 그러나 행/열 또는 시트를 삽입하거나 삭제하는 경우에는 대기 중인 계산이 취소되며, 이후 계산은 조정된 수식을 기준으로 수행됩니다.

incrementalCalculation 옵션을 true로 설정하면, CalculationProgress 이벤트를 사용하여 진행 상황을 추적할 수 있습니다.

다음 코드 샘플은 CalculationProgress 이벤트에서 진행 상황을 추적하는 방법을 보여줍니다:

// 이 예제는 CalculationProgress 이벤트를 사용하여 계산 진행 상황을 로그로 출력합니다.
spread.options.incrementalCalculation = true;
spread.bind(GC.Spread.Sheets.Events.CalculationProgress, function (e, info) { 
    var msg = "Calculate "; 
    if (info.pendingCells === 0) { 
        msg += "finished"; 
    } else if (info.iterate >= 0) { 
        msg += info.pendingCells + " cells in iterative calculation round " + info.iterate; 
    } else { 
        msg += (info.totalCells - info.pendingCells) + "/" + info.totalCells + "cells"; 
    } 
    console.log(msg); 
}); 

상태 표시줄 항목 추가

incrementalCalculation 옵션이 true로 설정된 경우, 점진적 계산은 계산 진행 상황을 나타내기 위해 상태 표시줄에도 표시됩니다.

다음 코드 샘플은 상태 표시줄을 Spread에 바인딩하여 자동으로 계산 진행 상황을 표시하는 방법을 보여줍니다:

// 상태 표시줄을 초기화하고 Spread에 바인딩합니다.
var statusBar = new GC.Spread.Sheets.StatusBar.StatusBar(document.getElementById('statusBar'));
statusBar.bind(spread);

순환 참조가 없는 셀의 경우: 계산 진행 상황은 아래 이미지와 같이 백분율 형식으로 표시됩니다:


image


순환 참조가 있는 셀의 경우: iterativeCalculationtrue로 설정하여 반복 계산을 구현하며, 계산 진행 상황은 다음 GIF와 같이 반복 라운드(Iterative rounds)로 표시됩니다:


image


다음 코드 샘플은 순환 참조에 대해 iterativeCalculation을 설정하는 방법을 보여줍니다:

// IterativeCalculation 활성화
spread.options.iterativeCalculation = true;
spread.options.iterativeCalculationMaximumIterations = 24;