--- /dev/null
+/*
+ * 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);
+ }
+ }
+
+}