From 13573b17dc3441853551fa4fabb9cf6b515b93b5 Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 22 Apr 2014 17:15:02 +0200 Subject: [PATCH] Function `setWindow` now accepts an object with properties `start` and `end`. --- HISTORY.md | 8 ++++---- src/timeline/Timeline.js | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 2d91b69b..2b2f3ce4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,10 +6,10 @@ http://visjs.org ### Timeline -- Large refactoring of the Timeline code: - - Simplifications in the code. - - Performance improvements. - - Improved layout of box-items inside groups. +- Large refactoring of the Timeline, simplifying the code. +- Performance improvements. +- Improved layout of box-items inside groups. +- Function `setWindow` now accepts an object with properties `start` and `end`. - Fixed option `autoResize` forcing a repaint of the Timeline with every check rather than when the Timeline is actually resized. - Fixed `select` event fired repeatedly when clicking an empty place on the diff --git a/src/timeline/Timeline.js b/src/timeline/Timeline.js index 03b53e5d..fbe26a65 100644 --- a/src/timeline/Timeline.js +++ b/src/timeline/Timeline.js @@ -534,21 +534,31 @@ Timeline.prototype.getSelection = function getSelection() { /** * Set the visible window. Both parameters are optional, you can change only - * start or only end. + * start or only end. Syntax: + * + * TimeLine.setWindow(start, end) + * TimeLine.setWindow(range) + * + * Where start and end can be a Date, number, or string, and range is an + * object with properties start and end. + * * @param {Date | Number | String} [start] Start date of visible window * @param {Date | Number | String} [end] End date of visible window */ -// TODO: implement support for setWindow({start: ..., end: ...}) -// TODO: rename setWindow to setRange? Timeline.prototype.setWindow = function setWindow(start, end) { - this.range.setRange(start, end); + if (arguments.length == 1) { + var range = arguments[0]; + this.range.setRange(range.start, range.end); + } + else { + this.range.setRange(start, end); + } }; /** * Get the visible window * @return {{start: Date, end: Date}} Visible range */ -// TODO: rename getWindow to getRange? Timeline.prototype.getWindow = function setWindow() { var range = this.range.getRange(); return {