Search in sources :

Example 41 with Chart

use of org.eclipse.swtchart.Chart in project tracecompass by tracecompass.

the class SwtScatterChart method refreshDisplayLabels.

@Override
protected void refreshDisplayLabels() {
    /**
     * TODO: support for the Y axis too
     */
    /* Only refresh if labels are visible */
    Chart chart = getChart();
    IAxisSet axisSet = chart.getAxisSet();
    IAxis xAxis = axisSet.getXAxis(0);
    if (!xAxis.getTick().isVisible()) {
        return;
    }
    /*
         * Shorten all the labels to 5 characters plus "…" when the longest
         * label length is more than 50% of the chart height.
         */
    Rectangle rect = chart.getClientArea();
    int lengthLimit = (int) (rect.height * 0.40);
    GC gc = new GC(getParent());
    gc.setFont(xAxis.getTick().getFont());
    // labels.
    if (!fXStringMap.isEmpty()) {
        /* Find the longest category string */
        String longestString = Collections.max(fXStringMap.keySet(), Comparator.comparingInt(String::length));
        /* Get the length and height of the longest label in pixels */
        Point pixels = gc.stringExtent(longestString);
        /* Completely arbitrary */
        int cutLen = 5;
        if (pixels.x > lengthLimit) {
            /* We have to cut down some strings */
            for (Entry<String, Integer> entry : fXStringMap.entrySet()) {
                String reference = checkNotNull(entry.getKey());
                if (reference.length() > cutLen) {
                    String key = reference.substring(0, cutLen) + ELLIPSIS;
                    fVisibleXMap.remove(reference);
                    fVisibleXMap.put(key, entry.getValue());
                } else {
                    fVisibleXMap.inverse().remove(entry.getValue());
                    fVisibleXMap.put(reference, entry.getValue());
                }
            }
        } else {
            /* All strings should fit */
            resetBiMap(fXStringMap, fVisibleXMap);
        }
        for (IAxis axis : axisSet.getXAxes()) {
            IAxisTick tick = axis.getTick();
            tick.setFormat(new LabelFormat(fVisibleXMap));
        }
    }
    /* Cleanup */
    gc.dispose();
}
Also used : IAxisTick(org.eclipse.swtchart.IAxisTick) LabelFormat(org.eclipse.tracecompass.internal.tmf.chart.ui.format.LabelFormat) IAxisSet(org.eclipse.swtchart.IAxisSet) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Example 42 with Chart

use of org.eclipse.swtchart.Chart in project tracecompass by tracecompass.

the class NewCounterViewTest method testManipulatingTreeViewer.

/**
 * Ensure the data displayed in the chart viewer reflects the tree viewer's
 * selected entries.
 */
@Test
public void testManipulatingTreeViewer() {
    final Chart chart = getChart();
    assertNotNull(chart);
    assertEquals(0, chart.getSeriesSet().getSeries().length);
    SWTBotTree treeBot = getSWTBotView().bot().tree();
    WaitUtils.waitUntil(tree -> tree.rowCount() >= 1, treeBot, "The tree viewer did not finish loading.");
    SWTBotTreeItem root = treeBot.getTreeItem(TRACE_NAME);
    assertNotNull(root);
    SWTBotTreeItem counter = retrieveTreeItem(root, COUNTER_NAME);
    assertNotNull(counter);
    // Check all elements of the tree
    root.check();
    WaitUtils.waitUntil(SWTBotTreeItem::isChecked, root, "Root entry was not checked");
    assertTrue(counter.isChecked());
    assertFalse(root.isGrayed());
    assertFalse(counter.isGrayed());
    WaitUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 3, chart, "The data series did not load.");
    // Uncheck a leaf of the tree
    counter.uncheck();
    assertTrue(root.isChecked());
    assertTrue(root.isGrayed());
    assertFalse(counter.isChecked());
    assertFalse(counter.isGrayed());
    WaitUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 2, chart, "A data series has not been removed.");
}
Also used : SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) Chart(org.eclipse.swtchart.Chart) Test(org.junit.Test) XYDataProviderBaseTest(org.eclipse.tracecompass.tmf.ui.swtbot.tests.views.xychart.XYDataProviderBaseTest)

Example 43 with Chart

use of org.eclipse.swtchart.Chart in project tracecompass by tracecompass.

the class NewCounterViewTest method testDisplayingDataSeries.

/**
 * Validate the Counters view data model.
 */
@Test
public void testDisplayingDataSeries() {
    // Setup the chart viewer
    IViewPart viewPart = getSWTBotView().getViewReference().getView(true);
    assertTrue(viewPart instanceof CounterView);
    final TmfCommonXAxisChartViewer chartViewer = (TmfCommonXAxisChartViewer) getChartViewer(viewPart);
    assertNotNull(chartViewer);
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    chartViewer.setNbPoints(NUMBER_OF_POINTS);
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    final Chart chart = getChart();
    assertNotNull(chart);
    assertEquals(0, chart.getSeriesSet().getSeries().length);
    // Check the counter entry
    SWTBotTree treeBot = getSWTBotView().bot().tree();
    WaitUtils.waitUntil(tree -> tree.rowCount() >= 1, treeBot, "The tree viewer did not finish loading.");
    SWTBotTreeItem root = treeBot.getTreeItem(TRACE_NAME);
    SWTBotTreeItem counter = retrieveTreeItem(root, COUNTER_NAME);
    assertNotNull(counter);
    counter.check();
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    WaitUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 1, chart, "The data series did not load.");
    // Ensure the data series has the correct styling
    verifySeriesStyle(MAIN_SERIES_NAME, ISeries.SeriesType.LINE, BLUE, LineStyle.SOLID, false);
    // Ensure the data model is valid
    WaitUtils.waitUntil(json -> isChartDataValid(chart, json), "resources/minor_faults-res50.json", "The chart data is not valid.");
}
Also used : IViewPart(org.eclipse.ui.IViewPart) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) CounterView(org.eclipse.tracecompass.analysis.counters.ui.views.CounterView) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) TmfCommonXAxisChartViewer(org.eclipse.tracecompass.tmf.ui.viewers.xychart.linechart.TmfCommonXAxisChartViewer) Chart(org.eclipse.swtchart.Chart) Test(org.junit.Test) XYDataProviderBaseTest(org.eclipse.tracecompass.tmf.ui.swtbot.tests.views.xychart.XYDataProviderBaseTest)

Example 44 with Chart

use of org.eclipse.swtchart.Chart in project tracecompass by tracecompass.

the class LamiChartViewerTest method testSimilarRows.

/**
 * Test a few charts with the multiple similar row dataset.
 *
 * @throws SecurityException
 *             If a security manager is present and any the wrong class is
 *             loaded or the class loader is not the same as its ancestor's
 *             loader.
 *
 * @throws IllegalArgumentException
 *             the object is not the correct class type
 */
@Test
public void testSimilarRows() throws SecurityException, IllegalArgumentException {
    SWTBotView viewBot = executeAnalysis(LamiAnalyses.MULTIPLE_SIMILAR_ROW);
    // Create a new chart
    SWTBotRootMenu viewMenu = viewBot.viewMenu();
    SWTBotMenu menu = viewMenu.menu("New custom chart");
    menu.click();
    // Create a bar chart of Wakee process (name) vs scheduling latency,
    // Priority and Target CPU
    SWTBotCustomChartUtils.selectChartType(fBot, ChartType.BAR_CHART);
    SWTBotCustomChartUtils.addSeries(fBot, "Wakee process (name)", ImmutableSet.of("Scheduling latency (ns)", "Priority", "Target CPU"));
    SWTBotCustomChartUtils.confirmDialog(fBot);
    WaitUtils.waitForJobs();
    // Wait for the viewer and verify its parameters
    @Nullable Chart customChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class), 0);
    assertNotNull(customChart);
    Event mouseMove = new Event();
    mouseMove.type = SWT.MouseEnter;
    customChart.getDisplay().post(mouseMove);
    fBot.waitUntil(ConditionHelpers.numberOfSeries(customChart, 3));
    SWTBotChart chartBot = new SWTBotChart(customChart);
    assertVisible(chartBot);
    // Verify the titles
    SWTBotCustomChartUtils.assertTitles(customChart, "Scheduling log", "Wakee process (name)", "Value");
    // Make sure the axis formatter have the right categories and range
    String[] xValues = new String[6];
    Arrays.fill(xValues, "swapper/5");
    SWTBotCustomChartUtils.assertCategoriesAxis(customChart, AxisType.X, xValues);
    SWTBotCustomChartUtils.assertAxisRange(customChart, AxisType.Y, 0, 2);
    SWTBotCustomChartUtils.assertAxisLogscale(customChart, AxisType.Y, false);
    // Verify the series titles
    SWTBotCustomChartUtils.assertSeriesTitle(customChart, ImmutableList.of("Scheduling latency (ns)", "Priority", "Target CPU"));
    closeCharts();
    // Create a bar chart of Waker process (name) vs scheduling latency,
    // Priority and Target CPU
    menu.click();
    fBot.shell("Custom chart creation").activate();
    SWTBotCustomChartUtils.selectChartType(fBot, ChartType.BAR_CHART);
    SWTBotCustomChartUtils.addSeries(fBot, "Waker process (name)", ImmutableSet.of("Scheduling latency (ns)", "Priority", "Target CPU"));
    SWTBotCustomChartUtils.confirmDialog(fBot);
    WaitUtils.waitForJobs();
    // Wait for the viewer and verify its parameters
    customChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class), 0);
    assertNotNull(customChart);
    customChart.getDisplay().post(mouseMove);
    fBot.waitUntil(ConditionHelpers.numberOfSeries(customChart, 3));
    chartBot = new SWTBotChart(customChart);
    assertVisible(chartBot);
    // Verify the titles
    SWTBotCustomChartUtils.assertTitles(customChart, "Scheduling log", "Waker process (name)", "Value");
    // Make sure the axis formatter have the right categories and range
    Arrays.fill(xValues, "?");
    SWTBotCustomChartUtils.assertCategoriesAxis(customChart, AxisType.X, xValues);
    SWTBotCustomChartUtils.assertAxisRange(customChart, AxisType.Y, 0, 2);
    SWTBotCustomChartUtils.assertAxisLogscale(customChart, AxisType.Y, false);
    // Verify the series titles
    SWTBotCustomChartUtils.assertSeriesTitle(customChart, ImmutableList.of("Scheduling latency (ns)", "Priority", "Target CPU"));
    closeCharts();
}
Also used : SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) SWTBotRootMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotRootMenu) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) Event(org.eclipse.swt.widgets.Event) Nullable(org.eclipse.jdt.annotation.Nullable) Chart(org.eclipse.swtchart.Chart) Test(org.junit.Test)

Example 45 with Chart

use of org.eclipse.swtchart.Chart in project tracecompass by tracecompass.

the class LamiChartViewerTest method testScatterMultipleRow.

/**
 * Test a few scatter charts with the multiple row dataset.
 *
 * @throws SecurityException
 *             If a security manager is present and any the wrong class is
 *             loaded or the class loader is not the same as its ancestor's
 *             loader.
 *
 * @throws IllegalArgumentException
 *             the object is not the correct class type
 */
@Test
public void testScatterMultipleRow() throws SecurityException, IllegalArgumentException {
    SWTBotView viewBot = executeAnalysis(LamiAnalyses.MULTIPLE_ROW);
    // Get the expected maximum and minimum values of each axis
    LamiResultTable resultTable = LamiAnalyses.MULTIPLE_ROW.getAnalysis().getResultTable(0);
    Long minX = Long.MAX_VALUE;
    Long maxX = Long.MIN_VALUE;
    Long minY = Long.MAX_VALUE;
    Long maxY = Long.MIN_VALUE;
    for (LamiTableEntry entry : resultTable.getEntries()) {
        Long wakeupTs = ((LamiLongNumber) entry.getValue(0)).getValue();
        Long switchTs = ((LamiLongNumber) entry.getValue(1)).getValue();
        Long latency = ((LamiLongNumber) entry.getValue(2)).getValue();
        if (wakeupTs != null) {
            minX = Math.min(minX, wakeupTs);
            maxX = Math.max(maxX, wakeupTs);
        }
        if (switchTs != null) {
            minX = Math.min(minX, switchTs);
            maxX = Math.max(maxX, switchTs);
        }
        if (latency != null) {
            minY = Math.min(minY, latency);
            maxY = Math.max(maxY, latency);
        }
    }
    // Create a new chart
    SWTBotRootMenu viewMenu = viewBot.viewMenu();
    SWTBotMenu menu = viewMenu.menu("New custom chart");
    menu.click();
    // Create a scatter chart of Wakeup timestamp vs scheduling latency
    // and Switch timestamp vs scheduling latency
    SWTBotCustomChartUtils.selectChartType(fBot, ChartType.SCATTER_CHART);
    SWTBotCustomChartUtils.addSeries(fBot, "Wakeup timestamp", Collections.singleton("Scheduling latency (ns)"));
    SWTBotCustomChartUtils.addSeries(fBot, "Switch timestamp", Collections.singleton("Scheduling latency (ns)"));
    SWTBotCustomChartUtils.confirmDialog(fBot);
    WaitUtils.waitForJobs();
    // Wait for the viewer and verify its parameters
    @Nullable Chart customChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class), 0);
    Event mouseMove = new Event();
    mouseMove.type = SWT.MouseEnter;
    customChart.getDisplay().post(mouseMove);
    assertNotNull(customChart);
    fBot.waitUntil(ConditionHelpers.numberOfSeries(customChart, 2));
    SWTBotChart chartBot = new SWTBotChart(customChart);
    assertVisible(chartBot);
    // Verify the titles
    SWTBotCustomChartUtils.assertTitles(customChart, "Scheduling log", "Value (ss.SSS)", "Scheduling latency (ns)");
    // Make sure the axis formatters have the right range
    SWTBotCustomChartUtils.assertAxisRange(customChart, AxisType.X, minX, maxX);
    SWTBotCustomChartUtils.assertAxisRange(customChart, AxisType.Y, minY, maxY);
    SWTBotCustomChartUtils.assertAxisLogscale(customChart, AxisType.Y, false);
    // Verify the series titles
    SWTBotCustomChartUtils.assertSeriesTitle(customChart, ImmutableList.of("Scheduling latency by Wakeup timestamp", "Scheduling latency by Switch timestamp"));
    closeCharts();
    // Create the same chart, but with log scale enabled in Y. Make sure
    // the results are the same
    menu.click();
    SWTBotCustomChartUtils.selectChartType(fBot, ChartType.SCATTER_CHART);
    SWTBotCustomChartUtils.addSeries(fBot, "Wakeup timestamp", Collections.singleton("Scheduling latency (ns)"));
    SWTBotCustomChartUtils.addSeries(fBot, "Switch timestamp", Collections.singleton("Scheduling latency (ns)"));
    SWTBotCustomChartUtils.setLogScale(fBot, AxisType.Y);
    SWTBotCustomChartUtils.confirmDialog(fBot);
    WaitUtils.waitForJobs();
    // Wait for the viewer and verify its parameters
    customChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class), 0);
    assertNotNull(customChart);
    customChart.getDisplay().post(mouseMove);
    fBot.waitUntil(ConditionHelpers.numberOfSeries(customChart, 2));
    chartBot = new SWTBotChart(customChart);
    assertVisible(chartBot);
    // Verify the titles
    SWTBotCustomChartUtils.assertTitles(customChart, "Scheduling log", "Value (ss.SSS)", "Scheduling latency (ns)");
    // Make sure the axis formatter have the right range
    SWTBotCustomChartUtils.assertAxisRange(customChart, AxisType.X, minX, maxX);
    // Logscale charts are clamped to 0
    SWTBotCustomChartUtils.assertAxisRange(customChart, AxisType.Y, 0, maxY);
    SWTBotCustomChartUtils.assertAxisLogscale(customChart, AxisType.Y, true);
    // Verify the series titles
    SWTBotCustomChartUtils.assertSeriesTitle(customChart, ImmutableList.of("Scheduling latency by Wakeup timestamp", "Scheduling latency by Switch timestamp"));
    closeCharts();
}
Also used : LamiResultTable(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiResultTable) SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) LamiTableEntry(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiTableEntry) SWTBotRootMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotRootMenu) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) Event(org.eclipse.swt.widgets.Event) LamiLongNumber(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiLongNumber) Nullable(org.eclipse.jdt.annotation.Nullable) Chart(org.eclipse.swtchart.Chart) Test(org.junit.Test)

Aggregations

Chart (org.eclipse.swtchart.Chart)45 Test (org.junit.Test)14 ILineSeries (org.eclipse.swtchart.ILineSeries)13 ISeries (org.eclipse.swtchart.ISeries)11 IAxis (org.eclipse.swtchart.IAxis)8 XYDataProviderBaseTest (org.eclipse.tracecompass.tmf.ui.swtbot.tests.views.xychart.XYDataProviderBaseTest)8 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)7 IBarSeries (org.eclipse.swtchart.IBarSeries)7 TmfCommonXAxisChartViewer (org.eclipse.tracecompass.tmf.ui.viewers.xychart.linechart.TmfCommonXAxisChartViewer)6 IViewPart (org.eclipse.ui.IViewPart)6 MouseEvent (org.eclipse.swt.events.MouseEvent)5 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)5 SWTBotView (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)5 ISeriesSet (org.eclipse.swtchart.ISeriesSet)4 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)4 Nullable (org.eclipse.jdt.annotation.Nullable)3 IAction (org.eclipse.jface.action.IAction)3 Point (org.eclipse.swt.graphics.Point)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 SWTBotTree (org.eclipse.swtbot.swt.finder.widgets.SWTBotTree)3