use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.
the class RScriptExportHandler method printLinePlot.
private void printLinePlot(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
*/
int seriesSize = getSeriesSize(series, exportVisibleOnly);
printWriter.println("# Header");
printWriter.println("xValueList<-vector(\"list\", " + seriesSize + ")");
printWriter.println("yValueList<-vector(\"list\", " + seriesSize + ")");
printWriter.println("");
/*
* Data
*/
printWriter.println("# Data");
int widthPlotArea = baseChart.getPlotArea().getBounds().width;
int index = 1;
for (ISeries dataSeries : series) {
if (dataSeries != null) {
if (exportVisibleOnly) {
if (dataSeries.isVisible()) {
printLineData(dataSeries, widthPlotArea, axisSettings, index++, printWriter);
}
} else {
printLineData(dataSeries, widthPlotArea, axisSettings, index++, printWriter);
}
}
}
printWriter.println("");
/*
* Footer
*/
printWriter.println("# Footer");
printWriter.println("colorList<-c(\"black\", \"red\", \"blue\", \"green\", \"grey\", \"purple\", \"brown\", \"pink\", \"yellow\", \"orange\")");
//
printWriter.println("");
printWriter.println("plot(");
printWriter.println(" xValueList[[1]], yValueList[[1]],");
printWriter.println(" xlim=c(range(xValueList)[1], range(xValueList)[2]),");
printWriter.println(" ylim=c(range(yValueList)[1], range(yValueList)[2]),");
printWriter.println(" type='l',");
printWriter.println(" col=colorList[1],");
printWriter.println(" ylab='" + axisSettingsY.getLabel() + "',");
printWriter.println(" xlab='" + axisSettingsX.getLabel() + "'");
printWriter.println(")");
printWriter.println("");
//
if (seriesSize > 1) {
printWriter.println("for(i in 2:" + seriesSize + "){");
printWriter.println(" points(xValueList[[i]], yValueList[[i]], type='l', col=colorList[(i+8)%%9+1])");
printWriter.println("}");
printWriter.println("");
}
//
int size;
//
int k;
printWriter.println("legend('topleft',");
printWriter.println(" c(");
k = 0;
size = series.length;
for (ISeries dataSeries : series) {
if (dataSeries != null) {
printWriter.print(" 'Series " + dataSeries.getDescription() + "'");
if (k < size - 1) {
printWriter.print(",");
}
printWriter.println();
k++;
}
}
printWriter.println(" ),");
printWriter.println(" col=c(");
k = 0;
size = series.length;
for (ISeries dataSeries : series) {
if (dataSeries != null) {
printWriter.print(" colorList[(" + (k + 1) + "+8)%%9+1]");
if (k < size - 1) {
printWriter.print(",");
}
printWriter.println();
k++;
}
}
printWriter.println(" ),");
printWriter.println(" lwd=2");
printWriter.println(" )");
printWriter.println("");
}
use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.
the class RScriptExportHandler method printBarPlot.
private void printBarPlot(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("count_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()) {
printBarData(dataSeries, widthPlotArea, axisSettings, printWriter);
}
} else {
printBarData(dataSeries, widthPlotArea, axisSettings, printWriter);
}
}
}
printWriter.println("");
/*
* Footer
*/
printWriter.println("# Footer");
printWriter.println("hist(count_values, breaks = range(count_values)[2]-range(count_values)[1]+1, axes=FALSE, xlab='" + axisSettingsX.getLabel() + "', ylab='" + axisSettingsY.getLabel() + "', main='" + scrollableChart.getChartSettings().getTitle() + "')");
printWriter.println("");
printWriter.println("axis(2, at = NULL)");
printWriter.println("lower_x <- NULL");
printWriter.println("if(min(count_values) %% 10 != 0){");
printWriter.println(" lower_x <- round(min(count_values) %/% 10,0)*10");
printWriter.println("} else {");
printWriter.println(" lower_x <- min(count_values)+0.5");
printWriter.println("}");
printWriter.println("");
printWriter.println("upper_x <- round(max(count_values)/10,0)*10+0.5");
printWriter.println("axis(1, at = seq(lower_x+0.5, upper_x+0.5, 10), labels=seq(lower_x, upper_x, 10), tick = TRUE )");
}
use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.
the class ResetSelectedSeriesHandler method execute.
@Override
public void execute(Shell shell, ScrollableChart scrollableChart) {
BaseChart baseChart = scrollableChart.getBaseChart();
baseChart.resetSeriesSettings();
}
use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.
the class AbstractSeparatedValueHandler 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[] { fileExtension });
//
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.print(axisSettingsX.getLabel());
printWriter.print(delimiter);
printWriter.println(axisSettingsY.getLabel());
/*
* 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.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 LineSeries_Edit_Part method createButtonLeft.
private void createButtonLeft(Composite parent) {
Button button = new Button(parent, SWT.PUSH);
button.setToolTipText("Move Left");
button.setText(Activator.getDefault() != null ? "" : "Move Left");
button.setImage(Activator.getDefault() != null ? Activator.getDefault().getImage(Activator.ICON_LEFT) : null);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
BaseChart baseChart = chromatogramChart.getBaseChart();
double shiftX = getShift(IExtendedChart.X_AXIS) * -1.0d;
String selectedSeriesId = comboSelectSeries.getText().trim();
baseChart.shiftSeries(selectedSeriesId, shiftX, 0.0d);
baseChart.redraw();
}
});
}
Aggregations