Search in sources :

Example 11 with Chart

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

the class LargeSeriesExample method createChart.

/**
 * create the chart.
 *
 * @param parent
 *            The parent composite
 * @return The created chart
 */
public static Chart createChart(Composite parent) {
    // create a chart
    Chart chart = new Chart(parent, SWT.NONE);
    // set titles
    chart.getTitle().setText("Large Series");
    chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
    chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");
    // create line series
    ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
    lineSeries.setYSeries(getSeries());
    lineSeries.setSymbolType(PlotSymbolType.NONE);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    return chart;
}
Also used : ILineSeries(org.eclipse.swtchart.ILineSeries) Chart(org.eclipse.swtchart.Chart)

Example 12 with Chart

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

the class ChartLayout method parseControls.

/**
 * Parses the controls on given composite.
 *
 * @param composite
 *            the composite
 * @return true if all children found
 */
private boolean parseControls(Composite composite) {
    for (Control child : composite.getChildren()) {
        if (child instanceof Legend) {
            legend = (Legend) child;
        } else if (child instanceof PlotArea) {
            plot = (PlotArea) child;
        }
    }
    if (composite instanceof Chart) {
        IAxisSet axisSet = ((Chart) composite).getAxisSet();
        if (axisSet != null) {
            axes = (Axis[]) axisSet.getAxes();
            if (((Chart) composite).getOrientation() == SWT.HORIZONTAL) {
                horizontalAxes = (Axis[]) axisSet.getXAxes();
                verticalAxes = (Axis[]) axisSet.getYAxes();
            } else {
                verticalAxes = (Axis[]) axisSet.getXAxes();
                horizontalAxes = (Axis[]) axisSet.getYAxes();
            }
        }
        title = (ChartTitle) ((Chart) composite).getTitle();
    }
    if (title == null || legend == null || plot == null || axes == null) {
        // the initialization of chart is not completed yet
        return false;
    }
    return true;
}
Also used : Control(org.eclipse.swt.widgets.Control) IAxisSet(org.eclipse.swtchart.IAxisSet) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 13 with Chart

use of org.eclipse.swtchart.Chart in project org.eclipse.linuxtools by eclipse-linuxtools.

the class ChartTests method testChartCallback.

@Test
public void testChartCallback() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testChartCallback");
    IAction chartAction = getChartAction();
    assertNotNull(chartAction);
    chartAction.run();
    IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    assertTrue(part instanceof ChartEditor);
    Chart control = ((ChartEditor) part).getControl();
    ILineSeries lsTotal = (ILineSeries) control.getSeriesSet().getSeries(// $NON-NLS-1$
    Messages.getString("HeapChart.Total_Heap"));
    Point p1 = lsTotal.getPixelCoordinates(4);
    HeapChart heapChart = ((ChartEditorInput) ((ChartEditor) part).getEditorInput()).getChart();
    int x = control.getAxisSet().getXAxis(0).getPixelCoordinate(heapChart.time[4]);
    int y = control.getAxisSet().getYAxis(0).getPixelCoordinate(heapChart.dataTotal[4]);
    assertEquals(x, p1.x);
    assertEquals(y, p1.y);
}
Also used : HeapChart(org.eclipse.linuxtools.internal.valgrind.massif.charting.HeapChart) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ChartEditor(org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartEditor) IAction(org.eclipse.jface.action.IAction) ILineSeries(org.eclipse.swtchart.ILineSeries) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) ChartEditorInput(org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartEditorInput) Chart(org.eclipse.swtchart.Chart) HeapChart(org.eclipse.linuxtools.internal.valgrind.massif.charting.HeapChart) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Example 14 with Chart

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

the class TmfChartView method getZoomOutAction.

private Action getZoomOutAction() {
    Action zoomOutAction = fZoomOutAction;
    if (zoomOutAction == null) {
        zoomOutAction = new Action() {

            @Override
            public void run() {
                TmfXYChartViewer viewer = getChartViewer();
                if (viewer == null) {
                    return;
                }
                Chart chart = viewer.getSwtChart();
                if (chart == null) {
                    return;
                }
                TmfXyUiUtils.zoom(viewer, XYAxis.create(chart.getAxisSet().getXAxis(0)), false);
            }
        };
        zoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText);
        zoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText);
        zoomOutAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
    }
    return zoomOutAction;
}
Also used : TmfXYChartViewer(org.eclipse.tracecompass.tmf.ui.viewers.xychart.TmfXYChartViewer) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Chart(org.eclipse.swtchart.Chart)

Example 15 with Chart

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

the class DisksIOViewTest method testDiskView.

/**
 * Test to check the Disks IO Activity view. First, when trace opened, there
 * should not be any activity. Then, we move to a time range where there are
 * write activity. Afterward, we test the zoom
 */
@Test
public void testDiskView() {
    // Wait for analysis to finish.
    WaitUtils.waitForJobs();
    IViewPart viewPart = getSWTBotView().getViewReference().getView(true);
    assertTrue(viewPart instanceof DiskIOActivityView);
    final TmfCommonXAxisChartViewer chartViewer = (TmfCommonXAxisChartViewer) getChartViewer(viewPart);
    assertNotNull(chartViewer);
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    final Chart chart = getChart();
    assertNotNull(chart);
    SWTBotTreeItem[] items = getSWTBotView().bot().tree().getAllItems();
    for (SWTBotTreeItem item : items) {
        item.check();
    }
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length > 0, chart, "No data available");
    chartViewer.setNbPoints(NUMBER_OF_POINT);
    /* Initially, no disk activity */
    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, WRITE_SERIES_NAME), "resources/disk/disk0-res50.json", "Chart data is not valid");
    /* Change time range where there is disks activity */
    TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, new TmfTimeRange(ZOOM_START_TIME, ZOOM_END_TIME)));
    fBot.waitUntil(ConditionHelpers.windowRange(new TmfTimeRange(ZOOM_START_TIME, ZOOM_END_TIME)));
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    /* Test type, style and color of series */
    verifyChartStyle();
    /* Test data model */
    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, WRITE_SERIES_NAME), "resources/disk/disk1-res50.json", "Chart data is not valid");
    /* Change Zoom and number of points */
    chartViewer.setNbPoints(MORE_POINTS);
    /* Test type, style and color of series */
    verifyChartStyle();
    /* Test data model */
    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, WRITE_SERIES_NAME), "resources/disk/disk2-res100.json", "Chart data is not valid");
}
Also used : DiskIOActivityView(org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.io.diskioactivity.DiskIOActivityView) IViewPart(org.eclipse.ui.IViewPart) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) TmfCommonXAxisChartViewer(org.eclipse.tracecompass.tmf.ui.viewers.xychart.linechart.TmfCommonXAxisChartViewer) TmfWindowRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) Chart(org.eclipse.swtchart.Chart) Test(org.junit.Test) XYDataProviderBaseTest(org.eclipse.tracecompass.tmf.ui.swtbot.tests.views.xychart.XYDataProviderBaseTest)

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