use of org.eclipse.swtchart.internal.series.Series in project swtchart by eclipse.
the class Axis method adjustRange.
/**
* Adjusts the axis range to the series belonging to the axis.
*
* @param update
* true if updating chart layout
*/
public void adjustRange(boolean update) {
if (isValidCategoryAxis()) {
setRange(new Range(0, categorySeries.length - 1));
return;
}
double minimum = Double.NaN;
double maximum = Double.NaN;
for (ISeries series : chart.getSeriesSet().getSeries()) {
int axisId = direction == Direction.X ? series.getXAxisId() : series.getYAxisId();
if (!series.isVisible() || getId() != axisId) {
continue;
}
// get axis length
int length;
if (isHorizontalAxis) {
length = chart.getPlotArea().getSize().x;
} else {
length = chart.getPlotArea().getSize().y;
}
// get min and max value of series
Range range = ((Series) series).getAdjustedRange(this, length);
if (Double.isNaN(minimum) || range.lower < minimum) {
minimum = range.lower;
}
if (Double.isNaN(maximum) || range.upper > maximum) {
maximum = range.upper;
}
}
// set adjusted range
if (!Double.isNaN(minimum) && !Double.isNaN(maximum)) {
if (minimum == maximum) {
double margin = (minimum == 0) ? 1d : Math.abs(minimum / 2d);
minimum -= margin;
maximum += margin;
}
setRange(new Range(minimum, maximum), update);
}
}
use of org.eclipse.swtchart.internal.series.Series in project swtchart by eclipse.
the class PlotArea method paintControl.
/*
* @see PaintListener#paintControl(PaintEvent)
*/
public void paintControl(PaintEvent e) {
Point p = getSize();
GC gc = e.gc;
// draw the plot area background
Color oldBackground = gc.getBackground();
gc.setBackground(getBackground());
gc.fillRectangle(0, 0, p.x, p.y);
// draw grid
for (IAxis axis : chart.getAxisSet().getAxes()) {
((Grid) axis.getGrid()).draw(gc, p.x, p.y);
}
// draw behind series
for (ICustomPaintListener listener : paintListeners) {
if (listener.drawBehindSeries()) {
listener.paintControl(e);
}
}
// draw series. The line series should be drawn on bar series.
for (ISeries series : chart.getSeriesSet().getSeries()) {
if (series instanceof IBarSeries) {
((Series) series).draw(gc, p.x, p.y);
}
}
for (ISeries series : chart.getSeriesSet().getSeries()) {
if (series instanceof ILineSeries) {
((Series) series).draw(gc, p.x, p.y);
}
}
// draw over series
for (ICustomPaintListener listener : paintListeners) {
if (!listener.drawBehindSeries()) {
listener.paintControl(e);
}
}
e.gc.setBackground(oldBackground);
}
Aggregations