Search in sources :

Example 11 with BaseChart

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

the class LineSeries_Edit_Part method createButtonDown.

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            BaseChart baseChart = chromatogramChart.getBaseChart();
            double shiftY = getShift(IExtendedChart.Y_AXIS) * -1.0d;
            String selectedSeriesId = comboSelectSeries.getText().trim();
            baseChart.shiftSeries(selectedSeriesId, 0.0d, shiftY);
            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)

Example 12 with BaseChart

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

the class ScatterSeries_Edit_Part method createButtonReset.

private void createButtonReset(Composite parent) {
    Button button = new Button(parent, SWT.PUSH);
    button.setToolTipText("Reset the data");
    button.setText(Activator.getDefault() != null ? "" : "Reset");
    button.setImage(Activator.getDefault() != null ? Activator.getDefault().getImage(Activator.ICON_RESET) : null);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            isCustomSelection = false;
            BaseChart baseChart = handledChart.getBaseChart();
            baseChart.resetSeriesSettings();
            enableButtons();
        }
    });
}
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)

Example 13 with BaseChart

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

the class BarChart method addSeriesData.

/**
 * BarWidthStyle.STRETCHED will be used automatically instead of BarWidthStyle.FIXED
 * if the series data is too large. This leads to a better performance.
 *
 * @param barSeriesDataList
 */
public void addSeriesData(List<IBarSeriesData> barSeriesDataList, int compressToLength) {
    /*
		 * Suspend the update when adding new data to improve the performance.
		 */
    if (barSeriesDataList != null && barSeriesDataList.size() > 0) {
        BaseChart baseChart = getBaseChart();
        baseChart.suspendUpdate(true);
        for (IBarSeriesData barSeriesData : barSeriesDataList) {
            /*
				 * Get the series data and apply the settings.
				 */
            try {
                ISeriesData seriesData = barSeriesData.getSeriesData();
                ISeriesData optimizedSeriesData = calculateSeries(seriesData, compressToLength);
                IBarSeriesSettings barSeriesSettings = barSeriesData.getBarSeriesSettings();
                // Initialize
                barSeriesSettings.getSeriesSettingsHighlight();
                IBarSeries barSeries = (IBarSeries) createSeries(optimizedSeriesData, barSeriesSettings);
                baseChart.applyBarSeriesSettings(barSeries, barSeriesSettings);
                /*
					 * Automatically use stretched if it is a large data set.
					 */
                if (isLargeDataSet(optimizedSeriesData.getXSeries(), optimizedSeriesData.getYSeries(), LENGTH_HINT_DATA_POINTS)) {
                    barSeries.setBarWidthStyle(BarWidthStyle.STRETCHED);
                } else {
                    barSeries.setBarWidthStyle(barSeriesSettings.getBarWidthStyle());
                }
            } catch (SeriesException e) {
            // 
            }
        }
        baseChart.suspendUpdate(false);
        adjustRange(true);
        baseChart.redraw();
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) IBarSeries(org.eclipse.swtchart.IBarSeries) SeriesException(org.eclipse.swtchart.extensions.exceptions.SeriesException)

Example 14 with BaseChart

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

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

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