use of org.eclipse.swtchart.extensions.core.IAxisScaleConverter 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.IAxisScaleConverter 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.IAxisScaleConverter 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.IAxisScaleConverter 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.IAxisScaleConverter in project swtchart by eclipse.
the class LineSeries_Edit_Part method getShift.
private double getShift(String axis) {
double shiftValue = 0.0d;
try {
/*
* Try to calculate the primary unit.
*/
BaseChart baseChart = chromatogramChart.getBaseChart();
DecimalFormat decimalFormat;
int selectedAxis;
//
if (axis.equals(IExtendedChart.X_AXIS)) {
selectedAxis = comboScaleX.getSelectionIndex();
decimalFormat = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, selectedAxis);
} else {
selectedAxis = comboScaleY.getSelectionIndex();
decimalFormat = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, selectedAxis);
}
//
double secondaryValue;
if (axis.equals(IExtendedChart.X_AXIS)) {
secondaryValue = decimalFormat.parse(textShiftX.getText().trim()).doubleValue();
} else {
secondaryValue = decimalFormat.parse(textShiftY.getText().trim()).doubleValue();
}
/*
* Convert the range on demand.
*/
if (selectedAxis == 0) {
shiftValue = secondaryValue;
} else {
IAxisScaleConverter axisScaleConverter = baseChart.getAxisScaleConverter(axis, selectedAxis);
shiftValue = axisScaleConverter.convertToPrimaryUnit(secondaryValue);
}
} catch (ParseException e) {
System.out.println(e);
}
//
return shiftValue;
}
Aggregations