Zooming in Angular Gantt component
27 Apr 202416 minutes to read
The zooming support provides options to increase or decrease the width of timeline cells and also provides options to change the timeline units dynamically. This support enables you to view the tasks in a project clearly from minute to decade timespan. To enable the zooming features, define the ZoomIn
, ZoomOut
, and ZoomToFit
items to toolbar items collections, and this action can be performed on external actions such as button click using the zoomIn
, zoomOut
, and fitToProject
built-in methods. The following zooming options are available to view the project:
Zoom in
This support is used to increase the timeline width and timeline unit from years to minutes timespan. When the ZoomIn
icon was clicked, the timeline cell width is increased when the cell size exceeds the specified range and the timeline unit is changed based on the current zoom levels.
Zoom out
This support is used to increase the timeline width and timeline unit from minutes to years timespan. When the ZoomOut
icon was clicked, the timeline cell width is decreased when the cell size falls behind the specified range and the timeline view mode is changed based on the current zooming levels.
Zoom to fit
This support is used to view all the tasks available in a project within available area on the chart part of Gantt. When users click the ZoomToFit
icon, then all the tasks are rendered within the available chart container width.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { EditService, SelectionService, ToolbarService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { Gantt } from '@syncfusion/ej2-gantt';
import { ToolbarItem } from '@syncfusion/ej2-angular-gantt';
import { projectNewData } from './data';
@Component({
imports: [
GanttModule
],
providers: [EditService, SelectionService, ToolbarService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings"[toolbar]="toolbar"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
public ngOnInit(): void {
this.data = projectNewData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
dependency: 'Predecessor',
child: 'subtasks'
};
this.toolbar = ['ZoomIn', 'ZoomOut', 'ZoomToFit'];
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Customizing zooming levels
In Gantt, the zoom in and zoom out actions are performed based on the predefined zooming levels in the zoomingLevels
property. You can customize the zooming actions by defining the required zooming collection to the zoomingLevels
property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { FilterService, ToolbarService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt } from '@syncfusion/ej2-gantt';
import { GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ToolbarItem, ZoomTimelineSettings } from '@syncfusion/ej2-angular-gantt';
import { projectNewData } from './data';
@Component({
imports: [
GanttModule
],
providers: [FilterService, ToolbarService],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings"[toolbar]="toolbar" (dataBound)="dataBound()"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public toolbar?: ToolbarItem[];
@ViewChild('gantt', {static: true})
public ganttObj?: GanttComponent| any;
public customZoomingLevels: ZoomTimelineSettings[] = [{
topTier: { unit: 'Month', format: 'MMM, yy', count: 1 },
bottomTier: { unit: 'Week', format: 'dd', count: 1 }, timelineUnitSize: 33, level: 0,
timelineViewMode: 'Month', weekStartDay: 0, updateTimescaleView: true, weekendBackground: undefined, showTooltip: true
},
{
topTier: { unit: 'Month', format: 'MMM, yyyy', count: 1 },
bottomTier: { unit: 'Week', format: 'dd MMM', count: 1 }, timelineUnitSize: 66, level: 1,
timelineViewMode: 'Month', weekStartDay: 0, updateTimescaleView: true, weekendBackground: undefined, showTooltip: true
},
{
topTier: { unit: 'Month', format: 'MMM, yyyy', count: 1 },
bottomTier: { unit: 'Week', format: 'dd MMM', count: 1 }, timelineUnitSize: 99, level: 2,
timelineViewMode: 'Month', weekStartDay: 0, updateTimescaleView: true, weekendBackground: undefined, showTooltip: true
},
{
topTier: { unit: 'Week', format: 'MMM dd, yyyy', count: 1 },
bottomTier: { unit: 'Day', format: 'd', count: 1 }, timelineUnitSize: 33, level: 3,
timelineViewMode: 'Week', weekStartDay: 0, updateTimescaleView: true, weekendBackground: undefined, showTooltip: true
},
{
topTier: { unit: 'Week', format: 'MMM dd, yyyy', count: 1 },
bottomTier: { unit: 'Day', format: 'd', count: 1 }, timelineUnitSize: 66, level: 4,
timelineViewMode: 'Week', weekStartDay: 0, updateTimescaleView: true, weekendBackground: undefined, showTooltip: true
},
{
topTier: { unit: 'Day', format: 'E dd yyyy', count: 1 },
bottomTier: { unit: 'Hour', format: 'hh a', count: 12 }, timelineUnitSize: 66, level: 5,
timelineViewMode: 'Day', weekStartDay: 0, updateTimescaleView: true, weekendBackground: undefined, showTooltip: true
},
{
topTier: { unit: 'Day', format: 'E dd yyyy', count: 1 },
bottomTier: { unit: 'Hour', format: 'hh a', count: 6 }, timelineUnitSize: 99, level: 6,
timelineViewMode: 'Day', weekStartDay: 0, updateTimescaleView: true, weekendBackground: undefined, showTooltip: true
},
];
public ngOnInit(): void {
this.data = projectNewData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
dependency: 'Predecessor',
child: 'subtasks'
};
this.toolbar = ['ZoomIn', 'ZoomOut', 'ZoomToFit'];
}
public dataBound(): void {
this.ganttObj.zoomingLevels = this.customZoomingLevels
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Zoom action by methods
You can perform the various zoom actions dynamically or on external click action using the following methods:
- Zoom in -
zoomIn
- Zoom out -
zoomOut
- Fit to project -
fitToProject
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { FilterService, ToolbarService } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ButtonComponent } from '@syncfusion/ej2-angular-buttons';
import { projectNewData } from './data';
@Component({
imports: [
GanttModule
],
providers: [FilterService, ToolbarService],
standalone: true,
selector: 'app-root',
template:
`<button ejs-button id='zoomIn' (click)='zoomIn()'>ZoomIn</button>
<button ejs-button id='zoomOut' (click)='zoomOut()'>ZoomOut</button>
<button ejs-button id='fitToProject' (click)='fitToProject()'>FitToProject</button>
<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
@ViewChild('gantt', {static: true})
public ganttObj?: GanttComponent| any;
public ngOnInit(): void {
this.data = projectNewData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
dependency: 'Predecessor',
child: 'subtasks'
};
}
zoomIn(): void {
this.ganttObj.zoomIn();
};
zoomOut(): void {
this.ganttObj.zoomOut();
};
fitToProject(): void{
this.ganttObj.fitToProject();
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));