From: kamuru Date: Wed, 20 Nov 2013 06:53:47 +0000 (+0900) Subject: [Title] Add new chart widget(ver 0.1) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6e5364fa2d345813fc452d77c31994a2209eedf0;p=sdk%2Ftools%2Fdynamic-analyzer.git [Title] Add new chart widget(ver 0.1) [Desc.] Add new chart widget for kernerl profiling [Issue] --- diff --git a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartPlot.java b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartPlot.java index 28db9e2..9d0482d 100644 --- a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartPlot.java +++ b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartPlot.java @@ -223,7 +223,8 @@ public class DAChartPlot { } public int getXPixcelFromX(double x, Rectangle r) { - return (int) (((double) r.width) * (x - visibleStartX) / (visibleEndX - visibleStartX)); + return (int) Math.round((r.width) * (x - visibleStartX) + / (visibleEndX - visibleStartX)); } public int getXPixcelFromX(double x) { diff --git a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartRenderer.java b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartRenderer.java index 4201f49..35cc7f2 100644 --- a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartRenderer.java +++ b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chart/DAChartRenderer.java @@ -49,7 +49,7 @@ public class DAChartRenderer { private static final int EVENT_WIDTH = 2; private static final double EVENT_HEIGHT_MARGIN_RATIO = 0.20; private static final double LOAD_HEIGHT_MARGIN_RATIO = 0.20; - private boolean bInitialized = false; + protected boolean bInitialized = false; protected List seriesList = null; protected DAChartPlot plot = null; protected Rectangle r = null; @@ -90,8 +90,8 @@ public class DAChartRenderer { drawRange(gc); } - private void drawToGc(GC gc, DAChart chart) { - if (false == bInitialized) { + protected boolean preDraw(GC gc, DAChart chart) { + if (!bInitialized) { initialize(gc, chart); } plot = chart.getPlot(); @@ -99,98 +99,107 @@ public class DAChartRenderer { // draw background Image Image backImage = plot.getBackgroundImage(); - if (null != backImage) { + if (backImage != null) { Rectangle rect = backImage.getBounds(); gc.drawImage(backImage, rect.x, rect.y, rect.width, rect.height, r.x, r.y, r.width, r.height); } - if (null != seriesList) { - int seriesSize = seriesList.size(); - DAChartSeries series; + if (seriesList == null) { + return false; + } - if (plot.getAutoHeightRange() == AutoRangeType.SEMI_AUTO || - plot.getAutoHeightRange() == AutoRangeType.AUTO) { - double maxY = 0; - for (int i = 0; i < seriesSize; i++) { - double tempY = seriesList.get(i).getMaxY(); - if (maxY < tempY) { - maxY = tempY; - } - } - if (maxY * 1.1 > plot.getVisibleEndY() * 1.1) { - plot.setAxisEndY(maxY * 1.1); - } - } - for (int i = 0; i < seriesSize; i++) { - series = seriesList.get(i); - switch (series.getStyle()) { - case DAChartSeries.SERIES_STYLE_EVENT: - drawEventSeries(gc, series); - break; - case DAChartSeries.SERIES_STYLE_EVENT_AREA: - drawEventAreaSeries(gc, series); - break; - case DAChartSeries.SERIES_STYLE_BAR: - drawBarSeries(gc, series); - break; - case DAChartSeries.SERIES_STYLE_NONE: - case DAChartSeries.SERIES_STYLE_LINE: - drawLineSeries(gc, series, false); - break; - case DAChartSeries.SERIES_STYLE_AREA: - drawAreaSeries(gc, series, false); - break; - case DAChartSeries.SERIES_STYLE_MULTI_CHECK_BAR: - drawMultiCheckBarSeries(gc, series, i, seriesSize); - break; - case DAChartSeries.SERIES_STYLE_STEP: - drawStepSeries(gc, series, true); - break; - case DAChartSeries.SERIES_STYLE_IMAGE: - drawImageSeries(gc, series); - break; - case DAChartSeries.SERIES_STYLE_LOAD: - drawLoadSeries(gc, series); - break; - case DAChartSeries.SERIES_STYLE_ARROW: - drawArrowSeries(gc, series); - break; - case DAChartSeries.SERIES_STYLE_STATE: - drawStateSeries(gc, series); - break; - case DAChartSeries.SERIES_STYLE_LAST_CONTINUE_STEP: - drawStepSeries(gc, series, false); - break; - case DAChartSeries.SERIES_STYLE_MULTI_LINE: - drawMultiLineSeries(gc, series, i, seriesSize); - break; - default: - System.out.println("Undefined series style"); - break; + if (plot.getAutoHeightRange() == AutoRangeType.SEMI_AUTO + || plot.getAutoHeightRange() == AutoRangeType.AUTO) { + double maxY = 0; + for(DAChartSeries series : seriesList) { + double tempY = series.getMaxY(); + if (maxY < tempY) { + maxY = tempY; } } - - if (plot.isShowAxis()) { - if (plot.isSeriesHeightRange()) { - for (int i = 0; i < seriesSize; i++) { - series = seriesList.get(i); - if (0 == i) { - drawAxis(gc, r, plot.getVisibleStartY(), - plot.getVisibleEndY(), true); - } else if (1 == i) { - drawAxis(gc, r, 0, series.getEndY(), false); - } else { - break; - } + if (maxY * 1.1 > plot.getVisibleEndY() * 1.1) { + plot.setAxisEndY(maxY * 1.1); + } + } + + return true; + } + + protected void drawAxis(GC gc) { + if (plot.isShowAxis()) { + if (plot.isSeriesHeightRange()) { + for (int i = 0; i < seriesList.size(); i++) { + DAChartSeries series = seriesList.get(i); + if (0 == i) { + drawAxis(gc, r, plot.getVisibleStartY(), + plot.getVisibleEndY(), true); + } else if (1 == i) { + drawAxis(gc, r, 0, series.getEndY(), false); + } else { + break; } - } else { - drawAxis(gc, r, plot.getVisibleStartY(), - plot.getVisibleEndY(), true); } + } else { + drawAxis(gc, r, plot.getVisibleStartY(), plot.getVisibleEndY(), + true); + } + } + } + + protected void drawToGc(GC gc, DAChart chart) { + if(!preDraw(gc, chart)) { + return; + } + + for (int i = 0; i < seriesList.size(); i++) { + DAChartSeries series = seriesList.get(i); + switch (series.getStyle()) { + case DAChartSeries.SERIES_STYLE_EVENT: + drawEventSeries(gc, series); + break; + case DAChartSeries.SERIES_STYLE_EVENT_AREA: + drawEventAreaSeries(gc, series); + break; + case DAChartSeries.SERIES_STYLE_BAR: + drawBarSeries(gc, series); + break; + case DAChartSeries.SERIES_STYLE_NONE: + case DAChartSeries.SERIES_STYLE_LINE: + drawLineSeries(gc, series, false); + break; + case DAChartSeries.SERIES_STYLE_AREA: + drawAreaSeries(gc, series, false); + break; + case DAChartSeries.SERIES_STYLE_MULTI_CHECK_BAR: + drawMultiCheckBarSeries(gc, series, i, seriesList.size()); + break; + case DAChartSeries.SERIES_STYLE_STEP: + drawStepSeries(gc, series, true); + break; + case DAChartSeries.SERIES_STYLE_IMAGE: + drawImageSeries(gc, series); + break; + case DAChartSeries.SERIES_STYLE_LOAD: + drawLoadSeries(gc, series); + break; + case DAChartSeries.SERIES_STYLE_ARROW: + drawArrowSeries(gc, series); + break; + case DAChartSeries.SERIES_STYLE_STATE: + drawStateSeries(gc, series); + break; + case DAChartSeries.SERIES_STYLE_LAST_CONTINUE_STEP: + drawStepSeries(gc, series, false); + break; + default: + System.out.println("Undefined series style"); + break; } } + + drawAxis(gc); } public void drawBuffer(Image buffer, DAChart chart) { @@ -200,7 +209,7 @@ public class DAChartRenderer { } // FIXME : current chart axis is based on byte value(less than 1000) - private void drawAxis(GC gc, Rectangle rt, double min, double max, + protected void drawAxis(GC gc, Rectangle rt, double min, double max, boolean bPosRight) { Color oldCol = gc.getForeground(); gc.setForeground(ColorResources.CHART_AXIS); @@ -323,7 +332,7 @@ public class DAChartRenderer { gc.setForeground(oldCol); } - private void initialize(GC gc, DAChart chart) { + protected void initialize(GC gc, DAChart chart) { this.seriesList = chart.getSeriesList(); bInitialized = true; } @@ -675,12 +684,10 @@ public class DAChartRenderer { } int seriesItemSize = seriesItems.size(); - if (seriesItemSize < 1) { return; } - DAChartSeriesItem seriesItem; Color color = series.getColor(); gc.setBackground(color); gc.setAlpha((int) (255 * 0.8)); @@ -695,7 +702,7 @@ public class DAChartRenderer { double maxY = getMaxYToDraw(series, index); for (int i = index; i < seriesItemSize; i++) { - seriesItem = seriesItems.get(i); + DAChartSeriesItem seriesItem = seriesItems.get(i); double barWidthTime = 0; if (seriesItem.getBarWidth() == -1) { @@ -772,7 +779,7 @@ public class DAChartRenderer { gc.setFont(oriFont); } if (seriesIndex != 0) { - gc.setForeground(ColorResources.UI_EVENT_CHART_SEPERATE_LINE); + gc.setForeground(ColorResources.CHART_SEPERATE_LINE); gc.drawLine(rect.x, rect.y, rect.width, rect.y); } @@ -1509,90 +1516,4 @@ public class DAChartRenderer { } } } - - private void drawMultiLineSeries(GC gc, DAChartSeries series, - int seriesIndex, int 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, r.height * seriesIndex / seriesSize, - rect.width, r.height * seriesIndex / seriesSize); - } - - gc.setForeground(ColorResources.SERIES_NAME_ANNOTATION); - Font oriFont = gc.getFont(); - Font nameAnnotationFont = series.getFont(); - gc.setFont(nameAnnotationFont); - gc.drawText(series.getName(), rect.x + 3, - rect.y + rect.height / 2 - gc.stringExtent(series.getName()).y - / 2, true); - gc.setFont(oriFont); - - List seriesItems = series.getSeriesItemList(); - if (seriesItems == null) { - return; - } - int seriesItemSize = seriesItems.size(); - if (seriesItemSize < 1) { - return; - } - - int index = series.getPrevIndexByXvalue(plot.getVisibleStartX()); - if (index < 0) { - index = 0; - } - - DAChartSeriesItem seriesItem = seriesItems.get(0); - - double maxY = getMaxYToDraw(series, index); - int oldPixcelX = plot.getXPixcelFromX(seriesItem.getX(), r); - double oldY = seriesItem.getY(); - - if (seriesItemSize == 1) { - if (oldPixcelX < r.x) { - return; - } - Color color = seriesItem.getEventColor(); - if (null == color) { - color = series.getColor(); - } - gc.setForeground(color); - gc.drawPoint(oldPixcelX, - plot.getYPixcelFromY(maxY, seriesItem.getY(), r)); - return; - } - - Color color = series.getColor(); - gc.setForeground(color); - gc.setLineStyle(SWT.LINE_SOLID); - gc.setAntialias(SWT.ON); - - seriesItem = seriesItems.get(index); - double currentX = seriesItem.getX(); - - int newPixcelX = plot.getXPixcelFromX(currentX, r); - double newY = seriesItem.getY(); - - for (int i = index; i < seriesItemSize; i++) { - seriesItem = seriesItems.get(i); - currentX = seriesItem.getX(); - - oldPixcelX = newPixcelX; - oldY = newY; - - newPixcelX = plot.getXPixcelFromX(currentX, r); - newY = seriesItem.getY(); - gc.drawLine(oldPixcelX, - (int) (rect.y + rect.height * (1.0 - (oldY / maxY))), - newPixcelX, - (int) (rect.y + rect.height * (1.0 - (newY / maxY)))); - if (currentX > plot.getVisibleEndX()) { - return; - } - } - } } diff --git a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chartBoard/DAChartBoardHeightChangeableItem.java b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chartBoard/DAChartBoardHeightChangeableItem.java index d4c81c6..823facc 100644 --- a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chartBoard/DAChartBoardHeightChangeableItem.java +++ b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/chartBoard/DAChartBoardHeightChangeableItem.java @@ -10,6 +10,10 @@ public class DAChartBoardHeightChangeableItem extends DAChartBoardItem { super(parent, itemName); } + public DAChartBoardHeightChangeableItem(DAChartBoard parent, String itemName) { + super(parent, itemName); + } + public void setHeightRatio(double ratio) { originalHeightRatio = ratio; diff --git a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/helper/ColorResources.java b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/helper/ColorResources.java index 502ee01..b56cb02 100644 --- a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/helper/ColorResources.java +++ b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/helper/ColorResources.java @@ -71,7 +71,7 @@ public class ColorResources { public static Color CHART_NAME_SELECT_BACK_END = getColor( "chart_name_back_select_end", new RGB(56, 178, 208)); //$NON-NLS-1$ - public static Color UI_EVENT_CHART_SEPERATE_LINE = getColor( + public static Color CHART_SEPERATE_LINE = getColor( "UI_event_chart_seperate_line", new RGB(189, 207, 213)); //$NON-NLS-1$ public static Color SERIES_NAME_ANNOTATION = getColor( "UI_event _chat_text", new RGB(83, 83, 83)); //$NON-NLS-1$ diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/common/TimelineChartMouseEventListener.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/common/TimelineChartMouseEventListener.java index 498fe0e..83ed9a7 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/common/TimelineChartMouseEventListener.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/common/TimelineChartMouseEventListener.java @@ -258,8 +258,9 @@ public class TimelineChartMouseEventListener extends MouseAdapter implements if (plot instanceof DAScreenshotChartPlot) { DAChartSeries series = chart.getSeries(0); - int index = series.getPrevIndexByXvalue(plot.getXFromXPixcel(e.x)); if (series != null) { + int index = series.getPrevIndexByXvalue(plot + .getXFromXPixcel(e.x)); if (index >= 0 && index < series.getSeriesItemList().size()) { DAChartSeriesItem item = series.getSeriesItemList().get( index); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/GLDetailsView.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/GLDetailsView.java index 8f7e949..f018293 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/GLDetailsView.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/GLDetailsView.java @@ -136,7 +136,7 @@ public class GLDetailsView extends DAView { @Override public void updateView(DASelectionData data) { String id = data.getViewId(); - if (id.equals(GLChartView.ID)) { + if (id.equals(GLChartView.ID) && data instanceof GLSelectionData) { detail = DETAIL_FRAME; int frameIndex = ((GLSelectionData)data).getFrameIndex(); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/apiList/GLAPIListView.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/apiList/GLAPIListView.java index 7e4857a..0316b27 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/apiList/GLAPIListView.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/apiList/GLAPIListView.java @@ -83,7 +83,7 @@ public class GLAPIListView extends DAView { @Override public void updateView(DASelectionData data) { String id = data.getViewId(); - if (id.equals(GLChartView.ID)) { + if (id.equals(GLChartView.ID) && data instanceof GLSelectionData) { int endFrameIndex = ((GLSelectionData) data) .getSecondFrameIndex(); int frameIndex = ((GLSelectionData) data).getFrameIndex(); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/context/GLContextView.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/context/GLContextView.java index 5eecac5..751d7ed 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/context/GLContextView.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/opengl/ui/context/GLContextView.java @@ -75,7 +75,7 @@ public class GLContextView extends DAView { @Override public void updateView(DASelectionData data) { String id = data.getViewId(); - if (id.equals(GLAPIListView.ID)) { + if (id.equals(GLAPIListView.ID) && data instanceof GLSelectionData) { GridItem[] gridItems = (GridItem[]) data.getData(); DATableDataFormat tableDataFormat = (DATableDataFormat) gridItems[0] .getData(); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUChart.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUChart.java index 1a05dca..3e94412 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUChart.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUChart.java @@ -40,11 +40,6 @@ import org.tizen.dynamicanalyzer.swap.logparser.LogPackage; import org.tizen.dynamicanalyzer.swap.logparser.Logs; import org.tizen.dynamicanalyzer.swap.model.data.LogData; import org.tizen.dynamicanalyzer.swap.model.data.SystemData; -import org.tizen.dynamicanalyzer.ui.common.PopupAnalysisMenuItemClickListener; -import org.tizen.dynamicanalyzer.ui.common.PopupClearMenuItemClickListener; -import org.tizen.dynamicanalyzer.ui.common.PopupEndMenuItemClickListener; -import org.tizen.dynamicanalyzer.ui.common.PopupFromSelectionMenuItemClickListener; -import org.tizen.dynamicanalyzer.ui.common.PopupStartMenuItemClickListener; import org.tizen.dynamicanalyzer.ui.common.TimelineChartMouseEventListener; import org.tizen.dynamicanalyzer.ui.common.TimelineChartMouseTrackAdapter; import org.tizen.dynamicanalyzer.ui.timeline.common.TimelineConstants; @@ -59,7 +54,6 @@ import org.tizen.dynamicanalyzer.widgets.chartBoard.DAChartBoard; import org.tizen.dynamicanalyzer.widgets.chartBoard.DAChartBoardHeightChangeableItem; import org.tizen.dynamicanalyzer.widgets.chartBoard.DAChartBoardItem; import org.tizen.dynamicanalyzer.widgets.popupMenu.DAPopupMenu; -import org.tizen.dynamicanalyzer.widgets.popupMenu.DAPopupMenuItem; public class CPUChart extends TimelineChart { private static CPUChart instance = null; @@ -175,38 +169,7 @@ public class CPUChart extends TimelineChart { childPlot.setShowAxis(true); childPlot.setMarkers(chartBoard.getMarkers()); - DAPopupMenu popupMenu = new DAPopupMenu(processesChart); - popupMenu.setFont(FontResources.CONTEXT_MENU_ITEM_FONT); - DAPopupMenuItem startItem = new DAPopupMenuItem(popupMenu); - startItem - .setText(TimelineChartLabels.RANGE_CONTEXT_SET_START); - startItem.addListener(new PopupStartMenuItemClickListener( - startItem, chartBoard)); - - DAPopupMenuItem endItem = new DAPopupMenuItem(popupMenu); - endItem.setText(TimelineChartLabels.RANGE_CONTEXT_SET_END); - endItem.addListener(new PopupEndMenuItemClickListener( - endItem, chartBoard)); - - DAPopupMenuItem fromSelectionItem = new DAPopupMenuItem( - popupMenu); - fromSelectionItem - .setText(TimelineChartLabels.RANGE_CONTEXT_SET_FROM_SELECTION); - fromSelectionItem - .addListener(new PopupFromSelectionMenuItemClickListener( - fromSelectionItem, chartBoard)); - - DAPopupMenuItem analysisItem = new DAPopupMenuItem( - popupMenu); - analysisItem - .setText(TimelineChartLabels.RANGE_CONTEXT_ANALYSIS); - analysisItem - .addListener(new PopupAnalysisMenuItemClickListener()); - - DAPopupMenuItem clearItem = new DAPopupMenuItem(popupMenu); - clearItem.setText(TimelineChartLabels.RANGE_CONTEXT_CLEAR); - clearItem - .addListener(new PopupClearMenuItemClickListener()); + initPopupMenu(chartBoard, new DAPopupMenu(processesChart)); TimelineChartMouseEventListener timelineChartMouseEventListener = new TimelineChartMouseEventListener( popupMenu, chartBoard.getTimeline()); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUCoreChart.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUCoreChart.java index cc3962e..1e38b53 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUCoreChart.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUCoreChart.java @@ -41,10 +41,13 @@ import org.tizen.dynamicanalyzer.swap.model.data.SystemData; import org.tizen.dynamicanalyzer.ui.timeline.common.TimelineConstants; import org.tizen.dynamicanalyzer.utils.Formatter; import org.tizen.dynamicanalyzer.widgets.chart.DAChartPlot.AutoRangeType; +import org.tizen.dynamicanalyzer.widgets.chart.DAChart; import org.tizen.dynamicanalyzer.widgets.chart.DAChartSeries; import org.tizen.dynamicanalyzer.widgets.chart.DAChartSeriesItem; import org.tizen.dynamicanalyzer.widgets.chartBoard.DAChartBoard; +import org.tizen.dynamicanalyzer.widgets.chartBoard.DAChartBoardHeightChangeableItem; import org.tizen.dynamicanalyzer.widgets.chartBoard.DAChartBoardItem; +import org.tizen.dynamicanalyzer.widgets.popupMenu.DAPopupMenu; public class CPUCoreChart extends TimelineChart { private static CPUCoreChart instance = null; @@ -112,7 +115,88 @@ public class CPUCoreChart extends TimelineChart { chart.getPlot().setAxisRangeY(0, 100); chart.getPlot().setAxisUnit("%"); chart.getPlot().setShowAxis(true); + + + //FIXME temporary + // core + DAChartBoardHeightChangeableItem coreItem = new DAChartBoardHeightChangeableItem( + item, "core"); + DAChartSeries coreSeries = new DAChartSeries("core", -1, ColorResources.BLUE); + + coreItem.useExpand(false); + coreItem.setHeightRatio(0.5); + + chart = coreItem.getChart(); + chart.addSeries(coreSeries); + + chart.getPlot().setAutoHeightRange(AutoRangeType.MANUAL); + chart.getPlot().setShowAxis(false); + + chart.setChartRenderer(new ContextSwitchingChartRenderer()); + initPopupMenu(board, new DAPopupMenu(chart)); + + coreSeries.addSeriesItem(new ContextSwitchingChartSeriesItem("core1", + 3, 4)); + + // function + DAChartBoardHeightChangeableItem functionItem = new DAChartBoardHeightChangeableItem( + item, "function"); + DAChartSeries functionSeries = new DAChartSeries("function", -1, + ColorResources.RED); + functionItem.useExpand(false); + functionItem.setHeightRatio(0.5); + + DAChart functionChart = functionItem.getChart(); + functionChart.addSeries(functionSeries); + + functionChart.getPlot().setAutoHeightRange(AutoRangeType.MANUAL); + functionChart.getPlot().setShowAxis(false); + + functionChart.setChartRenderer(new ContextSwitchingChartRenderer()); + initPopupMenu(board, new DAPopupMenu(functionChart)); + + functionSeries.addSeriesItem(new ContextSwitchingChartSeriesItem("a()", + ContextSwitchingChartSeriesItem.STYLE_OCTAGON, 2, 3)); + functionSeries.addSeriesItem(new ContextSwitchingChartSeriesItem("b()", + ContextSwitchingChartSeriesItem.STYLE_OCTAGON_LEFT_ONLY, 4, 5)); + functionSeries.addSeriesItem(new ContextSwitchingChartSeriesItem("c()", + ContextSwitchingChartSeriesItem.STYLE_OCTAGON_RIGHT_ONLY, 6, 7)); + + // call flow + DAChartBoardHeightChangeableItem callFlowItem = new DAChartBoardHeightChangeableItem( + item, "call flow"); + callFlowItem.useExpand(false); + callFlowItem.setHeightRatio(6 * 0.3); + + DAChartSeries seriesUnknown = new DAChartSeries("unknown", -1, ColorResources.RED); + DAChartSeries seriesA = new DAChartSeries("thread 1 a()", -1, ColorResources.RED); + DAChartSeries seriesB = new DAChartSeries("thread 1 b()", -1, ColorResources.RED); + DAChartSeries seriesC = new DAChartSeries("thread 1 c()", -1, ColorResources.RED); + DAChartSeries seriesD = new DAChartSeries("thread 1 d()", -1, ColorResources.RED); + DAChartSeries seriesE = new DAChartSeries("thread 1 e()", -1, ColorResources.RED); + + DAChart callFlowChart = callFlowItem.getChart(); + callFlowChart.addSeries(seriesUnknown); + callFlowChart.addSeries(seriesA); + callFlowChart.addSeries(seriesB); + callFlowChart.addSeries(seriesC); + callFlowChart.addSeries(seriesD); + callFlowChart.addSeries(seriesE); + + callFlowChart.getPlot().setAutoHeightRange(AutoRangeType.MANUAL); + callFlowChart.getPlot().setShowAxis(false); + + callFlowChart.setChartRenderer(new ContextSwitchingChartRenderer()); + initPopupMenu(board, new DAPopupMenu(callFlowChart)); + + seriesA.addSeriesItem(new ContextSwitchingChartSeriesItem(1, 0.0, 0.10)); + seriesA.addSeriesItem(new ContextSwitchingChartSeriesItem(2, 0.20, 0.30)); + seriesB.addSeriesItem(new ContextSwitchingChartSeriesItem(-1, 0.10, 0.20)); + seriesC.addSeriesItem(new ContextSwitchingChartSeriesItem(1, 0.30, 0.45)); + seriesC.addSeriesItem(new ContextSwitchingChartSeriesItem(0.85, 1.05)); + seriesD.addSeriesItem(new ContextSwitchingChartSeriesItem(-1, 0.45, 0.85)); + return item; } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/ContextSwitchingChartRenderer.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/ContextSwitchingChartRenderer.java new file mode 100644 index 0000000..2789e3e --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/ContextSwitchingChartRenderer.java @@ -0,0 +1,164 @@ +package org.tizen.dynamicanalyzer.ui.timeline.chart; + +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; +import org.tizen.dynamicanalyzer.widgets.chart.DAChart; +import org.tizen.dynamicanalyzer.widgets.chart.DAChartRenderer; +import org.tizen.dynamicanalyzer.widgets.chart.DAChartSeries; +import org.tizen.dynamicanalyzer.widgets.chart.DAChartSeriesItem; +import org.tizen.dynamicanalyzer.widgets.helper.ColorResources; + +public class ContextSwitchingChartRenderer extends DAChartRenderer { + private static final int ARC = 6; + @Override + protected void drawToGc(GC gc, DAChart chart) { + if (!preDraw(gc, chart)) { + return; + } + + for (int i = 0; i < seriesList.size(); i++) { + drawContextSwitching(gc, seriesList.get(i), i); + } + + drawAxis(gc); + } + + private void drawContextSwitching(GC gc, DAChartSeries series, + int seriesIndex) { + int seriesSize = seriesList.size(); + Rectangle rect = new Rectangle(r.x, r.y + r.height * seriesIndex + / seriesSize, r.width, r.height / seriesSize); + + if (seriesIndex != 0) { + gc.setForeground(ColorResources.CHART_SEPERATE_LINE); + gc.drawLine(rect.x, r.height * seriesIndex / seriesSize, + rect.width, r.height * seriesIndex / seriesSize); + } + + List seriesItems = series.getSeriesItemList(); + if (seriesItems == null) { + return; + } + int seriesItemSize = seriesItems.size(); + if (seriesItemSize < 1) { + return; + } + + Color color = series.getColor(); + gc.setForeground(color); + gc.setLineStyle(SWT.LINE_SOLID); + gc.setAntialias(SWT.ON); + + int index = series.getPrevIndexByXvalue(plot.getVisibleStartX()); + if (index < 0) { + index = 0; + } + + for (int i = index; i < seriesItemSize; i++) { + ContextSwitchingChartSeriesItem seriesItem = (ContextSwitchingChartSeriesItem) seriesItems + .get(i); + double x = seriesItem.getX(); + if (x > plot.getVisibleEndX()) { + return; + } + + double endX = seriesItem.getEndX(); + + int pixcelX = plot.getXPixcelFromX(x, r); + int pixcelEndX = plot.getXPixcelFromX(endX, r); + + gc.setBackground(series.getColor()); + + int leftX = pixcelX + ARC; + int rightX = pixcelEndX - ARC; + int upperY = rect.y + (int) Math.round((rect.height * 0.1)); + int underY = rect.y + (int) Math.round((rect.height * 0.9)); + int[] points; + switch (seriesItem.getStyle()) { + case ContextSwitchingChartSeriesItem.STYLE_OCTAGON: + if(leftX > rightX) { + int gap = leftX - rightX; + leftX = leftX - gap / 2; + rightX = rightX + gap / 2; + } + points = new int[] { + leftX, upperY, + pixcelX, upperY + ARC, + pixcelX, underY - ARC, + leftX, underY, + rightX, underY, + pixcelEndX, underY - ARC, + pixcelEndX, upperY + ARC, + rightX, upperY + }; + gc.drawPolygon(points); + break; + case ContextSwitchingChartSeriesItem.STYLE_OCTAGON_LEFT_ONLY: + if(leftX > pixcelEndX) { + int gap = leftX - pixcelEndX; + leftX = leftX - gap; + } + points = new int[] { + leftX, upperY, + pixcelX, upperY + ARC, + pixcelX, underY - ARC, + leftX, underY, + pixcelEndX, underY, + pixcelEndX, upperY, + }; + gc.drawPolygon(points); + break; + case ContextSwitchingChartSeriesItem.STYLE_OCTAGON_RIGHT_ONLY: + if(rightX < pixcelX) { + int gap = pixcelX - rightX; + rightX = rightX + gap; + } + points = new int[] { + pixcelX , upperY, + pixcelX, underY, + rightX, underY, + pixcelEndX, underY - ARC, + pixcelEndX, upperY + ARC, + rightX, upperY + }; + gc.drawPolygon(points); + break; + case ContextSwitchingChartSeriesItem.STYLE_SQUARE: + default: + gc.drawRectangle(pixcelX, rect.y + (int) (rect.height * 0.1), + pixcelEndX - pixcelX, (int) (rect.height * 0.8)); + break; + } + + String name = seriesItem.getName(); + if (name != null) { + int extentX = gc.stringExtent(name).x; + if (extentX < pixcelEndX - pixcelX) { + gc.drawText(name, (pixcelEndX + pixcelX) / 2 - extentX / 2, + rect.y + rect.height / 2 - gc.stringExtent(name).y + / 2, true); + } + } + + int arrow = seriesItem.getArrow(); + if (arrow != 0) { + int arrowHeadY = rect.y + rect.height / 2 + rect.height * arrow; + gc.drawLine(pixcelEndX, rect.y + rect.height / 2, pixcelEndX, + arrowHeadY); + int y = -5; + if (arrow < 0) { + y = 5; + } + gc.drawLine(pixcelEndX, arrowHeadY, pixcelEndX - 5, arrowHeadY + + y); + gc.drawLine(pixcelEndX, arrowHeadY, pixcelEndX + 5, arrowHeadY + + y); + + } + } + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/ContextSwitchingChartSeriesItem.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/ContextSwitchingChartSeriesItem.java new file mode 100644 index 0000000..be88f9f --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/ContextSwitchingChartSeriesItem.java @@ -0,0 +1,52 @@ +package org.tizen.dynamicanalyzer.ui.timeline.chart; + +import org.tizen.dynamicanalyzer.widgets.chart.DAChartSeriesItem; + +public class ContextSwitchingChartSeriesItem extends DAChartSeriesItem { + public static final int STYLE_SQUARE = 0; + public static final int STYLE_OCTAGON = 1; + public static final int STYLE_OCTAGON_LEFT_ONLY = 2; + public static final int STYLE_OCTAGON_RIGHT_ONLY = 3; + + private String name; + private int style; + private double endX; + private int arrow; + + public ContextSwitchingChartSeriesItem(double x, double endX) { + this(null, x, endX); + } + + public ContextSwitchingChartSeriesItem(int arrow, double x, double endX) { + this(null, x, endX); + this.arrow = arrow; + } + + public ContextSwitchingChartSeriesItem(String name, double x, double endX) { + this(name, STYLE_SQUARE, x, endX); + } + + public ContextSwitchingChartSeriesItem(String name, int style, double x, + double endX) { + super(x, 0); + this.name = name; + this.style = style; + this.endX = endX; + } + + public String getName() { + return name; + } + + public int getStyle() { + return style; + } + + public double getEndX() { + return endX; + } + + public int getArrow() { + return arrow; + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/HeapChart.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/HeapChart.java index 4eeea79..8e11930 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/HeapChart.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/HeapChart.java @@ -128,9 +128,6 @@ public class HeapChart extends TimelineChart { if (MEM_API_TYPE_ALLOC == memApiType || MEM_API_TYPE_FREE == memApiType || MEM_API_TYPE_MANAGE == memApiType) { - double time = 0; - time = logData.getTime() - / TimelineConstants.MEGA_DOUBLE; addNewSeriesUserAllocData(memApiType, logData); } 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 index 358b841..d5a7471 100644 --- 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 @@ -31,13 +31,117 @@ import java.util.List; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; +import org.tizen.dynamicanalyzer.widgets.chart.DAChart; 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.DAChartSeriesItem; import org.tizen.dynamicanalyzer.widgets.chart.DAUIEventChartPlot; +import org.tizen.dynamicanalyzer.widgets.helper.ColorResources; public class ProcessesChartRenderer extends DAChartRenderer { + protected void drawToGc(GC gc, DAChart chart) { + if (!preDraw(gc, chart)) { + return; + } + + for (int i = 0; i < seriesList.size(); i++) { + drawMultiLineSeries(gc, seriesList.get(i), i); + } + + drawAxis(gc); + } + + private void drawMultiLineSeries(GC gc, DAChartSeries series, + int seriesIndex) { + int seriesSize = seriesList.size(); + Rectangle rect = new Rectangle(r.x, + r.y + r.height * seriesIndex / seriesSize, + r.width, + r.height / seriesSize); + + if (seriesIndex != 0) { + gc.setForeground(ColorResources.CHART_SEPERATE_LINE); + gc.drawLine(rect.x, r.height * seriesIndex / seriesSize, + rect.width, r.height * seriesIndex / seriesSize); + } + + gc.setForeground(ColorResources.SERIES_NAME_ANNOTATION); + Font oriFont = gc.getFont(); + Font nameAnnotationFont = series.getFont(); + gc.setFont(nameAnnotationFont); + gc.drawText(series.getName(), rect.x + 3, + rect.y + rect.height / 2 - gc.stringExtent(series.getName()).y + / 2, true); + gc.setFont(oriFont); + + List seriesItems = series.getSeriesItemList(); + if (seriesItems == null) { + return; + } + int seriesItemSize = seriesItems.size(); + if (seriesItemSize < 1) { + return; + } + + int index = series.getPrevIndexByXvalue(plot.getVisibleStartX()); + if (index < 0) { + index = 0; + } + + DAChartSeriesItem seriesItem = seriesItems.get(0); + + double maxY = getMaxYToDraw(series, index); + int oldPixcelX = plot.getXPixcelFromX(seriesItem.getX(), r); + double oldY = seriesItem.getY(); + + if (seriesItemSize == 1) { + if (oldPixcelX < r.x) { + return; + } + Color color = seriesItem.getEventColor(); + if (null == color) { + color = series.getColor(); + } + gc.setForeground(color); + gc.drawPoint(oldPixcelX, + plot.getYPixcelFromY(maxY, seriesItem.getY(), r)); + return; + } + + Color color = series.getColor(); + gc.setForeground(color); + gc.setLineStyle(SWT.LINE_SOLID); + gc.setAntialias(SWT.ON); + + seriesItem = seriesItems.get(index); + double currentX = seriesItem.getX(); + + int newPixcelX = plot.getXPixcelFromX(currentX, r); + double newY = seriesItem.getY(); + + for (int i = index; i < seriesItemSize; i++) { + seriesItem = seriesItems.get(i); + currentX = seriesItem.getX(); + + oldPixcelX = newPixcelX; + oldY = newY; + + newPixcelX = plot.getXPixcelFromX(currentX, r); + newY = seriesItem.getY(); + gc.drawLine(oldPixcelX, + (int) (rect.y + rect.height * (1.0 - (oldY / maxY))), + newPixcelX, + (int) (rect.y + rect.height * (1.0 - (newY / maxY)))); + if (currentX > plot.getVisibleEndX()) { + return; + } + } + } + @Override protected void drawTooltip(GC gc) { DAChartPlotTooltip tooltip = plot.getTooltip(); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/TimelineChart.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/TimelineChart.java index 14f5c73..7f80b5c 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/TimelineChart.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/TimelineChart.java @@ -66,13 +66,18 @@ public abstract class TimelineChart { chart = item.getChart(); setChartStyle(); - popupMenu = new DAPopupMenu(chart); + initPopupMenu(chartBoard, popupMenu); + + return item; + } + + protected void initPopupMenu(DAChartBoard chartBoard, DAPopupMenu popupMenu) { popupMenu.setFont(FontResources.CONTEXT_MENU_ITEM_FONT); DAPopupMenuItem startItem = new DAPopupMenuItem(popupMenu); startItem.setText(TimelineChartLabels.RANGE_CONTEXT_SET_START); - startItem.addListener(new PopupStartMenuItemClickListener( - startItem, chartBoard)); + startItem.addListener(new PopupStartMenuItemClickListener(startItem, + chartBoard)); DAPopupMenuItem endItem = new DAPopupMenuItem(popupMenu); endItem.setText(TimelineChartLabels.RANGE_CONTEXT_SET_END); @@ -93,8 +98,6 @@ public abstract class TimelineChart { DAPopupMenuItem clearItem = new DAPopupMenuItem(popupMenu); clearItem.setText(TimelineChartLabels.RANGE_CONTEXT_CLEAR); clearItem.addListener(new PopupClearMenuItemClickListener()); - - return item; } public void clear() {