Search in sources :

Example 1 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle in project tracecompass by tracecompass.

the class ITimeGraphPresentationProvider method getEventStyle.

/**
 * Get the style map of a given ITimeEvent
 *
 * @param event
 *            the time event
 * @return the style map, as detailed in {@link ITimeEventStyleStrings}
 * @since 3.0
 */
default Map<String, Object> getEventStyle(ITimeEvent event) {
    if (event instanceof TimeEvent) {
        TimeEvent timeEvent = (TimeEvent) event;
        OutputElementStyle style = timeEvent.getModel().getStyle();
        if (style != null) {
            Map<@NonNull String, @NonNull Object> styleValues = style.getStyleValues();
            if (!styleValues.isEmpty()) {
                return styleValues;
            }
        }
    }
    StateItem stateItem = null;
    int index = getStateTableIndex(event);
    StateItem[] stateTable = getStateTable();
    if (index >= 0 && index < stateTable.length) {
        stateItem = stateTable[index];
    }
    Map<String, Object> styleMap = stateItem == null ? Collections.emptyMap() : stateItem.getStyleMap();
    Map<String, Object> specificEventStyles = getSpecificEventStyle(event);
    if (specificEventStyles.isEmpty()) {
        return styleMap;
    }
    if (styleMap.isEmpty()) {
        return specificEventStyles;
    }
    styleMap = new HashMap<>(styleMap);
    styleMap.putAll(specificEventStyles);
    return styleMap;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) TimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent)

Example 2 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle in project tracecompass by tracecompass.

the class LostEventsOutputAnnotationProvider method fetchAnnotations.

@SuppressWarnings("null")
@Override
public TmfModelResponse<AnnotationModel> fetchAnnotations(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    IProgressMonitor progressMonitor = monitor;
    if (progressMonitor == null) {
        progressMonitor = new NullProgressMonitor();
    }
    ITmfStateSystem ss = getStateSystem();
    if (ss == null) {
        return NO_DATA;
    }
    int lostEventsQuark = getLostEventsQuark(ss);
    if (lostEventsQuark == -1) {
        return NO_DATA;
    }
    List<Long> timeRequested = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
    @Nullable Set<@NonNull String> categories = DataProviderParameterUtils.extractSelectedCategories(fetchParameters);
    if (timeRequested == null || timeRequested.size() < 2 || (categories != null && !categories.contains(LOST_EVENTS))) {
        return NO_DATA;
    }
    if (timeRequested.equals(fLastRequest)) {
        // $NON-NLS-1$
        return new TmfModelResponse<>(fLastAnnotationModel, Status.COMPLETED, "");
    }
    fLastRequest = new ArrayList<>(timeRequested);
    TreeMultimap<String, Annotation> markers = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(Annotation::getStartTime));
    try {
        long start = Math.max(timeRequested.get(0), ss.getStartTime());
        long end = Math.min(timeRequested.get(timeRequested.size() - 1), ss.getCurrentEndTime());
        if (start <= end) {
            List<Long> times = new ArrayList<>(getTimes(ss, timeRequested));
            /* Update start to ensure that the previous marker is included. */
            start = Math.max(start - 1, ss.getStartTime());
            /* Update end to ensure that the next marker is included. */
            long nextStartTime = ss.querySingleState(end, lostEventsQuark).getEndTime() + 1;
            end = Math.min(nextStartTime, ss.getCurrentEndTime());
            times.set(0, start);
            times.set(times.size() - 1, end);
            for (ITmfStateInterval interval : ss.query2D(ImmutableList.of(lostEventsQuark), times)) {
                if (progressMonitor.isCanceled()) {
                    fLastRequest = Collections.emptyList();
                    fLastAnnotationModel = new AnnotationModel(Collections.emptyMap());
                    // $NON-NLS-1$
                    return new TmfModelResponse<>(fLastAnnotationModel, Status.CANCELLED, "");
                }
                if (interval.getStateValue().isNull()) {
                    continue;
                }
                long lostEventsStartTime = interval.getStartTime();
                /*
                     * The end time of the lost events range is the value of the
                     * attribute, not the end time of the interval.
                     */
                long lostEventsEndTime = interval.getStateValue().unboxLong();
                long duration = lostEventsEndTime - lostEventsStartTime;
                Map<String, Object> style = new HashMap<>();
                style.put(StyleProperties.COLOR, COLOR);
                style.put(StyleProperties.OPACITY, OPACITY);
                markers.put(LOST_EVENTS, new Annotation(lostEventsStartTime, duration, -1, AnnotationType.CHART, null, new OutputElementStyle(LOST_EVENTS, style)));
            }
        }
    } catch (StateSystemDisposedException e) {
    /* ignored */
    }
    fLastAnnotationModel = new AnnotationModel(markers.asMap());
    // $NON-NLS-1$
    return new TmfModelResponse<>(fLastAnnotationModel, Status.COMPLETED, "");
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Nullable(org.eclipse.jdt.annotation.Nullable) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 3 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle 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 4 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle in project tracecompass by tracecompass.

the class XYPresentationProvider method getSeriesStyle.

@Override
@NonNull
public OutputElementStyle getSeriesStyle(Long seriesId, @NonNull String type, int width) {
    OutputElementStyle appearance = fYAppearances.get(seriesId);
    if (appearance != null) {
        return appearance;
    }
    if (!SUPPORTED_TYPES.contains(type)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new UnsupportedOperationException("Series type: " + type + " is not supported.");
    }
    appearance = StyleProperties.SeriesType.SCATTER.equals(type) ? createScatter(seriesId, type, width) : createAppearance(seriesId, type, width);
    fYAppearances.put(seriesId, appearance);
    return appearance;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 5 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle in project tracecompass by tracecompass.

the class StyleManager method getFactorStyle.

/**
 * Get the style property factor value for the specified element style. The
 * style hierarchy is traversed until a number value is found, and the
 * returned float value will be multiplied by the first
 * {@link StyleProperties#FACTOR} suffixed modifier style that was found
 * along the way, if any.
 *
 * @param elementStyle
 *            the style
 * @param property
 *            the style property
 * @return the style float value, or null
 */
@Nullable
public Float getFactorStyle(OutputElementStyle elementStyle, String property) {
    Float factor = null;
    OutputElementStyle style = elementStyle;
    Stack<String> styleQueue = new Stack<>();
    while (style != null) {
        Map<String, Object> styleValues = style.getStyleValues();
        if (factor == null) {
            Object value = styleValues.get(property + StyleProperties.FACTOR);
            if (value instanceof Number) {
                factor = ((Number) value).floatValue();
            }
        }
        Object value = styleValues.get(property);
        if (value instanceof Number) {
            float floatValue = ((Number) value).floatValue();
            return (factor == null) ? floatValue : factor * floatValue;
        }
        // Get the next style
        style = popNextStyle(style, styleQueue);
    }
    return (factor == null) ? null : factor;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) Stack(java.util.Stack) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)31 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)12 Nullable (org.eclipse.jdt.annotation.Nullable)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 NonNull (org.eclipse.jdt.annotation.NonNull)7 LinkedHashMap (java.util.LinkedHashMap)5 Point (org.eclipse.swt.graphics.Point)5 LongPoint (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)5 Color (org.eclipse.swt.graphics.Color)4 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)4 StyleManager (org.eclipse.tracecompass.tmf.ui.model.StyleManager)4 ITimeEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent)4 Collection (java.util.Collection)3 Stack (java.util.Stack)3 RGB (org.eclipse.swt.graphics.RGB)3 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)3 IOutputStyleProvider (org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider)3 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)3 StateItem (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)3