You can read details about the Zoom extension in the Zooming article. The current article provides the API reference of the zoom object:
The Zoom extension uses a set of the scale settings and allows quickly switching between them.
ZoomLevel is an object that contains the scale settings. It has the following properties:
These are two examples of setting the zoom configuration:
var zoomConfig = {
levels: [
{
name:"day",
scale_height: 27,
min_column_width:80,
scales:[
{unit: "day", step: 1, format: "%d %M"}
]
},
{
name:"week",
scale_height: 50,
min_column_width:50,
scales:[
{unit: "week", step: 1, format: function (date) {
var dateToStr = gantt.date.date_to_str("%d %M");
var endDate = gantt.date.add(date, 6, "day");
var weekNum = gantt.date.date_to_str("%W")(date);
return "#" + weekNum + ", " + dateToStr(date) + " - " + dateToStr(endDate);
}},
{unit: "day", step: 1, format: "%j %D"}
]
},
{
name:"month",
scale_height: 50,
min_column_width:120,
scales:[
{unit: "month", format: "%F, %Y"},
{unit: "week", format: "Week #%W"}
]
},
{
name:"quarter",
height: 50,
min_column_width:90,
scales:[
{unit: "month", step: 1, format: "%M"},
{
unit: "quarter", step: 1, format: function (date) {
var dateToStr = gantt.date.date_to_str("%M");
var endDate = gantt.date.add(gantt.date.add(date, 3, "month"), -1, "day");
return dateToStr(date) + " - " + dateToStr(endDate);
}
}
]},
{
name:"year",
scale_height: 50,
min_column_width: 30,
scales:[
{unit: "year", step: 1, format: "%Y"}
]}
]
};
gantt.ext.zoom.init(zoomConfig);
// or, in a more simple way levels can be presented as scale arrays
var hourToStr = gantt.date.date_to_str("%H:%i");
var hourRangeFormat = function(step){
return function(date){
var intervalEnd = new Date(gantt.date.add(date, step, "hour") - 1)
return hourToStr(date) + " - " + hourToStr(intervalEnd);
};
};
var zoomConfig = {
levels: [
[
{ unit: "month", format: "%M %Y", step: 1},
],
[
{ unit: "month", format: "%M %Y", step: 1},
{ unit: "day", format: "%d %M", step: 1}
],
[
{ unit: "day", format: "%d %M", step: 1},
{ unit: "hour", format: hourRangeFormat(12), step: 12}
],
[
{unit: "day", format: "%d %M",step: 1},
{unit: "hour",format: hourRangeFormat(6),step: 6}
],
[
{ unit: "day", format: "%d %M", step: 1 },
{ unit: "hour", format: "%H:%i", step: 1}
]
]
}
gantt.ext.zoom.init(zoomConfig);
gantt.ext.zoom.getCurrentLevel();
gantt.ext.zoom.setLevel("year");
// or
gantt.ext.zoom.setLevel(5);
gantt.ext.zoom.getLevels();
Returns an array of zooming levels (ZoomLevels[]) passed to the init() method that initializes the extension.
gantt.ext.zoom.zoomIn();
For the same purpose you can also use:
gantt.ext.zoom.setLevel(zoom.getCurrentLevel() - 1)
gantt.ext.zoom.zoomOut();
For the same purpose you can also use:
gantt.ext.zoom.setLevel(zoom.getCurrentLevel() + 1)
attachEvent (name, handler): string - attaches an event handler
detachEvent (id): void - detaches a handler from an event
callEvent (name, params): boolean - calls an inner event
checkEvent (name): boolean - checks whether an event has some handler(s) specified
Returns true, if some handler is specified for the event.
gantt.ext.zoom.attachEvent("onAfterZoom", function(level, config){
document.querySelector(".gantt_radio[value='" +config.name+ "']").checked = true;
});
Back to top