List of usage examples for org.jfree.data.gantt TaskSeriesCollection getSeries
public TaskSeries getSeries(int series)
From source file:org.ietr.preesm.mapper.ui.MapperGanttToolTipGenerator.java
@Override public String generateToolTip(CategoryDataset set, int row, int column) { String tooltip = new String(); TaskSeriesCollection collection = (TaskSeriesCollection) set; if ((collection.getSeries(0).getItemCount() > column) && (collection.getSeries(0).get(column).getSubtaskCount() > row)) { Task currentTask = collection.getSeries(0).get(column).getSubtask(row); long startTime = currentTask.getDuration().getStart().getTime(); long endTime = currentTask.getDuration().getEnd().getTime(); tooltip = currentTask.getDescription() + "(" + startTime + "-" + endTime + "-" + (endTime - startTime) + ")"; }/*from w ww .j av a 2 s . c om*/ return tooltip; }
From source file:org.jfree.data.gantt.XYTaskDatasetTest.java
/** * Serialize an instance, restore it, and check for equality. *//*w w w. ja v a 2 s . c o m*/ @Test public void testSerialization() { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); XYTaskDataset d1 = new XYTaskDataset(u1); XYTaskDataset d2 = (XYTaskDataset) TestUtilities.serialised(d1); assertEquals(d1, d2); // basic check for independence s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); TaskSeriesCollection u2 = d2.getTasks(); TaskSeries s2 = u2.getSeries("Series"); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertTrue(d1.equals(d2)); }
From source file:org.jfree.data.gantt.XYTaskDatasetTest.java
/** * Confirm that cloning works./*ww w . ja va 2 s. co m*/ */ @Test public void testCloning() throws CloneNotSupportedException { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); XYTaskDataset d1 = new XYTaskDataset(u1); XYTaskDataset d2 = (XYTaskDataset) d1.clone(); assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); // basic check for independence s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); TaskSeriesCollection u2 = d2.getTasks(); TaskSeries s2 = u2.getSeries("Series"); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertTrue(d1.equals(d2)); }
From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java
public static ChartPanel buildChartPanelForNominalAttribute(final Instances ds, final Attribute attr, final int dateIdx) { final TaskSeriesCollection localTaskSeriesCollection = new TaskSeriesCollection(); final java.util.List<String> names = new ArrayList<String>(); final Set<String> present = WekaDataStatsUtil.getPresentValuesForNominalAttribute(ds, attr.index()); for (final String pr : present) { names.add(pr);//from w w w . ja v a2 s . com localTaskSeriesCollection.add(new TaskSeries(pr)); } final Calendar cal = Calendar.getInstance(); try { for (final double[] dd : WekaTimeSeriesUtil.split(ds, attr.index())) { cal.setTimeInMillis((long) dd[0]); final Date start = cal.getTime(); cal.setTimeInMillis((long) dd[1]); final Date end = cal.getTime(); final String sd = ds.instance((int) dd[2]).stringValue(attr); localTaskSeriesCollection.getSeries(sd).add(new Task("T", start, end)); } } catch (Exception e) { e.printStackTrace(); } final XYTaskDataset localXYTaskDataset = new XYTaskDataset(localTaskSeriesCollection); localXYTaskDataset.setTransposed(true); localXYTaskDataset.setSeriesWidth(0.6D); final DateAxis localDateAxis = new DateAxis(DATE_TIME_LABEL); final SymbolAxis localSymbolAxis = new SymbolAxis("", names.toArray(new String[names.size()])); localSymbolAxis.setGridBandsVisible(false); final XYBarRenderer localXYBarRenderer = new XYBarRenderer(); localXYBarRenderer.setUseYInterval(true); localXYBarRenderer.setShadowVisible(false); final XYPlot localXYPlot = new XYPlot(localXYTaskDataset, localDateAxis, localSymbolAxis, localXYBarRenderer); final CombinedDomainXYPlot localCombinedDomainXYPlot = new CombinedDomainXYPlot( new DateAxis(DATE_TIME_LABEL)); localCombinedDomainXYPlot.add(localXYPlot); final JFreeChart localJFreeChart = new JFreeChart("", localCombinedDomainXYPlot); localJFreeChart.setBackgroundPaint(Color.white); final ChartPanel cp = new ChartPanel(localJFreeChart, true); cp.setBorder(new TitledBorder(attr.name())); return cp; }
From source file:org.jfree.data.gantt.SlidingGanttCategoryDatasetTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from w ww. j a v a 2 s . c om*/ @Test public void testSerialization() { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); SlidingGanttCategoryDataset d1 = new SlidingGanttCategoryDataset(u1, 0, 5); SlidingGanttCategoryDataset d2 = (SlidingGanttCategoryDataset) TestUtilities.serialised(d1); assertEquals(d1, d2); // basic check for independence s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); TaskSeriesCollection u2 = (TaskSeriesCollection) d2.getUnderlyingDataset(); TaskSeries s2 = u2.getSeries("Series"); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertTrue(d1.equals(d2)); }
From source file:org.jfree.data.gantt.SlidingGanttCategoryDatasetTest.java
/** * Confirm that cloning works.//from ww w . ja va2s . c o m */ @Test public void testCloning() throws CloneNotSupportedException { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); SlidingGanttCategoryDataset d1 = new SlidingGanttCategoryDataset(u1, 0, 5); SlidingGanttCategoryDataset d2 = (SlidingGanttCategoryDataset) d1.clone(); assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); // basic check for independence s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); TaskSeriesCollection u2 = (TaskSeriesCollection) d2.getUnderlyingDataset(); TaskSeries s2 = u2.getSeries("Series"); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertTrue(d1.equals(d2)); }
From source file:org.jfree.data.gantt.TaskSeriesCollectionTest.java
/** * Some basic tests for the getSeries() methods. *///from w ww. ja v a2s . c o m @Test public void testGetSeries() { TaskSeries s1 = new TaskSeries("S1"); TaskSeries s2 = new TaskSeries("S2"); TaskSeriesCollection c = new TaskSeriesCollection(); c.add(s1); assertEquals(c.getSeries(0), s1); assertEquals(c.getSeries("S1"), s1); assertEquals(c.getSeries("XX"), null); c.add(s2); assertEquals(c.getSeries(1), s2); assertEquals(c.getSeries("S2"), s2); boolean pass = false; try { c.getSeries(null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.gantt.TaskSeriesCollectionTest.java
/** * Some basic checks for the remove() method. *///from ww w . j a v a2s . c o m @Test public void testRemove() { TaskSeriesCollection c = new TaskSeriesCollection(); TaskSeries s1 = new TaskSeries("S1"); c.add(s1); assertEquals("S1", c.getSeries(0).getKey()); c.remove(0); assertEquals(0, c.getSeriesCount()); c.add(s1); boolean pass = false; try { c.remove(-1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); pass = false; try { c.remove(1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.gantt.TaskSeriesCollectionTest.java
/** * Confirm that cloning works./* www .j a v a 2 s. co m*/ */ @Test public void testCloning() throws CloneNotSupportedException { TaskSeries s1 = new TaskSeries("S1"); s1.add(new Task("T1", new Date(1), new Date(2))); s1.add(new Task("T2", new Date(11), new Date(22))); TaskSeries s2 = new TaskSeries("S2"); s2.add(new Task("T1", new Date(33), new Date(44))); s2.add(new Task("T2", new Date(55), new Date(66))); TaskSeriesCollection c1 = new TaskSeriesCollection(); c1.add(s1); c1.add(s2); TaskSeriesCollection c2 = (TaskSeriesCollection) c1.clone(); assertTrue(c1 != c2); assertTrue(c1.getClass() == c2.getClass()); assertTrue(c1.equals(c2)); // basic check for independence s1.add(new Task("T3", new Date(21), new Date(33))); assertFalse(c1.equals(c2)); TaskSeries series = c2.getSeries("S1"); series.add(new Task("T3", new Date(21), new Date(33))); assertTrue(c1.equals(c2)); }
From source file:org.talend.dataprofiler.chart.TOPChartService.java
@Override public void createAnnotOnGantt(Object chart, List<Object[]> rowList, int multiDateColumn, int nominal) { Map<String, RowColumPair> hightlightSeriesMap = new HashMap<String, RowColumPair>(); CategoryPlot xyplot = (CategoryPlot) ((JFreeChart) chart).getPlot(); CategoryTextAnnotation an;//from w ww . j ava 2 s. c o m for (int seriesCount = 0; seriesCount < ((TaskSeriesCollection) xyplot.getDataset()) .getSeriesCount(); seriesCount++) { int indexOfRow = 0; int columnCount = 0; for (int itemCount = 0; itemCount < ((TaskSeriesCollection) xyplot.getDataset()).getSeries(seriesCount) .getItemCount(); itemCount++, columnCount++) { Task task = ((TaskSeriesCollection) xyplot.getDataset()).getSeries(seriesCount).get(itemCount); String taskDescription = task.getDescription(); String[] taskArray = taskDescription.split("\\|"); //$NON-NLS-1$ boolean isSameTime = task.getDuration().getStart().getTime() == task.getDuration().getEnd() .getTime(); if (!isSameTime && (rowList.get(indexOfRow))[multiDateColumn - 3] != null && (rowList.get(indexOfRow))[multiDateColumn - 2] != null && !((rowList.get(indexOfRow))[multiDateColumn]).equals(new BigDecimal(0L))) { RowColumPair pair = new RowColumPair(); pair.setRow(seriesCount); pair.setColumn(columnCount); hightlightSeriesMap.put(String.valueOf(seriesCount) + String.valueOf(columnCount), pair); an = new CategoryTextAnnotation("#nulls = " + (rowList.get(indexOfRow))[multiDateColumn], //$NON-NLS-1$ taskDescription, task.getDuration().getStart().getTime()); an.setTextAnchor(TextAnchor.CENTER_LEFT); an.setCategoryAnchor(CategoryAnchor.MIDDLE); xyplot.addAnnotation(an); } if (taskArray.length == nominal) { indexOfRow++; if (rowList.size() != indexOfRow && ((rowList.get(indexOfRow))[multiDateColumn - 3] == null || (rowList.get(indexOfRow))[multiDateColumn - 2] == null)) { indexOfRow++; } } } } CustomHideSeriesGanttRender renderer = new CustomHideSeriesGanttRender(hightlightSeriesMap); xyplot.setRenderer(renderer); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { TaskSeriesCollection taskSeriesColl = (TaskSeriesCollection) dataset; List<Task> taskList = new ArrayList<Task>(); for (int i = 0; i < taskSeriesColl.getSeriesCount(); i++) { for (int j = 0; j < taskSeriesColl.getSeries(i).getItemCount(); j++) { taskList.add(taskSeriesColl.getSeries(i).get(j)); } } Task task = taskList.get(column); // Task task = taskSeriesColl.getSeries(row).get(column); String taskDescription = task.getDescription(); Date startDate = task.getDuration().getStart(); Date endDate = task.getDuration().getEnd(); return taskDescription + ", " + startDate + "---->" + endDate; //$NON-NLS-1$ //$NON-NLS-2$ // return "this is a tooltip"; } }); xyplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10.0f); }