[Title] modifying da chart renderer
authorkamuru <kamuru@kamuru-Samsung-Desktop-System.(none)>
Fri, 15 Nov 2013 08:41:15 +0000 (17:41 +0900)
committerkamuru <kamuru@kamuru-Samsung-Desktop-System.(none)>
Fri, 15 Nov 2013 08:41:15 +0000 (17:41 +0900)
[Desc.] modifying da chart renderer for processes chart tooltip
[Issue] http://172.21.17.25/redmine/issues/5443

org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChart.java
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartRenderer.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUChart.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/ProcessesChartRenderer.java [new file with mode: 0644]

index 7b4d263..c7f804c 100644 (file)
@@ -139,7 +139,6 @@ public class DAChart extends Canvas {
        }
 
        private PaintListener chartPaintListener = new PaintListener() {
-
                @Override
                public void paintControl(PaintEvent e) {
                        redrawChart();
@@ -185,7 +184,6 @@ public class DAChart extends Canvas {
        }
 
        private ControlListener chartControlListener = new ControlListener() {
-
                @Override
                public void controlMoved(ControlEvent e) {
                }
@@ -210,9 +208,12 @@ public class DAChart extends Canvas {
                        this.removeListener(SWT.MouseExit, chartTooltipListener);
                }
        }
+       
+       public void setChartRenderer(DAChartRenderer chartRenderer) {
+               this.chartRenderer = chartRenderer;
+       }
 
        private Listener chartTooltipListener = new Listener() {
-
                @Override
                public void handleEvent(Event event) {
 
index 6ef5004..002dbe0 100644 (file)
@@ -50,9 +50,9 @@ public class DAChartRenderer {
        private static final double EVENT_HEIGHT_MARGIN_RATIO = 0.20;
        private static final double LOAD_HEIGHT_MARGIN_RATIO = 0.20;
        private boolean bInitialized = false;
-       private List<DAChartSeries> seriesList = null;
-       private DAChartPlot plot = null;
-       private Rectangle r = null;
+       protected List<DAChartSeries> seriesList = null;
+       protected DAChartPlot plot = null;
+       protected Rectangle r = null;
 
        private static final int SCREENSHOT_Y_POSITION_MINI = 4;
        private static final int SCREENSHOT_SELECTED_Y_POSITION = 4;
@@ -381,7 +381,7 @@ public class DAChartRenderer {
                gc.setLineWidth(oldLineWidth);
        }
 
-       private int getTooltipStartX(double startVal, int width, int margin) {
+       protected int getTooltipStartX(double startVal, int width, int margin) {
                int ret = plot.getXPixcelFromX(startVal);
                if (ret + width > r.x + r.width) {
                        ret = ret - width - margin;
@@ -394,7 +394,7 @@ public class DAChartRenderer {
                return ret;
        }
 
-       private String toTimeFormat(double sec) {
+       protected String toTimeFormat(double sec) {
                String ret;
                int second = (int) sec;
                int ms = ((int) (sec * 10)) % 10;
@@ -412,7 +412,7 @@ public class DAChartRenderer {
                return ret;
        }
 
-       private boolean checkOverlapFromPrevItem(DAChartSeries series, int index) {
+       protected boolean checkOverlapFromPrevItem(DAChartSeries series, int index) {
                double val = series.getSeriesItemList().get(index).getX();
                double prevVal;
 
@@ -431,7 +431,7 @@ public class DAChartRenderer {
                return false;
        }
 
-       private double getMaxYToDraw(DAChartSeries series,
+       protected double getMaxYToDraw(DAChartSeries series,
                        int startIndex) {
                if(!plot.isSeriesHeightRange()) {
                        return plot.getVisibleEndY();
@@ -462,7 +462,7 @@ public class DAChartRenderer {
                return maxY * 1.1;
        }
        
-       public void drawTooltip(GC gc) {
+       protected void drawTooltip(GC gc) {
                if (plot instanceof DAScreenshotChartPlot) {
                        return;
                }
@@ -1510,13 +1510,15 @@ public class DAChartRenderer {
 
        private void drawMultiLineSeries(GC gc, DAChartSeries series,
                        int seriesIndex, int seriesSize) {
-               Rectangle rect = new Rectangle(r.x, r.y
-                               + (r.height / seriesSize * seriesIndex), r.width, r.height
-                               / seriesSize);
+               Rectangle rect = new Rectangle(r.x, 
+                               r.y + r.height * seriesIndex / seriesSize,
+                               r.width,
+                               r.height / seriesSize);
 
                if (seriesIndex != 0) {
                        gc.setForeground(ColorResources.UI_EVENT_CHART_SEPERATE_LINE);
-                       gc.drawLine(rect.x, rect.y, rect.width, rect.y);
+                       gc.drawLine(rect.x, r.height * seriesIndex / seriesSize,
+                                       rect.width, r.height * seriesIndex / seriesSize);
                }
 
                gc.setForeground(ColorResources.SERIES_NAME_ANNOTATION);
@@ -1525,7 +1527,7 @@ public class DAChartRenderer {
                gc.setFont(nameAnnotationFont);
                gc.drawText(series.getName(), rect.x + 3,
                                rect.y + rect.height / 2 - gc.stringExtent(series.getName()).y
-                                               / 2 + seriesIndex, true);
+                                               / 2, true);
                gc.setFont(oriFont);
                
                List<DAChartSeriesItem> seriesItems = series.getSeriesItemList();
@@ -1541,12 +1543,12 @@ public class DAChartRenderer {
                if (index < 0) {
                        index = 0;
                }
+
+               DAChartSeriesItem seriesItem = seriesItems.get(0);
                
                double maxY = getMaxYToDraw(series, index);
-               
-               DAChartSeriesItem seriesItem = seriesItems.get(0);
                int oldPixcelX = plot.getXPixcelFromX(seriesItem.getX(), r);
-               int oldPixcelY = plot.getYPixcelFromY(maxY, seriesItem.getY(), r);
+               double oldY = seriesItem.getY();
 
                if (seriesItemSize == 1) {
                        if (oldPixcelX < r.x) {
@@ -1557,7 +1559,8 @@ public class DAChartRenderer {
                                color = series.getColor();
                        }
                        gc.setForeground(color);
-                       gc.drawPoint(oldPixcelX, oldPixcelY);
+                       gc.drawPoint(oldPixcelX,
+                                       plot.getYPixcelFromY(maxY, seriesItem.getY(), r));
                        return;
                }
 
@@ -1570,22 +1573,21 @@ public class DAChartRenderer {
                double currentX = seriesItem.getX();
 
                int newPixcelX = plot.getXPixcelFromX(currentX, r);
-               int newPixcelY = plot.getYPixcelFromY(maxY, seriesItem.getY(), r);
-
+               double newY = seriesItem.getY();
+               
                for (int i = index; i < seriesItemSize; i++) {
                        seriesItem = seriesItems.get(i);
                        currentX = seriesItem.getX();
 
                        oldPixcelX = newPixcelX;
-                       oldPixcelY = newPixcelY;
+                       oldY = newY;
 
                        newPixcelX = plot.getXPixcelFromX(currentX, r);
-                       newPixcelY = plot.getYPixcelFromY(maxY, seriesItem.getY(), r);
-
-                       gc.drawLine(oldPixcelX, 
-                                       oldPixcelY / seriesSize + r.height * seriesIndex / seriesSize, 
+                       newY = seriesItem.getY();
+                       gc.drawLine(oldPixcelX,
+                                       (int) (rect.y + rect.height * (1.0 - (oldY / maxY))),
                                        newPixcelX,
-                                       newPixcelY / seriesSize + r.height * seriesIndex / seriesSize);
+                                       (int) (rect.y + rect.height * (1.0 - (newY / maxY))));
                        if (currentX > plot.getVisibleEndX()) {
                                return;
                        }
index 15bc1eb..1a05dca 100644 (file)
@@ -160,8 +160,9 @@ public class CPUChart extends TimelineChart {
                                        processItem = new DAChartBoardHeightChangeableItem(item, "Processes");
                                        processItem.useExpand(false);
 
-                                       DAChart childChart = processItem.getChart();
-                                       DAChartPlot childPlot = childChart.getPlot();
+                                       DAChart processesChart = processItem.getChart();
+                                       processesChart.setChartRenderer(new ProcessesChartRenderer());
+                                       DAChartPlot childPlot = processesChart.getPlot();
                                        DAChartPlotTooltip tooltip = new DAChartPlotTooltip(-1);
 
                                        childPlot.setBackgroundImage(ImageResources.BG_GRADIENT);
@@ -174,7 +175,7 @@ public class CPUChart extends TimelineChart {
                                        childPlot.setShowAxis(true);
                                        childPlot.setMarkers(chartBoard.getMarkers());
 
-                                       DAPopupMenu popupMenu = new DAPopupMenu(childChart);
+                                       DAPopupMenu popupMenu = new DAPopupMenu(processesChart);
                                        popupMenu.setFont(FontResources.CONTEXT_MENU_ITEM_FONT);
                                        DAPopupMenuItem startItem = new DAPopupMenuItem(popupMenu);
                                        startItem
@@ -209,27 +210,36 @@ public class CPUChart extends TimelineChart {
 
                                        TimelineChartMouseEventListener timelineChartMouseEventListener = new TimelineChartMouseEventListener(
                                                        popupMenu, chartBoard.getTimeline());
-                                       childChart
+                                       processesChart
                                                        .addMouseListener(timelineChartMouseEventListener);
-                                       childChart
+                                       processesChart
                                                        .addMouseMoveListener(timelineChartMouseEventListener);
-                                       childChart
+                                       processesChart
                                                        .addMouseTrackListener(new TimelineChartMouseTrackAdapter(
                                                                        chartBoard.getTimeline()));
                                }
                        });
                }
 
-               String[] processLoadDatas = logData.getProcessLoad().split(COMMA);
-
-               if (time > 7) {
-                       processLoadDatas = new String[] { processLoadDatas[0],
-                                       processLoadDatas[1], "1", "10", "2", "20", "3", "70", "4",
-                                       "50", "5", "90", "6", "30" };
-               } else if (time > 4) {
-                       processLoadDatas = new String[] { processLoadDatas[0],
-                                       processLoadDatas[1], "1", "10", "2", "20", "3", "70", "4",
-                                       "50" };
+//             String[] processLoadDatas = logData.getProcessLoad().split(COMMA);
+//
+//             if (time > 7) {
+//                     processLoadDatas = new String[] { processLoadDatas[0],
+//                                     processLoadDatas[1], "1", "10", "2", "20", "3", "70", "4",
+//                                     "50", "5", "90", "6", "30" };
+//             } else if (time > 4) {
+//                     processLoadDatas = new String[] { processLoadDatas[0],
+//                                     processLoadDatas[1], "1", "4", "2", "2", "3", "3", "4",
+//                                     "7" };
+//             }
+               
+               
+               int max = 20;
+               String[] processLoadDatas = new String[max * 2];
+               for(int i = 1; i <= max * 2; i++) {
+                       processLoadDatas[i - 1] = Integer.toString(i);
+//                     processLoadDatas[++i - 1] = Integer.toString(i);
+                       processLoadDatas[++i - 1] = Integer.toString(1);
                }
 
                int prevChildSize = childSeriesMap.size();
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/ProcessesChartRenderer.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/ProcessesChartRenderer.java
new file mode 100644 (file)
index 0000000..358b841
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+ *  Dynamic Analyzer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * Sanghyun Lee <sanghyunnim.lee@samsung.com>
+ * Juyoung Kim <j0.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ * 
+ */
+
+package org.tizen.dynamicanalyzer.ui.timeline.chart;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.tizen.dynamicanalyzer.widgets.chart.DAChartPlotTooltip;
+import org.tizen.dynamicanalyzer.widgets.chart.DAChartRenderer;
+import org.tizen.dynamicanalyzer.widgets.chart.DAChartSeries;
+import org.tizen.dynamicanalyzer.widgets.chart.DAUIEventChartPlot;
+
+public class ProcessesChartRenderer extends DAChartRenderer {
+       @Override
+       protected void drawTooltip(GC gc) {
+               DAChartPlotTooltip tooltip = plot.getTooltip();
+               if (tooltip == null || tooltip.shouldBeDrawn() == false
+                               || tooltip.getStartVal() == -1) {
+                       return;
+               }
+
+               gc.setFont(tooltip.getFont());
+
+               List<String> tooltipTexts = new ArrayList<String>();
+               List<String> tooltipTimes = new ArrayList<String>();
+               List<Color> tooltipColor = new ArrayList<Color>();
+
+               // make text,time & draw auxiliary line
+               int textWidthMax = 0;
+               int textHeightMax = 0;
+               double realXVal = tooltip.getStartVal();
+               int tooltipSize = 0;
+               for (int i = 0; i < seriesList.size(); i++) {
+                       DAChartSeries series = seriesList.get(i);
+                       tooltipSize++;
+
+                       int index = series.getPrevIndexByXvalue(realXVal);
+                       String text = "";
+                       String time = "";
+                       Color color;
+                       if (index >= 0) {
+                               double xVal = series.getSeriesItemList().get(index).getX();
+
+                               text += series.getName() + ": ";
+                               time += toTimeFormat(xVal);
+
+                               if (series.isSummarizeTooltip()
+                                               && checkOverlapFromPrevItem(series, index)) {
+                                       text += series.getSummarizeString();
+                               } else {
+                                       text += series.getSeriesItemList().get(index)
+                                                       .getTooltipText();
+                               }
+
+                               gc.setForeground(tooltip.getLineColor());
+                               gc.setLineStyle(SWT.LINE_DOT);
+                               gc.setLineWidth(1);
+
+                               gc.drawLine(plot.getXPixcelFromX(xVal), 0,
+                                               plot.getXPixcelFromX(xVal), r.height);
+                               gc.setLineStyle(SWT.LINE_CUSTOM);
+
+                               // event color
+                               color = series.getSeriesItemList().get(index).getEventColor();
+                       } else {
+                               text = series.getName();
+                               color = null;
+                       }
+
+                       tooltipTexts.add(text);
+                       tooltipTimes.add(time);
+                       tooltipColor.add(color);
+
+                       int textWidth = gc.textExtent(text).x
+                                       + DAChartPlotTooltip.TOOLTIP_TIME_MARGIN
+                                       + gc.textExtent(time).x;
+                       int textHeight = gc.textExtent(text).y;
+                       if (textWidthMax < textWidth) {
+                               textWidthMax = textWidth;
+                       }
+                       if (textHeightMax < textHeight) {
+                               textHeightMax = textHeight;
+                       }
+               }
+
+               int preTextWidthMargin = DAChartPlotTooltip.TOOLTIP_MARGIN
+                               + DAChartPlotTooltip.TOOLTIP_SERIES_RECT_LENGTH
+                               + DAChartPlotTooltip.TOOLTIP_MARGIN;
+               int startX = getTooltipStartX(realXVal, textWidthMax
+                               + preTextWidthMargin, DAChartPlotTooltip.TOOLTIP_MARGIN);
+
+               int totalHeight = tooltipSize * textHeightMax
+                               + DAChartPlotTooltip.TOOLTIP_MARGIN
+                               + DAChartPlotTooltip.TOOLTIP_MARGIN;
+
+               int startY = (r.y + r.height / 2) - (totalHeight / 2);
+
+               gc.setAlpha(150);
+               gc.setBackground(tooltip.getBackgroundColor());
+               gc.setForeground(tooltip.getForegroundColor());
+               gc.fillGradientRectangle(startX, startY, preTextWidthMargin
+                               + textWidthMax + DAChartPlotTooltip.TOOLTIP_MARGIN,
+                               totalHeight, true);
+               gc.setAlpha(255);
+               gc.setForeground(tooltip.getLineColor());
+               gc.drawRoundRectangle(startX, r.y, preTextWidthMargin + textWidthMax
+                               + DAChartPlotTooltip.TOOLTIP_MARGIN, r.height, 5, 5);
+               gc.setFont(tooltip.getFont());
+
+               String timeStr;
+               tooltipSize = -1;
+               for (int i = 0; i < seriesList.size(); i++) {
+                       DAChartSeries series;
+                       if (plot instanceof DAUIEventChartPlot) {
+                               series = seriesList.get((int) (seriesList.size() * tooltip
+                                               .getYPosRatio()));
+                       } else {
+                               series = seriesList.get(i);
+                               if (series.isDisableTooltip()) {
+                                       continue;
+                               } else {
+                                       tooltipSize++;
+                               }
+                       }
+
+                       int yPosition = r.y + r.height * i / seriesList.size() + r.height
+                                       / seriesList.size() / 2 - textHeightMax / 2;
+
+                       Color col = tooltipColor.get(i);
+                       if (col == null) {
+                               gc.setBackground(series.getColor());
+                       } else {
+                               gc.setBackground(col);
+                       }
+                       gc.fillRectangle(
+                                       startX + DAChartPlotTooltip.TOOLTIP_MARGIN,
+                                       yPosition + textHeightMax / 2
+                                                       - DAChartPlotTooltip.TOOLTIP_SERIES_RECT_LENGTH / 2,
+                                       DAChartPlotTooltip.TOOLTIP_SERIES_RECT_LENGTH,
+                                       DAChartPlotTooltip.TOOLTIP_SERIES_RECT_LENGTH);
+                       gc.setBackground(tooltip.getBackgroundColor());
+
+                       gc.setForeground(tooltip.getTextColor());
+                       gc.drawText(tooltipTexts.get(i), startX
+                                       + DAChartPlotTooltip.TOOLTIP_MARGIN
+                                       + DAChartPlotTooltip.TOOLTIP_SERIES_RECT_LENGTH
+                                       + DAChartPlotTooltip.TOOLTIP_MARGIN, yPosition,
+                                       SWT.DRAW_DELIMITER | SWT.DRAW_TRANSPARENT);
+
+                       gc.setForeground(tooltip.getTimeColor());
+                       timeStr = tooltipTimes.get(i);
+                       gc.drawText(
+                                       tooltipTimes.get(i),
+                                       startX + DAChartPlotTooltip.TOOLTIP_MARGIN
+                                                       + DAChartPlotTooltip.TOOLTIP_SERIES_RECT_LENGTH
+                                                       + DAChartPlotTooltip.TOOLTIP_MARGIN + textWidthMax
+                                                       - DAChartPlotTooltip.TOOLTIP_MARGIN
+                                                       - gc.textExtent(timeStr).x, yPosition,
+                                       SWT.DRAW_DELIMITER | SWT.DRAW_TRANSPARENT);
+               }
+       }
+}