📄 ether-painters.js
字号:
/*==================================================
* Gregorian Ether Painter
*==================================================
*/
Timeline.GregorianEtherPainter = function(params) {
this._params = params;
this._theme = params.theme;
this._unit = params.unit;
this._multiple = ("multiple" in params) ? params.multiple : 1;
};
Timeline.GregorianEtherPainter.prototype.initialize = function(band, timeline) {
this._band = band;
this._timeline = timeline;
this._backgroundLayer = band.createLayerDiv(0);
this._backgroundLayer.setAttribute("name", "ether-background"); // for debugging
this._backgroundLayer.className = 'timeline-ether-bg';
// this._backgroundLayer.style.background = this._theme.ether.backgroundColors[band.getIndex()];
this._markerLayer = null;
this._lineLayer = null;
var align = ("align" in this._params && this._params.align != undefined) ? this._params.align :
this._theme.ether.interval.marker[timeline.isHorizontal() ? "hAlign" : "vAlign"];
var showLine = ("showLine" in this._params) ? this._params.showLine :
this._theme.ether.interval.line.show;
this._intervalMarkerLayout = new Timeline.EtherIntervalMarkerLayout(
this._timeline, this._band, this._theme, align, showLine);
this._highlight = new Timeline.EtherHighlight(
this._timeline, this._band, this._theme, this._backgroundLayer);
}
Timeline.GregorianEtherPainter.prototype.setHighlight = function(startDate, endDate) {
this._highlight.position(startDate, endDate);
}
Timeline.GregorianEtherPainter.prototype.paint = function() {
if (this._markerLayer) {
this._band.removeLayerDiv(this._markerLayer);
}
this._markerLayer = this._band.createLayerDiv(100);
this._markerLayer.setAttribute("name", "ether-markers"); // for debugging
this._markerLayer.style.display = "none";
if (this._lineLayer) {
this._band.removeLayerDiv(this._lineLayer);
}
this._lineLayer = this._band.createLayerDiv(1);
this._lineLayer.setAttribute("name", "ether-lines"); // for debugging
this._lineLayer.style.display = "none";
var minDate = this._band.getMinDate();
var maxDate = this._band.getMaxDate();
var timeZone = this._band.getTimeZone();
var labeller = this._band.getLabeller();
SimileAjax.DateTime.roundDownToInterval(minDate, this._unit, timeZone, this._multiple, this._theme.firstDayOfWeek);
var p = this;
var incrementDate = function(date) {
for (var i = 0; i < p._multiple; i++) {
SimileAjax.DateTime.incrementByInterval(date, p._unit);
}
};
while (minDate.getTime() < maxDate.getTime()) {
this._intervalMarkerLayout.createIntervalMarker(
minDate, labeller, this._unit, this._markerLayer, this._lineLayer);
incrementDate(minDate);
}
this._markerLayer.style.display = "block";
this._lineLayer.style.display = "block";
};
Timeline.GregorianEtherPainter.prototype.softPaint = function() {
};
Timeline.GregorianEtherPainter.prototype.zoom = function(netIntervalChange) {
if (netIntervalChange != 0) {
this._unit += netIntervalChange;
}
};
/*==================================================
* Hot Zone Gregorian Ether Painter
*==================================================
*/
Timeline.HotZoneGregorianEtherPainter = function(params) {
this._params = params;
this._theme = params.theme;
this._zones = [{
startTime: Number.NEGATIVE_INFINITY,
endTime: Number.POSITIVE_INFINITY,
unit: params.unit,
multiple: 1
}];
for (var i = 0; i < params.zones.length; i++) {
var zone = params.zones[i];
var zoneStart = SimileAjax.DateTime.parseGregorianDateTime(zone.start).getTime();
var zoneEnd = SimileAjax.DateTime.parseGregorianDateTime(zone.end).getTime();
for (var j = 0; j < this._zones.length && zoneEnd > zoneStart; j++) {
var zone2 = this._zones[j];
if (zoneStart < zone2.endTime) {
if (zoneStart > zone2.startTime) {
this._zones.splice(j, 0, {
startTime: zone2.startTime,
endTime: zoneStart,
unit: zone2.unit,
multiple: zone2.multiple
});
j++;
zone2.startTime = zoneStart;
}
if (zoneEnd < zone2.endTime) {
this._zones.splice(j, 0, {
startTime: zoneStart,
endTime: zoneEnd,
unit: zone.unit,
multiple: (zone.multiple) ? zone.multiple : 1
});
j++;
zone2.startTime = zoneEnd;
zoneStart = zoneEnd;
} else {
zone2.multiple = zone.multiple;
zone2.unit = zone.unit;
zoneStart = zone2.endTime;
}
} // else, try the next existing zone
}
}
};
Timeline.HotZoneGregorianEtherPainter.prototype.initialize = function(band, timeline) {
this._band = band;
this._timeline = timeline;
this._backgroundLayer = band.createLayerDiv(0);
this._backgroundLayer.setAttribute("name", "ether-background"); // for debugging
this._backgroundLayer.className ='timeline-ether-bg';
//this._backgroundLayer.style.background = this._theme.ether.backgroundColors[band.getIndex()];
this._markerLayer = null;
this._lineLayer = null;
var align = ("align" in this._params && this._params.align != undefined) ? this._params.align :
this._theme.ether.interval.marker[timeline.isHorizontal() ? "hAlign" : "vAlign"];
var showLine = ("showLine" in this._params) ? this._params.showLine :
this._theme.ether.interval.line.show;
this._intervalMarkerLayout = new Timeline.EtherIntervalMarkerLayout(
this._timeline, this._band, this._theme, align, showLine);
this._highlight = new Timeline.EtherHighlight(
this._timeline, this._band, this._theme, this._backgroundLayer);
}
Timeline.HotZoneGregorianEtherPainter.prototype.setHighlight = function(startDate, endDate) {
this._highlight.position(startDate, endDate);
}
Timeline.HotZoneGregorianEtherPainter.prototype.paint = function() {
if (this._markerLayer) {
this._band.removeLayerDiv(this._markerLayer);
}
this._markerLayer = this._band.createLayerDiv(100);
this._markerLayer.setAttribute("name", "ether-markers"); // for debugging
this._markerLayer.style.display = "none";
if (this._lineLayer) {
this._band.removeLayerDiv(this._lineLayer);
}
this._lineLayer = this._band.createLayerDiv(1);
this._lineLayer.setAttribute("name", "ether-lines"); // for debugging
this._lineLayer.style.display = "none";
var minDate = this._band.getMinDate();
var maxDate = this._band.getMaxDate();
var timeZone = this._band.getTimeZone();
var labeller = this._band.getLabeller();
var p = this;
var incrementDate = function(date, zone) {
for (var i = 0; i < zone.multiple; i++) {
SimileAjax.DateTime.incrementByInterval(date, zone.unit);
}
};
var zStart = 0;
while (zStart < this._zones.length) {
if (minDate.getTime() < this._zones[zStart].endTime) {
break;
}
zStart++;
}
var zEnd = this._zones.length - 1;
while (zEnd >= 0) {
if (maxDate.getTime() > this._zones[zEnd].startTime) {
break;
}
zEnd--;
}
for (var z = zStart; z <= zEnd; z++) {
var zone = this._zones[z];
var minDate2 = new Date(Math.max(minDate.getTime(), zone.startTime));
var maxDate2 = new Date(Math.min(maxDate.getTime(), zone.endTime));
SimileAjax.DateTime.roundDownToInterval(minDate2, zone.unit, timeZone, zone.multiple, this._theme.firstDayOfWeek);
SimileAjax.DateTime.roundUpToInterval(maxDate2, zone.unit, timeZone, zone.multiple, this._theme.firstDayOfWeek);
while (minDate2.getTime() < maxDate2.getTime()) {
this._intervalMarkerLayout.createIntervalMarker(
minDate2, labeller, zone.unit, this._markerLayer, this._lineLayer);
incrementDate(minDate2, zone);
}
}
this._markerLayer.style.display = "block";
this._lineLayer.style.display = "block";
};
Timeline.HotZoneGregorianEtherPainter.prototype.softPaint = function() {
};
Timeline.HotZoneGregorianEtherPainter.prototype.zoom = function(netIntervalChange) {
if (netIntervalChange != 0) {
for (var i = 0; i < this._zones.length; ++i) {
if (this._zones[i]) {
this._zones[i].unit += netIntervalChange;
}
}
}
};
/*==================================================
* Year Count Ether Painter
*==================================================
*/
Timeline.YearCountEtherPainter = function(params) {
this._params = params;
this._theme = params.theme;
this._startDate = SimileAjax.DateTime.parseGregorianDateTime(params.startDate);
this._multiple = ("multiple" in params) ? params.multiple : 1;
};
Timeline.YearCountEtherPainter.prototype.initialize = function(band, timeline) {
this._band = band;
this._timeline = timeline;
this._backgroundLayer = band.createLayerDiv(0);
this._backgroundLayer.setAttribute("name", "ether-background"); // for debugging
this._backgroundLayer.className = 'timeline-ether-bg';
// this._backgroundLayer.style.background = this._theme.ether.backgroundColors[band.getIndex()];
this._markerLayer = null;
this._lineLayer = null;
var align = ("align" in this._params) ? this._params.align :
this._theme.ether.interval.marker[timeline.isHorizontal() ? "hAlign" : "vAlign"];
var showLine = ("showLine" in this._params) ? this._params.showLine :
this._theme.ether.interval.line.show;
this._intervalMarkerLayout = new Timeline.EtherIntervalMarkerLayout(
this._timeline, this._band, this._theme, align, showLine);
this._highlight = new Timeline.EtherHighlight(
this._timeline, this._band, this._theme, this._backgroundLayer);
};
Timeline.YearCountEtherPainter.prototype.setHighlight = function(startDate, endDate) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -