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));
}
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);
}
Aggregations