Search in sources :

Example 11 with ILineSeries

use of org.eclipse.swtchart.ILineSeries in project netxms by netxms.

the class LineChart method getSeriesAtPoint.

/**
 * Get series at given point
 *
 * @param px
 * @param py
 * @return
 */
public ISeries<?> getSeriesAtPoint(int px, int py) {
    ISeries<?>[] series = getSeriesSet().getSeries();
    for (ISeries<?> s : series) {
        int size = s.getSize();
        for (int i = 1; i < size; i++) {
            Point p1 = s.getPixelCoordinates(i - 1);
            Point p2 = s.getPixelCoordinates(i);
            if ((px > p1.x + 2) || (px < p2.x - 2) || (py < Math.min(p1.y, p2.y) - 2) || (py > Math.max(p1.y, p2.y) + 2))
                continue;
            if (pointToLineDistance(px, py, p2, p1) <= ((ILineSeries<?>) s).getLineWidth() * 3.0)
                return s;
        }
    }
    return null;
}
Also used : ILineSeries(org.eclipse.swtchart.ILineSeries) DataPoint(org.netxms.nxmc.modules.charts.api.DataPoint) Point(org.eclipse.swt.graphics.Point) ISeries(org.eclipse.swtchart.ISeries) DataPoint(org.netxms.nxmc.modules.charts.api.DataPoint) Point(org.eclipse.swt.graphics.Point)

Example 12 with ILineSeries

use of org.eclipse.swtchart.ILineSeries 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 13 with ILineSeries

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

the class ChartEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    final ChartEditorInput input = (ChartEditorInput) getEditorInput();
    final HeapChart heapChart = input.getChart();
    control = new InteractiveChart(parent, SWT.FILL);
    heapChart.setChartControl(control);
    final Color LIGHTYELLOW = new Color(Display.getDefault(), 255, 255, 225);
    final Color WHITE = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
    final Color BLACK = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
    final Color RED = Display.getDefault().getSystemColor(SWT.COLOR_RED);
    final Color ORANGE = new Color(Display.getDefault(), 255, 165, 0);
    final Color GREEN = Display.getDefault().getSystemColor(SWT.COLOR_GREEN);
    final Color DARK_BLUE = new Color(Display.getDefault(), 64, 128, 128);
    final int TICK_GAP = 40;
    control.setBackground(WHITE);
    control.getPlotArea().setBackground(LIGHTYELLOW);
    control.setProposedSaveAsFilename(heapChart.title.substring(0, heapChart.title.indexOf(' ')));
    FontData fd = JFaceResources.getDialogFont().getFontData()[0];
    fd.setStyle(SWT.BOLD);
    Font font = new Font(Display.getDefault(), fd);
    fd.setHeight(fd.getHeight() + 2);
    Font titleFont = new Font(Display.getDefault(), fd);
    ITitle title = control.getTitle();
    title.setFont(titleFont);
    title.setForeground(BLACK);
    title.setText(heapChart.title);
    IAxis xAxis = control.getAxisSet().getXAxis(0);
    xAxis.getGrid().setStyle(LineStyle.NONE);
    xAxis.getTick().setForeground(BLACK);
    ITitle xTitle = xAxis.getTitle();
    xTitle.setFont(font);
    xTitle.setForeground(BLACK);
    xTitle.setText(heapChart.xUnits);
    IAxis yAxis = control.getAxisSet().getYAxis(0);
    yAxis.getGrid().setStyle(LineStyle.SOLID);
    yAxis.getTick().setForeground(BLACK);
    yAxis.getTick().setTickMarkStepHint(TICK_GAP);
    ITitle yTitle = yAxis.getTitle();
    yTitle.setFont(font);
    yTitle.setText(heapChart.yUnits);
    yTitle.setForeground(BLACK);
    control.getLegend().setPosition(SWT.BOTTOM);
    // data
    final ILineSeries lsUseful = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
    Messages.getString("HeapChart.Useful_Heap"));
    lsUseful.setXSeries(heapChart.time);
    lsUseful.setYSeries(heapChart.dataUseful);
    lsUseful.setSymbolType(PlotSymbolType.DIAMOND);
    lsUseful.setSymbolColor(RED);
    lsUseful.setLineColor(RED);
    final ILineSeries lsExtra = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
    Messages.getString("HeapChart.Extra_Heap"));
    lsExtra.setXSeries(heapChart.time);
    lsExtra.setYSeries(heapChart.dataExtra);
    lsExtra.setSymbolType(PlotSymbolType.DIAMOND);
    lsExtra.setSymbolColor(ORANGE);
    lsExtra.setLineColor(ORANGE);
    if (heapChart.dataStacks != null) {
        final ILineSeries lsStack = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
        Messages.getString("HeapChart.Stacks"));
        lsStack.setXSeries(heapChart.time);
        lsStack.setYSeries(heapChart.dataStacks);
        lsStack.setSymbolType(PlotSymbolType.DIAMOND);
        lsStack.setSymbolColor(DARK_BLUE);
        lsStack.setLineColor(DARK_BLUE);
    }
    final ILineSeries lsTotal = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
    Messages.getString("HeapChart.Total_Heap"));
    lsTotal.setXSeries(heapChart.time);
    lsTotal.setYSeries(heapChart.dataTotal);
    lsTotal.setSymbolType(PlotSymbolType.DIAMOND);
    lsTotal.setSymbolColor(GREEN);
    lsTotal.setLineColor(GREEN);
    // adjust axes
    control.getAxisSet().adjustRange();
    IAxisSet axisSet = control.getAxisSet();
    Range xRange = axisSet.getXAxis(0).getRange();
    Range yRange = axisSet.getYAxis(0).getRange();
    double xExtra = 0.05 * (xRange.upper - xRange.lower);
    double yExtra = 0.05 * (yRange.upper - yRange.lower);
    axisSet.getXAxis(0).setRange(new Range(xRange.lower, xRange.upper + xExtra));
    axisSet.getYAxis(0).setRange(new Range(yRange.lower, yRange.upper + yExtra));
    // listeners
    control.getPlotArea().getControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            showView();
            TableViewer viewer = input.getView().getTableViewer();
            input.getView().setTopControl(viewer.getControl());
            Point p = new Point(e.x, e.y);
            int closest = 0;
            double d1, d2, d3, currMin;
            double globalMin = Double.MAX_VALUE;
            for (int i = 0; i < heapChart.time.length; i++) {
                // get distance from click event to data points for the given index
                d1 = distance(lsUseful.getPixelCoordinates(i), p);
                d2 = distance(lsExtra.getPixelCoordinates(i), p);
                d3 = distance(lsTotal.getPixelCoordinates(i), p);
                // find the closest data point to the click event
                currMin = Math.min(Math.min(d1, d2), d3);
                if (currMin < globalMin) {
                    closest = i;
                    globalMin = currMin;
                }
            }
            MassifSnapshot snapshot = (MassifSnapshot) viewer.getElementAt(closest);
            viewer.setSelection(new StructuredSelection(snapshot), true);
            if (e.count == 2 && snapshot.isDetailed()) {
                ChartLocationsDialog dialog = new ChartLocationsDialog(Display.getCurrent().getActiveShell());
                dialog.setInput(snapshot);
                if (dialog.open() == Window.OK) {
                    dialog.openEditorForResult();
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) ILineSeries(org.eclipse.swtchart.ILineSeries) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MassifSnapshot(org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Point(org.eclipse.swt.graphics.Point) Range(org.eclipse.swtchart.Range) ITitle(org.eclipse.swtchart.ITitle) InteractiveChart(org.eclipse.swtchart.extensions.charts.InteractiveChart) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) IAxis(org.eclipse.swtchart.IAxis) IAxisSet(org.eclipse.swtchart.IAxisSet) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 14 with ILineSeries

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

the class MemoryUsageViewTest method testOpenMemoryUsage.

/**
 * Test if Memory Usage is populated
 */
@Test
public void testOpenMemoryUsage() {
    SWTBotView viewBot = fBot.viewById(UstMemoryUsageView.ID);
    viewBot.setFocus();
    // Do some basic validation
    Matcher<Chart> matcher = WidgetOfType.widgetOfType(Chart.class);
    Chart chart = viewBot.bot().widget(matcher);
    checkAllEntries();
    // Verify that the chart has 4 series
    fBot.waitUntil(ConditionHelpers.numberOfSeries(chart, EXPECTED_NUM_SERIES));
    ISeriesSet seriesSet = chart.getSeriesSet();
    ISeries<?>[] series = seriesSet.getSeries();
    // Verify that each series is a ILineSeries
    for (ISeries<?> serie : series) {
        assertTrue(serie instanceof ILineSeries);
    }
}
Also used : ISeriesSet(org.eclipse.swtchart.ISeriesSet) ILineSeries(org.eclipse.swtchart.ILineSeries) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart) Test(org.junit.Test) XYDataProviderBaseTest(org.eclipse.tracecompass.tmf.ui.swtbot.tests.views.xychart.XYDataProviderBaseTest)

Example 15 with ILineSeries

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

the class SwtScatterChart method createSwtSeries.

@Override
protected ISeries createSwtSeries(ChartSeries chartSeries, ISeriesSet swtSeriesSet, @NonNull Color color) {
    String title = chartSeries.getY().getName();
    if (getXDescriptors().stream().distinct().count() > 1) {
        title = NLS.bind(Messages.ChartSeries_MultiSeriesTitle, title, chartSeries.getX().getLabel());
    }
    ILineSeries swtSeries = (ILineSeries) swtSeriesSet.createSeries(SeriesType.LINE, title);
    swtSeries.setLineStyle(LineStyle.NONE);
    swtSeries.setSymbolColor(color);
    return swtSeries;
}
Also used : ILineSeries(org.eclipse.swtchart.ILineSeries)

Aggregations

ILineSeries (org.eclipse.swtchart.ILineSeries)29 Chart (org.eclipse.swtchart.Chart)13 Color (org.eclipse.swt.graphics.Color)7 Point (org.eclipse.swt.graphics.Point)5 IAxis (org.eclipse.swtchart.IAxis)5 IBarSeries (org.eclipse.swtchart.IBarSeries)5 ISeries (org.eclipse.swtchart.ISeries)5 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)2 ISeriesSet (org.eclipse.swtchart.ISeriesSet)2 InteractiveChart (org.eclipse.swtchart.extensions.charts.InteractiveChart)2 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)2 ISeriesData (org.eclipse.swtchart.extensions.core.ISeriesData)2 SeriesException (org.eclipse.swtchart.extensions.exceptions.SeriesException)2 Test (org.junit.Test)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 IAction (org.eclipse.jface.action.IAction)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1