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