use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.
the class Series method draw.
/**
* Draws series.
*
* @param gc
* the graphics context
* @param width
* the width to draw series
* @param height
* the height to draw series
*/
public void draw(GC gc, int width, int height) {
if (!visible || width < 0 || height < 0 || xSeries.length == 0 || ySeries.length == 0) {
return;
}
Axis xAxis = (Axis) chart.getAxisSet().getXAxis(getXAxisId());
Axis yAxis = (Axis) chart.getAxisSet().getYAxis(getYAxisId());
if (xAxis == null || yAxis == null) {
return;
}
draw(gc, width, height, xAxis, yAxis);
}
use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.
the class ChartLayout method adjustForRotatedTickLabels.
/**
* Adjust the axis size for rotated tick labels.
*
* @param r
* the rectangle to layout
*/
private void adjustForRotatedTickLabels(Rectangle r) {
for (IAxis axis : horizontalAxes) {
double angle = axis.getTick().getTickLabelAngle();
if (angle == 0 || !axis.getTick().isVisible()) {
continue;
}
// update tick label height
int tickLabelMaxLength = ((Axis) axis).getTick().getAxisTickLabels().getTickLabelMaxLength();
AxisLayoutData layoutData = axisLayoutDataMap.get(axis);
int height = Axis.MARGIN + (int) (tickLabelMaxLength * Math.sin(Math.toRadians(angle)) + Util.getExtentInGC(layoutData.axisTickLabels.getFont(), null).y * Math.cos(Math.toRadians(angle)));
int delta = height - layoutData.tickLabelsLayoutdata.heightHint;
layoutData.tickLabelsLayoutdata.heightHint = height;
// update axis height
if (axis.getPosition() == Position.Primary) {
bottomAxisHeight += delta;
} else {
topAxisHeight += delta;
}
// update plot area height
computePlotAreaSize(r);
updateVerticalAxisTick();
}
}
use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.
the class ChartLayout method parseControls.
/**
* Parses the controls on given composite.
*
* @param composite
* the composite
* @return true if all children found
*/
private boolean parseControls(Composite composite) {
for (Control child : composite.getChildren()) {
if (child instanceof Legend) {
legend = (Legend) child;
} else if (child instanceof PlotArea) {
plot = (PlotArea) child;
}
}
if (composite instanceof Chart) {
IAxisSet axisSet = ((Chart) composite).getAxisSet();
if (axisSet != null) {
axes = (Axis[]) axisSet.getAxes();
if (((Chart) composite).getOrientation() == SWT.HORIZONTAL) {
horizontalAxes = (Axis[]) axisSet.getXAxes();
verticalAxes = (Axis[]) axisSet.getYAxes();
} else {
verticalAxes = (Axis[]) axisSet.getXAxes();
horizontalAxes = (Axis[]) axisSet.getYAxes();
}
}
title = (ChartTitle) ((Chart) composite).getTitle();
}
if (title == null || legend == null || plot == null || axes == null) {
// the initialization of chart is not completed yet
return false;
}
return true;
}
use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.
the class BarSeries method getBoundsForCompressedSeries.
/**
* Gets the array of bar rectangles for compressed series.
*
* @return the array of bar rectangles for compressed series
*/
private Rectangle[] getBoundsForCompressedSeries() {
Axis xAxis = (Axis) chart.getAxisSet().getXAxis(xAxisId);
Axis yAxis = (Axis) chart.getAxisSet().getYAxis(yAxisId);
// get x and y series
double[] xseries = compressor.getCompressedXSeries();
double[] yseries = compressor.getCompressedYSeries();
int[] indexes = compressor.getCompressedIndexes();
if (xAxis.isValidCategoryAxis()) {
for (int i = 0; i < xseries.length; i++) {
xseries[i] = indexes[i];
}
}
Rectangle[] rectangles = new Rectangle[xseries.length];
Range xRange = xAxis.getRange();
Range yRange = yAxis.getRange();
for (int i = 0; i < xseries.length; i++) {
int x = xAxis.getPixelCoordinate(xseries[i]);
int y = yAxis.getPixelCoordinate(isValidStackSeries() ? stackSeries[indexes[i]] : yseries[i]);
double baseYCoordinate = yAxis.getRange().lower > 0 ? yAxis.getRange().lower : 0;
double riserwidth = getRiserWidth(xseries, i, xAxis, xRange.lower, xRange.upper);
double riserHeight = Math.abs(yAxis.getPixelCoordinate(yseries[i], yRange.lower, yRange.upper) - yAxis.getPixelCoordinate(yAxis.isLogScaleEnabled() ? yRange.lower : baseYCoordinate, yRange.lower, yRange.upper));
// adjust riser x coordinate and riser width for multiple series
int riserCnt = xAxis.getNumRisers();
if (riserCnt > 1) {
if (xAxis.isHorizontalAxis()) {
x = (int) (x - riserwidth / 2d + riserwidth / riserCnt * (riserIndex + 0.5));
} else {
x = (int) (x - riserwidth / 2d + riserwidth / riserCnt * (riserCnt - riserIndex - 0.5));
}
riserwidth /= riserCnt;
}
if (xAxis.isHorizontalAxis()) {
// adjust coordinate for negative series
if (y > yAxis.getPixelCoordinate(0)) {
y = yAxis.getPixelCoordinate(0);
}
int width = (int) Math.ceil(riserwidth);
width = (width == 0) ? 1 : width;
rectangles[i] = getVisibleRectangle((int) Math.floor(x - riserwidth / 2d), y, width, (int) riserHeight);
} else {
// adjust coordinate for negative series
if (y < yAxis.getPixelCoordinate(0)) {
y = yAxis.getPixelCoordinate(0);
}
int height = (int) Math.ceil(riserwidth);
height = (height == 0) ? 1 : height;
rectangles[i] = getVisibleRectangle((int) (y - riserHeight), (int) Math.floor(x - riserwidth / 2d), (int) riserHeight, height);
}
}
return rectangles;
}
use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.
the class ChartLayout method initAxisSize.
/**
* Initializes the size of axes.
*/
private void initAxisSize() {
axisLayoutDataMap.clear();
for (Axis axis : axes) {
AxisLayoutData layoutData = new AxisLayoutData(axis);
if (layoutData.titleLayoutdata == null || layoutData.tickLabelsLayoutdata == null || layoutData.tickMarksLayoutdata == null) {
continue;
}
axisLayoutDataMap.put(axis, layoutData);
Position position = axis.getPosition();
if (position == Position.Primary && axis.isHorizontalAxis()) {
bottomAxisHeight += layoutData.titleLayoutdata.heightHint + layoutData.tickLabelsLayoutdata.heightHint + layoutData.tickMarksLayoutdata.heightHint;
} else if (position == Position.Secondary && axis.isHorizontalAxis()) {
topAxisHeight += layoutData.titleLayoutdata.heightHint + layoutData.tickLabelsLayoutdata.heightHint + layoutData.tickMarksLayoutdata.heightHint;
} else if (position == Position.Primary && !axis.isHorizontalAxis()) {
leftAxisWidth += layoutData.titleLayoutdata.widthHint + layoutData.tickLabelsLayoutdata.widthHint + layoutData.tickMarksLayoutdata.widthHint;
} else if (position == Position.Secondary && !axis.isHorizontalAxis()) {
rightAxisWidth += layoutData.titleLayoutdata.widthHint + layoutData.tickLabelsLayoutdata.widthHint + layoutData.tickMarksLayoutdata.widthHint;
}
}
}
Aggregations