Search in sources :

Example 6 with IAxisSettings

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

use of org.eclipse.swtchart.extensions.core.IAxisSettings 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 8 with IAxisSettings

use of org.eclipse.swtchart.extensions.core.IAxisSettings 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 9 with IAxisSettings

use of org.eclipse.swtchart.extensions.core.IAxisSettings 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 10 with IAxisSettings

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

the class AbstractSeparatedValueHandler method exportSeries.

private void exportSeries(ISeries dataSeries, int widthPlotArea, AxisSettings axisSettings, PrintWriter printWriter) {
    int indexAxisX = axisSettings.getIndexAxisX();
    int indexAxisY = axisSettings.getIndexAxisY();
    IAxisSettings axisSettingsX = axisSettings.getAxisSettingsX();
    DecimalFormat decimalFormatX = axisSettingsX.getDecimalFormat();
    IAxisScaleConverter axisScaleConverterX = axisSettings.getAxisScaleConverterX();
    IAxisSettings axisSettingsY = axisSettings.getAxisSettingsY();
    DecimalFormat decimalFormatY = axisSettingsY.getDecimalFormat();
    IAxisScaleConverter axisScaleConverterY = axisSettings.getAxisScaleConverterY();
    /*
		 * Series
		 */
    printWriter.println(dataSeries.getId());
    // 
    double[] xSeries = dataSeries.getXSeries();
    double[] ySeries = dataSeries.getYSeries();
    int size = dataSeries.getXSeries().length;
    // 
    for (int i = 0; i < size; i++) {
        /*
			 * Only export if the data point is visible.
			 */
        Point point = dataSeries.getPixelCoordinates(i);
        if (point.x >= 0 && point.x <= widthPlotArea) {
            printValue(printWriter, xSeries[i], indexAxisX, BaseChart.ID_PRIMARY_X_AXIS, decimalFormatX, axisScaleConverterX);
            printWriter.print(delimiter);
            printValue(printWriter, ySeries[i], indexAxisY, BaseChart.ID_PRIMARY_Y_AXIS, decimalFormatY, axisScaleConverterY);
            printWriter.println("");
        }
    }
    // 
    printWriter.println("");
}
Also used : DecimalFormat(java.text.DecimalFormat) IAxisScaleConverter(org.eclipse.swtchart.extensions.core.IAxisScaleConverter) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Aggregations

IAxisSettings (org.eclipse.swtchart.extensions.core.IAxisSettings)10 Point (org.eclipse.swt.graphics.Point)8 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)8 IAxisScaleConverter (org.eclipse.swtchart.extensions.core.IAxisScaleConverter)7 ISeries (org.eclipse.swtchart.ISeries)5 File (java.io.File)3 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 DecimalFormat (java.text.DecimalFormat)2 BarChart (org.eclipse.swtchart.extensions.barcharts.BarChart)1 LineChart (org.eclipse.swtchart.extensions.linecharts.LineChart)1 ScatterChart (org.eclipse.swtchart.extensions.scattercharts.ScatterChart)1