Search in sources :

Example 36 with ISeries

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

the class BarChart method hideBars.

/*
     * Workaround for EBZ #427019: out-of-bounds bars appear, so change their values to
     * keep them properly hidden. Save actual bar values elsewhere so they can be retrieved.
     */
private void hideBars() {
    Range rangeX = xAxis.getRange();
    double bottomY = getAxisSet().getYAxis(0).getRange().lower;
    double nonNegBottomY = Math.max(0, bottomY);
    ISeries[] allSeries = getSeriesSet().getSeries();
    actualYSeries = new double[allSeries.length][];
    for (int i = 0, n = allSeries.length; i < n; i++) {
        double[] yseries = allSeries[i].getYSeries();
        if (yseries == null) {
            return;
        }
        // Store the true values of the bars into a different array, so they
        // can be displayed later if need be.
        actualYSeries[i] = new double[yseries.length];
        System.arraycopy(yseries, 0, actualYSeries[i], 0, yseries.length);
        for (int x = (int) rangeX.lower; x <= (int) rangeX.upper; x++) {
            if (yseries[x] < bottomY) {
                yseries[x] = bottomY;
            }
        }
        if (yseries.length - 1 > rangeX.upper) {
            yseries[(int) rangeX.upper + 1] = nonNegBottomY;
        }
        allSeries[i].setYSeries(yseries);
    }
}
Also used : Range(org.eclipse.swtchart.Range) ISeries(org.eclipse.swtchart.ISeries)

Example 37 with ISeries

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

the class TestCreateSystemtapScript method testGraphContents.

@Test
public void testGraphContents() {
    final String valA1 = "A1";
    final String valB1 = "B1";
    createAndViewDummyData(new String[] { valA1, valB1 }, new Integer[] { 0, 0, 1, 2, 2, 4, 3, 6, 4, 8, 5, 10, 6, 12, 7, 14, 8, 16, 9, 18 });
    SWTBotEditor graphEditorA = bot.activeEditor();
    final String valA2 = "A2";
    final String valB2 = "B2";
    createAndViewDummyData(new String[] { valA2, valB2 }, new Integer[] { 2, 0, 5, 1, 7, 2, 10, 3 });
    SWTBotEditor graphEditorB = bot.activeEditor();
    // Add graphs.
    setupGraphWithTests("Others", true);
    String graphTitle2 = "Others - Scatter Graph";
    graphEditorA.show();
    setupGraphWithTests("Values", true);
    String graphTitle1 = "Values - Scatter Graph";
    // Test table & graph contents.
    graphEditorA.bot().cTabItem("Data View").activate();
    SWTBotTable dataTable = bot.table();
    List<String> colNames = dataTable.columns();
    assertEquals(3, colNames.size());
    assertEquals(valA1, colNames.get(1));
    assertEquals(valB1, colNames.get(2));
    assertEquals("2", dataTable.cell(2, 1));
    assertEquals("4", dataTable.cell(2, 2));
    graphEditorA.bot().cTabItem(graphTitle1).activate();
    Matcher<AbstractChartBuilder> matcher = widgetOfType(AbstractChartBuilder.class);
    AbstractChartBuilder cb = bot.widget(matcher);
    ISeries[] series = cb.getChart().getSeriesSet().getSeries();
    assertEquals(2, series.length);
    assertEquals(10, series[0].getXSeries().length);
    assertEquals(10, series[1].getXSeries().length);
    assertEquals(2, (int) series[0].getYSeries()[2]);
    assertEquals(4, (int) series[1].getYSeries()[2]);
    graphEditorB.show();
    graphEditorB.bot().cTabItem("Data View").activate();
    dataTable = bot.table();
    colNames = dataTable.columns();
    assertEquals(3, colNames.size());
    assertEquals(valA2, colNames.get(1));
    assertEquals(valB2, colNames.get(2));
    assertEquals("7", dataTable.cell(2, 1));
    assertEquals("2", dataTable.cell(2, 2));
    graphEditorB.bot().cTabItem(graphTitle2).activate();
    cb = bot.widget(matcher);
    series = cb.getChart().getSeriesSet().getSeries();
    assertEquals(2, series.length);
    assertEquals(4, series[0].getXSeries().length);
    assertEquals(4, series[1].getXSeries().length);
    assertEquals(7, (int) series[0].getYSeries()[2]);
    assertEquals(2, (int) series[1].getYSeries()[2]);
    // Test filters on the data table & graphs.
    graphEditorA.show();
    graphEditorA.bot().cTabItem("Data View").activate();
    dataTable = bot.table();
    new SWTBotMenu(ContextMenuHelper.contextMenu(dataTable, "Add filter...")).click();
    SWTBotShell shell = bot.shell("Create Filter");
    shell.setFocus();
    // Match Filter - Remove a matching
    bot.button("Match Filter").click();
    bot.button("Next >").click();
    bot.text().setText("2");
    deselectDefaultSelection(0);
    bot.radio(1).click();
    bot.button("Finish").click();
    bot.waitUntil(Conditions.shellCloses(shell));
    bot.waitUntil(new TableHasUpdated(graphEditorA.bot().table(), 9, true));
    assertEquals("3", dataTable.cell(2, 1));
    assertEquals("6", dataTable.cell(2, 2));
    // Filters should be applied to graphs as well as data tables.
    graphEditorA.bot().cTabItem(graphTitle1).activate();
    cb = bot.widget(matcher);
    series = cb.getChart().getSeriesSet().getSeries();
    bot.waitUntil(new ChartHasUpdated(cb.getChart(), 9));
    assertEquals(3, (int) series[0].getYSeries()[2]);
    assertEquals(6, (int) series[1].getYSeries()[2]);
    // Each graph set should have its own filters.
    graphEditorB.show();
    graphEditorB.bot().cTabItem("Data View").activate();
    dataTable = bot.table();
    assertEquals(4, dataTable.rowCount());
    assertEquals("2", dataTable.cell(0, 1));
    // Test removing a filter.
    graphEditorA.show();
    graphEditorA.bot().cTabItem("Data View").activate();
    dataTable = bot.table();
    new SWTBotMenu(ContextMenuHelper.contextMenu(dataTable, "Remove filter...", "Match Filter: \"" + valA1 + "\" removing \"2\"")).click();
    bot.waitUntil(new TableHasUpdated(graphEditorA.bot().table(), 10, true));
    assertEquals("2", dataTable.cell(2, 1));
    assertEquals("4", dataTable.cell(2, 2));
}
Also used : SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) AbstractChartBuilder(org.eclipse.linuxtools.systemtap.graphing.ui.charts.AbstractChartBuilder) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) ISeries(org.eclipse.swtchart.ISeries) Test(org.junit.Test)

Example 38 with ISeries

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

the class LaTeXTableExportHandler method execute.

@Override
public void execute(Shell shell, ScrollableChart scrollableChart) {
    BaseChart baseChart = scrollableChart.getBaseChart();
    /*
		 * Select the export file.
		 */
    FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
    fileDialog.setOverwrite(true);
    fileDialog.setText(TITLE);
    fileDialog.setFilterExtensions(new String[] { FILE_EXTENSION });
    // 
    String fileName = fileDialog.open();
    if (fileName != null) {
        /*
			 * Select the X and Y axis to export.
			 */
        ExportSettingsDialog exportSettingsDialog = new ExportSettingsDialog(shell, baseChart);
        exportSettingsDialog.create();
        if (exportSettingsDialog.open() == Window.OK) {
            // 
            int indexAxisX = exportSettingsDialog.getIndexAxisSelectionX();
            int indexAxisY = exportSettingsDialog.getIndexAxisSelectionY();
            // 
            if (indexAxisX >= 0 && indexAxisY >= 0) {
                /*
					 * X Axis Settings
					 */
                IAxisSettings axisSettingsX = baseChart.getXAxisSettings(indexAxisX);
                IAxisScaleConverter axisScaleConverterX = null;
                if (axisSettingsX instanceof ISecondaryAxisSettings) {
                    ISecondaryAxisSettings secondaryAxisSettings = (ISecondaryAxisSettings) axisSettingsX;
                    axisScaleConverterX = secondaryAxisSettings.getAxisScaleConverter();
                }
                /*
					 * Y Axis Settings
					 */
                IAxisSettings axisSettingsY = baseChart.getYAxisSettings(indexAxisY);
                IAxisScaleConverter axisScaleConverterY = null;
                if (axisSettingsY instanceof ISecondaryAxisSettings) {
                    ISecondaryAxisSettings secondaryAxisSettings = (ISecondaryAxisSettings) axisSettingsY;
                    axisScaleConverterY = secondaryAxisSettings.getAxisScaleConverter();
                }
                /*
					 * Print the XY data.
					 */
                PrintWriter printWriter = null;
                try {
                    printWriter = new PrintWriter(new File(fileName));
                    /*
						 * Header
						 */
                    printWriter.println("\\begin{center}");
                    printWriter.println("\\begin{tabular}{ c c }");
                    // 
                    printWriter.print(TAB);
                    printWriter.print(axisSettingsX.getLabel());
                    printWriter.print(DELIMITER);
                    printWriter.print(axisSettingsY.getLabel());
                    printWriter.println(LINE_END);
                    /*
						 * Axis settings.
						 */
                    boolean exportVisibleOnly = exportSettingsDialog.isExportVisibleOnly();
                    AxisSettings axisSettings = new AxisSettings();
                    axisSettings.setIndexAxisX(indexAxisX);
                    axisSettings.setIndexAxisY(indexAxisY);
                    axisSettings.setAxisSettingsX(axisSettingsX);
                    axisSettings.setAxisScaleConverterX(axisScaleConverterX);
                    axisSettings.setAxisSettingsY(axisSettingsY);
                    axisSettings.setAxisScaleConverterY(axisScaleConverterY);
                    axisSettings.setExportVisibleOnly(exportVisibleOnly);
                    /*
						 * Data
						 */
                    int widthPlotArea = baseChart.getPlotArea().getBounds().width;
                    ISeries[] series = baseChart.getSeriesSet().getSeries();
                    for (ISeries dataSeries : series) {
                        if (dataSeries != null) {
                            if (exportVisibleOnly) {
                                if (dataSeries.isVisible()) {
                                    exportSeries(dataSeries, widthPlotArea, axisSettings, printWriter);
                                }
                            } else {
                                exportSeries(dataSeries, widthPlotArea, axisSettings, printWriter);
                            }
                        }
                    }
                    // 
                    printWriter.println("\\end{tabular}");
                    printWriter.println("\\end{center}");
                    printWriter.flush();
                    MessageDialog.openInformation(shell, TITLE, MESSAGE_OK);
                } catch (FileNotFoundException e) {
                    MessageDialog.openError(shell, TITLE, MESSAGE_ERROR);
                    System.out.println(e);
                } finally {
                    if (printWriter != null) {
                        printWriter.close();
                    }
                }
            }
        }
    }
}
Also used : ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) FileNotFoundException(java.io.FileNotFoundException) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisScaleConverter(org.eclipse.swtchart.extensions.core.IAxisScaleConverter) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 39 with ISeries

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

the class RScriptExportHandler method printScatterPlot.

private void printScatterPlot(String fileName, PrintWriter printWriter, ScrollableChart scrollableChart, AxisSettings axisSettings) {
    IAxisSettings axisSettingsX = axisSettings.getAxisSettingsX();
    IAxisSettings axisSettingsY = axisSettings.getAxisSettingsY();
    boolean exportVisibleOnly = axisSettings.isExportVisibleOnly();
    // 
    BaseChart baseChart = scrollableChart.getBaseChart();
    ISeries[] series = baseChart.getSeriesSet().getSeries();
    /*
		 * Read from script.
		 */
    printExecuteInfo(fileName, printWriter);
    /*
		 * Header
		 */
    printWriter.println("# Header");
    printWriter.println("scatter_labels <- NULL");
    printWriter.println("x_values <- NULL");
    printWriter.println("y_values <- NULL");
    printWriter.println("");
    /*
		 * Data
		 */
    printWriter.println("# Data");
    int widthPlotArea = baseChart.getPlotArea().getBounds().width;
    for (ISeries dataSeries : series) {
        if (dataSeries != null) {
            if (exportVisibleOnly) {
                if (dataSeries.isVisible()) {
                    printScatterData(dataSeries, widthPlotArea, axisSettings, printWriter);
                }
            } else {
                printScatterData(dataSeries, widthPlotArea, axisSettings, printWriter);
            }
        }
    }
    printWriter.println("");
    /*
		 * Footer
		 */
    printWriter.println("#  Footer");
    printWriter.println("plot_data<-cbind(x_values, y_values)");
    printWriter.println("plot(plot_data, xlab=\"" + axisSettingsX.getLabel() + "\", ylab=\"" + axisSettingsY.getLabel() + "\")");
    printWriter.println("text(plot_data[,1], plot_data[,2], scatter_labels, pos=3)");
    printWriter.println("abline(h=0)");
    printWriter.println("abline(v=0)");
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 40 with ISeries

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

the class RScriptExportHandler method printLinePlot.

private void printLinePlot(String fileName, PrintWriter printWriter, ScrollableChart scrollableChart, AxisSettings axisSettings) {
    IAxisSettings axisSettingsX = axisSettings.getAxisSettingsX();
    IAxisSettings axisSettingsY = axisSettings.getAxisSettingsY();
    boolean exportVisibleOnly = axisSettings.isExportVisibleOnly();
    // 
    BaseChart baseChart = scrollableChart.getBaseChart();
    ISeries[] series = baseChart.getSeriesSet().getSeries();
    /*
		 * Read from script.
		 */
    printExecuteInfo(fileName, printWriter);
    /*
		 * Header
		 */
    int seriesSize = getSeriesSize(series, exportVisibleOnly);
    printWriter.println("# Header");
    printWriter.println("xValueList<-vector(\"list\", " + seriesSize + ")");
    printWriter.println("yValueList<-vector(\"list\", " + seriesSize + ")");
    printWriter.println("");
    /*
		 * Data
		 */
    printWriter.println("# Data");
    int widthPlotArea = baseChart.getPlotArea().getBounds().width;
    int index = 1;
    for (ISeries dataSeries : series) {
        if (dataSeries != null) {
            if (exportVisibleOnly) {
                if (dataSeries.isVisible()) {
                    printLineData(dataSeries, widthPlotArea, axisSettings, index++, printWriter);
                }
            } else {
                printLineData(dataSeries, widthPlotArea, axisSettings, index++, printWriter);
            }
        }
    }
    printWriter.println("");
    /*
		 * Footer
		 */
    printWriter.println("#  Footer");
    printWriter.println("colorList<-c(\"black\", \"red\", \"blue\", \"green\", \"grey\", \"purple\", \"brown\", \"pink\", \"yellow\", \"orange\")");
    // 
    printWriter.println("");
    printWriter.println("plot(");
    printWriter.println("	xValueList[[1]], yValueList[[1]],");
    printWriter.println("	xlim=c(range(xValueList)[1], range(xValueList)[2]),");
    printWriter.println("	ylim=c(range(yValueList)[1], range(yValueList)[2]),");
    printWriter.println("	type='l',");
    printWriter.println("	col=colorList[1],");
    printWriter.println("	ylab='" + axisSettingsY.getLabel() + "',");
    printWriter.println("	xlab='" + axisSettingsX.getLabel() + "'");
    printWriter.println(")");
    printWriter.println("");
    // 
    if (seriesSize > 1) {
        printWriter.println("for(i in 2:" + seriesSize + "){");
        printWriter.println("	points(xValueList[[i]], yValueList[[i]], type='l', col=colorList[(i+8)%%9+1])");
        printWriter.println("}");
        printWriter.println("");
    }
    // 
    int size;
    // 
    int k;
    printWriter.println("legend('topleft',");
    printWriter.println("		c(");
    k = 0;
    size = series.length;
    for (ISeries dataSeries : series) {
        if (dataSeries != null) {
            printWriter.print("			'Series " + dataSeries.getDescription() + "'");
            if (k < size - 1) {
                printWriter.print(",");
            }
            printWriter.println();
            k++;
        }
    }
    printWriter.println("		),");
    printWriter.println("		col=c(");
    k = 0;
    size = series.length;
    for (ISeries dataSeries : series) {
        if (dataSeries != null) {
            printWriter.print("			colorList[(" + (k + 1) + "+8)%%9+1]");
            if (k < size - 1) {
                printWriter.print(",");
            }
            printWriter.println();
            k++;
        }
    }
    printWriter.println("		),");
    printWriter.println("		lwd=2");
    printWriter.println("	)");
    printWriter.println("");
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

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