📄 detailed-painter.js
字号:
var labelLeft = latestStartPixel + theme.event.label.offsetFromLine;
var labelTrack = this._findFreeTrackForText(tapeTrack, labelLeft + labelSize.width, function(t) { t.line = latestStartPixel - 2; });
this._getTrackData(labelTrack).text = latestStartPixel - 2;
this._paintEventLine(evt, latestStartPixel, tapeTrack, labelTrack, metrics, theme);
var labelTop = Math.round(
metrics.trackOffset + labelTrack * metrics.trackIncrement +
metrics.trackHeight / 2 - labelSize.height / 2);
var labelElmtData = this._paintEventLabel(evt, text, labelLeft, labelTop, labelSize.width, labelSize.height, theme);
var self = this;
var clickHandler = function(elmt, domEvt, target) {
return self._onClickDurationEvent(tapeElmtData.elmt, domEvt, evt);
};
SimileAjax.DOM.registerEvent(tapeElmtData.elmt, "mousedown", clickHandler);
SimileAjax.DOM.registerEvent(labelElmtData.elmt, "mousedown", clickHandler);
this._createHighlightDiv(highlightIndex, tapeElmtData, theme);
this._eventIdToElmt[evt.getID()] = tapeElmtData.elmt;
};
Timeline.DetailedEventPainter.prototype._findFreeTrackForSolid = function(solidEdge, softEdge) {
for (var i = 0; true; i++) {
if (i < this._lowerTracks.length) {
var t = this._lowerTracks[i];
if (Math.min(t.solid, t.text) > solidEdge && (!(softEdge) || t.line > softEdge)) {
return i;
}
} else {
this._lowerTracks.push({
solid: Number.POSITIVE_INFINITY,
text: Number.POSITIVE_INFINITY,
line: Number.POSITIVE_INFINITY
});
return i;
}
if (i < this._upperTracks.length) {
var t = this._upperTracks[i];
if (Math.min(t.solid, t.text) > solidEdge && (!(softEdge) || t.line > softEdge)) {
return -1 - i;
}
} else {
this._upperTracks.push({
solid: Number.POSITIVE_INFINITY,
text: Number.POSITIVE_INFINITY,
line: Number.POSITIVE_INFINITY
});
return -1 - i;
}
}
};
Timeline.DetailedEventPainter.prototype._findFreeTrackForText = function(fromTrack, edge, occupiedTrackVisitor) {
var extendUp;
var index;
var firstIndex;
var result;
if (fromTrack < 0) {
extendUp = true;
firstIndex = -fromTrack;
index = this._findFreeUpperTrackForText(firstIndex, edge);
result = -1 - index;
} else if (fromTrack > 0) {
extendUp = false;
firstIndex = fromTrack + 1;
index = this._findFreeLowerTrackForText(firstIndex, edge);
result = index;
} else {
var upIndex = this._findFreeUpperTrackForText(0, edge);
var downIndex = this._findFreeLowerTrackForText(1, edge);
if (downIndex - 1 <= upIndex) {
extendUp = false;
firstIndex = 1;
index = downIndex;
result = index;
} else {
extendUp = true;
firstIndex = 0;
index = upIndex;
result = -1 - index;
}
}
if (extendUp) {
if (index == this._upperTracks.length) {
this._upperTracks.push({
solid: Number.POSITIVE_INFINITY,
text: Number.POSITIVE_INFINITY,
line: Number.POSITIVE_INFINITY
});
}
for (var i = firstIndex; i < index; i++) {
occupiedTrackVisitor(this._upperTracks[i]);
}
} else {
if (index == this._lowerTracks.length) {
this._lowerTracks.push({
solid: Number.POSITIVE_INFINITY,
text: Number.POSITIVE_INFINITY,
line: Number.POSITIVE_INFINITY
});
}
for (var i = firstIndex; i < index; i++) {
occupiedTrackVisitor(this._lowerTracks[i]);
}
}
return result;
};
Timeline.DetailedEventPainter.prototype._findFreeLowerTrackForText = function(index, edge) {
for (; index < this._lowerTracks.length; index++) {
var t = this._lowerTracks[index];
if (Math.min(t.solid, t.text) >= edge) {
break;
}
}
return index;
};
Timeline.DetailedEventPainter.prototype._findFreeUpperTrackForText = function(index, edge) {
for (; index < this._upperTracks.length; index++) {
var t = this._upperTracks[index];
if (Math.min(t.solid, t.text) >= edge) {
break;
}
}
return index;
};
Timeline.DetailedEventPainter.prototype._getTrackData = function(index) {
return (index < 0) ? this._upperTracks[-index - 1] : this._lowerTracks[index];
};
Timeline.DetailedEventPainter.prototype._paintEventLine = function(evt, left, startTrack, endTrack, metrics, theme) {
var top = Math.round(metrics.trackOffset + startTrack * metrics.trackIncrement + metrics.trackHeight / 2);
var height = Math.round(Math.abs(endTrack - startTrack) * metrics.trackIncrement);
var lineStyle = "1px solid " + theme.event.label.lineColor;
var lineDiv = this._timeline.getDocument().createElement("div");
lineDiv.style.position = "absolute";
lineDiv.style.left = left + "px";
lineDiv.style.width = theme.event.label.offsetFromLine + "px";
lineDiv.style.height = height + "px";
if (startTrack > endTrack) {
lineDiv.style.top = (top - height) + "px";
lineDiv.style.borderTop = lineStyle;
} else {
lineDiv.style.top = top + "px";
lineDiv.style.borderBottom = lineStyle;
}
lineDiv.style.borderLeft = lineStyle;
this._lineLayer.appendChild(lineDiv);
};
Timeline.DetailedEventPainter.prototype._paintEventIcon = function(evt, iconTrack, left, metrics, theme) {
var icon = evt.getIcon();
icon = icon != null ? icon : metrics.icon;
var middle = metrics.trackOffset + iconTrack * metrics.trackIncrement + metrics.trackHeight / 2;
var top = Math.round(middle - metrics.iconHeight / 2);
var img = SimileAjax.Graphics.createTranslucentImage(icon);
var iconDiv = this._timeline.getDocument().createElement("div");
iconDiv.style.position = "absolute";
iconDiv.style.left = left + "px";
iconDiv.style.top = top + "px";
iconDiv.appendChild(img);
iconDiv.style.cursor = "pointer";
if(evt._title != null)
iconDiv.title = evt._title
this._eventLayer.appendChild(iconDiv);
return {
left: left,
top: top,
width: metrics.iconWidth,
height: metrics.iconHeight,
elmt: iconDiv
};
};
Timeline.DetailedEventPainter.prototype._paintEventLabel = function(evt, text, left, top, width, height, theme) {
var doc = this._timeline.getDocument();
var labelBackgroundDiv = doc.createElement("div");
labelBackgroundDiv.style.position = "absolute";
labelBackgroundDiv.style.left = left + "px";
labelBackgroundDiv.style.width = width + "px";
labelBackgroundDiv.style.top = top + "px";
labelBackgroundDiv.style.height = height + "px";
labelBackgroundDiv.style.backgroundColor = theme.event.label.backgroundColor;
SimileAjax.Graphics.setOpacity(labelBackgroundDiv, theme.event.label.backgroundOpacity);
this._eventLayer.appendChild(labelBackgroundDiv);
var labelDiv = doc.createElement("div");
labelDiv.style.position = "absolute";
labelDiv.style.left = left + "px";
labelDiv.style.width = width + "px";
labelDiv.style.top = top + "px";
labelDiv.innerHTML = text;
labelDiv.style.cursor = "pointer";
if(evt._title != null)
labelDiv.title = evt._title;
var color = evt.getTextColor();
if (color == null) {
color = evt.getColor();
}
if (color != null) {
labelDiv.style.color = color;
}
this._eventLayer.appendChild(labelDiv);
return {
left: left,
top: top,
width: width,
height: height,
elmt: labelDiv
};
};
Timeline.DetailedEventPainter.prototype._paintEventTape = function(
evt, iconTrack, startPixel, endPixel, color, opacity, metrics, theme) {
var tapeWidth = endPixel - startPixel;
var tapeHeight = theme.event.tape.height;
var middle = metrics.trackOffset + iconTrack * metrics.trackIncrement + metrics.trackHeight / 2;
var top = Math.round(middle - tapeHeight / 2);
var tapeDiv = this._timeline.getDocument().createElement("div");
tapeDiv.style.position = "absolute";
tapeDiv.style.left = startPixel + "px";
tapeDiv.style.width = tapeWidth + "px";
tapeDiv.style.top = top + "px";
tapeDiv.style.height = tapeHeight + "px";
tapeDiv.style.backgroundColor = color;
tapeDiv.style.overflow = "hidden";
tapeDiv.style.cursor = "pointer";
if(evt._title != null)
tapeDiv.title = evt._title;
SimileAjax.Graphics.setOpacity(tapeDiv, opacity);
this._eventLayer.appendChild(tapeDiv);
return {
left: startPixel,
top: top,
width: tapeWidth,
height: tapeHeight,
elmt: tapeDiv
};
}
Timeline.DetailedEventPainter.prototype._createHighlightDiv = function(highlightIndex, dimensions, theme) {
if (highlightIndex >= 0) {
var doc = this._timeline.getDocument();
var eventTheme = theme.event;
var color = eventTheme.highlightColors[Math.min(highlightIndex, eventTheme.highlightColors.length - 1)];
var div = doc.createElement("div");
div.style.position = "absolute";
div.style.overflow = "hidden";
div.style.left = (dimensions.left - 2) + "px";
div.style.width = (dimensions.width + 4) + "px";
div.style.top = (dimensions.top - 2) + "px";
div.style.height = (dimensions.height + 4) + "px";
div.style.background = color;
this._highlightLayer.appendChild(div);
}
};
Timeline.DetailedEventPainter.prototype._onClickInstantEvent = function(icon, domEvt, evt) {
var c = SimileAjax.DOM.getPageCoordinates(icon);
this._showBubble(
c.left + Math.ceil(icon.offsetWidth / 2),
c.top + Math.ceil(icon.offsetHeight / 2),
evt
);
this._fireOnSelect(evt.getID());
domEvt.cancelBubble = true;
SimileAjax.DOM.cancelEvent(domEvt);
return false;
};
Timeline.DetailedEventPainter.prototype._onClickDurationEvent = function(target, domEvt, evt) {
if ("pageX" in domEvt) {
var x = domEvt.pageX;
var y = domEvt.pageY;
} else {
var c = SimileAjax.DOM.getPageCoordinates(target);
var x = domEvt.offsetX + c.left;
var y = domEvt.offsetY + c.top;
}
this._showBubble(x, y, evt);
this._fireOnSelect(evt.getID());
domEvt.cancelBubble = true;
SimileAjax.DOM.cancelEvent(domEvt);
return false;
};
Timeline.DetailedEventPainter.prototype.showBubble = function(evt) {
var elmt = this._eventIdToElmt[evt.getID()];
if (elmt) {
var c = SimileAjax.DOM.getPageCoordinates(elmt);
this._showBubble(c.left + elmt.offsetWidth / 2, c.top + elmt.offsetHeight / 2, evt);
}
};
Timeline.DetailedEventPainter.prototype._showBubble = function(x, y, evt) {
var div = document.createElement("div");
var themeBubble = this._params.theme.event.bubble;
evt.fillInfoBubble(div, this._params.theme, this._band.getLabeller());
SimileAjax.WindowManager.cancelPopups();
SimileAjax.Graphics.createBubbleForContentAndPoint(div, x, y,
themeBubble.width, null, themeBubble.maxHeight);
};
Timeline.DetailedEventPainter.prototype._fireOnSelect = function(eventID) {
for (var i = 0; i < this._onSelectListeners.length; i++) {
this._onSelectListeners[i](eventID);
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -