[UI] Add ChartRenderer for new File Analysis chart 42/21442/1
authorjungwook.ryu <jungwook.ryu@samsung.com>
Wed, 21 May 2014 02:04:27 +0000 (11:04 +0900)
committerjungwook.ryu <jungwook.ryu@samsung.com>
Wed, 21 May 2014 02:07:03 +0000 (11:07 +0900)
Change-Id: If73c008d6060e1245449b671496623f6d2863d53
Signed-off-by: jungwook.ryu <jungwook.ryu@samsung.com>
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartRenderer.java
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartSeries.java
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartSeriesItem.java

index 6c9a59e..b53fc66 100644 (file)
@@ -216,6 +216,9 @@ public class DAChartRenderer {
                        case DAChartSeries.SERIES_STYLE_LAST_CONTINUE_STEP:
                                drawStepSeries(gc, series, false);
                                break;
+                       case DAChartSeries.SERIES_STYLE_STATE_AREA:
+                               drawStateAreaSeries(gc, series, i, seriesList.size());
+                               break;
                        default:
                                DA_LOG.debug("Undefined series style");
                                break;
@@ -1023,7 +1026,116 @@ public class DAChartRenderer {
 
                gc.setAlpha(255);
        }
-
+       
+       private void drawStateAreaSeries(GC gc, DAChartSeries series, int seriesIndex, 
+                       int seriesSize) {
+               List<DAChartSeriesItem> seriesItems = series.getSeriesItemList();
+               if (null == seriesItems) {
+                       return;
+               }
+               
+               int seriesItemSize = seriesItems.size();
+               if (seriesItemSize < 1) {
+                       return;
+               }
+               int index = series.getPrevIndexByXvalue(plot.getVisibleStartX());
+               if (index < 0) {
+                       index = 0;
+               }
+               
+               final int MARGIN_PERCENT = 20;                  // It's mean 20%
+               final int STATE_AREA_BAR_WIDTH = 1;
+               final int DIAGONAL_DIVIDE = 16;                 // divided in 16 pieces for diagonal box size.
+               final Color DIAGONAL_BOX_COLOR = ColorResources.WHITE;
+               /*
+                * Formula to divide in equal series heights.
+                */
+               int margin = (int)((r.height * (MARGIN_PERCENT / 100.0)) / (seriesSize + 1));
+               int areaHeight = (r.height - margin * (seriesSize + 1)) / seriesSize;
+               int pixcelStartY = (margin * (seriesIndex + 1)) + (areaHeight * seriesIndex);
+               
+               List<DAChartSeriesItem> barSeriesItems = new ArrayList<DAChartSeriesItem>();
+               /*
+                * 1. Draw Start/End Status Area.
+                */
+               for (int i = 0; i < seriesItemSize; i++) {
+                       DAChartSeriesItem seriesItem = seriesItems.get(i);
+                       DAChartSeriesItem endSeriesItem = null;
+                       
+                       int type = (int) seriesItem.getY();
+                       if (DAChartSeriesItem.SERIES_AREA_START == type) {
+                               int startCount = 1;
+                               /*
+                                * Find end series item matched with start series item.
+                                */
+                               for (int ii = i + 1; ii < seriesItemSize; ii++) {
+                                       DAChartSeriesItem nextSeriesItem = seriesItems.get(ii);
+                                       int nextType = (int) nextSeriesItem.getY();
+                                       if (nextType == DAChartSeriesItem.SERIES_AREA_START) {
+                                               startCount += 1;
+                                       } else if (nextType == DAChartSeriesItem.SERIES_AREA_END) {
+                                               --startCount;
+                                               if (startCount == 0) {
+                                                       endSeriesItem = nextSeriesItem;
+                                                       break;
+                                               }
+                                       }
+                               }
+                               Color foreGroundColor = seriesItem.getGradationForegroundColor();
+                               Color backGroundcolor = seriesItem.getColor();
+                               gc.setForeground(foreGroundColor);
+                               gc.setBackground(backGroundcolor);
+                               
+                               int pixcelStartX = plot.getXPixcelFromX(seriesItem.getX(), r);
+                               int pixcelWidth;
+                               if (endSeriesItem != null) {
+                                       pixcelWidth = plot.getXPixcelFromX(endSeriesItem.getX(), r) - pixcelStartX;
+                               } else {
+                                       /*
+                                        * endSeriesItem is null when end series is not exist. this case, draw it as much as visibleEndX.
+                                        */
+                                       pixcelWidth = plot.getXPixcelFromX(plot.getVisibleEndX(), r) - pixcelStartX;
+                               }
+                               gc.fillRectangle(pixcelStartX, pixcelStartY, pixcelWidth, areaHeight);
+                               
+                               /*
+                                * If it's needed, draw diagonal line. diagonal line is composed of square boxes.
+                                * Direction of diagonal line is right top to left down like "/".
+                                */
+                               if (seriesItem.getDiagonal()) {
+                                       int diagonalBoxSize = areaHeight / DIAGONAL_DIVIDE;
+                                       gc.setForeground(DIAGONAL_BOX_COLOR);
+                                       gc.setBackground(DIAGONAL_BOX_COLOR);
+                                       for (int j = 0; j < 16; j++) {
+                                               int boxY = pixcelStartY + (diagonalBoxSize * j);
+                                               // Formula to draw diagonal line like "/" 
+                                               for (int k = 3 - (j % 4) - (j / 4); k < pixcelWidth; k = k + 3) {
+                                                       int boxX = diagonalBoxSize * k + pixcelStartX;
+                                                       if (pixcelStartX <= boxX && boxX <= pixcelWidth + pixcelStartX - diagonalBoxSize) {
+                                                               gc.fillRectangle(boxX, boxY, diagonalBoxSize, diagonalBoxSize);
+                                                       }
+                                               }
+                                       }
+                               }
+                       } else if (DAChartSeriesItem.SERIES_AREA_BAR == type) {
+                               barSeriesItems.add(seriesItem);
+                       }
+               }
+               
+               /*
+                * 2. Draw Bar series
+                */
+               for (int i = 0; i < barSeriesItems.size(); i++) {
+                       DAChartSeriesItem barSeriesItem = barSeriesItems.get(i);
+                       Color foreGroundColor = barSeriesItem.getGradationForegroundColor();
+                       Color backGroundcolor = barSeriesItem.getColor();
+                       gc.setForeground(foreGroundColor);
+                       gc.setBackground(backGroundcolor);
+                       int pixcelStartX = plot.getXPixcelFromX(barSeriesItem.getX(), r);
+                       gc.fillRectangle(pixcelStartX, pixcelStartY, STATE_AREA_BAR_WIDTH, areaHeight);
+               }
+       }
+       
        private void drawStepSeries(GC gc, DAChartSeries series, boolean bEndVal) {
                List<DAChartSeriesItem> seriesItems = series.getSeriesItemList();
                if (seriesItems == null) {
index 181d898..0f8887a 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact: 
+ * Jungwook Ryu <jungwook.ryu@samsung.com>
  * yeongtaik byeon <yeongtaik.byeon@samsung.com>
  * Juyoung Kim <j0.kim@samsung.com>
  *
@@ -49,6 +50,7 @@ public class DAChartSeries {
        public static final int SERIES_STYLE_STATE = 13;
        public static final int SERIES_STYLE_LAST_CONTINUE_STEP = 14;
        public static final int SERIES_STYLE_MULTI_LINE = 15;
+       public static final int SERIES_STYLE_STATE_AREA = 16;
 
        public static final double SERIES_DEFAULT_BAR_WIDTH = 0.5;
        public static final int SERIES_BAR_ALIGN_LEFT = 0;
index 77a5395..413def0 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact: 
+ * Jungwook Ryu <jungwook.ryu@samsung.com>
  * yeongtaik byeon <yeongtaik.byeon@samsung.com>
  * Juyoung Kim <j0.kim@samsung.com>
  *
@@ -35,6 +36,9 @@ public class DAChartSeriesItem {
        public static final int SERIES_ARROW_NONE = 0;
        public static final int SERIES_ARROW_LEFT = -1;
        public static final int SERIES_ARROW_RIGHT = 1;
+       public static final int SERIES_AREA_START = 0;
+       public static final int SERIES_AREA_END = 1;
+       public static final int SERIES_AREA_BAR = 2;
        protected double x = 0;
        private double y = 0;
        private double barWidth = -1;
@@ -43,6 +47,7 @@ public class DAChartSeriesItem {
        private Image image = null;
        private String tooltipText;
        private boolean showTimeInfo = true;
+       private boolean diagonal = false;
        
        public DAChartSeriesItem(double x, double y) {
                this.x = x;
@@ -89,6 +94,16 @@ public class DAChartSeriesItem {
                this.color = gradationBackgroundColor;
                this.tooltipText = tooltipText;
        }
+       
+       public DAChartSeriesItem(double x, double y,
+                       Color gradationForegroundColor,
+                       Color gradationBackgroundColor, 
+                       boolean diagonal,
+                       String tooltipText) {
+               this(x, y, gradationForegroundColor, 
+                               gradationBackgroundColor, tooltipText);
+               this.diagonal = diagonal;
+       }
 
        public DAChartSeriesItem(double x, double y, Image image) {
                this.x = x;
@@ -152,4 +167,8 @@ public class DAChartSeriesItem {
                        Color gradationForegroundColor) {
                this.gradationForegroundColor = gradationForegroundColor;
        }
+       
+       public boolean getDiagonal() {
+               return this.diagonal; 
+       }
 }