📄 ether-painters.js
字号:
this._highlight.position(startDate, endDate);
};
Timeline.YearCountEtherPainter.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 = new Date(this._startDate.getTime());
var maxDate = this._band.getMaxDate();
var yearDiff = this._band.getMinDate().getUTCFullYear() - this._startDate.getUTCFullYear();
minDate.setUTCFullYear(this._band.getMinDate().getUTCFullYear() - yearDiff % this._multiple);
var p = this;
var incrementDate = function(date) {
for (var i = 0; i < p._multiple; i++) {
SimileAjax.DateTime.incrementByInterval(date, SimileAjax.DateTime.YEAR);
}
};
var labeller = {
labelInterval: function(date, intervalUnit) {
var diff = date.getUTCFullYear() - p._startDate.getUTCFullYear();
return {
text: diff,
emphasized: diff == 0
};
}
};
while (minDate.getTime() < maxDate.getTime()) {
this._intervalMarkerLayout.createIntervalMarker(
minDate, labeller, SimileAjax.DateTime.YEAR, this._markerLayer, this._lineLayer);
incrementDate(minDate);
}
this._markerLayer.style.display = "block";
this._lineLayer.style.display = "block";
};
Timeline.YearCountEtherPainter.prototype.softPaint = function() {
};
/*==================================================
* Quarterly Ether Painter
*==================================================
*/
Timeline.QuarterlyEtherPainter = function(params) {
this._params = params;
this._theme = params.theme;
this._startDate = SimileAjax.DateTime.parseGregorianDateTime(params.startDate);
};
Timeline.QuarterlyEtherPainter.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.QuarterlyEtherPainter.prototype.setHighlight = function(startDate, endDate) {
this._highlight.position(startDate, endDate);
};
Timeline.QuarterlyEtherPainter.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 = new Date(0);
var maxDate = this._band.getMaxDate();
minDate.setUTCFullYear(Math.max(this._startDate.getUTCFullYear(), this._band.getMinDate().getUTCFullYear()));
minDate.setUTCMonth(this._startDate.getUTCMonth());
var p = this;
var incrementDate = function(date) {
date.setUTCMonth(date.getUTCMonth() + 3);
};
var labeller = {
labelInterval: function(date, intervalUnit) {
var quarters = (4 + (date.getUTCMonth() - p._startDate.getUTCMonth()) / 3) % 4;
if (quarters != 0) {
return { text: "Q" + (quarters + 1), emphasized: false };
} else {
return { text: "Y" + (date.getUTCFullYear() - p._startDate.getUTCFullYear() + 1), emphasized: true };
}
}
};
while (minDate.getTime() < maxDate.getTime()) {
this._intervalMarkerLayout.createIntervalMarker(
minDate, labeller, SimileAjax.DateTime.YEAR, this._markerLayer, this._lineLayer);
incrementDate(minDate);
}
this._markerLayer.style.display = "block";
this._lineLayer.style.display = "block";
};
Timeline.QuarterlyEtherPainter.prototype.softPaint = function() {
};
/*==================================================
* Ether Interval Marker Layout
*==================================================
*/
Timeline.EtherIntervalMarkerLayout = function(timeline, band, theme, align, showLine) {
var horizontal = timeline.isHorizontal();
if (horizontal) {
if (align == "Top") {
this.positionDiv = function(div, offset) {
div.style.left = offset + "px";
div.style.top = "0px";
};
} else {
this.positionDiv = function(div, offset) {
div.style.left = offset + "px";
div.style.bottom = "0px";
};
}
} else {
if (align == "Left") {
this.positionDiv = function(div, offset) {
div.style.top = offset + "px";
div.style.left = "0px";
};
} else {
this.positionDiv = function(div, offset) {
div.style.top = offset + "px";
div.style.right = "0px";
};
}
}
var markerTheme = theme.ether.interval.marker;
var lineTheme = theme.ether.interval.line;
var weekendTheme = theme.ether.interval.weekend;
var stylePrefix = (horizontal ? "h" : "v") + align;
var labelStyler = markerTheme[stylePrefix + "Styler"];
var emphasizedLabelStyler = markerTheme[stylePrefix + "EmphasizedStyler"];
var day = SimileAjax.DateTime.gregorianUnitLengths[SimileAjax.DateTime.DAY];
this.createIntervalMarker = function(date, labeller, unit, markerDiv, lineDiv) {
var offset = Math.round(band.dateToPixelOffset(date));
if (showLine && unit != SimileAjax.DateTime.WEEK) {
var divLine = timeline.getDocument().createElement("div");
divLine.className = "timeline-ether-lines";
if (lineTheme.opacity < 100) {
SimileAjax.Graphics.setOpacity(divLine, lineTheme.opacity);
}
if (horizontal) {
//divLine.className += " timeline-ether-lines-vertical";
divLine.style.left = offset + "px";
} else {
//divLine.className += " timeline-ether-lines-horizontal";
divLine.style.top = offset + "px";
}
lineDiv.appendChild(divLine);
}
if (unit == SimileAjax.DateTime.WEEK) {
var firstDayOfWeek = theme.firstDayOfWeek;
var saturday = new Date(date.getTime() + (6 - firstDayOfWeek - 7) * day);
var monday = new Date(saturday.getTime() + 2 * day);
var saturdayPixel = Math.round(band.dateToPixelOffset(saturday));
var mondayPixel = Math.round(band.dateToPixelOffset(monday));
var length = Math.max(1, mondayPixel - saturdayPixel);
var divWeekend = timeline.getDocument().createElement("div");
divWeekend.className = 'timeline-ether-weekends'
if (weekendTheme.opacity < 100) {
SimileAjax.Graphics.setOpacity(divWeekend, weekendTheme.opacity);
}
if (horizontal) {
divWeekend.style.left = saturdayPixel + "px";
divWeekend.style.width = length + "px";
} else {
divWeekend.style.top = saturdayPixel + "px";
divWeekend.style.height = length + "px";
}
lineDiv.appendChild(divWeekend);
}
var label = labeller.labelInterval(date, unit);
var div = timeline.getDocument().createElement("div");
div.innerHTML = label.text;
div.className = 'timeline-date-label'
if(label.emphasized) div.className += ' timeline-date-label-em'
this.positionDiv(div, offset);
markerDiv.appendChild(div);
return div;
};
};
/*==================================================
* Ether Highlight Layout
*==================================================
*/
Timeline.EtherHighlight = function(timeline, band, theme, backgroundLayer) {
var horizontal = timeline.isHorizontal();
this._highlightDiv = null;
this._createHighlightDiv = function() {
if (this._highlightDiv == null) {
this._highlightDiv = timeline.getDocument().createElement("div");
this._highlightDiv.setAttribute("name", "ether-highlight"); // for debugging
this._highlightDiv.className = 'timeline-ether-highlight'
var opacity = theme.ether.highlightOpacity;
if (opacity < 100) {
SimileAjax.Graphics.setOpacity(this._highlightDiv, opacity);
}
backgroundLayer.appendChild(this._highlightDiv);
}
}
this.position = function(startDate, endDate) {
this._createHighlightDiv();
var startPixel = Math.round(band.dateToPixelOffset(startDate));
var endPixel = Math.round(band.dateToPixelOffset(endDate));
var length = Math.max(endPixel - startPixel, 3);
if (horizontal) {
this._highlightDiv.style.left = startPixel + "px";
this._highlightDiv.style.width = length + "px";
this._highlightDiv.style.height = (band.getViewWidth() - 4) + "px";
} else {
this._highlightDiv.style.top = startPixel + "px";
this._highlightDiv.style.height = length + "px";
this._highlightDiv.style.width = (band.getViewWidth() - 4) + "px";
}
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -