use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.
the class ResourcesPresentationProvider method getSpecificEventStyle.
@Override
public Map<String, Object> getSpecificEventStyle(ITimeEvent event) {
Map<String, Object> map = new HashMap<>(super.getSpecificEventStyle(event));
if (isType(event.getEntry(), Type.CURRENT_THREAD) && event instanceof TimeEvent) {
if (event instanceof MarkerEvent) {
TimeEvent timeEvent = (TimeEvent) event;
OutputElementStyle style = timeEvent.getModel().getStyle();
if (style != null) {
return style.getStyleValues();
}
} else {
int threadEventValue = ((TimeEvent) event).getValue();
RGBAColor color = PALETTE.get(Math.floorMod(threadEventValue + COLOR_DIFFERENCIATION_FACTOR, NUM_COLORS));
map.put(StyleProperties.BACKGROUND_COLOR, ColorUtils.toHexColor(color.getRed(), color.getGreen(), color.getBlue()));
map.put(StyleProperties.STYLE_NAME, String.valueOf(threadEventValue));
}
} else if (event.getEntry() instanceof TimeGraphEntry && ((TimeGraphEntry) event.getEntry()).getEntryModel() instanceof ITimeGraphEntryModelWeighted) {
ITimeGraphEntryModelWeighted model = (ITimeGraphEntryModelWeighted) ((TimeGraphEntry) event.getEntry()).getEntryModel();
int eventValue = ((TimeEvent) event).getValue();
map.put(StyleProperties.HEIGHT, (float) model.getWeight(eventValue));
}
return map;
}
use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.
the class FlameGraphPresentationProvider method getStateTable.
@Override
public StateItem[] getStateTable() {
if (fStateTable[1] == null) {
Map<@NonNull String, @NonNull OutputElementStyle> styles = FlameDefaultPalette.getStyles();
if (styles.isEmpty()) {
for (int i = 0; i < NUM_COLORS; i++) {
fStateTable[i + 1] = new StateItem(Collections.emptyMap());
}
return fStateTable;
}
int tableIndex = 1;
for (Entry<@NonNull String, @NonNull OutputElementStyle> styleEntry : styles.entrySet()) {
String styleKey = styleEntry.getKey();
fKeyToIndex.put(styleKey, tableIndex);
OutputElementStyle elementStyle = styleEntry.getValue();
Map<String, Object> styleMap = new HashMap<>();
RGBAColor bgColor = getColorStyle(elementStyle, StyleProperties.BACKGROUND_COLOR);
if (bgColor != null) {
RGB rgb = new RGB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue());
styleMap.put(StyleProperties.BACKGROUND_COLOR, ColorUtils.toHexColor(rgb));
}
RGBAColor color = getColorStyle(elementStyle, StyleProperties.COLOR);
if (color != null) {
RGB rgb = new RGB(color.getRed(), color.getGreen(), color.getBlue());
styleMap.put(StyleProperties.COLOR, ColorUtils.toHexColor(rgb));
}
Object styleName = getStyle(elementStyle, StyleProperties.STYLE_NAME);
if (styleName instanceof String) {
styleMap.put(StyleProperties.STYLE_NAME, styleName);
} else {
styleMap.put(StyleProperties.STYLE_NAME, styleEntry.getKey());
}
Float height = getFloatStyle(elementStyle, StyleProperties.HEIGHT);
if (height != null) {
styleMap.put(StyleProperties.HEIGHT, height);
}
Float width = getFloatStyle(elementStyle, StyleProperties.WIDTH);
if (width != null) {
styleMap.put(StyleProperties.WIDTH, width.intValue());
}
Object symbolType = getStyle(elementStyle, StyleProperties.SYMBOL_TYPE);
if (symbolType instanceof String) {
styleMap.put(StyleProperties.SYMBOL_TYPE, symbolType);
}
Object styleGroup = getStyle(elementStyle, StyleProperties.STYLE_GROUP);
if (styleGroup != null) {
styleMap.put(StyleProperties.STYLE_GROUP, styleGroup);
}
fStateTable[tableIndex] = new StateItem(styleMap);
tableIndex++;
}
}
return fStateTable;
}
use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.
the class TimeGraphViewTest method testPalettes.
/**
* Test time graph with color palettes
*/
@Ignore
@Test
public void testPalettes() {
resetTimeRange();
TimeGraphViewStub view = getView();
Rectangle bounds = fBounds;
IPaletteProvider paletteBlue = SequentialPaletteProvider.create(new RGBAColor(0x23, 0x67, 0xf3, 0xff), 5);
UIThreadRunnable.syncExec(() -> view.setPresentationProvider(new PalettedPresentationProvider() {
@Override
public IPaletteProvider getPalette() {
return paletteBlue;
}
}));
List<RGB> rgbs = Lists.transform(paletteBlue.get(), a -> RGBAUtil.fromInt(a.toInt()).rgb);
fViewBot.bot().waitUntil(new PaletteIsPresent(rgbs, bounds));
IPaletteProvider paletteGreen = SequentialPaletteProvider.create(new RGBAColor(0x23, 0xf3, 0x67, 0xff), 5);
UIThreadRunnable.syncExec(() -> view.setPresentationProvider(new PalettedPresentationProvider() {
@Override
public IPaletteProvider getPalette() {
return paletteGreen;
}
}));
rgbs = Lists.transform(paletteGreen.get(), a -> RGBAUtil.fromInt(a.toInt()).rgb);
fViewBot.bot().waitUntil(new PaletteIsPresent(rgbs, bounds));
IPaletteProvider rotating = new QualitativePaletteProvider.Builder().setAttenuation(0.5f).setBrightness(1.0f).setNbColors(4).build();
UIThreadRunnable.syncExec(() -> view.setPresentationProvider(new PalettedPresentationProvider() {
@Override
public IPaletteProvider getPalette() {
return rotating;
}
}));
rgbs = Lists.transform(rotating.get(), a -> RGBAUtil.fromInt(a.toInt()).rgb);
fViewBot.bot().waitUntil(new PaletteIsPresent(rgbs, bounds));
}
use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.
the class BaseDataProviderTimeGraphPresentationProvider method updateStyles.
/**
* This method updates the styles map returned by the data provider(s) to
* overwrite any style property value that was changed by the user in the
* legend dialog with the value from the state table (ie. legend value).
*/
private void updateStyles() {
Map<String, OutputElementStyle> stylesMap = fStylesMap;
StateItem[] stateTable = fStateTable;
if (stylesMap == null || stateTable == null) {
return;
}
for (Entry<String, Integer> entry : fKeyToIndex.entrySet()) {
OutputElementStyle elementStyle = stylesMap.get(entry.getKey());
Integer index = entry.getValue();
if (elementStyle == null || index >= stateTable.length) {
continue;
}
StateItem stateItem = stateTable[index];
RGB rgb = stateItem.getStateColor();
Map<@NonNull String, @NonNull Object> styleValues = elementStyle.getStyleValues();
RGBAColor rgba = getColorStyle(elementStyle, StyleProperties.BACKGROUND_COLOR);
/*
* Update if there is a color and it does not match the legend, or
* if there is no color and the legend is not the default.
*/
if ((rgba != null && !new RGB(rgba.getRed(), rgba.getGreen(), rgba.getBlue()).equals(rgb)) || (rgba == null && !new RGB(0, 0, 0).equals(rgb))) {
String hexColor = ColorUtils.toHexColor(rgb);
styleValues.put(StyleProperties.BACKGROUND_COLOR, hexColor);
styleValues.put(StyleProperties.COLOR, hexColor);
styleValues.put(StyleProperties.OPACITY, 1.0f);
}
/* Use the WIDTH property if it is defined, use HEIGHT otherwise */
if (elementStyle.getStyleValues().containsKey(StyleProperties.WIDTH)) {
int widthFactor = stateItem.getStateWidth();
Float prevWidthFactor = getFloatStyle(elementStyle, StyleProperties.WIDTH);
if (prevWidthFactor == null) {
prevWidthFactor = 1.0f;
}
/*
* Update if the width with factor does not match the legend. In
* that case update the base width without factor.
*/
if (!Float.valueOf(widthFactor).equals(prevWidthFactor)) {
Object width = elementStyle.getStyleValues().get(StyleProperties.WIDTH);
width = width instanceof Integer ? width : 1;
styleValues.put(StyleProperties.WIDTH, Math.round((int) width * widthFactor / prevWidthFactor));
}
} else {
float heightFactor = stateItem.getStateHeightFactor();
Float prevHeightFactor = getFloatStyle(elementStyle, StyleProperties.HEIGHT);
if (prevHeightFactor == null) {
prevHeightFactor = 1.0f;
}
/*
* Update if the height with factor does not match the legend. In
* that case update the base height without factor.
*/
if (!Float.valueOf(heightFactor).equals(prevHeightFactor)) {
Object height = elementStyle.getStyleValues().get(StyleProperties.HEIGHT);
height = height instanceof Float ? height : 1.0f;
styleValues.put(StyleProperties.HEIGHT, (float) height * heightFactor / prevHeightFactor);
}
}
}
}
use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.
the class BaseDataProviderTimeGraphPresentationProvider method getStateTable.
@Override
public StateItem[] getStateTable() {
@Nullable StateItem[] stateTable = fStateTable;
if (stateTable == null) {
Map<@NonNull String, @NonNull OutputElementStyle> styles = fetchStyles();
if (styles.isEmpty()) {
stateTable = new StateItem[0];
fStateTable = stateTable;
return stateTable;
}
List<StateItem> stateItemList = new ArrayList<>();
int tableIndex = 0;
for (Entry<@NonNull String, @NonNull OutputElementStyle> styleEntry : styles.entrySet()) {
String styleKey = styleEntry.getKey();
fKeyToIndex.put(styleKey, tableIndex++);
OutputElementStyle elementStyle = styleEntry.getValue();
Map<String, Object> styleMap = new HashMap<>();
RGBAColor bgColor = getColorStyle(elementStyle, StyleProperties.BACKGROUND_COLOR);
if (bgColor != null) {
RGB rgb = new RGB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue());
styleMap.put(StyleProperties.BACKGROUND_COLOR, ColorUtils.toHexColor(rgb));
}
RGBAColor color = getColorStyle(elementStyle, StyleProperties.COLOR);
if (color != null) {
RGB rgb = new RGB(color.getRed(), color.getGreen(), color.getBlue());
styleMap.put(StyleProperties.COLOR, ColorUtils.toHexColor(rgb));
}
Object styleName = getStyle(elementStyle, StyleProperties.STYLE_NAME);
if (styleName instanceof String) {
styleMap.put(StyleProperties.STYLE_NAME, styleName);
} else {
styleMap.put(StyleProperties.STYLE_NAME, styleEntry.getKey());
}
Float height = getFloatStyle(elementStyle, StyleProperties.HEIGHT);
if (height != null) {
styleMap.put(StyleProperties.HEIGHT, height);
}
Float width = getFloatStyle(elementStyle, StyleProperties.WIDTH);
if (width != null) {
styleMap.put(StyleProperties.WIDTH, width.intValue());
}
Object symbolType = getStyle(elementStyle, StyleProperties.SYMBOL_TYPE);
if (symbolType instanceof String) {
styleMap.put(StyleProperties.SYMBOL_TYPE, symbolType);
}
Object styleGroup = getStyle(elementStyle, StyleProperties.STYLE_GROUP);
if (styleGroup != null) {
styleMap.put(StyleProperties.STYLE_GROUP, styleGroup);
}
stateItemList.add(new StateItem(styleMap));
}
stateTable = stateItemList.toArray(new StateItem[stateItemList.size()]);
fStateTable = stateTable;
}
return stateTable;
}
Aggregations