📄 timeline.js
字号:
/*=================================================
*
* Coding standards:
*
* We aim towards Douglas Crockford's Javascript conventions.
* See: http://javascript.crockford.com/code.html
* See also: http://www.crockford.com/javascript/javascript.html
*
* That said, this JS code was written before some recent JS
* support libraries became widely used or available.
* In particular, the _ character is used to indicate a class function or
* variable that should be considered private to the class.
*
* The code mostly uses accessor methods for getting/setting the private
* class variables.
*
* Over time, we'd like to formalize the convention by using support libraries
* which enforce privacy in objects.
*
* We also want to use jslint: http://www.jslint.com/
*
*
*==================================================
*/
/*==================================================
* Timeline VERSION
*==================================================
*/
// Note: version is also stored in the build.xml file
Timeline.version = '2.3.0'; // use format 'pre 1.2.3' for trunk versions
Timeline.ajax_lib_version = SimileAjax.version; // Waiting for version string method from Ajax library
Timeline.display_version = Timeline.version + ' (with Ajax lib ' + Timeline.ajax_lib_version + ')';
// cf method Timeline.writeVersion
/*==================================================
* Timeline
*==================================================
*/
Timeline.strings = {}; // localization string tables
Timeline.HORIZONTAL = 0;
Timeline.VERTICAL = 1;
Timeline._defaultTheme = null;
Timeline.getDefaultLocale = function() {
return Timeline.clientLocale;
};
Timeline.toString=function(){ return "Timeline";};
Timeline.create = function(elmt, bandInfos, orientation, unit) {
if (Timeline.timelines == null) {
Timeline.timelines = [];
// Timeline.timelines array can have null members--Timelines that
// once existed on the page, but were later disposed of.
}
var timelineID = Timeline.timelines.length;
Timeline.timelines[timelineID] = null; // placeholder until we have the object
var new_tl = new Timeline._Impl(elmt, bandInfos, orientation, unit,
timelineID);
Timeline.timelines[timelineID] = new_tl;
return new_tl;
};
Timeline.createBandInfo = function(params) {
var theme = ("theme" in params) ? params.theme : Timeline.getDefaultTheme();
var eventSource = ("eventSource" in params) ? params.eventSource : null;
var ether = new Timeline.LinearEther({
centersOn: ("date" in params) ? params.date : new Date(),
interval: SimileAjax.DateTime.gregorianUnitLengths[params.intervalUnit],
pixelsPerInterval: params.intervalPixels,
theme: theme
});
var etherPainter = new Timeline.GregorianEtherPainter({
unit: params.intervalUnit,
multiple: ("multiple" in params) ? params.multiple : 1,
theme: theme,
align: ("align" in params) ? params.align : undefined
});
var eventPainterParams = {
showText: ("showEventText" in params) ? params.showEventText : true,
theme: theme
};
// pass in custom parameters for the event painter
if ("eventPainterParams" in params) {
for (var prop in params.eventPainterParams) {
eventPainterParams[prop] = params.eventPainterParams[prop];
}
}
if ("trackHeight" in params) {
eventPainterParams.trackHeight = params.trackHeight;
}
if ("trackGap" in params) {
eventPainterParams.trackGap = params.trackGap;
}
var layout = ("overview" in params && params.overview) ? "overview" : ("layout" in params ? params.layout : "original");
var eventPainter;
if ("eventPainter" in params) {
eventPainter = new params.eventPainter(eventPainterParams);
} else {
switch (layout) {
case "overview" :
eventPainter = new Timeline.OverviewEventPainter(eventPainterParams);
break;
case "detailed" :
eventPainter = new Timeline.DetailedEventPainter(eventPainterParams);
break;
default:
eventPainter = new Timeline.OriginalEventPainter(eventPainterParams);
}
}
return {
width: params.width,
eventSource: eventSource,
timeZone: ("timeZone" in params) ? params.timeZone : 0,
ether: ether,
etherPainter: etherPainter,
eventPainter: eventPainter,
theme: theme,
zoomIndex: ("zoomIndex" in params) ? params.zoomIndex : 0,
zoomSteps: ("zoomSteps" in params) ? params.zoomSteps : null,
toString: function(){return "BandInfo";}
};
};
Timeline.createHotZoneBandInfo = function(params) {
var theme = ("theme" in params) ? params.theme : Timeline.getDefaultTheme();
var eventSource = ("eventSource" in params) ? params.eventSource : null;
var ether = new Timeline.HotZoneEther({
centersOn: ("date" in params) ? params.date : new Date(),
interval: SimileAjax.DateTime.gregorianUnitLengths[params.intervalUnit],
pixelsPerInterval: params.intervalPixels,
zones: params.zones,
theme: theme
});
var etherPainter = new Timeline.HotZoneGregorianEtherPainter({
unit: params.intervalUnit,
zones: params.zones,
theme: theme,
align: ("align" in params) ? params.align : undefined
});
var eventPainterParams = {
showText: ("showEventText" in params) ? params.showEventText : true,
theme: theme
};
// pass in custom parameters for the event painter
if ("eventPainterParams" in params) {
for (var prop in params.eventPainterParams) {
eventPainterParams[prop] = params.eventPainterParams[prop];
}
}
if ("trackHeight" in params) {
eventPainterParams.trackHeight = params.trackHeight;
}
if ("trackGap" in params) {
eventPainterParams.trackGap = params.trackGap;
}
var layout = ("overview" in params && params.overview) ? "overview" : ("layout" in params ? params.layout : "original");
var eventPainter;
if ("eventPainter" in params) {
eventPainter = new params.eventPainter(eventPainterParams);
} else {
switch (layout) {
case "overview" :
eventPainter = new Timeline.OverviewEventPainter(eventPainterParams);
break;
case "detailed" :
eventPainter = new Timeline.DetailedEventPainter(eventPainterParams);
break;
default:
eventPainter = new Timeline.OriginalEventPainter(eventPainterParams);
}
}
return {
width: params.width,
eventSource: eventSource,
timeZone: ("timeZone" in params) ? params.timeZone : 0,
ether: ether,
etherPainter: etherPainter,
eventPainter: eventPainter,
theme: theme,
zoomIndex: ("zoomIndex" in params) ? params.zoomIndex : 0,
zoomSteps: ("zoomSteps" in params) ? params.zoomSteps : null
};
};
Timeline.getDefaultTheme = function() {
if (Timeline._defaultTheme == null) {
Timeline._defaultTheme = Timeline.ClassicTheme.create(Timeline.getDefaultLocale());
}
return Timeline._defaultTheme;
};
Timeline.setDefaultTheme = function(theme) {
Timeline._defaultTheme = theme;
};
Timeline.loadXML = function(url, f) {
var fError = function(statusText, status, xmlhttp) {
alert("Failed to load data xml from " + url + "\n" + statusText);
};
var fDone = function(xmlhttp) {
var xml = xmlhttp.responseXML;
if (!xml.documentElement && xmlhttp.responseStream) {
xml.load(xmlhttp.responseStream);
}
f(xml, url);
};
SimileAjax.XmlHttp.get(url, fError, fDone);
};
Timeline.loadJSON = function(url, f) {
var fError = function(statusText, status, xmlhttp) {
alert("Failed to load json data from " + url + "\n" + statusText);
};
var fDone = function(xmlhttp) {
f(eval('(' + xmlhttp.responseText + ')'), url);
};
SimileAjax.XmlHttp.get(url, fError, fDone);
};
Timeline.getTimelineFromID = function(timelineID) {
return Timeline.timelines[timelineID];
};
// Write the current Timeline version as the contents of element with id el_id
Timeline.writeVersion = function(el_id) {
document.getElementById(el_id).innerHTML = this.display_version;
};
/*==================================================
* Timeline Implementation object
*==================================================
*/
Timeline._Impl = function(elmt, bandInfos, orientation, unit, timelineID) {
SimileAjax.WindowManager.initialize();
this._containerDiv = elmt;
this._bandInfos = bandInfos;
this._orientation = orientation == null ? Timeline.HORIZONTAL : orientation;
this._unit = (unit != null) ? unit : SimileAjax.NativeDateUnit;
this._starting = true; // is the Timeline being created? Used by autoWidth
// functions
this._autoResizing = false;
// autoWidth is a "public" property of the Timeline object
this.autoWidth = bandInfos && bandInfos[0] && bandInfos[0].theme &&
bandInfos[0].theme.autoWidth;
this.autoWidthAnimationTime = bandInfos && bandInfos[0] && bandInfos[0].theme &&
bandInfos[0].theme.autoWidthAnimationTime;
this.timelineID = timelineID; // also public attribute
this.timeline_start = bandInfos && bandInfos[0] && bandInfos[0].theme &&
bandInfos[0].theme.timeline_start;
this.timeline_stop = bandInfos && bandInfos[0] && bandInfos[0].theme &&
bandInfos[0].theme.timeline_stop;
this.timeline_at_start = false; // already at start or stop? Then won't
this.timeline_at_stop = false; // try to move further in the wrong direction
this._initialize();
};
//
// Public functions used by client sw
//
Timeline._Impl.prototype.dispose = function() {
for (var i = 0; i < this._bands.length; i++) {
this._bands[i].dispose();
}
this._bands = null;
this._bandInfos = null;
this._containerDiv.innerHTML = "";
// remove from array of Timelines
Timeline.timelines[this.timelineID] = null;
};
Timeline._Impl.prototype.toString=function(){
return "Timeline Implementationn class";
};
Timeline._Impl.prototype.getBandCount = function() {
return this._bands.length;
};
Timeline._Impl.prototype.getBand = function(index) {
return this._bands[index];
};
Timeline._Impl.prototype.finishedEventLoading = function() {
// Called by client after events have been loaded into Timeline
// Only used if the client has set autoWidth
// Sets width to Timeline's requested amount and will shrink down the div if
// need be.
this._autoWidthCheck(true);
this._starting = false;
};
Timeline._Impl.prototype.layout = function() {
// called by client when browser is resized
this._autoWidthCheck(true);
this._distributeWidths();
};
Timeline._Impl.prototype.paint = function() {
for (var i = 0; i < this._bands.length; i++) {
this._bands[i].paint();
}
};
Timeline._Impl.prototype.getDocument = function() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -