Search in sources :

Example 6 with RGBAColor

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;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ITimeGraphEntryModelWeighted(org.eclipse.tracecompass.internal.provisional.tmf.core.model.timegraph.ITimeGraphEntryModelWeighted) MarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) NullTimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent) TimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent) ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)

Example 7 with RGBAColor

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;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) RGB(org.eclipse.swt.graphics.RGB) StateItem(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)

Example 8 with RGBAColor

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));
}
Also used : TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) UIThreadRunnable(org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable) TmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp) Conditions(org.eclipse.swtbot.swt.finder.waits.Conditions) DefaultCondition(org.eclipse.swtbot.swt.finder.waits.DefaultCondition) SWTBotText(org.eclipse.swtbot.swt.finder.widgets.SWTBotText) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) ConditionHelpers(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers) Point(org.eclipse.swt.graphics.Point) TmfSelectionRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal) Logger(org.apache.log4j.Logger) SWTBotUtils(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils) KeyEvent(org.eclipse.swt.events.KeyEvent) After(org.junit.After) IPaletteProvider(org.eclipse.tracecompass.tmf.core.presentation.IPaletteProvider) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) SequentialPaletteProvider(org.eclipse.tracecompass.tmf.core.presentation.SequentialPaletteProvider) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) TimeGraphControl(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl) AfterClass(org.junit.AfterClass) Predicate(java.util.function.Predicate) SimpleLayout(org.apache.log4j.SimpleLayout) SWTBotPreferences(org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences) QualitativePaletteProvider(org.eclipse.tracecompass.tmf.core.presentation.QualitativePaletteProvider) TmfContext(org.eclipse.tracecompass.tmf.core.trace.TmfContext) Multisets(com.google.common.collect.Multisets) Display(org.eclipse.swt.widgets.Display) SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) Collectors(java.util.stream.Collectors) TmfFileDialogFactory(org.eclipse.tracecompass.tmf.ui.dialog.TmfFileDialogFactory) Objects(java.util.Objects) MouseEvent(org.eclipse.swt.events.MouseEvent) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) List(java.util.List) AbstractTimeGraphView(org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView) Assert.assertFalse(org.junit.Assert.assertFalse) ConsoleAppender(org.apache.log4j.ConsoleAppender) SWT(org.eclipse.swt.SWT) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfLocation(org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation) TmfSignalManager(org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager) TmfTraceStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub) NonNull(org.eclipse.jdt.annotation.NonNull) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) KeyStroke(org.eclipse.jface.bindings.keys.KeyStroke) BeforeClass(org.junit.BeforeClass) Multiset(com.google.common.collect.Multiset) RunWith(org.junit.runner.RunWith) Rectangle(org.eclipse.swt.graphics.Rectangle) Keystrokes(org.eclipse.swtbot.swt.finder.keyboard.Keystrokes) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Lists(com.google.common.collect.Lists) ImageHelper(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ImageHelper) ImmutableMultiset(com.google.common.collect.ImmutableMultiset) RGB(org.eclipse.swt.graphics.RGB) SWTWorkbenchBot(org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) Before(org.junit.Before) ITimeDataProvider(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) File(java.io.File) SWTBotButton(org.eclipse.swtbot.swt.finder.widgets.SWTBotButton) SWTBotTimeGraphEntry(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraphEntry) SWTBotJunit4ClassRunner(org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner) ListResult(org.eclipse.swtbot.swt.finder.results.ListResult) Ignore(org.junit.Ignore) Result(org.eclipse.swtbot.swt.finder.results.Result) SWTBotTimeGraph(org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraph) ICondition(org.eclipse.swtbot.swt.finder.waits.ICondition) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) TmfWindowRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal) Assert.assertEquals(org.junit.Assert.assertEquals) Control(org.eclipse.swt.widgets.Control) RGBAUtil(org.eclipse.tracecompass.tmf.ui.colors.RGBAUtil) IPaletteProvider(org.eclipse.tracecompass.tmf.core.presentation.IPaletteProvider) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Rectangle(org.eclipse.swt.graphics.Rectangle) RGB(org.eclipse.swt.graphics.RGB) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with RGBAColor

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);
            }
        }
    }
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) RGB(org.eclipse.swt.graphics.RGB) StateItem(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)

Example 10 with RGBAColor

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;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ArrayList(java.util.ArrayList) RGB(org.eclipse.swt.graphics.RGB) StateItem(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem) Nullable(org.eclipse.jdt.annotation.Nullable)

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