FVS 슬라이더 » 이력 » 버전 1
김 미진, 2025/04/22 10:38
1 | 1 | 김 미진 | h1. FVS 슬라이더 |
---|---|---|---|
2 | |||
3 | <pre> |
||
4 | "use document"; |
||
5 | // 초기 설정 |
||
6 | let currentChart = ''; // 현재 표시 중인 차트 ID |
||
7 | let mouseOnChart = false; // 마우스가 현재 차트 위에 있는지 여부 |
||
8 | let chartArr = []; // 차트 배열 |
||
9 | |||
10 | // 동적 초기 값 설정 모듈 |
||
11 | const setupInitialValues = (charts, defaultChartId) => { |
||
12 | chartArr = charts; |
||
13 | currentChart = defaultChartId; |
||
14 | }; |
||
15 | |||
16 | // 타겟 잡는 모듈 |
||
17 | const targetChart = (chartId) => chartArr.findIndex(item => item === chartId); |
||
18 | |||
19 | // 슬라이딩 돌리는 모듈 |
||
20 | const toggleCharts = () => { |
||
21 | const currentIndex = targetChart(currentChart); |
||
22 | const nextIndex = (currentIndex + 1) % chartArr.length; |
||
23 | const nextChart = chartArr[nextIndex]; |
||
24 | |||
25 | duchamp.getWidgetByName(currentChart).setVisible(false); |
||
26 | duchamp.getWidgetByName(nextChart).setVisible(true); |
||
27 | currentChart = nextChart; |
||
28 | }; |
||
29 | |||
30 | // 인터벌 제어 모듈 |
||
31 | let intervalId; |
||
32 | const intervalTime = 1000; // 인터벌 시간 (1초) |
||
33 | |||
34 | const startInterval = (callback, interval) => { |
||
35 | clearInterval(intervalId); // 기존 인터벌이 있으면 중지 |
||
36 | intervalId = setInterval(callback, interval); |
||
37 | }; |
||
38 | |||
39 | const stopInterval = () => { |
||
40 | clearInterval(intervalId); |
||
41 | console.log("인터벌이 중지되었습니다."); |
||
42 | }; |
||
43 | |||
44 | const intervalCallback = () => { |
||
45 | toggleCharts(); |
||
46 | toggleManage(); // 슬라이더 상태 동기화 |
||
47 | }; |
||
48 | |||
49 | const toggleManage = () => { |
||
50 | if (mouseOnChart) { |
||
51 | stopInterval(); |
||
52 | } else { |
||
53 | startInterval(intervalCallback, intervalTime); |
||
54 | } |
||
55 | }; |
||
56 | |||
57 | // 이벤트 처리 모듈 |
||
58 | const setupMouseEvents = () => { |
||
59 | document.querySelectorAll("[data-name^='chart']").forEach(element => { |
||
60 | element.addEventListener('mouseover', () => { |
||
61 | mouseOnChart = true; |
||
62 | toggleManage(); |
||
63 | }); |
||
64 | element.addEventListener('mouseout', () => { |
||
65 | mouseOnChart = false; |
||
66 | toggleManage(); |
||
67 | }); |
||
68 | }); |
||
69 | }; |
||
70 | |||
71 | // 초기화 모듈 |
||
72 | const initialize = (charts, defaultChartId) => { |
||
73 | setupInitialValues(charts, defaultChartId); |
||
74 | setupMouseEvents(); |
||
75 | startInterval(intervalCallback, intervalTime); |
||
76 | } |
||
77 | |||
78 | // 페이지 로드 후 초기화 실행 |
||
79 | setTimeout(() => { |
||
80 | initialize(['chart2', 'chart3'], 'chart2'); // 초기 차트 배열과 기본 차트 ID를 설정 |
||
81 | }, 200); // 페이지 로딩 후 200ms 뒤에 실행 |
||
82 | </pre> |