타임라인 뷰
이 뷰는 Scheduler PRO 버전에만 포함되어 있습니다.
타임라인 뷰는 이벤트를 수평으로 표시하며, 각각의 타임라인을 좌우로 나란히 배치합니다.

초기화
스케줄러에 타임라인 뷰를 추가하려면 다음 단계를 따르세요:
- 페이지에서 Timeline 확장 기능을 활성화하세요:
- Timeline - 'Bar' 및 'Cell' 모드용
- Timeline, Treetimeline - 'Tree' 모드용
- Timeline, Daytimeline - 'Days' 모드용
scheduler.plugins({
timeline: true,
treetimeline: true,
daytimeline: true
});
- 스케줄러의 마크업에 뷰 탭을 추가하세요:
<div id="scheduler_here" class="dhx_cal_container" ...>
<div class="dhx_cal_navline">
...
<div class="dhx_cal_tab" name="timeline_tab"></div>
</div>
...
</div>
- 탭의 라벨을 설정하세요:
//'timeline_tab'은 div의 이름을 참조합니다
scheduler.locale.labels.timeline_tab ="Timeline";
- createTimelineView 메서드를 호출하세요:
scheduler.createTimelineView({
name:"timeline",
x_unit:"minute", // X축의 단위
x_date:"%H:%i", // X축에 표시되는 날짜 포맷
x_step:30, // X축 단위의 간격
x_size:24, // X축에 표시되는 'x_step'의 총 개수
x_start:16, // X축 시작 오프셋 (x_unit 기준)
x_length:48, // 한 번에 스크롤되는 'x_step'의 개수
y_unit: // Y축에 표시되는 섹션
[{key:1, label:"Section A"},
{key:2, label:"Section B"},
{key:3, label:"Section C"},
{key:4, label:"Section D"}],
y_property:"section_id", // 데이터를 섹션에 매핑하는 속성
render:"bar" // 뷰 모드
});
'Days' 모드를 사용할 때, 타임 스케일은 반드시 정확히 하루를 포함해야 합니다. 설정이 더 짧거나 길면 타임라인이 올바르게 렌더링되지 않습니다.
스케일 구성 예시
createTimelineView 메서드는 많은 파라미터를 포함하고 있지만, 실제로는 간단합니다.
예시: 09:00부터 15:00까지 30분 간격으로, 하루 단위로 스크롤되는 타임 스케일.
{
x_unit:"minute",// 스케일 단위는 분
x_step:30, // 30분 간격, 예: 09:00 - 09:30
x_size:12, // 09:00~15:00까지 30분 구간의 개수
// 15 - 9 = 6시간 = 360분 = 360/30 = 12
x_start:18, // 스케일 시작은 09:00, 즉 00:00으로부터 9시간
// 9시간 = 540분 = 540/30 = 18 'x_step'
x_length:48,// 하루 스크롤: 1일 = 24시간 = 1440분 = 1440/30 = 48 'x_step'
...
}
타임라인 뷰 구성
이름에 (timeline)_some이 포함된 모든 템플릿 함수는 뷰를 생성한 후에 정의해야 합니다. 이러한 함수들은 타임라인 생성자에 의해 동적으로 할당되며 createTimelineView 호출 시 덮어쓰기 때문입니다.
타임라인 뷰의 시작 날짜 설정
예를 들어, 타임라인 뷰의 시작 날짜를 설정하는 방법은 다음과 같습니다.
모든 뷰의 시작 날짜는 scheduler.date[<viewName> +"_start"] 함수로 제어됩니다. 타임라인 스케일의 첫날을 조정하려면, scheduler.createTimelineView() 호출 후 scheduler.date.timeline_start 함수를 오버라이드하세요:
// 주의 시작을 월요일로 설정
scheduler.config.start_on_monday = true;
// 타임라인 뷰 생성
scheduler.createTimelineView({
name: "timeline",
render: "tree",
days: 7,
folder_dy: 20,
x_unit: "day",
x_date: "%D %j %F",
x_step: 1,
x_size: 7,
x_start: 0,
x_length: 7,
y_unit:[],
y_property: "section_id"
});
// 생성 후 시작 날짜 함수 오버라이드
scheduler.date.timeline_start = scheduler.date.week_start;
// 스케줄러 초기화
scheduler.init("timeline_tree", new Date(), "timeline");
타임라인 객체 API
타임라인 뷰와 상호작용할 수 있는 여러 메서드가 제공됩니다.
타임라인 뷰 생성
스케줄러에서 타임라인 인스턴스를 생성하세요:
scheduler.createTimelineView({
name:'timeline',
...
});
var timeline = scheduler.matrix.timeline;
생성 후 아래의 메서드들을 사용할 수 있습니다.
타임라인 뷰 가져오기
타임라인 뷰 객체를 가져오려면 getView 메서드를 사용하세요. 뷰의 이름을 파라미터로 받습니다. 파라미터가 없으면 현재 뷰를 반환합니다.
var timeline = scheduler.getView();
timeline.x_size = 8;
scheduler.setCurrentView();
스케일 범위 설정
setRange() 메서드를 사용하여 스케일 범위를 정의할 수 있습니다. 두 개의 파라미터가 필요합니다:
- startDate - (Date) 범위 시작
- endDate - (Date) 범위 끝
timeline.setRange(startDate, endDate);
왼쪽 패널의 컬럼 지정
왼쪽 패널의 내용은 두 가지 방법으로 설정할 수 있습니다.
기본적으로는 하나의 컬럼만 포함합니다. 섹션 라벨은 y_unit 객체의 label 속성에서 가져오며, timeline_scale_label 템플릿으로 커스터마이즈할 수 있습니다.
여러 컬럼을 정의하려면 createTimelineView 메서드에서 columns 속성을 사용하세요:
scheduler.createTimelineView({
name: "timeline",
x_unit: "minute",
x_date: "%H:%i",
x_step: 30,
x_size: 24,
x_start: 16,
x_length: 48,
y_unit: sections,
event_dy: "full",
y_property: "section_id",
render:"bar",
columns: [
{ label: "Room #", width: 70, template: function(obj){ return obj.room_no; } },
{ label: "Type", width: 90, template: function(obj){ return obj.room_type; } },
{ label: "Status", width: 90, template: function(obj){ return obj.room_status; } }
]
});
각 컬럼 객체는 다음 속성을 가질 수 있습니다:
- label -
string- 헤더 라벨(선택) - width -
number- 컬럼 너비(선택) - template -
function- 섹션 객체를 받는 셀 템플릿 함수
특정 위치/날짜/섹션으로 스크롤
이 기능은 타임라인에서 수평 스크롤이 활성화된 경우에만 동작합니다.
특정 지점으로 스크롤하려면 scrollTo() 메서드를 사용하세요. 다양한 파라미터 타입을 지원합니다:
- Date 객체를 전달하여 특정 날짜로 스크롤:
timeline.scrollTo(new Date());
- 픽셀 값을 전달하여 특정 위치로 스크롤:
timeline.scrollTo(500);
- 날짜와 섹션 키가 포함된 객체를 전달하여 수평 및 수직으로 특정 섹션의 특정 날짜로 스크롤:
timeline.scrollTo({date:new Date(), section:4});
- left와 top 픽셀 값이 있는 객체를 전달하여 수평, 수직 위치로 스크롤:
timeline.scrollTo({left:300, top:500});
특정 위치의 좌표 얻기
- 스케일에서 특정 날짜의 X좌표를 얻으려면 **posFromDate()**를 Date 파라미터와 함께 사용하세요:
var left = timeline.posFromDate(new Date());
이 메서드는 날짜가 스케일 범위를 벗어나면 0 또는 최대 X좌표를 반환합니다.
- 특정 행의 Y좌표를 얻으려면 **getSectionTop()**을 섹션 번호와 함께 사용하세요:
var top = timeline.getSectionTop(section.key);
행을 찾을 수 없으면 -1을 반환합니다.
- 타임라인 좌표에 해당하는 날짜와 섹션을 찾으려면 **resolvePosition()**을
(left: number, top: number)객체와 함께 사용하세요:
const position = timeline.resolvePosition({top: 120, left: 400});
- 시간 스케일의 특정 left 좌표에서
Date를 얻으려면 **dateFromPos()**를 사용하세요:
const date = timeline.dateFromPos(300);
- 특정 이벤트의 top 좌표를 얻으려면 **getEventTop()**을 이벤트 객체와 함께 사용하세요:
const top = timeline.getEventTop(scheduler.getEvent(event.id));
스크롤 위치 가져오기
현재 스크롤바 위치를 확인하려면 **timeline.getScrollPosition()**을 호출하세요. 스크롤 좌표가 담긴 객체를 반환합니다:
var timeline = scheduler.getView();
timeline.getScrollPosition(); // { left: 0, top: 0 }
반환 객체는 다음을 포함합니다:
- left - (number) 수평 스크롤 위치
- top - (number) 수직 스크롤 위치
onScroll 이벤트를 사용해 스크롤 변경을 감지할 수도 있습니다. 이 이벤트는 새로운 left, top 위치를 전달받습니다:
var timeline = scheduler.getView();
timeline.attachEvent("onScroll", function(left, top){});
특정 섹션에 할당된 이벤트 가져오기
특정 섹션에 할당된 이벤트 배열을 얻으려면 **timeline.selectEvents()**를 구성 객체와 함께 사용하세요:
{
section: string|number,
date: Date,
selectNested: boolean
}
설명:
- section - 섹션의 id
- date - 선택 사항, 지정한 날짜 컬럼에 겹치는 이벤트만 필터링
- selectNested - 선택 사항, true이면 섹션이 트리 타임라인 폴더일 때 모든 하위 섹션의 이벤트도 선택
이 메서드는 이벤트 객체 배열을 반환합니다.
var timeline = scheduler.getView();
var events = timeline.selectEvents({
section: section.key,
date: date,
selectNested: true
});
속성의 동적 변경
모든 타임라인 객체는 scheduler.matrix 객체에 저장됩니다. 이름으로 원하는 타임라인 뷰에 접근해 속성을 업데이트할 수 있습니다. 변경 사항은 스케줄러를 새로고침한 후 적용됩니다:
scheduler.getView('timeline').x_size = 12;
scheduler.setCurrentView(); // 스케줄러를 다시 그림
여기서 'timeline'은 createTimelineView 메서드에서 지정한 이름과 일치해야 합니다:
scheduler.createTimelineView({
name:'timeline',
...
});
섹션 동적 변경
타임라인 뷰에서 단위(유닛) 목록을 실시간으로 업데이트해야 할 때는 serverList 및 updateCollection 메서드 사용을 권장합니다.
데이터 로딩
Day, Month, Year와 같은 단순한 뷰와 달리, Units 및 Timeline과 같은 다중 리소스 뷰에서는 각 데이터 항목에 추가 필드가 반드시 포함되어야 합니다.
- y_property - (string) 이벤트를 특정 섹션에 할당하는 데 사용되는 데이터 프로퍼티를 지정합니다.

scheduler.createTimelineView({
name:"timeline",
...
y_unit:
[{key:1, label:"Room 1"},
{key:2, label:"Room 2"},
{key:3, label:"Room 3"}],
y_property:"room_id",
});
scheduler.init('scheduler_here');
scheduler.parse([
{text:"Conference", start_date:"17/09/2012 12:00", end_date:"18/09/2012 21:00",
room_id:"1"},
{text:"Meeting", start_date:"17/09/2012 09:00", end_date:"17/09/2012 21:00",
room_id:"2"},
{text:"Conference", start_date:"17/09/2012 15:00", end_date:"18/09/2012 15:00",
room_id:"3"}
]);
여러 섹션에 이벤트 할당
스케줄러는 하나의 이벤트를 여러 섹션에 동시에 할당하는 기능을 지원합니다.

이 기능을 활성화하려면:
- Multisection 확장 기능을 페이지에 포함합니다.
- multisection 속성을 true로 설정합니다.
- (선택 사항) "Multiselect" 확장 기능을 추가하여 스케줄러 내에서 편리하게 섹션을 전환할 수 있는 "Multiselect" 컨트롤을 제공합니다.
<script src="codebase/dhtmlxscheduler.js"></script>
<link rel="stylesheet" href="codebase/dhtmlxscheduler.css" type="text/css">
<script>
scheduler.plugins({
multisection: true, /*!*/
multiselect: true,
timeline: true
});
scheduler.config.multisection = true; /*!*/
scheduler.init('scheduler_here');
</script>
설정 후, 이벤트의 관련 데이터 프로퍼티에 여러 섹션을 (기본적으로 쉼표로 구분하여, 자세한 내용은 section_delimiter 참고) 나열할 수 있으며, 해당 이벤트는 모든 지정된 섹션에 표시됩니다.
scheduler.createTimelineView({
name: "timeline",
y_unit: [
{key: 1, label: "James Smith"},
{key: 2, label: "John Williams"},
{key: 3, label: "David Miller"},
{key: 4, label: "Linda Brown"}],
y_property: "section_id", /*!*/
...
});
scheduler.init('scheduler_here', new Date(2012, 5, 30), "timeline");
scheduler.parse([
{ id:1, text:"Task A", section_id:'1', ...},/*!*/
{ id:2, text:"Task B", section_id:'1,3', ...},/*!*/
{ id:3, text:"Task C", section_id:'4', ...},/*!*/
{ id:4, text:"Task D", section_id:'2,3,4', ...}/*!*/
]);
Multisection events in Timeline and Units view
뷰 모드
타임라인 뷰는 네 가지 고유한 모드를 제공합니다:
- Bar

- Cell (기본값)

- Tree

- Days

원하는 모드는 render 파라미터로 선택할 수 있습니다.
scheduler.createTimelineView({
name: "timeline",
render: "bar"
});
'Days' 모드 상세
Days 모드를 사용할 때는 다음 사항에 유의해야 합니다.
- 타임 스케일은 반드시 하루를 정확히 커버해야 합니다. 더 짧거나 긴 기간으로 설정하면 타임라인이 올바르게 렌더링되지 않을 수 있습니다:
scheduler.createTimelineView({
name:"timeline",
render:"days",
days:7,
//time scale configured to cover 1 day /*!*/
x_unit:"minute", /*!*/
x_date:"%H:%i", /*!*/
x_step:30, /*!*/
x_size:24, /*!*/
x_start:16 /*!*/
});
- 이 모드에서는 차단 및 표시 기능이 지원되지 않습니다.
- Y축 레이블 형식은 scale_label 템플릿으로 제어할 수 있습니다:
scheduler.templates.timeline_scale_label = function(key, label, section){
// Day 뷰와 동일한 레이블 사용
return scheduler.templates.day_date(label);
};
- 표시 구간의 시작일을 조정하려면 scheduler.date.(timeline_name)_start 함수를 사용하세요:
scheduler.date.timeline_start = function (date) {
date = scheduler.date.week_start(date);
date = scheduler.date.add(date, config.x_step*config.x_start, config.x_unit);
return date;
};