Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

[Timeline] Group height mode #3670

Merged
merged 4 commits into from
Dec 9, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/timeline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ <h3 id="groups">Groups</h3>
<td>no</td>
<td>Assuming the group has nested groups, this will set the initial state of the group - shown or collapsed. The <code>showNested</code> is defaulted to <code>true</code>.</td>
</tr>
<tr>
<td>heightMode</td>
<td>String</td>
<td>no</td>
<td>This field is optional. If set this overrides the global <code>groupHeightMode</code> configuration option for this group.</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please all the valid option ('auto' and 'fixed') to this description.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

</tr>
</table>


Expand Down Expand Up @@ -664,6 +670,13 @@ <h2 id="Configuration_Options">Configuration Options</h2>
<td>If true, groups can be dragged to change their order. Only applicable when the Timeline has groups. For this option to work properly the groupOrder and groupOrderSwap options have to be set as well.</td>
</tr>

<tr>
<td>groupHeightMode</td>
<td>String</td>
<td>'auto'</td>
<td>Specifies how the height of a group is calculated. Choose from 'auto' and 'fixed'. If it is set to 'auto' the height will be calculated based on the visible items. While if it is set to 'fixed' the group will keep the same height even if there are no visible items in the window.</td>
</tr>

<tr>
<td>groupOrder</td>
<td>String or Function</td>
Expand Down
27 changes: 20 additions & 7 deletions lib/timeline/component/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ function Group (groupId, data, itemSet) {
}
}

if (data && data.heightMode) {
this.heightMode = data.heightMode;
} else {
this.heightMode = itemSet.options.groupHeightMode;
}

this.nestedInGroup = null;

this.dom = {};
Expand Down Expand Up @@ -535,20 +541,27 @@ Group.prototype._isGroupVisible = function (range, margin) {
*/
Group.prototype._calculateHeight = function (margin) {
// recalculate the height of the group
var height;
var itemsInRange = this.visibleItems;
if (itemsInRange.length > 0) {
var min = itemsInRange[0].top;
var max = itemsInRange[0].top + itemsInRange[0].height;
util.forEach(itemsInRange, function (item) {
var height, items;

if (this.heightMode === 'fixed') {
items = util.toArray(this.items);
} else {
// default or 'auto'
items = this.visibleItems;
}

if (items.length > 0) {
var min = items[0].top;
var max = items[0].top + items[0].height;
util.forEach(items, function (item) {
min = Math.min(min, item.top);
max = Math.max(max, (item.top + item.height));
});
if (min > margin.axis) {
// there is an empty gap between the lowest item and the axis
var offset = min - margin.axis;
max -= offset;
util.forEach(itemsInRange, function (item) {
util.forEach(items, function (item) {
item.top -= offset;
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/timeline/component/ItemSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ ItemSet.prototype.setOptions = function(options) {
var fields = [
'type', 'rtl', 'align', 'order', 'stack', 'stackSubgroups', 'selectable', 'multiselect',
'multiselectPerGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'visibleFrameTemplate',
'hide', 'snap', 'groupOrderSwap', 'showTooltips', 'tooltip', 'tooltipOnItemUpdateTime', 'onTimeout'
'hide', 'snap', 'groupOrderSwap', 'showTooltips', 'tooltip', 'tooltipOnItemUpdateTime', 'groupHeightMode', 'onTimeout'
];
util.selectiveExtend(fields, this.options, options);

Expand Down
3 changes: 2 additions & 1 deletion lib/timeline/optionsTimeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ let allOptions = {
__type__: {object}
},
moment: {'function': 'function'},
groupHeightMode: {string},
groupOrder: {string, 'function': 'function'},
groupEditable: {
add: { 'boolean': bool, 'undefined': 'undefined'},
Expand Down Expand Up @@ -213,7 +214,7 @@ let configureOptions = {
year: ''
}
},

groupHeightMode: ['auto', 'fixed'],
//groupOrder: {string, 'function': 'function'},
groupsDraggable: false,
height: '',
Expand Down