Search in sources :

Example 1 with CategoryToolTipGenerator

use of org.jfree.chart.labels.CategoryToolTipGenerator 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)

Example 2 with CategoryToolTipGenerator

use of org.jfree.chart.labels.CategoryToolTipGenerator in project tdq-studio-se by Talend.

the class HideSeriesGanttRenderer method drawTask.

/**
 * Draws a single task.
 *
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the data plot area.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the data.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 */
protected void drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    // Y0
    Number value0 = dataset.getEndValue(row, column);
    if (value0 == null) {
        return;
    }
    double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);
    // Y1
    Number value1 = dataset.getStartValue(row, column);
    if (value1 == null) {
        return;
    }
    double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);
    if (java2dValue1 < java2dValue0) {
        double temp = java2dValue1;
        java2dValue1 = java2dValue0;
        java2dValue0 = temp;
        Number tempNum = value1;
        value1 = value0;
        value0 = tempNum;
    }
    // count the number of non-null values
    int totalBars = countNonNullValues(dataset, column);
    if (totalBars == 0) {
        return;
    }
    // count non-null values up to but not including the current value
    int priorBars = countPriorNonNullValues(dataset, column, row);
    // double rectStart = calculateBarW0(plot, orientation, dataArea,
    // domainAxis, state, row, column);
    // double rectBreadth = state.getBarWidth();
    double rectBreadth = (domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())) / totalBars;
    double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) + rectBreadth * priorBars;
    double rectLength = Math.abs(java2dValue1 - java2dValue0);
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth);
    } else if (orientation == PlotOrientation.VERTICAL) {
        bar = new Rectangle2D.Double(rectStart, java2dValue1, rectBreadth, rectLength);
    }
    Rectangle2D completeBar = null;
    Rectangle2D incompleteBar = null;
    Number percent = dataset.getPercentComplete(row, column);
    double start = getStartPercent();
    double end = getEndPercent();
    if (percent != null) {
        double p = percent.doubleValue();
        if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start));
            incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start));
        } else if (plot.getOrientation() == PlotOrientation.VERTICAL) {
            completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p);
            incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1, rectBreadth * (end - start), rectLength * (1 - p));
        }
    }
    Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (completeBar != null) {
        g2.setPaint(getCompletePaint());
        g2.fill(completeBar);
    }
    if (incompleteBar != null) {
        g2.setPaint(getIncompletePaint());
        g2.fill(incompleteBar);
    }
    // draw the outline...
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = getItemOutlineStroke(row, column);
        Paint paint = getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, false);
    }
    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, row, dataset.getColumnKey(column), column);
            entities.add(entity);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) Paint(java.awt.Paint) EntityCollection(org.jfree.chart.entity.EntityCollection) CategoryToolTipGenerator(org.jfree.chart.labels.CategoryToolTipGenerator) CategoryItemEntity(org.jfree.chart.entity.CategoryItemEntity) RectangleEdge(org.jfree.ui.RectangleEdge)

Aggregations

CategoryToolTipGenerator (org.jfree.chart.labels.CategoryToolTipGenerator)2 Paint (java.awt.Paint)1 Stroke (java.awt.Stroke)1 Rectangle2D (java.awt.geom.Rectangle2D)1 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 CategoryTextAnnotation (org.jfree.chart.annotations.CategoryTextAnnotation)1 CategoryItemEntity (org.jfree.chart.entity.CategoryItemEntity)1 EntityCollection (org.jfree.chart.entity.EntityCollection)1 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)1 CategoryPlot (org.jfree.chart.plot.CategoryPlot)1 PlotOrientation (org.jfree.chart.plot.PlotOrientation)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