Search in sources :

Example 1 with BaseChart

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

the class ImageFactory_3_UITest method test1.

public void test1() {
    try {
        /*
			 * Create the factory.
			 */
        ImageFactory<PCAChart> imageFactory = new ImageFactory<PCAChart>(PCAChart.class, 800, 600);
        /*
			 * Modify the chart.
			 */
        PCAChart pcaChart = imageFactory.getChart();
        BaseChart baseChart = pcaChart.getBaseChart();
        pcaChart.setBackground(baseChart.getDisplay().getSystemColor(SWT.COLOR_WHITE));
        List<ISeriesData> scatterSeriesList = SeriesConverter.getSeriesScatter(TestPathHelper.getAbsolutePath(TestPathHelper.TESTFILE_SCATTER_SERIES_1));
        List<IScatterSeriesData> scatterSeriesDataList = new ArrayList<IScatterSeriesData>();
        // 
        for (ISeriesData seriesData : scatterSeriesList) {
            IScatterSeriesData scatterSeriesData = new ScatterSeriesData(seriesData);
            IScatterSeriesSettings scatterSeriesSettings = scatterSeriesData.getScatterSeriesSettings();
            /*
				 * Set the color and symbol type.
				 */
            double x = seriesData.getXSeries()[0];
            double y = seriesData.getYSeries()[0];
            scatterSeriesSettings.setSymbolSize(SYMBOL_SIZE);
            // 
            if (x > 0 && y > 0) {
                scatterSeriesSettings.setSymbolColor(baseChart.getDisplay().getSystemColor(SWT.COLOR_RED));
                scatterSeriesSettings.setSymbolType(PlotSymbolType.SQUARE);
            } else if (x > 0 && y < 0) {
                scatterSeriesSettings.setSymbolColor(baseChart.getDisplay().getSystemColor(SWT.COLOR_BLUE));
                scatterSeriesSettings.setSymbolType(PlotSymbolType.TRIANGLE);
            } else if (x < 0 && y > 0) {
                scatterSeriesSettings.setSymbolColor(baseChart.getDisplay().getSystemColor(SWT.COLOR_MAGENTA));
                scatterSeriesSettings.setSymbolType(PlotSymbolType.DIAMOND);
            } else if (x < 0 && y < 0) {
                scatterSeriesSettings.setSymbolColor(baseChart.getDisplay().getSystemColor(SWT.COLOR_CYAN));
                scatterSeriesSettings.setSymbolType(PlotSymbolType.INVERTED_TRIANGLE);
            } else {
                scatterSeriesSettings.setSymbolColor(baseChart.getDisplay().getSystemColor(SWT.COLOR_GRAY));
                scatterSeriesSettings.setSymbolType(PlotSymbolType.CIRCLE);
            }
            // 
            scatterSeriesDataList.add(scatterSeriesData);
        }
        pcaChart.addSeriesData(scatterSeriesDataList);
        /*
			 * Export the images.
			 */
        String exportFolder = TestPathHelper.getAbsolutePath(TestPathHelper.TESTFOLDER_EXPORT);
        String prefix = "ScatterSeries1";
        // 
        String png = exportFolder + File.separator + prefix + ".png";
        imageFactory.saveImage(png, SWT.IMAGE_PNG);
        File filePng = new File(png);
        assertTrue(filePng.exists());
        filePng.delete();
        // 
        String jpg = exportFolder + File.separator + prefix + ".jpg";
        imageFactory.saveImage(jpg, SWT.IMAGE_JPEG);
        File fileJpg = new File(jpg);
        assertTrue(fileJpg.exists());
        fileJpg.delete();
        // 
        String bmp = exportFolder + File.separator + prefix + ".bmp";
        imageFactory.saveImage(bmp, SWT.IMAGE_BMP);
        File fileBmp = new File(bmp);
        assertTrue(fileBmp.exists());
        fileBmp.delete();
        // 
        imageFactory.closeShell();
    // 
    } catch (InstantiationException e) {
        System.out.println(e);
    } catch (IllegalAccessException e) {
        System.out.println(e);
    }
}
Also used : IScatterSeriesData(org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesData) IScatterSeriesData(org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesData) ScatterSeriesData(org.eclipse.swtchart.extensions.scattercharts.ScatterSeriesData) ISeriesData(org.eclipse.swtchart.extensions.core.ISeriesData) IScatterSeriesSettings(org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesSettings) ArrayList(java.util.ArrayList) ImageFactory(org.eclipse.swtchart.extensions.images.ImageFactory) BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) PCAChart(org.eclipse.swtchart.extensions.customcharts.PCAChart) File(java.io.File)

Example 2 with BaseChart

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

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

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

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

the class LabelMarker method paintControl.

@Override
public void paintControl(PaintEvent e) {
    BaseChart baseChart = getBaseChart();
    Rectangle rectangle = baseChart.getPlotArea().getClientArea();
    ISeries[] series = baseChart.getSeriesSet().getSeries();
    if (indexSeries >= 0 && indexSeries < series.length) {
        ISeries serie = series[indexSeries];
        int size = serie.getXSeries().length;
        for (int index : labels.keySet()) {
            if (index < size) {
                /*
					 * Draw the label if the index is within the
					 * range of the double array.
					 */
                String label = labels.get(index);
                Point point = serie.getPixelCoordinates(index);
                // 
                if (rectangle.contains(point)) {
                    /*
						 * Calculate x and y
						 */
                    int x;
                    int y;
                    Point labelSize = e.gc.textExtent(label);
                    GC gc = e.gc;
                    if (transform != null) {
                        gc.setTransform(transform);
                        x = -labelSize.x - (point.y - labelSize.x - 15);
                        y = point.x - (labelSize.y / 2);
                    } else {
                        x = point.x - labelSize.x / 2;
                        y = point.y - labelSize.y - 15;
                    }
                    gc.drawText(label, x, y, true);
                    gc.setTransform(null);
                }
            }
        }
    }
}
Also used : BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) 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