[Title]custom chart(step series add)
authoryeongtaik.byeon <yeongtaik.byeon@samsung.com>
Fri, 14 Sep 2012 08:12:33 +0000 (17:12 +0900)
committeryeongtaik.byeon <yeongtaik.byeon@samsung.com>
Fri, 14 Sep 2012 08:12:33 +0000 (17:12 +0900)
[Type]feature
[Module]chart
[Priority]normal
[CQ#]
[Redmine#]6184
[Problem]
[Cause]
[Solution]
[TestCase]

org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DACustomChartRenderer.java

index 16df293..0cfa05e 100644 (file)
@@ -33,7 +33,6 @@ import org.eclipse.swt.graphics.Color;
 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;
@@ -87,12 +86,15 @@ public class DACustomChartRenderer {
                                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);
@@ -243,7 +245,7 @@ public class DACustomChartRenderer {
                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());
@@ -330,7 +332,7 @@ public class DACustomChartRenderer {
                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++) {
@@ -350,7 +352,7 @@ public class DACustomChartRenderer {
                }
                // 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);
@@ -388,7 +390,7 @@ public class DACustomChartRenderer {
 
                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());
@@ -413,9 +415,9 @@ public class DACustomChartRenderer {
                        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);
@@ -424,12 +426,79 @@ public class DACustomChartRenderer {
                }
                // 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);
+               }
+       }
 }