Search in sources :

Example 1 with CategoryTextAnnotation

use of org.jfree.chart.annotations.CategoryTextAnnotation in project hmftools by hartwigmedical.

the class GradientBarCustomizer method addLabel.

private static void addLabel(@NotNull final CategoryPlot categoryPlot, @NotNull final String labelText, final int position, @NotNull final Color color, @NotNull final TextAnchor anchor) {
    final Object category = categoryPlot.getCategories().get(0);
    if (category instanceof Comparable) {
        final Comparable categoryKey = (Comparable) category;
        final CategoryTextAnnotation label = new CategoryTextAnnotation(labelText, categoryKey, position);
        label.setPaint(color);
        label.setTextAnchor(anchor);
        categoryPlot.addAnnotation(label);
    }
}
Also used : CategoryTextAnnotation(org.jfree.chart.annotations.CategoryTextAnnotation)

Example 2 with CategoryTextAnnotation

use of org.jfree.chart.annotations.CategoryTextAnnotation in project tdq-studio-se by Talend.

the class TOPChartService method createAnnotOnGantt.

// used by HideSeriesChartComposite
@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;
    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();
            // $NON-NLS-1$
            String[] taskArray = taskDescription.split("\\|");
            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 // $NON-NLS-1$
                CategoryTextAnnotation(// $NON-NLS-1$
                "#nulls = " + (rowList.get(indexOfRow))[multiDateColumn], 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();
            // $NON-NLS-1$ //$NON-NLS-2$
            return taskDescription + ",     " + startDate + "---->" + endDate;
        // return "this is a tooltip";
        }
    });
    xyplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10.0f);
}
Also used : Task(org.jfree.data.gantt.Task) HashMap(java.util.HashMap) CustomHideSeriesGanttRender(org.talend.dataprofiler.chart.preview.CustomHideSeriesGanttRender) CategoryPlot(org.jfree.chart.plot.CategoryPlot) BigDecimal(java.math.BigDecimal) Date(java.util.Date) TaskSeriesCollection(org.jfree.data.gantt.TaskSeriesCollection) RowColumPair(org.talend.dataprofiler.chart.preview.RowColumPair) CategoryToolTipGenerator(org.jfree.chart.labels.CategoryToolTipGenerator) DefaultBoxAndWhiskerCategoryDataset(org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) BoxAndWhiskerCategoryDataset(org.jfree.data.statistics.BoxAndWhiskerCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) List(java.util.List) ArrayList(java.util.ArrayList) CategoryTextAnnotation(org.jfree.chart.annotations.CategoryTextAnnotation)

Aggregations

CategoryTextAnnotation (org.jfree.chart.annotations.CategoryTextAnnotation)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CategoryToolTipGenerator (org.jfree.chart.labels.CategoryToolTipGenerator)1 CategoryPlot (org.jfree.chart.plot.CategoryPlot)1 CategoryDataset (org.jfree.data.category.CategoryDataset)1 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)1 Task (org.jfree.data.gantt.Task)1 TaskSeriesCollection (org.jfree.data.gantt.TaskSeriesCollection)1 BoxAndWhiskerCategoryDataset (org.jfree.data.statistics.BoxAndWhiskerCategoryDataset)1 DefaultBoxAndWhiskerCategoryDataset (org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset)1 CustomHideSeriesGanttRender (org.talend.dataprofiler.chart.preview.CustomHideSeriesGanttRender)1 RowColumPair (org.talend.dataprofiler.chart.preview.RowColumPair)1