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);
}
}
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();
}
}
}
}
}
}
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)));
}
}
}
}
}
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)));
}
}
}
}
}
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);
}
}
}
}
}
Aggregations