Search in sources :

Example 1 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class CustomAnnotationProvider method getSubMarkerList.

private void getSubMarkerList(WeightedMarker weightedMarker, Annotation markerEvent, Map<String, Collection<@NonNull Annotation>> annotationMap, long startTime, long endTime, long minDuration, Long[] times) {
    if (markerEvent.getTime() > endTime || markerEvent.getTime() + markerEvent.getDuration() < startTime) {
        return;
    }
    long start = markerEvent.getTime();
    long length = 0;
    List<@NonNull Annotation> annotationsList = new ArrayList<>();
    for (int i = 0; i < weightedMarker.getSegments().size(); i++) {
        MarkerSegment segment = weightedMarker.getSegments().get(i);
        length += segment.getLength();
        long end = markerEvent.getTime() + Math.round((length / (double) weightedMarker.getTotalLength()) * markerEvent.getDuration());
        long duration = end - start;
        if (end >= startTime && duration > minDuration && !segment.getColor().isEmpty()) {
            RGBAColor color = getColor(segment);
            Annotation subAnnotation = new Annotation(start, end - start, -1, String.format(segment.getLabel(), i), getOutputStyle(color));
            for (SubMarker subMarker : segment.getSubMarkers()) {
                getSubMarkerList(Objects.requireNonNull(subMarker), subAnnotation, annotationMap, startTime, endTime, minDuration, times);
            }
            for (SubMarker subMarker : weightedMarker.getSubMarkers()) {
                getSubMarkerList(Objects.requireNonNull(subMarker), subAnnotation, annotationMap, startTime, endTime, minDuration, times);
            }
            annotationsList.add(subAnnotation);
        }
        if (start >= endTime) {
            break;
        }
        start = end;
    }
    populateMap(annotationMap, annotationsList, Objects.requireNonNull(weightedMarker.getName()));
}
Also used : RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) SubMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker) ArrayList(java.util.ArrayList) MarkerSegment(org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSegment) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)

Example 2 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class PeriodicAnnotationProvider method fetchAnnotations.

@Override
@NonNull
public TmfModelResponse<@NonNull AnnotationModel> fetchAnnotations(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    List<Long> times = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
    if (times == null) {
        return EMPTY_MODEL_RESPONSE;
    }
    int size = times.size() - 1;
    long startTime = times.get(0);
    long endTime = times.get(size);
    long resolution = (endTime - startTime) / (size);
    if (startTime > endTime) {
        return EMPTY_MODEL_RESPONSE;
    }
    long step = Math.max(Math.round(fPeriod), resolution);
    OutputElementStyle[] styles = new OutputElementStyle[2];
    styles[0] = generateOutputElementStyle(fColor1);
    RGBAColor color2 = fColor2;
    styles[1] = color2 == null ? styles[0] : generateOutputElementStyle(color2);
    Collection<Annotation> annotations = new ArrayList<>();
    /* Subtract 1.5 periods to ensure previous marker is included */
    long time = startTime - Math.max(Math.round(1.5 * fPeriod), resolution);
    ITimeReference reference = adjustReference(fReference, time);
    Annotation annotation = null;
    while (true) {
        long index = Math.round((time - reference.getTime()) / fPeriod) + reference.getIndex();
        long markerTime = Math.round((index - reference.getIndex()) * fPeriod) + reference.getTime();
        long duration = (fColor2 == null) ? 0 : Math.round((index + 1 - reference.getIndex()) * fPeriod) + reference.getTime() - markerTime;
        long labelIndex = index;
        if (fRollover != 0) {
            labelIndex %= fRollover;
            if (labelIndex < 0) {
                labelIndex += fRollover;
            }
        }
        /* Add previous marker if current is visible */
        if ((markerTime >= startTime || markerTime + duration > startTime) && annotation != null) {
            annotations.add(annotation);
        }
        if (isApplicable(labelIndex)) {
            OutputElementStyle style = Objects.requireNonNull((index % 2) == 0 ? styles[0] : styles[1]);
            annotation = new Annotation(markerTime, duration, -1, getAnnotationLabel(labelIndex), style);
        } else {
            annotation = null;
        }
        if (markerTime > endTime || (monitor != null && monitor.isCanceled())) {
            if (annotation != null && isApplicable(labelIndex)) {
                /* The next marker out of range is included */
                annotations.add(annotation);
            }
            break;
        }
        time += step;
    }
    Map<String, Collection<Annotation>> model = new HashMap<>();
    model.put(fCategory, annotations);
    // $NON-NLS-1$
    return new TmfModelResponse<>(new AnnotationModel(model), Status.COMPLETED, "");
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Collection(java.util.Collection) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 3 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class StyleManager method getColorStyle.

/**
 * Get the style property color value for the specified element style. The
 * style hierarchy is traversed until a color and opacity value is found,
 * and the returned color value will be blended with the first
 * {@link StyleProperties#BLEND} suffixed modifier style that was found
 * along the way, if any.
 *
 * @param elementStyle
 *            the style
 * @param property
 *            the style property
 * @return the style value, or null
 */
@Nullable
public RGBAColor getColorStyle(OutputElementStyle elementStyle, String property) {
    String color = null;
    Float opacity = null;
    RGBAColor blend = null;
    OutputElementStyle style = elementStyle;
    Stack<String> styleQueue = new Stack<>();
    while (style != null) {
        Map<String, Object> styleValues = style.getStyleValues();
        if (blend == null) {
            Object value = styleValues.get(property + StyleProperties.BLEND);
            if (value instanceof String) {
                RGBAColor rgba = RGBAColor.fromString((String) value);
                if (rgba != null) {
                    blend = rgba;
                }
            }
        }
        if (opacity == null) {
            Object value = styleValues.get(StyleProperties.OPACITY);
            if (value instanceof Number) {
                opacity = ((Number) value).floatValue();
                if (color != null) {
                    break;
                }
            }
        }
        if (color == null) {
            Object value = styleValues.get(property);
            if (value instanceof String) {
                color = (String) value;
                if (opacity != null) {
                    break;
                }
            }
        }
        // Get the next style
        style = popNextStyle(style, styleQueue);
    }
    int alpha = (opacity == null) ? 255 : (int) (opacity * 255);
    RGBAColor rgba = (color == null) ? (opacity == null ? null : new RGBAColor(0, 0, 0, alpha)) : RGBAColor.fromString(color, alpha);
    return (rgba == null) ? null : (blend == null) ? rgba : blend(rgba, blend);
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Stack(java.util.Stack) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 4 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class XYChartLegendImageProvider method getLegendImage.

@Override
public Image getLegendImage(int imageHeight, int imageWidth, @NonNull Long id) {
    /*
         * If series exists in chart, then image legend match that series. Image will
         * make sense if series exists in chart. If it does not exists, an image will
         * still be created.
         */
    OutputElementStyle appearance = fChartViewer.getSeriesStyle(id);
    BaseXYPresentationProvider presProvider = fChartViewer.getPresentationProvider();
    RGBAColor rgb = presProvider.getColorStyleOrDefault(appearance, StyleProperties.COLOR, DEFAULT_COLOR);
    Color lineColor = new Color(Display.getDefault(), rgb.getRed(), rgb.getGreen(), rgb.getBlue());
    Color background = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
    PaletteData palette = new PaletteData(background.getRGB(), lineColor.getRGB());
    ImageData imageData = new ImageData(imageWidth, imageHeight, 8, palette);
    imageData.transparentPixel = 0;
    Image image = new Image(Display.getDefault(), imageData);
    GC gc = new GC(image);
    gc.setBackground(background);
    gc.fillRectangle(0, 0, imageWidth, imageHeight);
    drawStyleLine(gc, lineColor, imageWidth, imageHeight, appearance);
    drawStyledDot(gc, lineColor, imageWidth, imageHeight, appearance);
    gc.dispose();
    lineColor.dispose();
    return image;
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ImageData(org.eclipse.swt.graphics.ImageData) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 5 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class StateSystemPresentationProvider method getStateTable.

@Override
public StateItem[] getStateTable() {
    if (STATE_TABLE[0] == null) {
        List<@NonNull RGBAColor> colors = fPalette.get();
        for (int i = 0; i < colors.size(); i++) {
            RGBAColor rgbaColor = colors.get(i);
            STATE_TABLE[i] = new StateItem(RGBAUtil.fromInt(rgbaColor.toInt()).rgb, rgbaColor.toString());
        }
    }
    return STATE_TABLE;
}
Also used : RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) StateItem(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)

Aggregations

RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)25 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)12 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 NonNull (org.eclipse.jdt.annotation.NonNull)5 Color (org.eclipse.swt.graphics.Color)5 Point (org.eclipse.swt.graphics.Point)5 RGB (org.eclipse.swt.graphics.RGB)5 PeriodicMarker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker)5 SubMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker)5 StateItem (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Marker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker)4 MarkerSet (org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet)4 SplitMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker)4 WeightedMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker)4 LongPoint (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)4 StyleManager (org.eclipse.tracecompass.tmf.ui.model.StyleManager)4 Test (org.junit.Test)4