Search in sources :

Example 1 with DeferredLine

use of org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredLine in project tracecompass by tracecompass.

the class TimeGraphControl method drawLineGraphEntry.

private void drawLineGraphEntry(long time0, @NonNull Rectangle rect, double pixelsPerNanoSec, Iterator<ITimeEvent> iterator) {
    // clamp 0 - max positive
    long max = Long.MIN_VALUE;
    long min = 0;
    List<@NonNull List<@NonNull LongPoint>> seriesModel = new ArrayList<>();
    TimeLineEvent lastValid = null;
    while (iterator.hasNext()) {
        ITimeEvent event = iterator.next();
        if (!(event instanceof TimeLineEvent)) {
            continue;
        }
        int x = SaturatedArithmetic.add(rect.x, (int) ((event.getTime() - time0) * pixelsPerNanoSec));
        if (x >= rect.x + rect.width) {
            // event is out of bounds
            continue;
        }
        TimeLineEvent timeEvent = (TimeLineEvent) event;
        List<Long> values = timeEvent.getValues();
        for (int i = 0; i < values.size(); i++) {
            if (seriesModel.size() <= i) {
                seriesModel.add(new ArrayList<>());
            }
            Long val = values.get(i);
            if (val != null) {
                // get max and min, this is a relative scale.
                max = Math.max(Math.abs(val), max);
                min = 0;
                lastValid = timeEvent;
                seriesModel.get(i).add(new LongPoint(x, val));
            }
        }
    }
    if (lastValid == null) {
        return;
    }
    double scale = (max - min) == 0 ? 1.0 : (double) rect.height / (max - min);
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(lastValid);
    if (elementStyle == null) {
        return;
    }
    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.COLOR);
    fLines.add(new DeferredLine(rect, min, seriesModel, rgba == null ? BLACK : rgba, scale));
}
Also used : ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ArrayList(java.util.ArrayList) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) DeferredLine(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredLine) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) TimeLineEvent(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.model.TimeLineEvent) NonNull(org.eclipse.jdt.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager)

Example 2 with DeferredLine

use of org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredLine in project tracecompass by tracecompass.

the class TimeGraphControl method drawItems.

/**
 * Draw many items at once
 *
 * @param bounds
 *            The bounds of the control
 * @param timeProvider
 *            The time provider
 * @param items
 *            The array items to draw
 * @param topIndex
 *            The index of the first element to draw
 * @param nameSpace
 *            The name space width
 * @param gc
 *            Graphics context
 */
public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, Item[] items, int topIndex, int nameSpace, GC gc) {
    int bottomIndex = Integer.min(topIndex + countPerPage() + 1, items.length);
    for (int i = topIndex; i < bottomIndex; i++) {
        Item item = items[i];
        drawItem(item, bounds, timeProvider, i, nameSpace, gc);
    }
    TraceCompassLogUtils.traceCounter(LOGGER, Level.FINER, fDrawItemsCountLabel, bottomIndex - topIndex);
    if (gc == null) {
        return;
    }
    /*
         * Draw entries, entries contain events
         */
    for (DeferredEntry entry : fPostDrawEntries) {
        entry.draw(fTimeGraphProvider, gc);
    }
    // Defer line drawing
    for (DeferredLine line : fLines) {
        line.draw(fTimeGraphProvider, gc);
    }
    Color prev = gc.getForeground();
    Color black = TimeGraphRender.getColor(BLACK.toInt());
    gc.setForeground(black);
    int prevAA = gc.getAntialias();
    /*
         * BUG: Doesn't work in certain distros of Linux the end result is
         * anti-aliased points. They may actually look better but are not as
         * accurate.
         */
    gc.setAntialias(SWT.OFF);
    int prevLineWidth = gc.getLineWidth();
    gc.setLineWidth(1);
    // Deferred point drawing, they are aggregated into segments
    for (DeferredSegment seg : fPoints) {
        seg.draw(fTimeGraphProvider, gc);
    }
    gc.setLineWidth(prevLineWidth);
    gc.setAntialias(prevAA);
    // Draw selection at very end
    for (Rectangle rectangle : fSelectedRectangles) {
        int arc = Math.min(rectangle.height + 1, rectangle.width) / 2;
        gc.drawRoundRectangle(rectangle.x - 1, rectangle.y - 1, rectangle.width, rectangle.height + 1, arc, arc);
    }
    gc.setForeground(prev);
}
Also used : StateItem(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem) DeferredItem(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredItem) DeferredEntry(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredEntry) DeferredSegment(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredSegment) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Rectangle(org.eclipse.swt.graphics.Rectangle) DeferredLine(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredLine) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)

Aggregations

Point (org.eclipse.swt.graphics.Point)2 DeferredLine (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredLine)2 LongPoint (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)2 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Color (org.eclipse.swt.graphics.Color)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 DeferredEntry (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredEntry)1 DeferredItem (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredItem)1 DeferredSegment (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredSegment)1 TimeLineEvent (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.model.TimeLineEvent)1 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)1 StyleManager (org.eclipse.tracecompass.tmf.ui.model.StyleManager)1 StateItem (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)1 ITimeEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent)1