Skip to content

Commit c25a9c7

Browse files
Merge pull request #68 from mlakatkou/GS-3308
[update] zoom article
2 parents 3b139bc + 268b7d8 commit c25a9c7

1 file changed

Lines changed: 90 additions & 89 deletions

File tree

docs/guides/zoom.md

Lines changed: 90 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ sidebar_label: "Zoom Extension"
55

66
# Zoom Extension
77

8-
9-
10-
You can read details about the Zoom extension in the [Zooming](guides/zooming.md) article. The current article provides the API reference of the **zoom** object:
11-
8+
You can read details about the Zoom extension in the [Zooming](guides/zooming.md) article. The current article provides the API reference of the `zoom` object:
129

1310
## Zoom Levels
1411

1512
The Zoom extension uses a set of the scale settings and allows quickly switching between them.
1613

17-
**ZoomLevel** is an object that contains the scale settings. It has the following properties:
14+
`ZoomLevel` is an object that contains the scale settings. It has the following properties:
1815

1916
- <span class="subproperty">**name**</span> - (*string*) - the name of the level
2017
- <span class="subproperty">**scale_height?**</span> - (*number*) - the height of the scale
@@ -25,7 +22,7 @@ The Zoom extension uses a set of the scale settings and allows quickly switching
2522

2623
## Methods
2724

28-
- <span class="submethod">**init (zoomConfig): void**</span> - initializes the extension with the provided configuration.
25+
- <span class="submethod">**init(zoomConfig): void**</span> - initializes the extension with the provided configuration.
2926
- **_zoomConfig_** - (*object*) - an object with configuration settings that contains the *levels* array of zooming levels and a number of additional properties:
3027
- **_levels_** - (*ZoomLevel[]*) - required, an array of zooming levels
3128
- **_handler?_** - (*Function*): void - allows specifying a custom handler of the mouse wheel to work with zooming manually
@@ -40,111 +37,115 @@ The Zoom extension uses a set of the scale settings and allows quickly switching
4037
- **_trigger?_** - (*string | null | undefined*) - the trigger of zooming: "wheel" | null | undefined
4138
- **_element?_** - (*HTMLElement | Function*): HTMLElement - a DOM element over which zooming is triggered or a function that returns a DOM element
4239

43-
These are two examples of setting the **zoom** configuration:
40+
These are two examples of setting the `zoom` configuration:
4441

4542
~~~js
46-
var zoomConfig = {
43+
const zoomConfig = {
4744
levels: [
48-
{
49-
name:"day",
50-
scale_height: 27,
51-
min_column_width:80,
52-
scales:[
53-
{unit: "day", step: 1, format: "%d %M"}
54-
]
55-
},
56-
{
57-
name:"week",
58-
scale_height: 50,
59-
min_column_width:50,
60-
scales:[
61-
{unit: "week", step: 1, format: function (date) {
62-
var dateToStr = gantt.date.date_to_str("%d %M");
63-
var endDate = gantt.date.add(date, 6, "day");
64-
var weekNum = gantt.date.date_to_str("%W")(date);
65-
return "#" + weekNum + ", " + dateToStr(date) + " - " + dateToStr(endDate);
66-
}},
67-
{unit: "day", step: 1, format: "%j %D"}
68-
]
69-
},
70-
{
71-
name:"month",
72-
scale_height: 50,
73-
min_column_width:120,
74-
scales:[
75-
{unit: "month", format: "%F, %Y"},
76-
{unit: "week", format: "Week #%W"}
77-
]
45+
{
46+
name: "day",
47+
scale_height: 27,
48+
min_column_width: 80,
49+
scales: [{ unit: "day", step: 1, format: "%d %M" }]
50+
},
51+
{
52+
name: "week",
53+
scale_height: 50,
54+
min_column_width: 50,
55+
scales: [
56+
{
57+
unit: "week",
58+
step: 1,
59+
format: (date) => {
60+
const dateToStr = gantt.date.date_to_str("%d %M");
61+
const endDate = gantt.date.add(date, 6, "day");
62+
const weekNumber = gantt.date.date_to_str("%W")(date);
63+
64+
return `#${weekNumber}, ${dateToStr(date)} - ${dateToStr(endDate)}`;
65+
}
66+
},
67+
{ unit: "day", step: 1, format: "%j %D" }
68+
]
7869
},
7970
{
80-
name:"quarter",
81-
height: 50,
82-
min_column_width:90,
83-
scales:[
84-
{unit: "month", step: 1, format: "%M"},
85-
{
86-
unit: "quarter", step: 1, format: function (date) {
87-
var dateToStr = gantt.date.date_to_str("%M");
88-
var endDate = gantt.date.add(gantt.date.add(date, 3, "month"), -1, "day");
89-
return dateToStr(date) + " - " + dateToStr(endDate);
90-
}
91-
}
92-
]},
71+
name: "month",
72+
scale_height: 50,
73+
min_column_width: 120,
74+
scales: [{ unit: "month", format: "%F, %Y" }, { unit: "week", format: "Week #%W" }]
75+
},
9376
{
94-
name:"year",
95-
scale_height: 50,
96-
min_column_width: 30,
97-
scales:[
98-
{unit: "year", step: 1, format: "%Y"}
99-
]}
77+
name: "quarter",
78+
height: 50,
79+
min_column_width: 90,
80+
scales: [
81+
{ unit: "month", step: 1, format: "%M" },
82+
{
83+
unit: "quarter",
84+
step: 1,
85+
format: (date) => {
86+
const dateToStr = gantt.date.date_to_str("%M");
87+
const endDate = gantt.date.add(gantt.date.add(date, 3, "month"), -1, "day");
88+
89+
return `${dateToStr(date)} - ${dateToStr(endDate)}`;
90+
}
91+
}
92+
]
93+
},
94+
{
95+
name: "year",
96+
scale_height: 50,
97+
min_column_width: 30,
98+
scales: [{ unit: "year", step: 1, format: "%Y" }]
99+
}
100100
]
101101
};
102102

103103
gantt.ext.zoom.init(zoomConfig);
104104

105105

106106
// or, in a more simple way levels can be presented as scale arrays
107-
var hourToStr = gantt.date.date_to_str("%H:%i");
108-
var hourRangeFormat = function(step){
109-
return function(date){
110-
var intervalEnd = new Date(gantt.date.add(date, step, "hour") - 1)
111-
return hourToStr(date) + " - " + hourToStr(intervalEnd);
107+
const hourToStr = gantt.date.date_to_str("%H:%i");
108+
const hourRangeFormat = (step) => {
109+
return (date) => {
110+
const intervalEnd = new Date(gantt.date.add(date, step, "hour") - 1);
111+
112+
return `${hourToStr(date)} - ${hourToStr(intervalEnd)}`;
112113
};
113114
};
114-
var zoomConfig = {
115+
const simpleZoomConfig = {
115116
levels: [
116117
[
117-
{ unit: "month", format: "%M %Y", step: 1},
118+
{ unit: "month", format: "%M %Y", step: 1 }
118119
],
119120
[
120-
{ unit: "month", format: "%M %Y", step: 1},
121-
{ unit: "day", format: "%d %M", step: 1}
121+
{ unit: "month", format: "%M %Y", step: 1 },
122+
{ unit: "day", format: "%d %M", step: 1 }
122123
],
123124
[
124-
{ unit: "day", format: "%d %M", step: 1},
125-
{ unit: "hour", format: hourRangeFormat(12), step: 12}
125+
{ unit: "day", format: "%d %M", step: 1 },
126+
{ unit: "hour", format: hourRangeFormat(12), step: 12 }
126127
],
127128
[
128-
{unit: "day", format: "%d %M",step: 1},
129-
{unit: "hour",format: hourRangeFormat(6),step: 6}
129+
{ unit: "day", format: "%d %M", step: 1 },
130+
{ unit: "hour", format: hourRangeFormat(6), step: 6 }
130131
],
131132
[
132133
{ unit: "day", format: "%d %M", step: 1 },
133-
{ unit: "hour", format: "%H:%i", step: 1}
134+
{ unit: "hour", format: "%H:%i", step: 1 }
134135
]
135136
]
136-
}
137+
};
137138

138-
gantt.ext.zoom.init(zoomConfig);
139+
gantt.ext.zoom.init(simpleZoomConfig);
139140
~~~
140141

141-
- <span class="submethod">**getCurrentLevel (): number**</span> - returns the number (index) of the current zooming level
142+
- <span class="submethod">**getCurrentLevel(): number**</span> - returns the number (index) of the current zooming level
142143

143144
~~~js
144145
gantt.ext.zoom.getCurrentLevel();
145146
~~~
146147

147-
- <span class="submethod">**setLevel (level): void**</span> - switches to the specified zooming level.
148+
- <span class="submethod">**setLevel(level): void**</span> - switches to the specified zooming level.
148149
- **_level_** - (*number | string*) - The level is defined either by a string (the name of the level from the config, e.g. "year"), or by its number in the array of levels
149150

150151
~~~js
@@ -153,15 +154,15 @@ gantt.ext.zoom.setLevel("year");
153154
gantt.ext.zoom.setLevel(5);
154155
~~~
155156

156-
- <span class="submethod">**getLevels (): ZoomLevel[]**</span> - allows getting all zooming levels
157+
- <span class="submethod">**getLevels(): ZoomLevel[]**</span> - allows getting all zooming levels
157158

158159
~~~js
159160
gantt.ext.zoom.getLevels();
160161
~~~
161162

162-
Returns an array of zooming levels (*ZoomLevels[]*) passed to the **init()** method that initializes the extension.
163+
Returns an array of zooming levels (*ZoomLevels[]*) passed to `init()`, which initializes the extension.
163164

164-
- <span class="submethod">**zoomIn (): void**</span> - increases the current zooming level
165+
- <span class="submethod">**zoomIn(): void**</span> - increases the current zooming level
165166

166167
~~~js
167168
gantt.ext.zoom.zoomIn();
@@ -170,10 +171,10 @@ gantt.ext.zoom.zoomIn();
170171
For the same purpose you can also use:
171172

172173
~~~js
173-
gantt.ext.zoom.setLevel(zoom.getCurrentLevel() - 1)
174+
gantt.ext.zoom.setLevel(gantt.ext.zoom.getCurrentLevel() - 1);
174175
~~~
175176

176-
- <span class="submethod">**zoomOut (): void**</span> - decreases the current zooming level
177+
- <span class="submethod">**zoomOut(): void**</span> - decreases the current zooming level
177178

178179
~~~js
179180
gantt.ext.zoom.zoomOut();
@@ -182,36 +183,36 @@ gantt.ext.zoom.zoomOut();
182183
For the same purpose you can also use:
183184

184185
~~~js
185-
gantt.ext.zoom.setLevel(zoom.getCurrentLevel() + 1)
186+
gantt.ext.zoom.setLevel(gantt.ext.zoom.getCurrentLevel() + 1);
186187
~~~
187188

188-
- <span class="submethod">**attachEvent (name, handler): string**</span> - attaches an event handler
189+
- <span class="submethod">**attachEvent(name, handler): string**</span> - attaches an event handler
189190
- **_name_** - (*string*) - the name of the event handler
190191
- **_handler_** - (*Function*) - the function that will be called when the event fires
191192

192-
- <span class="submethod">**detachEvent (id): void**</span> - detaches a handler from an event
193+
- <span class="submethod">**detachEvent(id): void**</span> - detaches a handler from an event
193194
- **_id_** - (*string*) - the id of the attached event handler
194195

195-
- <span class="submethod">**callEvent (name, params): boolean**</span> - calls an inner event
196+
- <span class="submethod">**callEvent(name, params): boolean**</span> - calls an inner event
196197
- **_name_** - (*string*) - the event's name, case-insensitive
197198
- **_params_** - (*Array&lt;any&gt;*) - optional, an array of the event-related data
198199

199-
- <span class="submethod">**checkEvent (name): boolean**</span> - checks whether an event has some handler(s) specified
200+
- <span class="submethod">**checkEvent(name): boolean**</span> - checks whether an event has some handler(s) specified
200201
- **_name_** - (*string*) - the event's name
201202

202203
Returns <i>true</i>, if some handler is specified for the event.
203204

204205
## Events
205206

206207
- **<span class="eventname">onAfterZoom</span>** - fires during switching of the zooming level.
207-
The arguments are:
208+
The arguments are:
208209
<span class="eventarguments">
209210
- **_level_** - (*number | string*) - the number of the level
210211
- **_config_** - (*ZoomLevel*) - the config of the level
211212
</span>
212213

213214
~~~js
214-
gantt.ext.zoom.attachEvent("onAfterZoom", function(level, config){
215-
document.querySelector(".gantt_radio[value='" +config.name+ "']").checked = true;
216-
});
215+
gantt.ext.zoom.attachEvent("onAfterZoom", (level, config) => {
216+
document.querySelector(`.gantt_radio[value='${config.name}']`).checked = true;
217+
});
217218
~~~

0 commit comments

Comments
 (0)