Search in sources :

Example 1 with PCAChart

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

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)1 ISeriesData (org.eclipse.swtchart.extensions.core.ISeriesData)1 PCAChart (org.eclipse.swtchart.extensions.customcharts.PCAChart)1 ImageFactory (org.eclipse.swtchart.extensions.images.ImageFactory)1 IScatterSeriesData (org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesData)1 IScatterSeriesSettings (org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesSettings)1 ScatterSeriesData (org.eclipse.swtchart.extensions.scattercharts.ScatterSeriesData)1