use of org.eclipse.swtchart.IAxis in project swtchart by eclipse.
the class AbstractExtendedChart method adjustSecondaryXAxes.
@Override
public void adjustSecondaryXAxes() {
IAxisSet axisSet = getAxisSet();
IAxis xAxis = axisSet.getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
Range range = xAxis.getRange();
for (int id : axisSet.getXAxisIds()) {
if (id != BaseChart.ID_PRIMARY_X_AXIS) {
IAxis axis = axisSet.getXAxis(id);
IAxisSettings axisSettings = xAxisSettingsMap.get(id);
if (axis != null && axisSettings instanceof ISecondaryAxisSettings) {
IAxisScaleConverter axisScaleConverter = ((ISecondaryAxisSettings) axisSettings).getAxisScaleConverter();
axisScaleConverter.setChartDataCoordinates(this);
double start = axisScaleConverter.convertToSecondaryUnit(range.lower);
double end = axisScaleConverter.convertToSecondaryUnit(range.upper);
if (end > start) {
Range adjustedRange = new Range(start, end);
axis.setRange(adjustedRange);
} else {
System.out.println("Can't set secondary x axes range: " + start + "\t" + end);
}
}
}
}
}
use of org.eclipse.swtchart.IAxis in project swtchart by eclipse.
the class InteractiveChart method handleSelectionEvent.
/**
* Handles the selection event.
*
* @param event
* the event
*/
private void handleSelectionEvent(Event event) {
if (!(event.widget instanceof MenuItem)) {
return;
}
MenuItem menuItem = (MenuItem) event.widget;
if (menuItem.getText().equals(Messages.ADJUST_AXIS_RANGE)) {
getAxisSet().adjustRange();
} else if (menuItem.getText().equals(Messages.ADJUST_X_AXIS_RANGE)) {
for (IAxis axis : getAxisSet().getXAxes()) {
axis.adjustRange();
}
} else if (menuItem.getText().equals(Messages.ADJUST_Y_AXIS_RANGE)) {
for (IAxis axis : getAxisSet().getYAxes()) {
axis.adjustRange();
}
} else if (menuItem.getText().equals(Messages.ZOOMIN)) {
getAxisSet().zoomIn();
} else if (menuItem.getText().equals(Messages.ZOOMIN_X)) {
for (IAxis axis : getAxisSet().getXAxes()) {
axis.zoomIn();
}
} else if (menuItem.getText().equals(Messages.ZOOMIN_Y)) {
for (IAxis axis : getAxisSet().getYAxes()) {
axis.zoomIn();
}
} else if (menuItem.getText().equals(Messages.ZOOMOUT)) {
getAxisSet().zoomOut();
} else if (menuItem.getText().equals(Messages.ZOOMOUT_X)) {
for (IAxis axis : getAxisSet().getXAxes()) {
axis.zoomOut();
}
} else if (menuItem.getText().equals(Messages.ZOOMOUT_Y)) {
for (IAxis axis : getAxisSet().getYAxes()) {
axis.zoomOut();
}
} else if (menuItem.getText().equals(Messages.SAVE_AS)) {
openSaveAsDialog();
} else if (menuItem.getText().equals(Messages.PROPERTIES)) {
openPropertiesDialog();
}
redraw();
}
use of org.eclipse.swtchart.IAxis in project swtchart by eclipse.
the class BaseChart method getShiftValue.
public double getShiftValue(int positionStart, int positionStop, String orientation) {
double shiftValue = 0.0d;
double start;
double stop;
int length;
/*
* Get the axis.
*/
if (orientation.equals(IExtendedChart.X_AXIS)) {
IAxis axis = getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
start = axis.getRange().lower;
stop = axis.getRange().upper;
length = getPlotArea().getBounds().width;
} else {
IAxis axis = getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
start = axis.getRange().lower;
stop = axis.getRange().upper;
length = getPlotArea().getBounds().height;
}
//
if (positionStart > 0 && positionStop > 0 && positionStart < length && positionStop < length) {
//
double delta = stop - start;
double percentageStart;
double percentageStop;
//
if (orientation.equals(IExtendedChart.X_AXIS)) {
percentageStart = ((100.0d / length) * positionStart) / 100.0d;
percentageStop = ((100.0d / length) * positionStop) / 100.0d;
} else {
percentageStart = (100.0d - ((100.0d / length) * positionStart)) / 100.0d;
percentageStop = (100.0d - ((100.0d / length) * positionStop)) / 100.0d;
}
//
shiftValue = (start + delta * percentageStop) - (start + delta * percentageStart);
}
return shiftValue;
}
use of org.eclipse.swtchart.IAxis in project swtchart by eclipse.
the class BaseChart method getSelectedPrimaryAxisValue.
public double getSelectedPrimaryAxisValue(int position, String orientation) {
double primaryValue = 0.0d;
double start;
double stop;
int length;
//
if (orientation.equals(IExtendedChart.X_AXIS)) {
IAxis axis = getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
start = axis.getRange().lower;
stop = axis.getRange().upper;
length = getPlotArea().getBounds().width;
} else {
IAxis axis = getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
start = axis.getRange().lower;
stop = axis.getRange().upper;
length = getPlotArea().getBounds().height;
}
//
if (position <= 0) {
primaryValue = start;
} else if (position > length) {
primaryValue = stop;
} else {
double delta = stop - start;
double percentage;
if (orientation.equals(IExtendedChart.X_AXIS)) {
percentage = ((100.0d / length) * position) / 100.0d;
} else {
percentage = (100.0d - ((100.0d / length) * position)) / 100.0d;
}
primaryValue = start + delta * percentage;
}
return primaryValue;
}
use of org.eclipse.swtchart.IAxis in project swtchart by eclipse.
the class BaseChart method getAxisLabels.
public String[] getAxisLabels(String axisOrientation) {
IAxis[] axes = getAxes(axisOrientation);
int size = axes.length;
String[] items = new String[size];
//
for (int i = 0; i < size; i++) {
/*
* Get the label.
*/
String label;
IAxisSettings axisSettings = getAxisSettings(axisOrientation, i);
if (axisSettings != null) {
label = axisSettings.getLabel();
} else {
label = "not set";
}
items[i] = label;
}
return items;
}
Aggregations