|
|
@ -58,60 +58,58 @@ BoxItem.prototype.isVisible = function(range) { |
|
|
|
return isVisible; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Repaint the item |
|
|
|
*/ |
|
|
|
BoxItem.prototype.redraw = function() { |
|
|
|
var dom = this.dom; |
|
|
|
if (!dom) { |
|
|
|
BoxItem.prototype._createDomElement = function() { |
|
|
|
if (!this.dom) { |
|
|
|
// create DOM
|
|
|
|
this.dom = {}; |
|
|
|
dom = this.dom; |
|
|
|
|
|
|
|
// create main box
|
|
|
|
dom.box = document.createElement('DIV'); |
|
|
|
this.dom.box = document.createElement('DIV'); |
|
|
|
|
|
|
|
// contents box (inside the background box). used for making margins
|
|
|
|
dom.content = document.createElement('DIV'); |
|
|
|
dom.content.className = 'vis-item-content'; |
|
|
|
dom.box.appendChild(dom.content); |
|
|
|
this.dom.content = document.createElement('DIV'); |
|
|
|
this.dom.content.className = 'vis-item-content'; |
|
|
|
this.dom.box.appendChild(this.dom.content); |
|
|
|
|
|
|
|
// line to axis
|
|
|
|
dom.line = document.createElement('DIV'); |
|
|
|
dom.line.className = 'vis-line'; |
|
|
|
this.dom.line = document.createElement('DIV'); |
|
|
|
this.dom.line.className = 'vis-line'; |
|
|
|
|
|
|
|
// dot on axis
|
|
|
|
dom.dot = document.createElement('DIV'); |
|
|
|
dom.dot.className = 'vis-dot'; |
|
|
|
this.dom.dot = document.createElement('DIV'); |
|
|
|
this.dom.dot.className = 'vis-dot'; |
|
|
|
|
|
|
|
// attach this item as attribute
|
|
|
|
dom.box['timeline-item'] = this; |
|
|
|
this.dom.box['timeline-item'] = this; |
|
|
|
|
|
|
|
this.dirty = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// append DOM to parent DOM
|
|
|
|
BoxItem.prototype._appendDomElement = function() { |
|
|
|
if (!this.parent) { |
|
|
|
throw new Error('Cannot redraw item: no parent attached'); |
|
|
|
} |
|
|
|
if (!dom.box.parentNode) { |
|
|
|
if (!this.dom.box.parentNode) { |
|
|
|
var foreground = this.parent.dom.foreground; |
|
|
|
if (!foreground) throw new Error('Cannot redraw item: parent has no foreground container element'); |
|
|
|
foreground.appendChild(dom.box); |
|
|
|
foreground.appendChild(this.dom.box); |
|
|
|
} |
|
|
|
if (!dom.line.parentNode) { |
|
|
|
if (!this.dom.line.parentNode) { |
|
|
|
var background = this.parent.dom.background; |
|
|
|
if (!background) throw new Error('Cannot redraw item: parent has no background container element'); |
|
|
|
background.appendChild(dom.line); |
|
|
|
background.appendChild(this.dom.line); |
|
|
|
} |
|
|
|
if (!dom.dot.parentNode) { |
|
|
|
if (!this.dom.dot.parentNode) { |
|
|
|
var axis = this.parent.dom.axis; |
|
|
|
if (!background) throw new Error('Cannot redraw item: parent has no axis container element'); |
|
|
|
axis.appendChild(dom.dot); |
|
|
|
axis.appendChild(this.dom.dot); |
|
|
|
} |
|
|
|
this.displayed = true; |
|
|
|
} |
|
|
|
|
|
|
|
// Update DOM when item is marked dirty. An item is marked dirty when:
|
|
|
|
BoxItem.prototype._updateDirtyDomComponents = function() { |
|
|
|
// An item is marked dirty when:
|
|
|
|
// - the item is not yet rendered
|
|
|
|
// - the item's data is changed
|
|
|
|
// - the item is selected/deselected
|
|
|
@ -126,41 +124,104 @@ BoxItem.prototype.redraw = function() { |
|
|
|
var className = (this.data.className? ' ' + this.data.className : '') + |
|
|
|
(this.selected ? ' vis-selected' : '') + |
|
|
|
(editable ? ' vis-editable' : ' vis-readonly'); |
|
|
|
dom.box.className = 'vis-item vis-box' + className; |
|
|
|
dom.line.className = 'vis-item vis-line' + className; |
|
|
|
dom.dot.className = 'vis-item vis-dot' + className; |
|
|
|
|
|
|
|
// set initial position in the visible range of the grid so that the
|
|
|
|
// rendered box size can be determinated correctly, even the content
|
|
|
|
// has a dynamic width (fixes #2032).
|
|
|
|
var previousRight = dom.box.style.right; |
|
|
|
var previousLeft = dom.box.style.left; |
|
|
|
if (this.options.rtl) { |
|
|
|
dom.box.style.right = "0px"; |
|
|
|
} else { |
|
|
|
dom.box.style.left = "0px"; |
|
|
|
} |
|
|
|
|
|
|
|
// recalculate size
|
|
|
|
this.props.dot.height = dom.dot.offsetHeight; |
|
|
|
this.props.dot.width = dom.dot.offsetWidth; |
|
|
|
this.props.line.width = dom.line.offsetWidth; |
|
|
|
this.width = dom.box.offsetWidth; |
|
|
|
this.height = dom.box.offsetHeight; |
|
|
|
this.dom.box.className = 'vis-item vis-box' + className; |
|
|
|
this.dom.line.className = 'vis-item vis-line' + className; |
|
|
|
this.dom.dot.className = 'vis-item vis-dot' + className; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// restore previous position
|
|
|
|
if (this.options.rtl) { |
|
|
|
dom.box.style.right = previousRight; |
|
|
|
} else { |
|
|
|
dom.box.style.left = previousLeft; |
|
|
|
BoxItem.prototype._getDomComponentsSizes = function() { |
|
|
|
return { |
|
|
|
previous: { |
|
|
|
right: this.dom.box.style.right, |
|
|
|
left: this.dom.box.style.left |
|
|
|
}, |
|
|
|
dot: { |
|
|
|
height: this.dom.dot.offsetHeight, |
|
|
|
width: this.dom.dot.offsetWidth |
|
|
|
}, |
|
|
|
line: { |
|
|
|
width: this.dom.line.offsetWidth |
|
|
|
}, |
|
|
|
box: { |
|
|
|
width: this.dom.box.offsetWidth, |
|
|
|
height: this.dom.box.offsetHeight |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
BoxItem.prototype._updateDomComponentsSizes = function(sizes) { |
|
|
|
if (this.options.rtl) { |
|
|
|
this.dom.box.style.right = "0px"; |
|
|
|
} else { |
|
|
|
this.dom.box.style.left = "0px"; |
|
|
|
} |
|
|
|
|
|
|
|
this.dirty = false; |
|
|
|
// recalculate size
|
|
|
|
this.props.dot.height = sizes.dot.height; |
|
|
|
this.props.dot.width = sizes.dot.width; |
|
|
|
this.props.line.width = sizes.line.width; |
|
|
|
this.width = sizes.box.width; |
|
|
|
this.height = sizes.box.height; |
|
|
|
|
|
|
|
// restore previous position
|
|
|
|
if (this.options.rtl) { |
|
|
|
this.dom.box.style.right = sizes.previous.right; |
|
|
|
} else { |
|
|
|
this.dom.box.style.left = sizes.previous.left; |
|
|
|
} |
|
|
|
|
|
|
|
this._repaintOnItemUpdateTimeTooltip(dom.box); |
|
|
|
this.dirty = false; |
|
|
|
} |
|
|
|
|
|
|
|
BoxItem.prototype._repaintDomAdditionals = function() { |
|
|
|
this._repaintOnItemUpdateTimeTooltip(this.dom.box); |
|
|
|
this._repaintDragCenter(); |
|
|
|
this._repaintDeleteButton(dom.box); |
|
|
|
this._repaintDeleteButton(this.dom.box); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Repaint the item |
|
|
|
* @param {boolean} [returnQueue=false] return the queue |
|
|
|
* @return {boolean} the redraw queue if returnQueue=true |
|
|
|
*/ |
|
|
|
BoxItem.prototype.redraw = function(returnQueue) { |
|
|
|
var sizes |
|
|
|
var queue = [ |
|
|
|
// create item DOM
|
|
|
|
this._createDomElement.bind(this), |
|
|
|
|
|
|
|
// append DOM to parent DOM
|
|
|
|
this._appendDomElement.bind(this), |
|
|
|
|
|
|
|
// update dirty DOM
|
|
|
|
this._updateDirtyDomComponents.bind(this), |
|
|
|
|
|
|
|
(function() { |
|
|
|
if (this.dirty) { |
|
|
|
sizes = this._getDomComponentsSizes(); |
|
|
|
} |
|
|
|
}).bind(this), |
|
|
|
|
|
|
|
(function() { |
|
|
|
if (this.dirty) { |
|
|
|
this._updateDomComponentsSizes.bind(this)(sizes); |
|
|
|
} |
|
|
|
}).bind(this), |
|
|
|
|
|
|
|
// repaint DOM additionals
|
|
|
|
this._repaintDomAdditionals.bind(this) |
|
|
|
]; |
|
|
|
|
|
|
|
if (returnQueue) { |
|
|
|
return queue; |
|
|
|
} else { |
|
|
|
var result; |
|
|
|
queue.forEach(function (fn) { |
|
|
|
result = fn(); |
|
|
|
}); |
|
|
|
return result; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|