Search in sources :

Example 1 with IAxisSettings

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

the class LaTeXTableExportHandler 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(TAB + HORIZONTAL_LINE);
    printWriter.println(TAB + dataSeries.getId() + DELIMITER + LINE_END);
    printWriter.println(TAB + HORIZONTAL_LINE);
    // 
    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) {
            printWriter.print(TAB);
            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(LINE_END);
        }
    }
    // 
    printWriter.print(TAB);
    printWriter.print(DELIMITER);
    printWriter.println(LINE_END);
}
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)

Example 2 with IAxisSettings

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

the class RScriptExportHandler 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));
                    /*
						 * Axis settings.
						 */
                    AxisSettings axisSettings = new AxisSettings();
                    axisSettings.setIndexAxisX(indexAxisX);
                    axisSettings.setIndexAxisY(indexAxisY);
                    axisSettings.setAxisSettingsX(axisSettingsX);
                    axisSettings.setAxisScaleConverterX(axisScaleConverterX);
                    axisSettings.setAxisSettingsY(axisSettingsY);
                    axisSettings.setAxisScaleConverterY(axisScaleConverterY);
                    axisSettings.setExportVisibleOnly(exportSettingsDialog.isExportVisibleOnly());
                    // 
                    if (scrollableChart instanceof LineChart) {
                        printLinePlot(fileName, printWriter, scrollableChart, axisSettings);
                    } else if (scrollableChart instanceof BarChart) {
                        printBarPlot(fileName, printWriter, scrollableChart, axisSettings);
                    } else if (scrollableChart instanceof ScatterChart) {
                        printScatterPlot(fileName, printWriter, scrollableChart, axisSettings);
                    }
                    // 
                    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) ScatterChart(org.eclipse.swtchart.extensions.scattercharts.ScatterChart) 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) Point(org.eclipse.swt.graphics.Point) BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisScaleConverter(org.eclipse.swtchart.extensions.core.IAxisScaleConverter) BarChart(org.eclipse.swtchart.extensions.barcharts.BarChart) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) LineChart(org.eclipse.swtchart.extensions.linecharts.LineChart) PrintWriter(java.io.PrintWriter)

Example 3 with IAxisSettings

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

the class LegendMarker method drawYAxes.

private void drawYAxes(double primaryValueY) {
    /*
		 * Y Axes
		 */
    BaseChart baseChart = getBaseChart();
    IAxisSettings axisSettingsY = baseChart.getYAxisSettings(BaseChart.ID_PRIMARY_Y_AXIS);
    if (axisSettingsY != null && axisSettingsY.isVisible()) {
        if (stringBuilder.length() > 0) {
            stringBuilder.append("\n");
        }
        stringBuilder.append(axisLabelsY[BaseChart.ID_PRIMARY_Y_AXIS]);
        stringBuilder.append(": ");
        stringBuilder.append(decimalFormatY.format(primaryValueY));
    }
    // 
    for (int id : baseChart.getAxisSet().getYAxisIds()) {
        if (id != BaseChart.ID_PRIMARY_Y_AXIS) {
            IAxisSettings axisSettings = baseChart.getYAxisSettings(id);
            if (axisSettings != null) {
                IAxisScaleConverter axisScaleConverter = baseChart.getAxisScaleConverter(IExtendedChart.Y_AXIS, id);
                if (axisSettings.isVisible() && axisScaleConverter != null) {
                    if (stringBuilder.length() > 0) {
                        stringBuilder.append("\n");
                    }
                    stringBuilder.append(axisLabelsY[id]);
                    stringBuilder.append(": ");
                    stringBuilder.append(axisSettings.getDecimalFormat().format(axisScaleConverter.convertToSecondaryUnit(primaryValueY)));
                }
            }
        }
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisScaleConverter(org.eclipse.swtchart.extensions.core.IAxisScaleConverter) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings)

Example 4 with IAxisSettings

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

the class LegendMarker method drawXAxes.

private void drawXAxes(double primaryValueX) {
    /*
		 * X Axes
		 */
    BaseChart baseChart = getBaseChart();
    IAxisSettings axisSettingsX = baseChart.getXAxisSettings(BaseChart.ID_PRIMARY_X_AXIS);
    if (axisSettingsX != null && axisSettingsX.isVisible()) {
        stringBuilder.append(axisLabelsX[BaseChart.ID_PRIMARY_X_AXIS]);
        stringBuilder.append(": ");
        stringBuilder.append(decimalFormatX.format(primaryValueX));
    }
    // 
    for (int id : baseChart.getAxisSet().getXAxisIds()) {
        if (id != BaseChart.ID_PRIMARY_X_AXIS) {
            IAxisSettings axisSettings = baseChart.getXAxisSettings(id);
            if (axisSettings != null) {
                IAxisScaleConverter axisScaleConverter = baseChart.getAxisScaleConverter(IExtendedChart.X_AXIS, id);
                if (axisSettings.isVisible() && axisScaleConverter != null) {
                    if (stringBuilder.length() > 0) {
                        stringBuilder.append("\n");
                    }
                    stringBuilder.append(axisLabelsX[id]);
                    stringBuilder.append(": ");
                    stringBuilder.append(axisSettings.getDecimalFormat().format(axisScaleConverter.convertToSecondaryUnit(primaryValueX)));
                }
            }
        }
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisScaleConverter(org.eclipse.swtchart.extensions.core.IAxisScaleConverter) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings)

Example 5 with IAxisSettings

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

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