2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.ddmuilib.log.event;
19 import org.jfree.chart.axis.ValueAxis;
20 import org.jfree.chart.plot.CrosshairState;
21 import org.jfree.chart.plot.PlotOrientation;
22 import org.jfree.chart.plot.PlotRenderingInfo;
23 import org.jfree.chart.plot.XYPlot;
24 import org.jfree.chart.renderer.xy.XYItemRendererState;
25 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
26 import org.jfree.data.time.TimeSeriesCollection;
27 import org.jfree.data.xy.XYDataset;
28 import org.jfree.ui.RectangleEdge;
30 import java.awt.Graphics2D;
31 import java.awt.Paint;
32 import java.awt.Stroke;
33 import java.awt.geom.Line2D;
34 import java.awt.geom.Rectangle2D;
37 * Custom renderer to render event occurrence. This rendered ignores the y value, and simply
38 * draws a line from min to max at the time of the item.
40 public class OccurrenceRenderer extends XYLineAndShapeRenderer {
42 private static final long serialVersionUID = 1L;
45 public void drawItem(Graphics2D g2,
46 XYItemRendererState state,
48 PlotRenderingInfo info,
55 CrosshairState crosshairState,
57 TimeSeriesCollection timeDataSet = (TimeSeriesCollection)dataset;
59 // get the x value for the series/item.
60 double x = timeDataSet.getX(series, item).doubleValue();
62 // get the min/max of the range axis
63 double yMin = rangeAxis.getLowerBound();
64 double yMax = rangeAxis.getUpperBound();
66 RectangleEdge domainEdge = plot.getDomainAxisEdge();
67 RectangleEdge rangeEdge = plot.getRangeAxisEdge();
69 // convert the coordinates to java2d.
70 double x2D = domainAxis.valueToJava2D(x, dataArea, domainEdge);
71 double yMin2D = rangeAxis.valueToJava2D(yMin, dataArea, rangeEdge);
72 double yMax2D = rangeAxis.valueToJava2D(yMax, dataArea, rangeEdge);
74 // get the paint information for the series/item
75 Paint p = getItemPaint(series, item);
76 Stroke s = getItemStroke(series, item);
79 PlotOrientation orientation = plot.getOrientation();
80 if (orientation == PlotOrientation.HORIZONTAL) {
81 line = new Line2D.Double(yMin2D, x2D, yMax2D, x2D);
83 else if (orientation == PlotOrientation.VERTICAL) {
84 line = new Line2D.Double(x2D, yMin2D, x2D, yMax2D);