Search in sources :

Example 16 with BaseChart

use of org.eclipse.swtchart.extensions.core.BaseChart 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)

Example 17 with BaseChart

use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.

the class RScriptExportHandler method printBarPlot.

private void printBarPlot(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("count_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()) {
                    printBarData(dataSeries, widthPlotArea, axisSettings, printWriter);
                }
            } else {
                printBarData(dataSeries, widthPlotArea, axisSettings, printWriter);
            }
        }
    }
    printWriter.println("");
    /*
		 * Footer
		 */
    printWriter.println("#  Footer");
    printWriter.println("hist(count_values, breaks = range(count_values)[2]-range(count_values)[1]+1, axes=FALSE, xlab='" + axisSettingsX.getLabel() + "', ylab='" + axisSettingsY.getLabel() + "', main='" + scrollableChart.getChartSettings().getTitle() + "')");
    printWriter.println("");
    printWriter.println("axis(2, at = NULL)");
    printWriter.println("lower_x <- NULL");
    printWriter.println("if(min(count_values) %% 10 != 0){");
    printWriter.println("  lower_x <- round(min(count_values) %/% 10,0)*10");
    printWriter.println("} else {");
    printWriter.println("  lower_x <- min(count_values)+0.5");
    printWriter.println("}");
    printWriter.println("");
    printWriter.println("upper_x <- round(max(count_values)/10,0)*10+0.5");
    printWriter.println("axis(1, at = seq(lower_x+0.5, upper_x+0.5, 10), labels=seq(lower_x, upper_x, 10), tick = TRUE )");
}
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 18 with BaseChart

use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.

the class ResetSelectedSeriesHandler method execute.

@Override
public void execute(Shell shell, ScrollableChart scrollableChart) {
    BaseChart baseChart = scrollableChart.getBaseChart();
    baseChart.resetSeriesSettings();
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart)

Example 19 with BaseChart

use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.

the class AbstractSeparatedValueHandler 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[] { fileExtension });
    // 
    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.print(axisSettingsX.getLabel());
                    printWriter.print(delimiter);
                    printWriter.println(axisSettingsY.getLabel());
                    /*
						 * 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.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 20 with BaseChart

use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.

the class LineSeries_Edit_Part method createButtonLeft.

private void createButtonLeft(Composite parent) {
    Button button = new Button(parent, SWT.PUSH);
    button.setToolTipText("Move Left");
    button.setText(Activator.getDefault() != null ? "" : "Move Left");
    button.setImage(Activator.getDefault() != null ? Activator.getDefault().getImage(Activator.ICON_LEFT) : null);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            BaseChart baseChart = chromatogramChart.getBaseChart();
            double shiftX = getShift(IExtendedChart.X_AXIS) * -1.0d;
            String selectedSeriesId = comboSelectSeries.getText().trim();
            baseChart.shiftSeries(selectedSeriesId, shiftX, 0.0d);
            baseChart.redraw();
        }
    });
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)28 Point (org.eclipse.swt.graphics.Point)8 ISeries (org.eclipse.swtchart.ISeries)8 IAxisSettings (org.eclipse.swtchart.extensions.core.IAxisSettings)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 IAxisScaleConverter (org.eclipse.swtchart.extensions.core.IAxisScaleConverter)6 Button (org.eclipse.swt.widgets.Button)5 File (java.io.File)4 ISeriesData (org.eclipse.swtchart.extensions.core.ISeriesData)4 FileNotFoundException (java.io.FileNotFoundException)3 PrintWriter (java.io.PrintWriter)3 FileDialog (org.eclipse.swt.widgets.FileDialog)3 ISecondaryAxisSettings (org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings)3 SeriesException (org.eclipse.swtchart.extensions.exceptions.SeriesException)3 DecimalFormat (java.text.DecimalFormat)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 ILineSeries (org.eclipse.swtchart.ILineSeries)2