Search in sources :

Example 21 with ISeries

use of org.eclipse.swtchart.ISeries 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 22 with ISeries

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

the class AbstractChartWithAxisBuilder method buildXSeries.

/**
 * Builds X series.
 */
@Override
protected void buildXSeries() {
    Object[][] data = adapter.getData();
    if (data == null || data.length == 0) {
        return;
    }
    int start = 0, len = Math.min(this.maxItems, data.length), leny = data[0].length - 1;
    if (this.maxItems < data.length) {
        start = data.length - this.maxItems;
    }
    Double[] all_valx = new Double[len];
    Double[][] all_valy = new Double[leny][len];
    // Will want to centre view around points, so be as accurate with max/min as possible.
    double maxX = Double.NEGATIVE_INFINITY;
    double maxY = maxX;
    double minX = Double.POSITIVE_INFINITY;
    double minY = minX;
    // In the case of an empty (null) value in either axis, ignore both x & y axis data for that point.
    for (int i = 0; i < len; i++) {
        for (int j = 0; j < leny + 1; j++) {
            Double val = getDoubleOrNullValue(data[start + i][j]);
            if (j == 0) {
                if (val != null) {
                    all_valx[i] = val;
                    maxX = Math.max(val, maxX);
                    minX = Math.min(val, minX);
                } else {
                    break;
                }
            } else if (val != null) {
                all_valy[j - 1][i] = val;
                maxY = Math.max(val, maxY);
                minY = Math.min(val, minY);
            }
        }
    }
    // Now create dense arrays of x/y values that exclude null values,
    // and plot those values to the chart.
    ISeries[] allSeries = chart.getSeriesSet().getSeries();
    ISeries series = null;
    for (int i = 0; i < leny; i++) {
        if (i >= allSeries.length) {
            series = createChartISeries(i);
        } else {
            series = chart.getSeriesSet().getSeries()[i];
        }
        double[] valx = new double[len];
        double[] valy = new double[len];
        int len_trim = 0;
        for (int j = 0; j < len; j++) {
            if (all_valx[j] != null && all_valy[i][j] != null) {
                valx[len_trim] = all_valx[j].doubleValue();
                valy[len_trim] = all_valy[i][j].doubleValue();
                len_trim++;
            }
        }
        double[] valx_trim = new double[len_trim];
        double[] valy_trim = new double[len_trim];
        for (int j = 0; j < len_trim; j++) {
            valx_trim[j] = valx[j];
            valy_trim[j] = valy[j];
        }
        series.setXSeries(valx_trim);
        series.setYSeries(valy_trim);
    }
    if (series != null && series.getXSeries().length > 0) {
        applyRangeX(minX, maxX);
        applyRangeY(minY, maxY);
    }
    chart.redraw();
}
Also used : ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 23 with ISeries

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

the class BarChartMouseMoveListener method mouseMove.

@Override
public void mouseMove(MouseEvent e) {
    super.mouseMove(e);
    ISeries[] allSeries = chart.getSeriesSet().getSeries();
    if (allSeries.length == 0) {
        return;
    }
    IAxis xAxis = chart.getAxisSet().getXAxis(0);
    String[] categorySeries = ((BarChart) chart).getCategorySeries();
    int barIndex = (int) xAxis.getDataCoordinate(e.x);
    if (0 <= barIndex && barIndex < categorySeries.length) {
        // $NON-NLS-1$
        String textTip = "";
        for (int i = 0; i < allSeries.length; i++) {
            textTip = textTip.concat((i > 0 ? "\n" : "") + // $NON-NLS-1$ //$NON-NLS-2$
            MessageFormat.format(// $NON-NLS-1$ //$NON-NLS-2$
            Messages.BarChartBuilder_ToolTipCoords, allSeries[i].getId(), ((BarChart) chart).getBarValue(i, barIndex)));
        }
        setTextTip(textTip);
    } else {
        tipShell.setVisible(false);
    }
    chart.redraw();
}
Also used : BarChart(org.eclipse.linuxtools.internal.systemtap.graphing.ui.charts.BarChart) ISeries(org.eclipse.swtchart.ISeries) IAxis(org.eclipse.swtchart.IAxis)

Example 24 with ISeries

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

the class PatternDensityViewTest method testWithTrace.

/**
 * Test the pattern density view and its viewers data
 *
 * @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 NoSuchFieldException
 *             Field not available
 * @throws IllegalAccessException
 *             Field is inaccessible
 * @throws IllegalArgumentException
 *             the object is not the correct class type
 */
@Test
public void testWithTrace() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    setDensityViewer();
    WaitUtils.waitForJobs();
    // Test the table content
    SWTBotTable tableBot = new SWTBotTable(fDensityViewer.getTableViewer().getTable());
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, SYSTEM_CALL_PREFIX, 0, 3));
    tableBot.header(COLUMN_HEADER).click();
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, SYSTEM_CALL_PREFIX, 0, 3));
    tableBot.header(COLUMN_HEADER).click();
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, SYSTEM_CALL_PREFIX, 0, 3));
    // Test the chart content
    final Chart densityChart = fDensityChart;
    assertNotNull(densityChart);
    fBot.waitUntil(ConditionHelpers.numberOfSeries(densityChart, 1));
    SWTBotChart chartBot = new SWTBotChart(densityChart);
    assertVisible(chartBot);
    ISeriesSet seriesSet = fDensityChart.getSeriesSet();
    assertNotNull(seriesSet);
    ISeries<?>[] series = seriesSet.getSeries();
    assertNotNull(series);
    // Verify that the chart has 1 series
    assertEquals(1, series.length);
    // Verify that the series has data
    assertTrue(((IndexedSeriesModel<?>) series[0].getDataModel()).size() > 0);
}
Also used : ISeriesSet(org.eclipse.swtchart.ISeriesSet) IndexedSeriesModel(org.eclipse.swtchart.model.IndexedSeriesModel) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart) Test(org.junit.Test)

Example 25 with ISeries

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

the class PatternScatterChartViewTest method testWithTrace.

/**
 * Test the pattern latency scatter graph. This method test if the chart has one
 * series and the series has data
 */
@Test
public void testWithTrace() {
    // Get the chart viewer and wait for the view to be ready
    WaitUtils.waitForJobs();
    TmfXYChartViewer chartViewer = getChartViewer();
    assertNotNull(chartViewer);
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));
    // Check all the items in the tree
    final Chart chart = fScatterChart;
    assertNotNull(chart);
    SWTBotView viewBot = fBot.viewById(VIEW_ID);
    SWTBotTreeItem[] items = viewBot.bot().tree().getAllItems();
    for (SWTBotTreeItem item : items) {
        item.check();
    }
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length > 0, chart, "No data available");
    // Look at the presence of data in the chart
    SWTBotChart chartBot = new SWTBotChart(chart);
    assertVisible(chartBot);
    final Range range = chart.getAxisSet().getXAxes()[0].getRange();
    assertEquals(100000000, range.upper - range.lower, 0);
    ISeriesSet seriesSet = fScatterChart.getSeriesSet();
    assertNotNull(seriesSet);
    ISeries<?>[] series = seriesSet.getSeries();
    assertNotNull(series);
    // Verify that the chart has more than 1 series
    assertTrue(series.length > 1);
    // Verify that each series has data
    for (int i = 0; i < series.length; i++) {
        assertTrue("Verifying series " + i, ((IndexedSeriesModel<?>) series[i].getDataModel()).size() > 0);
    }
}
Also used : TmfXYChartViewer(org.eclipse.tracecompass.tmf.ui.viewers.xychart.TmfXYChartViewer) ISeriesSet(org.eclipse.swtchart.ISeriesSet) IndexedSeriesModel(org.eclipse.swtchart.model.IndexedSeriesModel) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) Range(org.eclipse.swtchart.Range) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart) Test(org.junit.Test)

Aggregations

ISeries (org.eclipse.swtchart.ISeries)60 Point (org.eclipse.swt.graphics.Point)21 ISeriesSet (org.eclipse.swtchart.ISeriesSet)11 Chart (org.eclipse.swtchart.Chart)10 IAxis (org.eclipse.swtchart.IAxis)9 Range (org.eclipse.swtchart.Range)9 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)8 Color (org.eclipse.swt.graphics.Color)5 IBarSeries (org.eclipse.swtchart.IBarSeries)5 ILineSeries (org.eclipse.swtchart.ILineSeries)5 IAxisSettings (org.eclipse.swtchart.extensions.core.IAxisSettings)5 Rectangle (org.eclipse.swt.graphics.Rectangle)4 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)3 GC (org.eclipse.swt.graphics.GC)3 Test (org.junit.Test)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2