List of usage examples for org.jfree.data.category SlidingCategoryDataset SlidingCategoryDataset
public SlidingCategoryDataset(CategoryDataset underlying, int firstColumn, int maxColumns)
From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java
public JPanel layoutDataPanel() { this.setLayout(new BorderLayout()); this.dataset = new SlidingCategoryDataset(new DefaultCategoryDataset(), 0, CATEGORY_MAX_COUNT); this.popup = new WaterfallPopup(); JPanel graphPanel = new JPanel(new BorderLayout()); graphPanel.add(getChartPanel(), BorderLayout.CENTER); graphPanel.add(getVerticalScroll(), BorderLayout.EAST); graphPanel.add(getHorizontalScroll(), BorderLayout.SOUTH); this.add(graphPanel, BorderLayout.CENTER); JPanel buttonsPanel = new JPanel(); buttonsPanel.add(getZoomInButton()); buttonsPanel.add(getZoomOutButton()); this.add(buttonsPanel, BorderLayout.SOUTH); return this; }
From source file:org.jfree.data.category.SlidingCategoryDatasetTest.java
/** * Some checks for the getColumnIndex() method. *//*from w ww .j a v a 2 s . com*/ @Test public void testGetColumnIndex() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.0, "R1", "C1"); underlying.addValue(2.0, "R1", "C2"); underlying.addValue(3.0, "R1", "C3"); underlying.addValue(4.0, "R1", "C4"); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 1, 2); assertEquals(-1, dataset.getColumnIndex("C1")); assertEquals(0, dataset.getColumnIndex("C2")); assertEquals(1, dataset.getColumnIndex("C3")); assertEquals(-1, dataset.getColumnIndex("C4")); }
From source file:org.jfree.data.category.SlidingCategoryDatasetTest.java
/** * Some checks for the getRowIndex() method. *///w w w .j a va 2 s . c o m @Test public void testGetRowIndex() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.0, "R1", "C1"); underlying.addValue(2.0, "R2", "C1"); underlying.addValue(3.0, "R3", "C1"); underlying.addValue(4.0, "R4", "C1"); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 1, 2); assertEquals(0, dataset.getRowIndex("R1")); assertEquals(1, dataset.getRowIndex("R2")); assertEquals(2, dataset.getRowIndex("R3")); assertEquals(3, dataset.getRowIndex("R4")); }
From source file:org.jfree.data.category.SlidingCategoryDatasetTest.java
/** * Some checks for the getValue() method. *///from ww w .j a v a 2 s . co m @Test public void testGetValue() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.0, "R1", "C1"); underlying.addValue(2.0, "R1", "C2"); underlying.addValue(3.0, "R1", "C3"); underlying.addValue(4.0, "R1", "C4"); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 1, 2); assertEquals(new Double(2.0), dataset.getValue("R1", "C2")); assertEquals(new Double(3.0), dataset.getValue("R1", "C3")); boolean pass = false; try { dataset.getValue("R1", "C1"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); pass = false; try { dataset.getValue("R1", "C4"); } catch (UnknownKeyException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.category.SlidingCategoryDatasetTest.java
/** * Some checks for the getColumnKeys() method. *///from www. j a v a2s .c o m @Test public void testGetColumnKeys() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.0, "R1", "C1"); underlying.addValue(2.0, "R1", "C2"); underlying.addValue(3.0, "R1", "C3"); underlying.addValue(4.0, "R1", "C4"); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 1, 2); List keys = dataset.getColumnKeys(); assertTrue(keys.contains("C2")); assertTrue(keys.contains("C3")); assertEquals(2, keys.size()); dataset.setFirstCategoryIndex(3); keys = dataset.getColumnKeys(); assertTrue(keys.contains("C4")); assertEquals(1, keys.size()); }
From source file:com.rapidminer.gui.plotter.charts.WebPlotter.java
@Override public void updatePlotter() { final int categoryCount = prepareData(); SwingUtilities.invokeLater(new Runnable() { @Override//from ww w . ja v a 2 s .co m public void run() { scrollablePlotterPanel.remove(viewScrollBar); } }); if (categoryCount > MAX_CATEGORY_VIEW_COUNT && showScrollbar) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewScrollBar.setOrientation(Adjustable.HORIZONTAL); scrollablePlotterPanel.add(viewScrollBar, BorderLayout.SOUTH); } }); this.slidingCategoryDataSet = new SlidingCategoryDataset(categoryDataSet, 0, MAX_CATEGORY_VIEW_COUNT); viewScrollBar.setMaximum(categoryCount); viewScrollBar.setValue(0); } else { this.slidingCategoryDataSet = null; } if (categoryCount <= MAX_CATEGORIES) { SpiderWebPlot plot = new SpiderWebPlot(categoryDataSet); plot.setAxisLinePaint(Color.LIGHT_GRAY); plot.setOutlinePaint(Color.WHITE); plot.setLabelGenerator(new StandardCategoryItemLabelGenerator()); JFreeChart chart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, true); double[] colorValues = null; if (groupByColumn >= 0 && this.dataTable.isNominal(groupByColumn)) { colorValues = new double[this.dataTable.getNumberOfValues(groupByColumn)]; } else { colorValues = new double[categoryDataSet.getColumnCount()]; } for (int i = 0; i < colorValues.length; i++) { colorValues[i] = i; } if (panel != null) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); scrollablePlotterPanel.add(panel, BorderLayout.CENTER); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); } // set the background color for the chart... chart.setBackgroundPaint(Color.white); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } if (groupByColumn < 0) { // no legend is needed when there is no group-by selection chart.removeLegend(); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.charts.BarChartPlotter.too_many_columns", new Object[] { categoryCount, MAX_CATEGORIES }); } }
From source file:com.rapidminer.gui.plotter.charts.BarChartPlotter.java
@Override public void updatePlotter() { final int categoryCount = prepareData(); SwingUtilities.invokeLater(new Runnable() { @Override/* w ww . j a v a 2 s.c o m*/ public void run() { scrollablePlotterPanel.remove(viewScrollBar); } }); CategoryDataset usedCategoryDataSet = categoryDataSet; if (categoryCount > MAX_CATEGORY_VIEW_COUNT && showScrollbar) { if (orientationIndex == ORIENTATION_TYPE_VERTICAL) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewScrollBar.setOrientation(Adjustable.HORIZONTAL); scrollablePlotterPanel.add(viewScrollBar, BorderLayout.SOUTH); } }); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { viewScrollBar.setOrientation(Adjustable.VERTICAL); scrollablePlotterPanel.add(viewScrollBar, BorderLayout.EAST); } }); } this.slidingCategoryDataSet = new SlidingCategoryDataset(categoryDataSet, 0, MAX_CATEGORY_VIEW_COUNT); viewScrollBar.setMaximum(categoryCount); viewScrollBar.setValue(0); usedCategoryDataSet = this.slidingCategoryDataSet; } else { this.slidingCategoryDataSet = null; } if (categoryCount <= MAX_CATEGORIES) { JFreeChart chart = ChartFactory.createBarChart(null, // chart title null, // domain axis label null, // range axis label usedCategoryDataSet, // data orientationIndex == ORIENTATION_TYPE_VERTICAL ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL, // orientation false, // include legend if group by column is set true, // tooltips false // URLs ); // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); String domainName = groupByColumn >= 0 ? dataTable.getColumnName(groupByColumn) : null; domainAxis.setLabel(domainName); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); String rangeName = valueColumn >= 0 ? dataTable.getColumnName(valueColumn) : null; rangeAxis.setLabel(rangeName); // bar renderer double[] colorValues = null; if (groupByColumn >= 0 && this.dataTable.isNominal(groupByColumn)) { colorValues = new double[this.dataTable.getNumberOfValues(groupByColumn)]; } else { colorValues = new double[categoryDataSet.getColumnCount()]; } for (int i = 0; i < colorValues.length; i++) { colorValues[i] = i; } BarRenderer renderer = new ColorizedBarRenderer(colorValues); renderer.setBarPainter(new RapidBarPainter()); renderer.setDrawBarOutline(true); int size = categoryDataSet.getRowCount(); if (size > 1) { for (int i = 0; i < size; i++) { renderer.setSeriesPaint(i, getColorProvider(true).getPointColor(i / (double) (size - 1))); } } plot.setRenderer(renderer); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } if (panel != null) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); scrollablePlotterPanel.add(panel, BorderLayout.CENTER); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { // LogService.getGlobal().logNote("Too many columns (" + categoryCount + // "), this chart is only able to plot up to " + MAX_CATEGORIES + // " different categories."); LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.charts.BarChartPlotter.too_many_columns", new Object[] { categoryCount, MAX_CATEGORIES }); } }
From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java
/** * Refreshes the waterfall display with the specified analysis data * @param Analyzed data from aro core./*from w ww . j a va2 s .c om*/ */ public void refresh(AROTraceData aModel) { this.popup.refresh(null, 0); this.popup.setVisible(false); double range = DEFAULT_TIMELINE; // Create sorted list of request/response pairs List<WaterfallCategory> categoryList = new ArrayList<WaterfallCategory>(); if (aModel != null && aModel.getAnalyzerResult() != null) { this.traceDuration = aModel.getAnalyzerResult().getTraceresult().getTraceDuration(); // add 20% to make sure labels close to the right edge of the screen are visible this.traceDuration *= 1.2; range = Math.min(this.traceDuration, DEFAULT_TIMELINE); for (Session tcpSession : aModel.getAnalyzerResult().getSessionlist()) { Session thisSession = tcpSession; if (!tcpSession.isUDP()) { for (HttpRequestResponseInfo reqResInfo : tcpSession.getRequestResponseInfo()) { if (reqResInfo.getDirection() == HttpDirection.REQUEST && reqResInfo.getWaterfallInfos() != null) { categoryList.add(new WaterfallCategory(reqResInfo, thisSession)); } } } } // Sort and set index Collections.sort(categoryList); int index = 0; for (WaterfallCategory wCategory : categoryList) { wCategory.setIndex(++index); } } // Horizontal scroll bar used to scroll through trace duration JScrollBar hScrollBar = getHorizontalScroll(); hScrollBar.setMaximum((int) Math.ceil(this.traceDuration)); // Set the visible time range setTimeRange(0, range); CategoryAxis cAxis = getCategoryAxis(); cAxis.clearCategoryLabelToolTips(); // Build the dataset DefaultCategoryDataset underlying = new DefaultCategoryDataset(); for (WaterfallCategory wfc : categoryList) { RequestResponseTimeline rrTimeLine = wfc.getReqResp().getWaterfallInfos(); underlying.addValue(rrTimeLine.getStartTime(), Waterfall.BEFORE, wfc); underlying.addValue(rrTimeLine.getDnsLookupDuration(), Waterfall.DNS_LOOKUP, wfc); underlying.addValue(rrTimeLine.getInitialConnDuration(), Waterfall.INITIAL_CONNECTION, wfc); underlying.addValue(rrTimeLine.getSslNegotiationDuration(), Waterfall.SSL_NEGOTIATION, wfc); underlying.addValue(rrTimeLine.getRequestDuration(), Waterfall.REQUEST_TIME, wfc); underlying.addValue(rrTimeLine.getTimeToFirstByte(), Waterfall.TIME_TO_FIRST_BYTE, wfc); underlying.addValue(rrTimeLine.getContentDownloadDuration(), Waterfall.CONTENT_DOWNLOAD, wfc); underlying.addValue(null, Waterfall.HTTP_3XX_REDIRECTION, wfc); underlying.addValue(null, Waterfall.HTTP_4XX_CLIENTERROR, wfc); int code = wfc.getReqResp().getAssocReqResp().getStatusCode(); double endTime = this.traceDuration - rrTimeLine.getStartTime() - rrTimeLine.getTotalTime(); if (code >= 300 && code < 400) { underlying.addValue(endTime, Waterfall.AFTER_3XX, wfc); } else if (code >= 400) { underlying.addValue(endTime, Waterfall.AFTER_4XX, wfc); } else { underlying.addValue(endTime, Waterfall.AFTER, wfc); } cAxis.addCategoryLabelToolTip(wfc, wfc.getTooltip()); } // Vertical scroll bar is used to scroll through data JScrollBar vScrollBar = getVerticalScroll(); int count = underlying.getColumnCount(); vScrollBar.setValue(0); vScrollBar.setMaximum(count); vScrollBar.setVisibleAmount(count > 0 ? this.dataset.getMaximumCategoryCount() - 1 / count : 1); // Add the dataset to the plot CategoryPlot plot = getChartPanel().getChart().getCategoryPlot(); this.dataset = new SlidingCategoryDataset(underlying, 0, CATEGORY_MAX_COUNT); plot.setDataset(this.dataset); // Place proper colors on renderer for waterfall states final CategoryItemRenderer renderer = plot.getRenderer(); for (Object obj : underlying.getRowKeys()) { Waterfall wFall = (Waterfall) obj; int index = underlying.getRowIndex(wFall); Color paint; switch (wFall) { case DNS_LOOKUP: paint = dnsLoolupColor; break; case INITIAL_CONNECTION: paint = initiaConnColor; break; case SSL_NEGOTIATION: paint = sslNegColor; break; case REQUEST_TIME: paint = requestTimeColor; break; case TIME_TO_FIRST_BYTE: paint = firstByteTimeColor; break; case CONTENT_DOWNLOAD: paint = contentDownloadColor; break; case AFTER_3XX: paint = noneColor; renderer.setSeriesItemLabelPaint(index, threexColor); renderer.setSeriesVisibleInLegend(index, false); break; case AFTER_4XX: paint = noneColor; renderer.setSeriesItemLabelPaint(index, fourxColor); renderer.setSeriesVisibleInLegend(index, false); break; case HTTP_3XX_REDIRECTION: paint = threexColor; break; case HTTP_4XX_CLIENTERROR: paint = fourxColor; break; default: renderer.setSeriesItemLabelPaint(index, Color.black); renderer.setSeriesVisibleInLegend(index, false); paint = noneColor; } renderer.setSeriesPaint(index, paint); } // Adding the label at the end of bars renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() { private static final long serialVersionUID = 1L; @Override public String generateLabel(CategoryDataset dataset, int row, int column) { if (Waterfall.AFTER == dataset.getRowKey(row) || Waterfall.AFTER_3XX == dataset.getRowKey(row) || Waterfall.AFTER_4XX == dataset.getRowKey(row)) { WaterfallCategory waterfallItem = (WaterfallCategory) dataset.getColumnKey(column); RequestResponseTimeline waterfallInfos = waterfallItem.getReqResp().getWaterfallInfos(); DecimalFormat formatter = new DecimalFormat("#.##"); int code = waterfallItem.getReqResp().getAssocReqResp().getStatusCode(); return MessageFormat.format(ResourceBundleHelper.getMessageString("waterfall.totalTime"), formatter.format(waterfallInfos.getTotalTime()), code > 0 ? waterfallItem.getReqResp().getScheme() + " " + code : ResourceBundleHelper.getMessageString("waterfall.unknownCode")); } return null; } }); }