Working solution below. I would be interested in any suggestions for
improved performance.
Timeline.CompactEventPainter.prototype.initialize = function(band,
timeline) {
....
// save event tape and label elements so we can make labels always
visible
this._eventElmt = [];
....
};
Timeline.CompactEventPainter.prototype.paintPreciseDurationEvent =
function(evt, metrics, theme, highlightIndex) {
...
// save event tape and label elements so we can make labels always
visible
this._eventElmt.push(result);
...
}
/**
* Overrides softPaint method. Causes Event title to always be
visible when scrolling
*/
Timeline.CompactEventPainter.prototype.softPaint = function() {
...
// get the left edge of the visible timeline
var minVisDate = this._band.getMinVisibleDate();
var minVisPixel =
Math.round(this._band.dateToPixelOffset(minVisDate));
// for every event, make sure the label is always visible
for (var i=0; i < this._eventElmt.length; i++) {
var tapeElmtData = this._eventElmt[i].tapeElmtData;
var labelElmtData = this._eventElmt[i].labelElmtData;
var tapeElmtRight = tapeElmtData.left + tapeElmtData.width;
// if the left event edge is left of the timeline visible
edge, scoot the label over
if (tapeElmtData.left < minVisPixel && tapeElmtRight >
minVisPixel) {
labelElmtData.elmt.style.left = minVisPixel;
labelElmtData.left = minVisPixel;
// else reset it back to normal to align with event tape left
edge
} else if (tapeElmtData.left > minVisPixel ||
(tapeElmtData.left < minVisPixel && tapeElmtRight < minVisPixel)) {
labelElmtData.elmt.style.left =
tapeElmtData.elmt.style.left;
labelElmtData.left = tapeElmtData.left;
}
}
};
The painter softPaint() function is called from a band scroll listener
function:
// scroll listener for all source bands, not including the overview
band
scrollListener : function(band) {
// make event labels always visible
band._softPaintEvents();
}
Jeff
On Aug 31, 3:30 pm, codebeneath <[email protected]> wrote:
> I changed my search terms a bit and found a previous post from 2008
> asking the same question. We are on Timeline v2.3.1.
>
> "This is possible, but complicated. Take a look
> inhttp://static.simile.mit.edu/timeline/api-2.0/scripts/original-painte...
> there is a method called
> "Timeline.OriginalEventPainter.prototype.softPaint"
> which is empty right now. This method is called every time the
> timeline
> is scrolled (even during the panning operation before the mouse button
> is released). What you will have to do is to re-position the event
> labels in this method. This requires you to keep references to the
> HTML
> elements generated in the
> Timeline.OriginalEventPainter.prototype.paint
> function to display the event labels. "
>
> Is this still the reasonable approach given the newer version of
> Timeline?
>
> Thanks,
>
> Jeff
>
> On Aug 31, 3:15 pm, codebeneath <[email protected]> wrote:
>
>
>
>
>
>
>
> > For long events that extend left and right of the visible timeline, we
> > would like to shift the event label to the leftmost visible edge on
> > the timeline. In this way, there would never be an event whose label
> > is not visible. Is this a "problem" with a solution already?
>
> > If not, my idea would be to either:
> > 1) add a listener to Timeline._Band.prototype.addOnScrollListener()
> > and when scrolling stops, find all visible events (is there a function
> > for this?) and shift event labels to the right if necessary.
> > 2) a previous post made me think the event painter may already know
> > which events are visible and draws the labels as necessary. maybe I
> > can tap into that to shift the label x position?
>
> > Jeff
--
You received this message because you are subscribed to the Google Groups
"SIMILE Widgets" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/simile-widgets?hl=en.