import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Display;
public class DACustomChartRenderer {
private boolean bInitialized = false;
case DACustomChartSeries.SERIES_STYLE_AREA:
drawAreaSeries(gc, series);
break;
+ case DACustomChartSeries.SERIES_STYLE_STEP:
+ drawStepSeries(gc, series);
+ break;
default:
break;
}
}
}
- if(r.height > DACustomChartPlotTooltip.TOOLTIP_SHOW_MIN){
+ if (r.height > DACustomChartPlotTooltip.TOOLTIP_SHOW_MIN) {
drawTooltip(gc);
}
drawRange(gc);
DACustomChartSeriesItem seriesItem;
Color color = series.getColor();
gc.setBackground(color);
- gc.setAlpha((int) (255*0.8));
+ gc.setAlpha((int) (255 * 0.8));
gc.setAntialias(SWT.ON);
int index = series.getPrevIndexByXvalue(plot.getVisibleStartX());
double currentX = seriesItem.getX();
int newPixcelX = plot.getXPixcelFromX(currentX, r);
-
+
int newPixcelY = plot.getYPixcelFromY(series, seriesItem.getY(), r);
for (int i = index; i < seriesItemSize; i++) {
}
// draw endVal
int endX = plot.getXPixcelFromX(plot.getValidEndX(), r);
- if(endX > newPixcelX){
+ if (endX > newPixcelX) {
gc.setLineStyle(SWT.LINE_DOT);
gc.drawLine(newPixcelX, newPixcelY, endX, newPixcelY);
gc.setLineStyle(SWT.LINE_CUSTOM);
Color color = series.getColor();
gc.setAntialias(SWT.ON);
- gc.setAlpha((int) (255*0.8));
+ gc.setAlpha((int) (255 * 0.8));
gc.setForeground(color);
gc.setBackground(color);
int index = series.getPrevIndexByXvalue(plot.getVisibleStartX());
newPixcelY = plot.getYPixcelFromY(series, seriesItem.getY(), r);
int[] polygon = { oldPixcelX, baseY, oldPixcelX, oldPixcelY,
newPixcelX, newPixcelY, newPixcelX, baseY };
- gc.setAlpha((int) (255*0.8));
+ gc.setAlpha((int) (255 * 0.8));
gc.fillPolygon(polygon);
- gc.setAlpha((int) (255*0.2));
+ gc.setAlpha((int) (255 * 0.2));
gc.drawPolygon(polygon);
if (currentX > plot.getVisibleEndX()) {
gc.setAlpha(255);
}
// draw endVal
int endX = plot.getXPixcelFromX(plot.getValidEndX(), r);
- if(endX > newPixcelX){
- gc.setAlpha((int) (255*0.4));
- int[] polygon = { newPixcelX, baseY, newPixcelX, newPixcelY,
- endX, newPixcelY, endX, baseY };
+ if (endX > newPixcelX) {
+ gc.setAlpha((int) (255 * 0.4));
+ int[] polygon = { newPixcelX, baseY, newPixcelX, newPixcelY, endX,
+ newPixcelY, endX, baseY };
gc.fillPolygon(polygon);
}
gc.setAlpha(255);
}
+
+ private void drawStepSeries(GC gc, DACustomChartSeries series) {
+ List<DACustomChartSeriesItem> seriesItems = series.getSeriesItemList();
+ if (null == seriesItems) {
+ return;
+ }
+ int seriesItemSize = seriesItems.size();
+ if (seriesItemSize < 1) {
+ return;
+ }
+
+ DACustomChartSeriesItem seriesItem = seriesItems.get(0);
+ int oldPixcelX = plot.getXPixcelFromX(seriesItem.getX(), r);
+ int oldPixcelY = plot.getYPixcelFromY(series, seriesItem.getY(), r);
+
+ if (seriesItemSize == 1) {
+ if (oldPixcelX < r.x) {
+ return;
+ }
+ Color color = seriesItem.getEventColor();
+ if (null == color) {
+ color = series.getColor();
+ }
+ gc.setForeground(color);
+ gc.drawPoint(oldPixcelX, oldPixcelY);
+ return;
+ }
+
+ Color color = series.getColor();
+ gc.setForeground(color);
+ gc.setLineStyle(SWT.LINE_SOLID);
+
+ int index = series.getPrevIndexByXvalue(plot.getVisibleStartX());
+ if (index < 0) {
+ index = 0;
+ }
+
+ seriesItem = seriesItems.get(index);
+ double currentX = seriesItem.getX();
+
+ int newPixcelX = plot.getXPixcelFromX(currentX, r);
+ int newPixcelY = plot.getYPixcelFromY(series, seriesItem.getY(), r);
+
+ for (int i = index; i < seriesItemSize; i++) {
+ seriesItem = seriesItems.get(i);
+ currentX = seriesItem.getX();
+
+ oldPixcelX = newPixcelX;
+ oldPixcelY = newPixcelY;
+
+ newPixcelX = plot.getXPixcelFromX(currentX, r);
+ newPixcelY = plot.getYPixcelFromY(series, seriesItem.getY(), r);
+
+ gc.drawLine(oldPixcelX, oldPixcelY, newPixcelX, oldPixcelY);
+ gc.drawLine(newPixcelX, oldPixcelY, newPixcelX, newPixcelY);
+ if (currentX > plot.getVisibleEndX()) {
+ return;
+ }
+ }
+ // draw endVal
+ int endX = plot.getXPixcelFromX(plot.getValidEndX(), r);
+ if (endX > newPixcelX) {
+ gc.setLineStyle(SWT.LINE_DOT);
+ gc.drawLine(newPixcelX, newPixcelY, endX, newPixcelY);
+ gc.setLineStyle(SWT.LINE_CUSTOM);
+ }
+ }
}