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