File ItemSet.js
has 1554 lines of code (exceeds 250 allowed). Consider refactoring. Open
var Hammer = require('../../module/hammer');
var util = require('../../util');
var DataSet = require('../../DataSet');
var DataView = require('../../DataView');
var TimeStep = require('../TimeStep');
Function setOptions
has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype.setOptions = function(options) {
if (options) {
// copy all options that we know
var fields = [
'type', 'rtl', 'align', 'order', 'stack', 'stackSubgroups', 'selectable', 'multiselect',
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _onMultiSelectItem
has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onMultiSelectItem = function (event) {
if (!this.options.selectable) return;
var item = this.itemFromTarget(event);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _onGroupDrag
has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onGroupDrag = function (event) {
if (this.options.groupEditable.order && this.groupTouchParams.group) {
event.stopPropagation();
var groupsData = this.groupsData;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function ItemSet
has 142 lines of code (exceeds 25 allowed). Consider refactoring. Open
function ItemSet(body, options) {
this.body = body;
this.defaultOptions = {
type: null, // 'box', 'point', 'range', 'background'
orientation: {
Function _onDrag
has 110 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onDrag = function (event) {
if (this.touchParams.itemProps) {
event.stopPropagation();
var me = this;
Function _onAddItem
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onAddItem = function (event) {
if (!this.options.selectable) return;
if (!this.options.editable.add) return;
var me = this;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getVisibleItems
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype.getVisibleItems = function() {
var range = this.body.range.getRange();
var right, left;
if (this.options.rtl) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _onDragStart
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onDragStart = function (event) {
if (this.touchParams.itemIsDragging) { return; }
var item = this.touchParams.item || null;
var me = this;
var props;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function setOptions
has 80 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype.setOptions = function(options) {
if (options) {
// copy all options that we know
var fields = [
'type', 'rtl', 'align', 'order', 'stack', 'stackSubgroups', 'selectable', 'multiselect',
Function redraw
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype.redraw = function() {
var margin = this.options.margin,
range = this.body.range,
asSize = util.option.asSize,
options = this.options,
Function _updateUngrouped
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._updateUngrouped = function() {
var ungrouped = this.groups[UNGROUPED];
var item, itemId;
if (this.groupsData) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _onGroupDrag
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onGroupDrag = function (event) {
if (this.options.groupEditable.order && this.groupTouchParams.group) {
event.stopPropagation();
var groupsData = this.groupsData;
Consider simplifying this complex logical expression. Open
if (this.touchParams.itemProps) {
event.stopPropagation();
var me = this;
var snap = this.options.snap || null;
Function _onDragStart
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onDragStart = function (event) {
if (this.touchParams.itemIsDragging) { return; }
var item = this.touchParams.item || null;
var me = this;
var props;
Function _onDrag
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onDrag = function (event) {
if (this.touchParams.itemProps) {
event.stopPropagation();
var me = this;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _onAddItem
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onAddItem = function (event) {
if (!this.options.selectable) return;
if (!this.options.editable.add) return;
var me = this;
Function _create
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._create = function(){
var frame = document.createElement('div');
frame.className = 'vis-itemset';
frame['timeline-itemset'] = this;
this.dom.frame = frame;
Function _onMultiSelectItem
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onMultiSelectItem = function (event) {
if (!this.options.selectable) return;
var item = this.itemFromTarget(event);
Function setGroups
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype.setGroups = function(groups) {
var me = this,
ids;
// unsubscribe from current dataset
Function _onDragStartAddItem
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onDragStartAddItem = function (event) {
var xAbs;
var x;
var snap = this.options.snap || null;
Function groupFromTarget
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype.groupFromTarget = function(event) {
var clientY = event.center ? event.center.y : event.clientY;
var groupIds = this.groupIds;
if (groupIds.length <= 0 && this.groupsData) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _onGroupDragEnd
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onGroupDragEnd = function (event) {
if (this.options.groupEditable.order && this.groupTouchParams.group) {
event.stopPropagation();
// update existing group
Function _onUpdate
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onUpdate = function(ids) {
var me = this;
ids.forEach(function (id) {
var itemData = me.itemsData.get(id, me.itemOptions);
Function _onDragEnd
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onDragEnd = function (event) {
this.touchParams.itemIsDragging = false;
if (this.touchParams.itemProps) {
event.stopPropagation();
Function _updateUngrouped
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._updateUngrouped = function() {
var ungrouped = this.groups[UNGROUPED];
var item, itemId;
if (this.groupsData) {
Function _onAddGroups
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onAddGroups = function(ids) {
var me = this;
ids.forEach(function (id) {
var groupData = me.groupsData.get(id);
Function setItems
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype.setItems = function(items) {
var me = this,
ids,
oldItemsData = this.itemsData;
Function getVisibleItems
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype.getVisibleItems = function() {
var range = this.body.range.getRange();
var right, left;
if (this.options.rtl) {
Function _onMouseOver
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype._onMouseOver = function (event) {
var item = this.itemFromTarget(event);
if (!item) return;
// Item we just left
Function _onMouseOver
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onMouseOver = function (event) {
var item = this.itemFromTarget(event);
if (!item) return;
// Item we just left
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function groupFromTarget
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
ItemSet.prototype.groupFromTarget = function(event) {
var clientY = event.center ? event.center.y : event.clientY;
var groupIds = this.groupIds;
if (groupIds.length <= 0 && this.groupsData) {
Function redraw
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype.redraw = function() {
var margin = this.options.margin,
range = this.body.range,
asSize = util.option.asSize,
options = this.options,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if (itemData.end != undefined) {
initialEnd = util.convert(props.data.end, 'Date');
end = new Date(initialEnd.valueOf() + offset);
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
itemData.end = snap ? snap(end, scale, step) : end;
Avoid deeply nested control flow statements. Open
while ((curPos+newOffset) < numGroups
&& (curPos+orgOffset) < numGroups
&& newOrder[curPos+newOffset] == origOrder[curPos+orgOffset]) {
curPos++;
}
Avoid deeply nested control flow statements. Open
if (curPos >= numGroups) {
break;
}
Avoid deeply nested control flow statements. Open
if (itemData.start != undefined) {
initialStart = util.convert(props.data.start, 'Date').valueOf();
start = new Date(initialStart + offset);
Avoid deeply nested control flow statements. Open
if (this.items.hasOwnProperty(id)) {
var _item = this.items[id];
var start = _item.data.start;
var end = (_item.data.end !== undefined) ? _item.data.end : start;
Avoid deeply nested control flow statements. Open
while (curPos < numGroups && newOrder[curPos] == origOrder[curPos]) {
curPos++;
}
Avoid deeply nested control flow statements. Open
if (typeof options.margin.item === 'number') {
this.options.margin.item.horizontal = options.margin.item;
this.options.margin.item.vertical = options.margin.item;
}
else if (typeof options.margin.item === 'object') {
Avoid deeply nested control flow statements. Open
if (curPos+newOffset >= numGroups) {
break;
}
Avoid deeply nested control flow statements. Open
if (newOrder[curPos+newOffset] == draggedId) {
newOffset = 1;
}
// if dragged group was move downwards everything above should have an offset
Function setSelection
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype.setSelection = function(ids) {
var i, ii, id, item;
if (ids == undefined) ids = [];
if (!Array.isArray(ids)) ids = [ids];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if ((item.right < left) && (item.right + item.width > right)) {
ids.push(item.id);
}
Avoid deeply nested control flow statements. Open
if (this.options.rtl) {
if (itemData.start != undefined) {
initialStart = util.convert(props.data.start, 'Date');
start = new Date(initialStart.valueOf() + offset);
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
Avoid deeply nested control flow statements. Open
if ((item.left < right) && (item.left + item.width > left)) {
ids.push(item.id);
}
Avoid deeply nested control flow statements. Open
if (itemData.start != undefined) {
initialStart = util.convert(props.data.start, 'Date');
start = new Date(initialStart.valueOf() + offset);
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
itemData.start = snap ? snap(start, scale, step) : start;
Function _onMouseMove
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onMouseMove = function (event) {
var item = this.itemFromTarget(event);
if (!item) return;
if (this.options.showTooltips && this.options.tooltip.followMouse) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function setGroups
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype.setGroups = function(groups) {
var me = this,
ids;
// unsubscribe from current dataset
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _onGroupClick
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onGroupClick = function (event) {
var group = this.groupFromTarget(event);
if (!group || !group.nestedGroups) return;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _onSelectItem
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onSelectItem = function (event) {
if (!this.options.selectable) return;
var ctrlKey = event.srcEvent && (event.srcEvent.ctrlKey || event.srcEvent.metaKey);
var shiftKey = event.srcEvent && event.srcEvent.shiftKey;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function show
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype.show = function() {
// show frame containing the items
if (!this.dom.frame.parentNode) {
this.body.dom.center.appendChild(this.dom.frame);
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _onDragStartAddItem
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._onDragStartAddItem = function (event) {
var xAbs;
var x;
var snap = this.options.snap || null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _cloneItemData
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
ItemSet.prototype._cloneItemData = function (itemData, type) {
var clone = util.extend({}, itemData);
if (!type) {
// convert start and end date to the type (Date, Moment, ...) configured in the DataSet
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
TODO found Open
// TODO: need to trigger a redraw?
- Exclude checks
TODO found Open
// TODO: deprecated since version 2.1.0 (or 3.0.0?). cleanup some day
- Exclude checks
TODO found Open
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
- Exclude checks
TODO found Open
item.id = id; // TODO: not so nice setting id afterwards
- Exclude checks
TODO found Open
// TODO: would be nicer to get this as a trigger from Range
- Exclude checks
TODO found Open
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
- Exclude checks
TODO found Open
// TODO: optimization: only reorder groups affected by the changed items
- Exclude checks
TODO found Open
newItem.id = id; // TODO: not so nice setting id afterwards
- Exclude checks
TODO found Open
// TODO: also check whether visible vertically
- Exclude checks
TODO found Open
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
- Exclude checks
TODO found Open
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
- Exclude checks
TODO found Open
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
- Exclude checks
TODO found Open
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
- Exclude checks