Search in sources :

Example 1 with BaseXYPresentationProvider

use of org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider 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;
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ImageData(org.eclipse.swt.graphics.ImageData) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 2 with BaseXYPresentationProvider

use of org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider in project tracecompass by tracecompass.

the class TmfFilteredXYChartViewer method handleCheckStateChangedEvent.

/**
 * Update the chart depending on the selected entries.
 *
 * @param entries
 *            Counters to display on the chart
 */
@Override
public void handleCheckStateChangedEvent(Collection<ITmfTreeViewerEntry> entries) {
    cancelUpdate();
    Iterable<TmfGenericTreeEntry> counterEntries = Iterables.filter(entries, TmfGenericTreeEntry.class);
    Collection<@NonNull Long> selectedIds = Sets.newHashSet(Iterables.transform(counterEntries, e -> e.getModel().getId()));
    if (!selectedIds.containsAll(fSelectedIds)) {
        clearContent();
    }
    fSelectedIds = selectedIds;
    // Update the styles as well
    BaseXYPresentationProvider presProvider = getPresentationProvider();
    for (ITmfTreeViewerEntry entry : entries) {
        if (entry instanceof TmfGenericTreeEntry) {
            TmfGenericTreeEntry<TmfTreeDataModel> genericEntry = (TmfGenericTreeEntry<TmfTreeDataModel>) entry;
            TmfTreeDataModel model = genericEntry.getModel();
            OutputElementStyle style = model.getStyle();
            if (style != null) {
                presProvider.setStyle(model.getId(), style);
            }
        }
    }
    updateContent();
}
Also used : Iterables(com.google.common.collect.Iterables) Chart(org.eclipse.swtchart.Chart) DataProviderManager(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager) ITmfTreeXYDataProvider(org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider) HashMap(java.util.HashMap) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) ICheckboxTreeViewerListener(org.eclipse.tracecompass.tmf.ui.viewers.tree.ICheckboxTreeViewerListener) Multimap(com.google.common.collect.Multimap) TmfGenericTreeEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfGenericTreeEntry) Nullable(org.eclipse.jdt.annotation.Nullable) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) TmfTraceSelectedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Collection(java.util.Collection) FetchParametersUtils(org.eclipse.tracecompass.internal.tmf.core.model.filters.FetchParametersUtils) IOutputStyleProvider(org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider) DataProviderParameterUtils(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderParameterUtils) Sets(com.google.common.collect.Sets) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) IYAppearance(org.eclipse.tracecompass.tmf.core.presentation.IYAppearance) Collections(java.util.Collections) NonNull(org.eclipse.jdt.annotation.NonNull) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider) ITmfXYDataProvider(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXYDataProvider) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) TmfGenericTreeEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfGenericTreeEntry) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider)

Example 3 with BaseXYPresentationProvider

use of org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider in project tracecompass by tracecompass.

the class TmfFilteredXYChartViewer method initializeDataProvider.

@Override
protected ITmfXYDataProvider initializeDataProvider(ITmfTrace trace) {
    ITmfTreeXYDataProvider<?> dataProvider = DataProviderManager.getInstance().getDataProvider(trace, fId, ITmfTreeXYDataProvider.class);
    BaseXYPresentationProvider presentationProvider = getPresentationProvider();
    fUseDefaultStyleValues.computeIfAbsent(presentationProvider, pp -> {
        if (dataProvider instanceof IOutputStyleProvider) {
            pp.addProvider(dataProvider);
            return false;
        }
        return true;
    });
    return dataProvider;
}
Also used : IOutputStyleProvider(org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider)

Example 4 with BaseXYPresentationProvider

use of org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider in project tracecompass by tracecompass.

the class XYChartLegendImageProvider method drawStyledDot.

private void drawStyledDot(GC gc, Color lineColor, int imageWidth, int imageHeight, @NonNull OutputElementStyle appearance) {
    BaseXYPresentationProvider presProvider = fChartViewer.getPresentationProvider();
    String symbolStyle = (String) presProvider.getStyleOrDefault(appearance, StyleProperties.SYMBOL_TYPE, StyleProperties.SymbolType.NONE);
    int symbolSize = Math.round(presProvider.getFloatStyleOrDefault(appearance, StyleProperties.HEIGHT, 1.0f).floatValue() * DEFAULT_SYMBOL_SIZE);
    int centerX = imageWidth / 2;
    int centerY = imageHeight / 2;
    Color prevBg = gc.getBackground();
    Color prevFg = gc.getForeground();
    switch(symbolStyle) {
        case StyleProperties.SymbolType.CIRCLE:
            SymbolHelper.drawCircle(gc, lineColor, symbolSize, centerX, centerY);
            break;
        case StyleProperties.SymbolType.DIAMOND:
            SymbolHelper.drawDiamond(gc, lineColor, symbolSize, centerX, centerY);
            break;
        case StyleProperties.SymbolType.SQUARE:
            SymbolHelper.drawSquare(gc, lineColor, symbolSize, centerX, centerY);
            break;
        case StyleProperties.SymbolType.CROSS:
            SymbolHelper.drawCross(gc, lineColor, symbolSize, centerX, centerY);
            break;
        case StyleProperties.SymbolType.PLUS:
            SymbolHelper.drawPlus(gc, lineColor, symbolSize, centerX, centerY);
            break;
        case StyleProperties.SymbolType.INVERTED_TRIANGLE:
            SymbolHelper.drawInvertedTriangle(gc, lineColor, symbolSize, centerX, centerY);
            break;
        case StyleProperties.SymbolType.TRIANGLE:
            SymbolHelper.drawTriangle(gc, lineColor, symbolSize, centerX, centerY);
            break;
        default:
            // Default is nothing
            break;
    }
    gc.setForeground(prevFg);
    gc.setBackground(prevBg);
}
Also used : Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider)

Example 5 with BaseXYPresentationProvider

use of org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider in project tracecompass by tracecompass.

the class XYChartLegendImageProvider method drawStyleLine.

private void drawStyleLine(GC gc, Color lineColor, int imageWidth, int imageHeight, @NonNull OutputElementStyle appearance) {
    Color prev = gc.getForeground();
    BaseXYPresentationProvider presProvider = fChartViewer.getPresentationProvider();
    LineStyle lineStyle = LineStyle.valueOf((String) presProvider.getStyleOrDefault(appearance, StyleProperties.SERIES_STYLE, StyleProperties.SeriesStyle.SOLID));
    if (lineStyle != LineStyle.NONE) {
        gc.setForeground(lineColor);
        gc.setLineWidth(((Number) presProvider.getFloatStyleOrDefault(appearance, StyleProperties.WIDTH, 1.0f)).intValue());
        gc.setLineStyle(lineStyle.ordinal());
        gc.drawLine(0, imageHeight / 2, imageWidth, imageHeight / 2);
        gc.setForeground(prev);
    }
}
Also used : LineStyle(org.eclipse.swtchart.LineStyle) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider)

Aggregations

BaseXYPresentationProvider (org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider)5 Color (org.eclipse.swt.graphics.Color)3 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)3 IOutputStyleProvider (org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider)2 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)2 Iterables (com.google.common.collect.Iterables)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 GC (org.eclipse.swt.graphics.GC)1 Image (org.eclipse.swt.graphics.Image)1 ImageData (org.eclipse.swt.graphics.ImageData)1 PaletteData (org.eclipse.swt.graphics.PaletteData)1 Composite (org.eclipse.swt.widgets.Composite)1 Chart (org.eclipse.swtchart.Chart)1