@ -8,6 +8,7 @@ var TimeAxis = require('./component/TimeAxis');
var CurrentTime = require ( './component/CurrentTime' ) ;
var CurrentTime = require ( './component/CurrentTime' ) ;
var CustomTime = require ( './component/CustomTime' ) ;
var CustomTime = require ( './component/CustomTime' ) ;
var ItemSet = require ( './component/ItemSet' ) ;
var ItemSet = require ( './component/ItemSet' ) ;
var Activator = require ( '../shared/Activator' ) ;
/ * *
/ * *
* Create a timeline visualization
* Create a timeline visualization
@ -50,6 +51,7 @@ Core.prototype._create = function (container) {
this . dom . shadowTopRight = document . createElement ( 'div' ) ;
this . dom . shadowTopRight = document . createElement ( 'div' ) ;
this . dom . shadowBottomRight = document . createElement ( 'div' ) ;
this . dom . shadowBottomRight = document . createElement ( 'div' ) ;
this . dom . root . className = 'vis timeline root' ;
this . dom . background . className = 'vispanel background' ;
this . dom . background . className = 'vispanel background' ;
this . dom . backgroundVertical . className = 'vispanel background vertical' ;
this . dom . backgroundVertical . className = 'vispanel background vertical' ;
this . dom . backgroundHorizontal . className = 'vispanel background horizontal' ;
this . dom . backgroundHorizontal . className = 'vispanel background horizontal' ;
@ -112,7 +114,9 @@ Core.prototype._create = function (container) {
events . forEach ( function ( event ) {
events . forEach ( function ( event ) {
var listener = function ( ) {
var listener = function ( ) {
var args = [ event ] . concat ( Array . prototype . slice . call ( arguments , 0 ) ) ;
var args = [ event ] . concat ( Array . prototype . slice . call ( arguments , 0 ) ) ;
me . emit . apply ( me , args ) ;
if ( ! me . activator || me . activator . active ) {
me . emit . apply ( me , args ) ;
}
} ;
} ;
me . hammer . on ( event , listener ) ;
me . hammer . on ( event , listener ) ;
me . listeners [ event ] = listener ;
me . listeners [ event ] = listener ;
@ -141,6 +145,67 @@ Core.prototype._create = function (container) {
container . appendChild ( this . dom . root ) ;
container . appendChild ( this . dom . root ) ;
} ;
} ;
/ * *
* Set options . Options will be passed to all components loaded in the Timeline .
* @ param { Object } [ options ]
* { String } orientation
* Vertical orientation for the Timeline ,
* can be 'bottom' ( default ) or 'top' .
* { String | Number } width
* Width for the timeline , a number in pixels or
* a css string like '1000px' or '75%' . '100%' by default .
* { String | Number } height
* Fixed height for the Timeline , a number in pixels or
* a css string like '400px' or '75%' . If undefined ,
* The Timeline will automatically size such that
* its contents fit .
* { String | Number } minHeight
* Minimum height for the Timeline , a number in pixels or
* a css string like '400px' or '75%' .
* { String | Number } maxHeight
* Maximum height for the Timeline , a number in pixels or
* a css string like '400px' or '75%' .
* { Number | Date | String } start
* Start date for the visible window
* { Number | Date | String } end
* End date for the visible window
* /
Core . prototype . setOptions = function ( options ) {
if ( options ) {
// copy the known options
var fields = [ 'width' , 'height' , 'minHeight' , 'maxHeight' , 'autoResize' , 'start' , 'end' , 'orientation' , 'activatable' ] ;
util . selectiveExtend ( fields , this . options , options ) ;
if ( 'activatable' in options ) {
if ( options . activatable ) {
this . activator = new Activator ( this . dom . root ) ;
}
else {
if ( this . activator ) {
this . activator . destroy ( ) ;
delete this . activator ;
}
}
}
// enable/disable autoResize
this . _initAutoResize ( ) ;
}
// propagate options to all components
this . components . forEach ( function ( component ) {
component . setOptions ( options ) ;
} ) ;
// TODO: remove deprecation error one day (deprecated since version 0.8.0)
if ( options && options . order ) {
throw new Error ( 'Option order is deprecated. There is no replacement for this feature.' ) ;
}
// redraw everything
this . redraw ( ) ;
} ;
/ * *
/ * *
* Destroy the Core , clean up all DOM elements and event listeners .
* Destroy the Core , clean up all DOM elements and event listeners .
* /
* /
@ -160,6 +225,12 @@ Core.prototype.destroy = function () {
}
}
this . dom = null ;
this . dom = null ;
// remove Activator
if ( this . activator ) {
this . activator . destroy ( ) ;
delete this . activator ;
}
// cleanup hammer touch events
// cleanup hammer touch events
for ( var event in this . listeners ) {
for ( var event in this . listeners ) {
if ( this . listeners . hasOwnProperty ( event ) ) {
if ( this . listeners . hasOwnProperty ( event ) ) {
@ -321,7 +392,14 @@ Core.prototype.redraw = function() {
if ( ! dom ) return ; // when destroyed
if ( ! dom ) return ; // when destroyed
// update class names
// update class names
dom . root . className = 'vis timeline root ' + options . orientation ;
if ( options . orientation == 'top' ) {
util . addClassName ( dom . root , 'top' ) ;
util . removeClassName ( dom . root , 'bottom' ) ;
}
else {
util . removeClassName ( dom . root , 'top' ) ;
util . addClassName ( dom . root , 'bottom' ) ;
}
// update root width and height options
// update root width and height options
dom . root . style . maxHeight = util . option . asSize ( options . maxHeight , '' ) ;
dom . root . style . maxHeight = util . option . asSize ( options . maxHeight , '' ) ;