use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.
the class SeriesLabelMarker method paintControl.
@Override
public void paintControl(PaintEvent e) {
if (isDraw()) {
BaseChart baseChart = getBaseChart();
ISeriesSet seriesSet = baseChart.getSeriesSet();
ISeries[] series = seriesSet.getSeries();
for (ISeries serie : series) {
String label = serie.getId();
ISeriesSettings seriesSettings = baseChart.getSeriesSettings(label);
if (seriesSettings.isVisible()) {
/*
* Only draw is series is visible.
*/
int symbolSize = 1;
if (seriesSettings instanceof IPointSeriesSettings) {
symbolSize = ((IPointSeriesSettings) seriesSettings).getSymbolSize();
}
/*
* Draw the label
*/
e.gc.setForeground(getForegroundColor());
for (int i = 0; i < serie.getXSeries().length; i++) {
Point point = serie.getPixelCoordinates(i);
Point labelSize = e.gc.textExtent(label);
e.gc.drawText(label, (int) (point.x - labelSize.x / 2.0d), (int) (point.y - labelSize.y - symbolSize / 2.0d), true);
}
}
}
}
}
use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.
the class AxisZeroMarker method paintControl.
@Override
public void paintControl(PaintEvent e) {
if (isDraw()) {
BaseChart baseChart = getBaseChart();
Range xRange = baseChart.getAxisSet().getXAxes()[BaseChart.ID_PRIMARY_X_AXIS].getRange();
Range yRange = baseChart.getAxisSet().getYAxes()[BaseChart.ID_PRIMARY_Y_AXIS].getRange();
/*
* Mark the zero lines if possible.
* Otherwise draw the marker in half width.
*/
if (xRange.lower < 0 && xRange.upper > 0 && yRange.lower < 0 && yRange.upper > 0) {
Rectangle rectangle = baseChart.getPlotArea().getClientArea();
int width = rectangle.width;
int height = rectangle.height;
int xWidth;
int yHeight;
/*
* Dependent where the zero values are.
* xDelta and yDelta can't be zero -> protect from division by zero.
*/
double xDelta = xRange.upper - xRange.lower;
double yDelta = yRange.upper - yRange.lower;
// lower is negative
double xDiff = xRange.lower * -1;
double yDiff = yRange.upper;
// percent -> 0.0 - 1.0
double xPart = ((100 / xDelta) * xDiff) / 100;
// percent -> 0.0 - 1.0
double yPart = ((100 / yDelta) * yDiff) / 100;
xWidth = (int) (width * xPart);
yHeight = (int) (height * yPart);
/*
* Draw the line.
*/
e.gc.setForeground(getForegroundColor());
// Vertical line through zero
e.gc.drawLine(xWidth, 0, xWidth, height);
// Horizontal line through zero
e.gc.drawLine(0, yHeight, width, yHeight);
}
}
}
use of org.eclipse.swtchart.extensions.core.BaseChart in project swtchart by eclipse.
the class LegendMarker method paintControl.
@Override
public void paintControl(PaintEvent e) {
if (isDraw()) {
stringBuilder.delete(0, stringBuilder.length());
e.gc.setForeground(getForegroundColor());
//
BaseChart baseChart = getBaseChart();
double primaryValueX = baseChart.getSelectedPrimaryAxisValue(getX(), IExtendedChart.X_AXIS);
double primaryValueY = baseChart.getSelectedPrimaryAxisValue(getY(), IExtendedChart.Y_AXIS);
//
drawXAxes(primaryValueX);
drawYAxes(primaryValueY);
e.gc.drawText(stringBuilder.toString(), 10, 10);
}
}
Aggregations