Browse Source

lint timeline (#3312)

revert-3409-performance
macleodbroad-wf 7 years ago
committed by Yotam Berkowitz
parent
commit
efc4b30011
8 changed files with 71 additions and 74 deletions
  1. +5
    -8
      lib/timeline/Core.js
  2. +14
    -14
      lib/timeline/DateUtil.js
  3. +0
    -2
      lib/timeline/Graph2d.js
  4. +17
    -18
      lib/timeline/Range.js
  5. +1
    -1
      lib/timeline/Stack.js
  6. +8
    -7
      lib/timeline/TimeStep.js
  7. +19
    -17
      lib/timeline/Timeline.js
  8. +7
    -7
      lib/timeline/optionsTimeline.js

+ 5
- 8
lib/timeline/Core.js View File

@ -2,10 +2,6 @@ var Emitter = require('emitter-component');
var Hammer = require('../module/hammer'); var Hammer = require('../module/hammer');
var hammerUtil = require('../hammerUtil'); var hammerUtil = require('../hammerUtil');
var util = require('../util'); var util = require('../util');
var DataSet = require('../DataSet');
var DataView = require('../DataView');
var Range = require('./Range');
var ItemSet = require('./component/ItemSet');
var TimeAxis = require('./component/TimeAxis'); var TimeAxis = require('./component/TimeAxis');
var Activator = require('../shared/Activator'); var Activator = require('../shared/Activator');
var DateUtil = require('./DateUtil'); var DateUtil = require('./DateUtil');
@ -698,13 +694,14 @@ Core.prototype.setWindow = function(start, end, options, callback) {
options = {}; options = {};
} }
var animation; var animation;
var range;
if (arguments.length == 1) { if (arguments.length == 1) {
var range = arguments[0];
range = arguments[0];
animation = (range.animation !== undefined) ? range.animation : true; animation = (range.animation !== undefined) ? range.animation : true;
this.range.setRange(range.start, range.end, { animation: animation }); this.range.setRange(range.start, range.end, { animation: animation });
} }
else if (arguments.length == 2 && typeof arguments[1] == "function") { else if (arguments.length == 2 && typeof arguments[1] == "function") {
var range = arguments[0];
range = arguments[0];
callback = arguments[1]; callback = arguments[1];
animation = (range.animation !== undefined) ? range.animation : true; animation = (range.animation !== undefined) ? range.animation : true;
this.range.setRange(range.start, range.end, { animation: animation }, callback); this.range.setRange(range.start, range.end, { animation: animation }, callback);
@ -1207,7 +1204,7 @@ Core.prototype._stopAutoResize = function () {
* @param {Event} event * @param {Event} event
* @private * @private
*/ */
Core.prototype._onTouch = function (event) {
Core.prototype._onTouch = function (event) { // eslint-disable-line no-unused-vars
this.touch.allowDragging = true; this.touch.allowDragging = true;
this.touch.initialScrollTop = this.props.scrollTop; this.touch.initialScrollTop = this.props.scrollTop;
}; };
@ -1217,7 +1214,7 @@ Core.prototype._onTouch = function (event) {
* @param {Event} event * @param {Event} event
* @private * @private
*/ */
Core.prototype._onPinch = function (event) {
Core.prototype._onPinch = function (event) { // eslint-disable-line no-unused-vars
this.touch.allowDragging = false; this.touch.allowDragging = false;
}; };

+ 14
- 14
lib/timeline/DateUtil.js View File

@ -83,7 +83,7 @@ exports.updateHiddenDates = function (moment, body, hiddenDates) {
runUntil.add(1, 'weeks'); runUntil.add(1, 'weeks');
break; break;
case "weekly": case "weekly":
var dayOffset = endDate.diff(startDate,'days')
var dayOffset = endDate.diff(startDate,'days');
var day = startDate.day(); var day = startDate.day();
// set the start date to the range.start // set the start date to the range.start
@ -101,7 +101,7 @@ exports.updateHiddenDates = function (moment, body, hiddenDates) {
endDate.subtract(1,'weeks'); endDate.subtract(1,'weeks');
runUntil.add(1, 'weeks'); runUntil.add(1, 'weeks');
break
break;
case "monthly": case "monthly":
if (startDate.month() != endDate.month()) { if (startDate.month() != endDate.month()) {
offset = 1; offset = 1;
@ -175,7 +175,7 @@ exports.updateHiddenDates = function (moment, body, hiddenDates) {
} }
} }
}
};
/** /**
@ -207,7 +207,7 @@ exports.removeDuplicates = function(body) {
} }
} }
for (var i = 0; i < hiddenDates.length; i++) {
for (i = 0; i < hiddenDates.length; i++) {
if (hiddenDates[i].remove !== true) { if (hiddenDates[i].remove !== true) {
safeDates.push(hiddenDates[i]); safeDates.push(hiddenDates[i]);
} }
@ -287,8 +287,9 @@ exports.stepOverHiddenDates = function(moment, timeStep, previousTime) {
* @returns {number} * @returns {number}
*/ */
exports.toScreen = function (Core, time, width) { exports.toScreen = function (Core, time, width) {
if (Core.body.hiddenDates.length == 0) {
var conversion = Core.range.conversion(width);
var conversion;
if (Core.body.hiddenDates.length == 0) {
conversion = Core.range.conversion(width);
return (time.valueOf() - conversion.offset) * conversion.scale; return (time.valueOf() - conversion.offset) * conversion.scale;
} else { } else {
var hidden = exports.isHidden(time, Core.body.hiddenDates); var hidden = exports.isHidden(time, Core.body.hiddenDates);
@ -298,7 +299,7 @@ exports.toScreen = function (Core, time, width) {
var duration = exports.getHiddenDurationBetween(Core.body.hiddenDates, Core.range.start, Core.range.end); var duration = exports.getHiddenDurationBetween(Core.body.hiddenDates, Core.range.start, Core.range.end);
if (time < Core.range.start) { if (time < Core.range.start) {
var conversion = Core.range.conversion(width, duration);
conversion = Core.range.conversion(width, duration);
var hiddenBeforeStart = exports.getHiddenDurationBeforeStart(Core.body.hiddenDates, time, conversion.offset); var hiddenBeforeStart = exports.getHiddenDurationBeforeStart(Core.body.hiddenDates, time, conversion.offset);
time = Core.options.moment(time).toDate().valueOf(); time = Core.options.moment(time).toDate().valueOf();
time = time + hiddenBeforeStart; time = time + hiddenBeforeStart;
@ -307,12 +308,12 @@ exports.toScreen = function (Core, time, width) {
} else if (time > Core.range.end) { } else if (time > Core.range.end) {
var rangeAfterEnd = {start: Core.range.start, end: time}; var rangeAfterEnd = {start: Core.range.start, end: time};
time = exports.correctTimeForHidden(Core.options.moment, Core.body.hiddenDates, rangeAfterEnd, time); time = exports.correctTimeForHidden(Core.options.moment, Core.body.hiddenDates, rangeAfterEnd, time);
var conversion = Core.range.conversion(width, duration);
conversion = Core.range.conversion(width, duration);
return (time.valueOf() - conversion.offset) * conversion.scale; return (time.valueOf() - conversion.offset) * conversion.scale;
} else { } else {
time = exports.correctTimeForHidden(Core.options.moment, Core.body.hiddenDates, Core.range, time); time = exports.correctTimeForHidden(Core.options.moment, Core.body.hiddenDates, Core.range, time);
var conversion = Core.range.conversion(width, duration);
conversion = Core.range.conversion(width, duration);
return (time.valueOf() - conversion.offset) * conversion.scale; return (time.valueOf() - conversion.offset) * conversion.scale;
} }
} }
@ -321,8 +322,7 @@ exports.toScreen = function (Core, time, width) {
/** /**
* Replaces the core toTime methods * Replaces the core toTime methods
* @param body
* @param range
* @param Core
* @param x * @param x
* @param width * @param width
* @returns {Date} * @returns {Date}
@ -415,7 +415,7 @@ exports.getHiddenDurationBefore = function(moment, hiddenDates, range, time) {
} }
} }
return timeOffset; return timeOffset;
}
};
/** /**
* sum the duration from start to finish, including the hidden duration, * sum the duration from start to finish, including the hidden duration,
@ -483,7 +483,7 @@ exports.snapAwayFromHidden = function(hiddenDates, time, direction, correctionEn
return time; return time;
} }
}
};
/** /**
@ -503,4 +503,4 @@ exports.isHidden = function(time, hiddenDates) {
} }
} }
return {hidden: false, startDate: startDate, endDate: endDate}; return {hidden: false, startDate: startDate, endDate: endDate};
}
};

+ 0
- 2
lib/timeline/Graph2d.js View File

@ -1,5 +1,3 @@
var Emitter = require('emitter-component');
var Hammer = require('../module/hammer');
var moment = require('../module/moment'); var moment = require('../module/moment');
var util = require('../util'); var util = require('../util');
var DataSet = require('../DataSet'); var DataSet = require('../DataSet');

+ 17
- 18
lib/timeline/Range.js View File

@ -1,5 +1,4 @@
var util = require('../util'); var util = require('../util');
var hammerUtil = require('../hammerUtil');
var moment = require('../module/moment'); var moment = require('../module/moment');
var Component = require('./component/Component'); var Component = require('./component/Component');
var DateUtil = require('./DateUtil'); var DateUtil = require('./DateUtil');
@ -22,7 +21,7 @@ function Range(body, options) {
this.start = start; this.start = start;
this.end = end; this.end = end;
} else { } else {
this.start = options.start || start
this.start = options.start || start;
this.end = options.end || end this.end = options.end || end
} }
@ -141,7 +140,6 @@ Range.prototype.startRolling = function() {
var start = t - interval * (me.options.rollingMode.offset); var start = t - interval * (me.options.rollingMode.offset);
var end = t + interval * (1 - me.options.rollingMode.offset); var end = t + interval * (1 - me.options.rollingMode.offset);
var animation = (me.options && me.options.animation !== undefined) ? me.options.animation : true;
var options = { var options = {
animation: false animation: false
@ -150,7 +148,7 @@ Range.prototype.startRolling = function() {
// determine interval to refresh // determine interval to refresh
var scale = me.conversion(me.body.domProps.center.width).scale; var scale = me.conversion(me.body.domProps.center.width).scale;
var interval = 1 / scale / 10;
interval = 1 / scale / 10;
if (interval < 30) interval = 30; if (interval < 30) interval = 30;
if (interval > 1000) interval = 1000; if (interval > 1000) interval = 1000;
@ -235,7 +233,7 @@ Range.prototype.setRange = function(start, end, options, callback) {
end: new Date(me.end), end: new Date(me.end),
byUser: options.byUser, byUser: options.byUser,
event: options.event event: options.event
}
};
if (changed) { if (changed) {
me.body.emitter.emit('rangechange', params); me.body.emitter.emit('rangechange', params);
@ -286,7 +284,7 @@ Range.prototype.getMillisecondsPerPixel = function() {
this.millisecondsPerPixelCache = (this.end - this.start) / this.body.dom.center.clientWidth; this.millisecondsPerPixelCache = (this.end - this.start) / this.body.dom.center.clientWidth;
} }
return this.millisecondsPerPixelCache; return this.millisecondsPerPixelCache;
}
};
/** /**
* Stop an animation * Stop an animation
@ -501,7 +499,7 @@ Range.prototype._onDragStart = function(event) {
* @private * @private
*/ */
Range.prototype._onDrag = function (event) { Range.prototype._onDrag = function (event) {
if (!event) return
if (!event) return;
if (!this.props.touch.dragging) return; if (!this.props.touch.dragging) return;
@ -524,11 +522,11 @@ Range.prototype._onDrag = function (event) {
interval -= duration; interval -= duration;
var width = (direction == 'horizontal') ? this.body.domProps.center.width : this.body.domProps.center.height; var width = (direction == 'horizontal') ? this.body.domProps.center.width : this.body.domProps.center.height;
var diffRange;
if (this.options.rtl) { if (this.options.rtl) {
var diffRange = delta / width * interval;
diffRange = delta / width * interval;
} else { } else {
var diffRange = -delta / width * interval;
diffRange = -delta / width * interval;
} }
var newStart = this.props.touch.start + diffRange; var newStart = this.props.touch.start + diffRange;
@ -640,7 +638,7 @@ Range.prototype._onMouseWheel = function(event) {
} }
// calculate center, the date to zoom around // calculate center, the date to zoom around
var pointerDate
var pointerDate;
if (this.rolling) { if (this.rolling) {
pointerDate = this.start + ((this.end - this.start) * this.options.rollingMode.offset); pointerDate = this.start + ((this.end - this.start) * this.options.rollingMode.offset);
} else { } else {
@ -659,7 +657,7 @@ Range.prototype._onMouseWheel = function(event) {
* Start of a touch gesture * Start of a touch gesture
* @private * @private
*/ */
Range.prototype._onTouch = function (event) {
Range.prototype._onTouch = function (event) { // eslint-disable-line no-unused-vars
this.props.touch.start = this.start; this.props.touch.start = this.start;
this.props.touch.end = this.end; this.props.touch.end = this.end;
this.props.touch.allowDragging = true; this.props.touch.allowDragging = true;
@ -714,7 +712,7 @@ Range.prototype._onPinch = function (event) {
animation: false, animation: false,
byUser: true, byUser: true,
event: event event: event
}
};
this.setRange(newStart, newEnd, options); this.setRange(newStart, newEnd, options);
this.startToFront = false; // revert to default this.startToFront = false; // revert to default
@ -732,10 +730,11 @@ Range.prototype._isInsideRange = function(event) {
// calculate the time where the mouse is, check whether inside // calculate the time where the mouse is, check whether inside
// and no scroll action should happen. // and no scroll action should happen.
var clientX = event.center ? event.center.x : event.clientX; var clientX = event.center ? event.center.x : event.clientX;
var x;
if (this.options.rtl) { if (this.options.rtl) {
var x = clientX - util.getAbsoluteLeft(this.body.dom.centerContainer);
x = clientX - util.getAbsoluteLeft(this.body.dom.centerContainer);
} else { } else {
var x = util.getAbsoluteRight(this.body.dom.centerContainer) - clientX;
x = util.getAbsoluteRight(this.body.dom.centerContainer) - clientX;
} }
var time = this.body.util.toTime(x); var time = this.body.util.toTime(x);
@ -783,7 +782,7 @@ Range.prototype.getPointer = function (touch, element) {
y: touch.y - util.getAbsoluteTop(element) y: touch.y - util.getAbsoluteTop(element)
}; };
} }
}
};
/** /**
* Zoom the range the given scale in or out. Start and end date will * Zoom the range the given scale in or out. Start and end date will
@ -823,7 +822,7 @@ Range.prototype.zoom = function(scale, center, delta, event) {
animation: false, animation: false,
byUser: true, byUser: true,
event: event event: event
}
};
this.setRange(newStart, newEnd, options); this.setRange(newStart, newEnd, options);
this.startToFront = false; // revert to default this.startToFront = false; // revert to default
@ -869,7 +868,7 @@ Range.prototype.moveTo = function(moveTo) {
animation: false, animation: false,
byUser: true, byUser: true,
event: null event: null
}
};
this.setRange(newStart, newEnd, options); this.setRange(newStart, newEnd, options);
}; };

+ 1
- 1
lib/timeline/Stack.js View File

@ -45,7 +45,7 @@ exports.stack = function(items, margin, force) {
} }
// calculate new, non-overlapping positions // calculate new, non-overlapping positions
for (var i = 0; i < items.length; i++) {
for (var i = 0; i < items.length; i++) { // eslint-disable-line no-redeclare
var item = items[i]; var item = items[i];
if (item.stack && item.top === null) { if (item.stack && item.top === null) {
// initialize top position // initialize top position

+ 8
- 7
lib/timeline/TimeStep.js View File

@ -158,13 +158,13 @@ TimeStep.prototype.roundToMinor = function() {
case 'year': case 'year':
this.current.year(this.step * Math.floor(this.current.year() / this.step)); this.current.year(this.step * Math.floor(this.current.year() / this.step));
this.current.month(0); this.current.month(0);
case 'month': this.current.date(1);
case 'week': // intentional fall through
case 'day': // intentional fall through
case 'weekday': this.current.hours(0);
case 'hour': this.current.minutes(0);
case 'minute': this.current.seconds(0);
case 'second': this.current.milliseconds(0);
case 'month': this.current.date(1); // eslint-disable-line no-fallthrough
case 'week': // eslint-disable-line no-fallthrough
case 'day': // eslint-disable-line no-fallthrough
case 'weekday': this.current.hours(0); // eslint-disable-line no-fallthrough
case 'hour': this.current.minutes(0); // eslint-disable-line no-fallthrough
case 'minute': this.current.seconds(0); // eslint-disable-line no-fallthrough
case 'second': this.current.milliseconds(0); // eslint-disable-line no-fallthrough
//case 'millisecond': // nothing to do for milliseconds //case 'millisecond': // nothing to do for milliseconds
} }
@ -578,6 +578,7 @@ TimeStep.prototype.getLabelMinor = function(date) {
if(this.isMajor() && date.weekday() !== 0){ if(this.isMajor() && date.weekday() !== 0){
return ""; return "";
} }
break;
default: default:
return (format && format.length > 0) ? this.moment(date).format(format) : ''; return (format && format.length > 0) ? this.moment(date).format(format) : '';
} }

+ 19
- 17
lib/timeline/Timeline.js View File

@ -1,5 +1,3 @@
var Emitter = require('emitter-component');
var Hammer = require('../module/hammer');
var moment = require('../module/moment'); var moment = require('../module/moment');
var util = require('../util'); var util = require('../util');
var DataSet = require('../DataSet'); var DataSet = require('../DataSet');
@ -431,6 +429,16 @@ Timeline.prototype.fit = function (options) {
} }
}; };
function getStart(item) {
return util.convert(item.data.start, 'Date').valueOf()
}
function getEnd(item) {
var end = item.data.end != undefined ? item.data.end : item.data.start;
return util.convert(end, 'Date').valueOf();
}
/** /**
* Determine the range of the items, taking into account their actual width * Determine the range of the items, taking into account their actual width
* and a margin of 10 pixels on both sides. * and a margin of 10 pixels on both sides.
@ -451,15 +459,6 @@ Timeline.prototype.getItemRange = function () {
} }
var factor = interval / this.props.center.width; var factor = interval / this.props.center.width;
function getStart(item) {
return util.convert(item.data.start, 'Date').valueOf()
}
function getEnd(item) {
var end = item.data.end != undefined ? item.data.end : item.data.start;
return util.convert(end, 'Date').valueOf();
}
// calculate the date of the left side and right side of the items given // calculate the date of the left side and right side of the items given
util.forEach(this.itemSet.items, function (item) { util.forEach(this.itemSet.items, function (item) {
if (item.groupShowing) { if (item.groupShowing) {
@ -469,13 +468,15 @@ Timeline.prototype.getItemRange = function () {
var start = getStart(item); var start = getStart(item);
var end = getEnd(item); var end = getEnd(item);
var startSide;
var endSide;
if (this.options.rtl) { if (this.options.rtl) {
var startSide = start - (item.getWidthRight() + 10) * factor;
var endSide = end + (item.getWidthLeft() + 10) * factor;
startSide = start - (item.getWidthRight() + 10) * factor;
endSide = end + (item.getWidthLeft() + 10) * factor;
} else { } else {
var startSide = start - (item.getWidthLeft() + 10) * factor;
var endSide = end + (item.getWidthRight() + 10) * factor;
startSide = start - (item.getWidthLeft() + 10) * factor;
endSide = end + (item.getWidthRight() + 10) * factor;
} }
@ -549,10 +550,11 @@ Timeline.prototype.getDataRange = function() {
Timeline.prototype.getEventProperties = function (event) { Timeline.prototype.getEventProperties = function (event) {
var clientX = event.center ? event.center.x : event.clientX; var clientX = event.center ? event.center.x : event.clientX;
var clientY = event.center ? event.center.y : event.clientY; var clientY = event.center ? event.center.y : event.clientY;
var x;
if (this.options.rtl) { if (this.options.rtl) {
var x = util.getAbsoluteRight(this.dom.centerContainer) - clientX;
x = util.getAbsoluteRight(this.dom.centerContainer) - clientX;
} else { } else {
var x = clientX - util.getAbsoluteLeft(this.dom.centerContainer);
x = clientX - util.getAbsoluteLeft(this.dom.centerContainer);
} }
var y = clientY - util.getAbsoluteTop(this.dom.centerContainer); var y = clientY - util.getAbsoluteTop(this.dom.centerContainer);

+ 7
- 7
lib/timeline/optionsTimeline.js View File

@ -76,10 +76,10 @@ let allOptions = {
moment: {'function': 'function'}, moment: {'function': 'function'},
groupOrder: {string, 'function': 'function'}, groupOrder: {string, 'function': 'function'},
groupEditable: { groupEditable: {
add: { 'boolean': bool, 'undefined': 'undefined'},
remove: { 'boolean': bool, 'undefined': 'undefined'},
order: { 'boolean': bool, 'undefined': 'undefined'},
__type__: { 'boolean': bool, object}
add: { 'boolean': bool, 'undefined': 'undefined'},
remove: { 'boolean': bool, 'undefined': 'undefined'},
order: { 'boolean': bool, 'undefined': 'undefined'},
__type__: { 'boolean': bool, object}
}, },
groupOrderSwap: {'function': 'function'}, groupOrderSwap: {'function': 'function'},
height: {string, number}, height: {string, number},
@ -90,9 +90,9 @@ let allOptions = {
__type__: {object, array} __type__: {object, array}
}, },
itemsAlwaysDraggable: { itemsAlwaysDraggable: {
item: { 'boolean': bool, 'undefined': 'undefined'},
range: { 'boolean': bool, 'undefined': 'undefined'},
__type__: { 'boolean': bool, object}
item: { 'boolean': bool, 'undefined': 'undefined'},
range: { 'boolean': bool, 'undefined': 'undefined'},
__type__: { 'boolean': bool, object}
}, },
locale:{string}, locale:{string},
locales:{ locales:{

Loading…
Cancel
Save