Network:changed items order in tooltip 88/38188/4
authorhyeran74.kim <hyeran74.kim@samsung.com>
Tue, 14 Apr 2015 08:36:57 +0000 (17:36 +0900)
committerwoojin jung <woojin2.jung@samsung.com>
Wed, 10 Jun 2015 10:59:29 +0000 (03:59 -0700)
Change-Id: Id0e62dde51e9f07d01ad898e5f1d020b7f4470a0
Signed-off-by: hyeran74.kim <hyeran74.kim@samsung.com>
org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartRenderer.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/network/NetworkChartBoard.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/network/NetworkChartRenderer.java [new file with mode: 0644]

index 607ba21..c7fc513 100644 (file)
@@ -720,7 +720,7 @@ public class DAChartRenderer {
                }
        }
 
-       private int findColumnSeriesCount(int tooltipSize, int maxSize) {
+       public int findColumnSeriesCount(int tooltipSize, int maxSize) {
                int maxSeriesCount = (maxSize - DAChartPlotTooltip.TOOLTIP_MARGIN + DAChartPlotTooltip.TOOLTIP_BOTTOM_MARGIN)
                                / (DAChartPlotTooltip.TOOLTIP_TEXT_HEIGHT + DAChartPlotTooltip.TOOLTIP_TEXT_MARGIN);
                return (tooltipSize > maxSeriesCount) ? maxSeriesCount : tooltipSize;
index 02cd3a9..8bfbba0 100644 (file)
@@ -178,7 +178,8 @@ public class NetworkChartBoard extends DAChartBoard {
                if (null == chart) {
                        return;
                }
-
+               // set network chart renderer
+               chart.setChartRenderer(new NetworkChartRenderer());
                DAChartPlot plot = chart.getPlot();
                if (null == plot) {
                        return;
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/network/NetworkChartRenderer.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/network/NetworkChartRenderer.java
new file mode 100644 (file)
index 0000000..7ec25d0
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ *  Dynamic Analyzer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * Hyeran kim <hyeran74.kim@samsung.com>
+ * Jungwook Ryu <jungwook.ryu@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.network;
+
+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;
+
+public class NetworkChartRenderer extends DAChartRenderer {
+       protected List<DAChartSeries> tooltipList = null;
+
+       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>();
+
+               
+               boolean isMultiColumn = false;
+               int seriesCountPerColumn = findColumnSeriesCount(seriesList.size(), r.height);
+               if (seriesCountPerColumn < seriesList.size()) {
+                       isMultiColumn = true;
+               }
+
+               // make text,time & draw auxiliary line
+               int textWidthMax = 0;
+               double realXVal = tooltip.getStartVal();
+               int tooltipSize = 0;
+               
+               tooltipList = new ArrayList<DAChartSeries>();
+               tooltipList.add(seriesList.get(1)); // API
+               tooltipList.add(seriesList.get(0)); // STATE
+               tooltipList.add(seriesList.get(2)); // WAIT
+               
+               for(int i = 0; i < tooltipList.size(); i++) {
+                       DAChartSeries series = tooltipList.get(i);
+                       int index = series.getPrevIndexByXvalue(realXVal);
+                       
+                       String time = "";
+                       String text = "";
+                       Color color = null;
+                       if (index >= 0) {
+                               color = tooltipList.get(i).getSeriesItemList().get(index).getColor();
+                               text = (tooltipList.get(i).getName() + ": " +
+                                               tooltipList.get(i).getSeriesItemList().get(index).getTooltipText());
+                               time = toTimeFormat(tooltipList.get(i).getSeriesItemList().get(index).getX());
+                       }else{
+                               text = series.getName();
+                               color = null;
+                       }
+                       
+                       tooltipColor.add(color);
+                       tooltipTexts.add(text);
+                       tooltipTimes.add(time);
+                       
+                       int timeMargin = DAChartPlotTooltip.TOOLTIP_TIME_MARGIN;
+                       if (isMultiColumn) {
+                               timeMargin = 10;
+                       }
+                       int textWidth = gc.textExtent(tooltipTexts.get(i)).x + timeMargin + gc.textExtent(tooltipTimes.get(i)).x;
+                       if (textWidthMax < textWidth) {
+                               textWidthMax = textWidth;
+                       }
+               }
+
+               
+               /*
+                * Drawing Tooltip Box
+                */
+               int preTextWidthMargin = DAChartPlotTooltip.TOOLTIP_SERIES_RECT_LENGTH
+                               + (DAChartPlotTooltip.TOOLTIP_MARGIN * 2);
+               int startX = getTooltipStartX(realXVal, (preTextWidthMargin + textWidthMax)
+                               * (tooltipSize / seriesCountPerColumn), DAChartPlotTooltip.TOOLTIP_MARGIN);
+
+               int totalHeight;
+                       totalHeight = seriesCountPerColumn * DAChartPlotTooltip.TOOLTIP_TEXT_HEIGHT
+                                       + DAChartPlotTooltip.TOOLTIP_MARGIN + DAChartPlotTooltip.TOOLTIP_BOTTOM_MARGIN
+                                       + (seriesCountPerColumn - 1) * DAChartPlotTooltip.TOOLTIP_TEXT_MARGIN;
+               
+                       int startY = (r.y + r.height / 2) - (totalHeight / 2);
+               
+               int tooltipBoxWidth = (preTextWidthMargin + textWidthMax)+ DAChartPlotTooltip.TOOLTIP_MARGIN;
+               gc.setAlpha(150);
+               gc.setBackground(tooltip.getBackgroundColor());
+               gc.setForeground(tooltip.getForegroundColor());
+               gc.fillGradientRectangle(startX, startY, tooltipBoxWidth, totalHeight, true);
+               gc.setAlpha(255);
+               gc.setForeground(tooltip.getLineColor());
+               gc.drawRoundRectangle(startX, startY, tooltipBoxWidth, totalHeight, 5, 5);
+               gc.setFont(tooltip.getFont());
+
+               
+               /*
+                * Drawing Tooltip contents (color square, text, time)
+                */
+               String timeStr;
+               tooltipSize = -1;
+               for (int i = 0; i < tooltipList.size(); i++) {
+                       DAChartSeries series = tooltipList.get(i);
+                       if (series.isDisableTooltip()) {
+                               continue;
+                       } else {
+                               tooltipSize++;
+                       }
+
+                       int y = startY
+                                       + (DAChartPlotTooltip.TOOLTIP_TEXT_HEIGHT * (tooltipSize % seriesCountPerColumn))
+                                       + DAChartPlotTooltip.TOOLTIP_MARGIN + (i % seriesCountPerColumn)
+                                       * DAChartPlotTooltip.TOOLTIP_TEXT_MARGIN;
+                       Color col = tooltipColor.get(i);
+                       if (col == null) {
+                               gc.setBackground(series.getColor());
+                       } else {
+                               gc.setBackground(col);
+                       }
+
+                       int startColumnX = startX + (i / seriesCountPerColumn)
+                                       * (preTextWidthMargin + textWidthMax);
+                       gc.fillRectangle(startColumnX + DAChartPlotTooltip.TOOLTIP_MARGIN, y
+                                       + DAChartPlotTooltip.TOOLTIP_TEXT_HEIGHT / 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), startColumnX + DAChartPlotTooltip.TOOLTIP_MARGIN
+                                       + DAChartPlotTooltip.TOOLTIP_SERIES_RECT_LENGTH
+                                       + DAChartPlotTooltip.TOOLTIP_MARGIN, y, 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
+                                       + (i / seriesCountPerColumn) * (preTextWidthMargin + textWidthMax), y,
+                                       SWT.DRAW_DELIMITER | SWT.DRAW_TRANSPARENT);
+               }
+       }
+       
+}