use of org.eclipse.swtchart.extensions.core.IAxisSettings in project swtchart by eclipse.
the class LaTeXTableExportHandler method exportSeries.
private void exportSeries(ISeries dataSeries, int widthPlotArea, AxisSettings axisSettings, PrintWriter printWriter) {
int indexAxisX = axisSettings.getIndexAxisX();
int indexAxisY = axisSettings.getIndexAxisY();
IAxisSettings axisSettingsX = axisSettings.getAxisSettingsX();
DecimalFormat decimalFormatX = axisSettingsX.getDecimalFormat();
IAxisScaleConverter axisScaleConverterX = axisSettings.getAxisScaleConverterX();
IAxisSettings axisSettingsY = axisSettings.getAxisSettingsY();
DecimalFormat decimalFormatY = axisSettingsY.getDecimalFormat();
IAxisScaleConverter axisScaleConverterY = axisSettings.getAxisScaleConverterY();
/*
* Series
*/
printWriter.println(TAB + HORIZONTAL_LINE);
printWriter.println(TAB + dataSeries.getId() + DELIMITER + LINE_END);
printWriter.println(TAB + HORIZONTAL_LINE);
//
double[] xSeries = dataSeries.getXSeries();
double[] ySeries = dataSeries.getYSeries();
int size = dataSeries.getXSeries().length;
//
for (int i = 0; i < size; i++) {
/*
* Only export if the data point is visible.
*/
Point point = dataSeries.getPixelCoordinates(i);
if (point.x >= 0 && point.x <= widthPlotArea) {
printWriter.print(TAB);
printValue(printWriter, xSeries[i], indexAxisX, BaseChart.ID_PRIMARY_X_AXIS, decimalFormatX, axisScaleConverterX);
printWriter.print(DELIMITER);
printValue(printWriter, ySeries[i], indexAxisY, BaseChart.ID_PRIMARY_Y_AXIS, decimalFormatY, axisScaleConverterY);
printWriter.println(LINE_END);
}
}
//
printWriter.print(TAB);
printWriter.print(DELIMITER);
printWriter.println(LINE_END);
}
use of org.eclipse.swtchart.extensions.core.IAxisSettings 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.IAxisSettings 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.IAxisSettings 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.IAxisSettings 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();
}
}
}
}
}
}
Aggregations