| Method from org.jfree.chart.plot.CategoryPlot Detail: |
public void addAnnotation(CategoryAnnotation annotation) {
addAnnotation(annotation, true);
}
Adds an annotation to the plot and sends a PlotChangeEvent to all
registered listeners. |
public void addAnnotation(CategoryAnnotation annotation,
boolean notify) {
if (annotation == null) {
throw new IllegalArgumentException("Null 'annotation' argument.");
}
this.annotations.add(annotation);
if (notify) {
fireChangeEvent();
}
}
Adds an annotation to the plot and, if requested, sends a
PlotChangeEvent to all registered listeners. |
public void addDomainMarker(CategoryMarker marker) {
addDomainMarker(marker, Layer.FOREGROUND);
}
Adds a marker for display (in the foreground) against the domain axis and
sends a PlotChangeEvent to all registered listeners. Typically a
marker will be drawn by the renderer as a line perpendicular to the
domain axis, however this is entirely up to the renderer. |
public void addDomainMarker(CategoryMarker marker,
Layer layer) {
addDomainMarker(0, marker, layer);
}
Adds a marker for display against the domain axis and sends a
PlotChangeEvent to all registered listeners. Typically a marker
will be drawn by the renderer as a line perpendicular to the domain
axis, however this is entirely up to the renderer. |
public void addDomainMarker(int index,
CategoryMarker marker,
Layer layer) {
addDomainMarker(index, marker, layer, true);
}
Adds a marker for display by a particular renderer and sends a
PlotChangeEvent to all registered listeners.
Typically a marker will be drawn by the renderer as a line perpendicular
to a domain axis, however this is entirely up to the renderer. |
public void addDomainMarker(int index,
CategoryMarker marker,
Layer layer,
boolean notify) {
if (marker == null) {
throw new IllegalArgumentException("Null 'marker' not permitted.");
}
if (layer == null) {
throw new IllegalArgumentException("Null 'layer' not permitted.");
}
Collection markers;
if (layer == Layer.FOREGROUND) {
markers = (Collection) this.foregroundDomainMarkers.get(
new Integer(index));
if (markers == null) {
markers = new java.util.ArrayList();
this.foregroundDomainMarkers.put(new Integer(index), markers);
}
markers.add(marker);
}
else if (layer == Layer.BACKGROUND) {
markers = (Collection) this.backgroundDomainMarkers.get(
new Integer(index));
if (markers == null) {
markers = new java.util.ArrayList();
this.backgroundDomainMarkers.put(new Integer(index), markers);
}
markers.add(marker);
}
marker.addChangeListener(this);
if (notify) {
fireChangeEvent();
}
}
Adds a marker for display by a particular renderer and, if requested,
sends a PlotChangeEvent to all registered listeners.
Typically a marker will be drawn by the renderer as a line perpendicular
to a domain axis, however this is entirely up to the renderer. |
public void addRangeMarker(Marker marker) {
addRangeMarker(marker, Layer.FOREGROUND);
}
Adds a marker for display (in the foreground) against the range axis and
sends a PlotChangeEvent to all registered listeners. Typically a
marker will be drawn by the renderer as a line perpendicular to the
range axis, however this is entirely up to the renderer. |
public void addRangeMarker(Marker marker,
Layer layer) {
addRangeMarker(0, marker, layer);
}
Adds a marker for display against the range axis and sends a
PlotChangeEvent to all registered listeners. Typically a marker
will be drawn by the renderer as a line perpendicular to the range axis,
however this is entirely up to the renderer. |
public void addRangeMarker(int index,
Marker marker,
Layer layer) {
addRangeMarker(index, marker, layer, true);
}
Adds a marker for display by a particular renderer and sends a
PlotChangeEvent to all registered listeners.
Typically a marker will be drawn by the renderer as a line perpendicular
to a range axis, however this is entirely up to the renderer. |
public void addRangeMarker(int index,
Marker marker,
Layer layer,
boolean notify) {
Collection markers;
if (layer == Layer.FOREGROUND) {
markers = (Collection) this.foregroundRangeMarkers.get(
new Integer(index));
if (markers == null) {
markers = new java.util.ArrayList();
this.foregroundRangeMarkers.put(new Integer(index), markers);
}
markers.add(marker);
}
else if (layer == Layer.BACKGROUND) {
markers = (Collection) this.backgroundRangeMarkers.get(
new Integer(index));
if (markers == null) {
markers = new java.util.ArrayList();
this.backgroundRangeMarkers.put(new Integer(index), markers);
}
markers.add(marker);
}
marker.addChangeListener(this);
if (notify) {
fireChangeEvent();
}
}
Adds a marker for display by a particular renderer and sends a
PlotChangeEvent to all registered listeners.
Typically a marker will be drawn by the renderer as a line perpendicular
to a range axis, however this is entirely up to the renderer. |
protected AxisSpace calculateAxisSpace(Graphics2D g2,
Rectangle2D plotArea) {
AxisSpace space = new AxisSpace();
space = calculateRangeAxisSpace(g2, plotArea, space);
space = calculateDomainAxisSpace(g2, plotArea, space);
return space;
}
Calculates the space required for the axes. |
protected AxisSpace calculateDomainAxisSpace(Graphics2D g2,
Rectangle2D plotArea,
AxisSpace space) {
if (space == null) {
space = new AxisSpace();
}
// reserve some space for the domain axis...
if (this.fixedDomainAxisSpace != null) {
if (this.orientation == PlotOrientation.HORIZONTAL) {
space.ensureAtLeast(
this.fixedDomainAxisSpace.getLeft(), RectangleEdge.LEFT);
space.ensureAtLeast(this.fixedDomainAxisSpace.getRight(),
RectangleEdge.RIGHT);
}
else if (this.orientation == PlotOrientation.VERTICAL) {
space.ensureAtLeast(this.fixedDomainAxisSpace.getTop(),
RectangleEdge.TOP);
space.ensureAtLeast(this.fixedDomainAxisSpace.getBottom(),
RectangleEdge.BOTTOM);
}
}
else {
// reserve space for the primary domain axis...
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
getDomainAxisLocation(), this.orientation);
if (this.drawSharedDomainAxis) {
space = getDomainAxis().reserveSpace(g2, this, plotArea,
domainEdge, space);
}
// reserve space for any domain axes...
for (int i = 0; i < this.domainAxes.size(); i++) {
Axis xAxis = (Axis) this.domainAxes.get(i);
if (xAxis != null) {
RectangleEdge edge = getDomainAxisEdge(i);
space = xAxis.reserveSpace(g2, this, plotArea, edge, space);
}
}
}
return space;
}
Calculates the space required for the domain axis/axes. |
protected AxisSpace calculateRangeAxisSpace(Graphics2D g2,
Rectangle2D plotArea,
AxisSpace space) {
if (space == null) {
space = new AxisSpace();
}
// reserve some space for the range axis...
if (this.fixedRangeAxisSpace != null) {
if (this.orientation == PlotOrientation.HORIZONTAL) {
space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(),
RectangleEdge.TOP);
space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(),
RectangleEdge.BOTTOM);
}
else if (this.orientation == PlotOrientation.VERTICAL) {
space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(),
RectangleEdge.LEFT);
space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(),
RectangleEdge.RIGHT);
}
}
else {
// reserve space for the range axes (if any)...
for (int i = 0; i < this.rangeAxes.size(); i++) {
Axis yAxis = (Axis) this.rangeAxes.get(i);
if (yAxis != null) {
RectangleEdge edge = getRangeAxisEdge(i);
space = yAxis.reserveSpace(g2, this, plotArea, edge, space);
}
}
}
return space;
}
Calculates the space required for the range axis/axes. |
public void clearAnnotations() {
this.annotations.clear();
fireChangeEvent();
}
Clears all the annotations and sends a PlotChangeEvent to all
registered listeners. |
public void clearDomainAxes() {
for (int i = 0; i < this.domainAxes.size(); i++) {
CategoryAxis axis = (CategoryAxis) this.domainAxes.get(i);
if (axis != null) {
axis.removeChangeListener(this);
}
}
this.domainAxes.clear();
fireChangeEvent();
}
Clears the domain axes from the plot and sends a PlotChangeEvent
to all registered listeners. |
public void clearDomainMarkers() {
if (this.backgroundDomainMarkers != null) {
Set keys = this.backgroundDomainMarkers.keySet();
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Integer key = (Integer) iterator.next();
clearDomainMarkers(key.intValue());
}
this.backgroundDomainMarkers.clear();
}
if (this.foregroundDomainMarkers != null) {
Set keys = this.foregroundDomainMarkers.keySet();
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Integer key = (Integer) iterator.next();
clearDomainMarkers(key.intValue());
}
this.foregroundDomainMarkers.clear();
}
fireChangeEvent();
}
Clears all the domain markers for the plot and sends a
PlotChangeEvent to all registered listeners. |
public void clearDomainMarkers(int index) {
Integer key = new Integer(index);
if (this.backgroundDomainMarkers != null) {
Collection markers
= (Collection) this.backgroundDomainMarkers.get(key);
if (markers != null) {
Iterator iterator = markers.iterator();
while (iterator.hasNext()) {
Marker m = (Marker) iterator.next();
m.removeChangeListener(this);
}
markers.clear();
}
}
if (this.foregroundDomainMarkers != null) {
Collection markers
= (Collection) this.foregroundDomainMarkers.get(key);
if (markers != null) {
Iterator iterator = markers.iterator();
while (iterator.hasNext()) {
Marker m = (Marker) iterator.next();
m.removeChangeListener(this);
}
markers.clear();
}
}
fireChangeEvent();
}
Clears all the domain markers for the specified renderer. |
public void clearRangeAxes() {
for (int i = 0; i < this.rangeAxes.size(); i++) {
ValueAxis axis = (ValueAxis) this.rangeAxes.get(i);
if (axis != null) {
axis.removeChangeListener(this);
}
}
this.rangeAxes.clear();
fireChangeEvent();
}
Clears the range axes from the plot and sends a PlotChangeEvent
to all registered listeners. |
public void clearRangeMarkers() {
if (this.backgroundRangeMarkers != null) {
Set keys = this.backgroundRangeMarkers.keySet();
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Integer key = (Integer) iterator.next();
clearRangeMarkers(key.intValue());
}
this.backgroundRangeMarkers.clear();
}
if (this.foregroundRangeMarkers != null) {
Set keys = this.foregroundRangeMarkers.keySet();
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Integer key = (Integer) iterator.next();
clearRangeMarkers(key.intValue());
}
this.foregroundRangeMarkers.clear();
}
fireChangeEvent();
}
Clears all the range markers for the plot and sends a
PlotChangeEvent to all registered listeners. |
public void clearRangeMarkers(int index) {
Integer key = new Integer(index);
if (this.backgroundRangeMarkers != null) {
Collection markers
= (Collection) this.backgroundRangeMarkers.get(key);
if (markers != null) {
Iterator iterator = markers.iterator();
while (iterator.hasNext()) {
Marker m = (Marker) iterator.next();
m.removeChangeListener(this);
}
markers.clear();
}
}
if (this.foregroundRangeMarkers != null) {
Collection markers
= (Collection) this.foregroundRangeMarkers.get(key);
if (markers != null) {
Iterator iterator = markers.iterator();
while (iterator.hasNext()) {
Marker m = (Marker) iterator.next();
m.removeChangeListener(this);
}
markers.clear();
}
}
fireChangeEvent();
}
Clears all the range markers for the specified renderer. |
public Object clone() throws CloneNotSupportedException {
CategoryPlot clone = (CategoryPlot) super.clone();
clone.domainAxes = new ObjectList();
for (int i = 0; i < this.domainAxes.size(); i++) {
CategoryAxis xAxis = (CategoryAxis) this.domainAxes.get(i);
if (xAxis != null) {
CategoryAxis clonedAxis = (CategoryAxis) xAxis.clone();
clone.setDomainAxis(i, clonedAxis);
}
}
clone.domainAxisLocations
= (ObjectList) this.domainAxisLocations.clone();
clone.rangeAxes = new ObjectList();
for (int i = 0; i < this.rangeAxes.size(); i++) {
ValueAxis yAxis = (ValueAxis) this.rangeAxes.get(i);
if (yAxis != null) {
ValueAxis clonedAxis = (ValueAxis) yAxis.clone();
clone.setRangeAxis(i, clonedAxis);
}
}
clone.rangeAxisLocations = (ObjectList) this.rangeAxisLocations.clone();
clone.datasets = (ObjectList) this.datasets.clone();
for (int i = 0; i < clone.datasets.size(); i++) {
CategoryDataset dataset = clone.getDataset(i);
if (dataset != null) {
dataset.addChangeListener(clone);
}
}
clone.datasetToDomainAxisMap
= (ObjectList) this.datasetToDomainAxisMap.clone();
clone.datasetToRangeAxisMap
= (ObjectList) this.datasetToRangeAxisMap.clone();
clone.renderers = (ObjectList) this.renderers.clone();
if (this.fixedDomainAxisSpace != null) {
clone.fixedDomainAxisSpace = (AxisSpace) ObjectUtilities.clone(
this.fixedDomainAxisSpace);
}
if (this.fixedRangeAxisSpace != null) {
clone.fixedRangeAxisSpace = (AxisSpace) ObjectUtilities.clone(
this.fixedRangeAxisSpace);
}
clone.annotations = (List) ObjectUtilities.deepClone(this.annotations);
clone.foregroundDomainMarkers = cloneMarkerMap(
this.foregroundDomainMarkers);
clone.backgroundDomainMarkers = cloneMarkerMap(
this.backgroundDomainMarkers);
clone.foregroundRangeMarkers = cloneMarkerMap(
this.foregroundRangeMarkers);
clone.backgroundRangeMarkers = cloneMarkerMap(
this.backgroundRangeMarkers);
if (this.fixedLegendItems != null) {
clone.fixedLegendItems
= (LegendItemCollection) this.fixedLegendItems.clone();
}
return clone;
}
Returns a clone of the plot. |
public void configureDomainAxes() {
for (int i = 0; i < this.domainAxes.size(); i++) {
CategoryAxis axis = (CategoryAxis) this.domainAxes.get(i);
if (axis != null) {
axis.configure();
}
}
}
Configures the domain axes. |
public void configureRangeAxes() {
for (int i = 0; i < this.rangeAxes.size(); i++) {
ValueAxis axis = (ValueAxis) this.rangeAxes.get(i);
if (axis != null) {
axis.configure();
}
}
}
Configures the range axes. |
public void datasetChanged(DatasetChangeEvent event) {
int count = this.rangeAxes.size();
for (int axisIndex = 0; axisIndex < count; axisIndex++) {
ValueAxis yAxis = getRangeAxis(axisIndex);
if (yAxis != null) {
yAxis.configure();
}
}
if (getParent() != null) {
getParent().datasetChanged(event);
}
else {
PlotChangeEvent e = new PlotChangeEvent(this);
e.setType(ChartChangeEventType.DATASET_UPDATED);
notifyListeners(e);
}
}
|
public void draw(Graphics2D g2,
Rectangle2D area,
Point2D anchor,
PlotState parentState,
PlotRenderingInfo state) {
// if the plot area is too small, just return...
boolean b1 = (area.getWidth() < = MINIMUM_WIDTH_TO_DRAW);
boolean b2 = (area.getHeight() < = MINIMUM_HEIGHT_TO_DRAW);
if (b1 || b2) {
return;
}
// record the plot area...
if (state == null) {
// if the incoming state is null, no information will be passed
// back to the caller - but we create a temporary state to record
// the plot area, since that is used later by the axes
state = new PlotRenderingInfo(null);
}
state.setPlotArea(area);
// adjust the drawing area for the plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
// calculate the data area...
AxisSpace space = calculateAxisSpace(g2, area);
Rectangle2D dataArea = space.shrink(area, null);
this.axisOffset.trim(dataArea);
state.setDataArea(dataArea);
// if there is a renderer, it draws the background, otherwise use the
// default background...
if (getRenderer() != null) {
getRenderer().drawBackground(g2, this, dataArea);
}
else {
drawBackground(g2, dataArea);
}
Map axisStateMap = drawAxes(g2, area, dataArea, state);
// don't let anyone draw outside the data area
Shape savedClip = g2.getClip();
g2.clip(dataArea);
drawDomainGridlines(g2, dataArea);
AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
if (rangeAxisState == null) {
if (parentState != null) {
rangeAxisState = (AxisState) parentState.getSharedAxisStates()
.get(getRangeAxis());
}
}
if (rangeAxisState != null) {
drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
}
// draw the markers...
for (int i = 0; i < this.renderers.size(); i++) {
drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND);
}
for (int i = 0; i < this.renderers.size(); i++) {
drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND);
}
// now render data items...
boolean foundData = false;
// set up the alpha-transparency...
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, getForegroundAlpha()));
DatasetRenderingOrder order = getDatasetRenderingOrder();
if (order == DatasetRenderingOrder.FORWARD) {
for (int i = 0; i < this.datasets.size(); i++) {
foundData = render(g2, dataArea, i, state) || foundData;
}
}
else { // DatasetRenderingOrder.REVERSE
for (int i = this.datasets.size() - 1; i >= 0; i--) {
foundData = render(g2, dataArea, i, state) || foundData;
}
}
// draw the foreground markers...
for (int i = 0; i < this.renderers.size(); i++) {
drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
}
for (int i = 0; i < this.renderers.size(); i++) {
drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
}
// draw the annotations (if any)...
drawAnnotations(g2, dataArea);
g2.setClip(savedClip);
g2.setComposite(originalComposite);
if (!foundData) {
drawNoDataMessage(g2, dataArea);
}
// draw range crosshair if required...
if (isRangeCrosshairVisible()) {
// FIXME: this doesn't handle multiple range axes
drawRangeCrosshair(g2, dataArea, getOrientation(),
getRangeCrosshairValue(), getRangeAxis(),
getRangeCrosshairStroke(), getRangeCrosshairPaint());
}
// draw an outline around the plot area...
if (getRenderer() != null) {
getRenderer().drawOutline(g2, this, dataArea);
}
else {
drawOutline(g2, dataArea);
}
}
Draws the plot on a Java 2D graphics device (such as the screen or a
printer).
At your option, you may supply an instance of PlotRenderingInfo .
If you do, it will be populated with information about the drawing,
including various plot dimensions and tooltip info. |
protected void drawAnnotations(Graphics2D g2,
Rectangle2D dataArea) {
if (getAnnotations() != null) {
Iterator iterator = getAnnotations().iterator();
while (iterator.hasNext()) {
CategoryAnnotation annotation
= (CategoryAnnotation) iterator.next();
annotation.draw(g2, this, dataArea, getDomainAxis(),
getRangeAxis());
}
}
}
|
protected Map drawAxes(Graphics2D g2,
Rectangle2D plotArea,
Rectangle2D dataArea,
PlotRenderingInfo plotState) {
AxisCollection axisCollection = new AxisCollection();
// add domain axes to lists...
for (int index = 0; index < this.domainAxes.size(); index++) {
CategoryAxis xAxis = (CategoryAxis) this.domainAxes.get(index);
if (xAxis != null) {
axisCollection.add(xAxis, getDomainAxisEdge(index));
}
}
// add range axes to lists...
for (int index = 0; index < this.rangeAxes.size(); index++) {
ValueAxis yAxis = (ValueAxis) this.rangeAxes.get(index);
if (yAxis != null) {
axisCollection.add(yAxis, getRangeAxisEdge(index));
}
}
Map axisStateMap = new HashMap();
// draw the top axes
double cursor = dataArea.getMinY() - this.axisOffset.calculateTopOutset(
dataArea.getHeight());
Iterator iterator = axisCollection.getAxesAtTop().iterator();
while (iterator.hasNext()) {
Axis axis = (Axis) iterator.next();
if (axis != null) {
AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea,
RectangleEdge.TOP, plotState);
cursor = axisState.getCursor();
axisStateMap.put(axis, axisState);
}
}
// draw the bottom axes
cursor = dataArea.getMaxY()
+ this.axisOffset.calculateBottomOutset(dataArea.getHeight());
iterator = axisCollection.getAxesAtBottom().iterator();
while (iterator.hasNext()) {
Axis axis = (Axis) iterator.next();
if (axis != null) {
AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea,
RectangleEdge.BOTTOM, plotState);
cursor = axisState.getCursor();
axisStateMap.put(axis, axisState);
}
}
// draw the left axes
cursor = dataArea.getMinX()
- this.axisOffset.calculateLeftOutset(dataArea.getWidth());
iterator = axisCollection.getAxesAtLeft().iterator();
while (iterator.hasNext()) {
Axis axis = (Axis) iterator.next();
if (axis != null) {
AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea,
RectangleEdge.LEFT, plotState);
cursor = axisState.getCursor();
axisStateMap.put(axis, axisState);
}
}
// draw the right axes
cursor = dataArea.getMaxX()
+ this.axisOffset.calculateRightOutset(dataArea.getWidth());
iterator = axisCollection.getAxesAtRight().iterator();
while (iterator.hasNext()) {
Axis axis = (Axis) iterator.next();
if (axis != null) {
AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea,
RectangleEdge.RIGHT, plotState);
cursor = axisState.getCursor();
axisStateMap.put(axis, axisState);
}
}
return axisStateMap;
}
A utility method for drawing the plot's axes. |
public void drawBackground(Graphics2D g2,
Rectangle2D area) {
fillBackground(g2, area, this.orientation);
drawBackgroundImage(g2, area);
}
Draws the plot background (the background color and/or image).
This method will be called during the chart drawing process and is
declared public so that it can be accessed by the renderers used by
certain subclasses. You shouldn't need to call this method directly. |
protected void drawDomainGridlines(Graphics2D g2,
Rectangle2D dataArea) {
// draw the domain grid lines, if any...
if (isDomainGridlinesVisible()) {
CategoryAnchor anchor = getDomainGridlinePosition();
RectangleEdge domainAxisEdge = getDomainAxisEdge();
Stroke gridStroke = getDomainGridlineStroke();
Paint gridPaint = getDomainGridlinePaint();
if ((gridStroke != null) && (gridPaint != null)) {
// iterate over the categories
CategoryDataset data = getDataset();
if (data != null) {
CategoryAxis axis = getDomainAxis();
if (axis != null) {
int columnCount = data.getColumnCount();
for (int c = 0; c < columnCount; c++) {
double xx = axis.getCategoryJava2DCoordinate(
anchor, c, columnCount, dataArea,
domainAxisEdge);
CategoryItemRenderer renderer1 = getRenderer();
if (renderer1 != null) {
renderer1.drawDomainGridline(g2, this,
dataArea, xx);
}
}
}
}
}
}
}
Draws the gridlines for the plot. |
protected void drawDomainMarkers(Graphics2D g2,
Rectangle2D dataArea,
int index,
Layer layer) {
CategoryItemRenderer r = getRenderer(index);
if (r == null) {
return;
}
Collection markers = getDomainMarkers(index, layer);
CategoryAxis axis = getDomainAxisForDataset(index);
if (markers != null && axis != null) {
Iterator iterator = markers.iterator();
while (iterator.hasNext()) {
CategoryMarker marker = (CategoryMarker) iterator.next();
r.drawDomainMarker(g2, this, axis, marker, dataArea);
}
}
}
Draws the domain markers (if any) for an axis and layer. This method is
typically called from within the draw() method. |
protected void drawRangeCrosshair(Graphics2D g2,
Rectangle2D dataArea,
PlotOrientation orientation,
double value,
ValueAxis axis,
Stroke stroke,
Paint paint) {
if (!axis.getRange().contains(value)) {
return;
}
Line2D line = null;
if (orientation == PlotOrientation.HORIZONTAL) {
double xx = axis.valueToJava2D(value, dataArea,
RectangleEdge.BOTTOM);
line = new Line2D.Double(xx, dataArea.getMinY(), xx,
dataArea.getMaxY());
}
else {
double yy = axis.valueToJava2D(value, dataArea,
RectangleEdge.LEFT);
line = new Line2D.Double(dataArea.getMinX(), yy,
dataArea.getMaxX(), yy);
}
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(line);
}
|
protected void drawRangeGridlines(Graphics2D g2,
Rectangle2D dataArea,
List ticks) {
// draw the range grid lines, if any...
if (isRangeGridlinesVisible()) {
Stroke gridStroke = getRangeGridlineStroke();
Paint gridPaint = getRangeGridlinePaint();
if ((gridStroke != null) && (gridPaint != null)) {
ValueAxis axis = getRangeAxis();
if (axis != null) {
Iterator iterator = ticks.iterator();
while (iterator.hasNext()) {
ValueTick tick = (ValueTick) iterator.next();
CategoryItemRenderer renderer1 = getRenderer();
if (renderer1 != null) {
renderer1.drawRangeGridline(g2, this,
getRangeAxis(), dataArea, tick.getValue());
}
}
}
}
}
}
Draws the gridlines for the plot. |
protected void drawRangeLine(Graphics2D g2,
Rectangle2D dataArea,
double value,
Stroke stroke,
Paint paint) {
double java2D = getRangeAxis().valueToJava2D(value, dataArea,
getRangeAxisEdge());
Line2D line = null;
if (this.orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(java2D, dataArea.getMinY(), java2D,
dataArea.getMaxY());
}
else if (this.orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(dataArea.getMinX(), java2D,
dataArea.getMaxX(), java2D);
}
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(line);
}
Utility method for drawing a line perpendicular to the range axis (used
for crosshairs). |
protected void drawRangeMarkers(Graphics2D g2,
Rectangle2D dataArea,
int index,
Layer layer) {
CategoryItemRenderer r = getRenderer(index);
if (r == null) {
return;
}
Collection markers = getRangeMarkers(index, layer);
ValueAxis axis = getRangeAxisForDataset(index);
if (markers != null && axis != null) {
Iterator iterator = markers.iterator();
while (iterator.hasNext()) {
Marker marker = (Marker) iterator.next();
r.drawRangeMarker(g2, this, axis, marker, dataArea);
}
}
}
Draws the range markers (if any) for an axis and layer. This method is
typically called from within the draw() method. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CategoryPlot)) {
return false;
}
CategoryPlot that = (CategoryPlot) obj;
if (this.orientation != that.orientation) {
return false;
}
if (!ObjectUtilities.equal(this.axisOffset, that.axisOffset)) {
return false;
}
if (!this.domainAxes.equals(that.domainAxes)) {
return false;
}
if (!this.domainAxisLocations.equals(that.domainAxisLocations)) {
return false;
}
if (this.drawSharedDomainAxis != that.drawSharedDomainAxis) {
return false;
}
if (!this.rangeAxes.equals(that.rangeAxes)) {
return false;
}
if (!this.rangeAxisLocations.equals(that.rangeAxisLocations)) {
return false;
}
if (!ObjectUtilities.equal(this.datasetToDomainAxisMap,
that.datasetToDomainAxisMap)) {
return false;
}
if (!ObjectUtilities.equal(this.datasetToRangeAxisMap,
that.datasetToRangeAxisMap)) {
return false;
}
if (!ObjectUtilities.equal(this.renderers, that.renderers)) {
return false;
}
if (this.renderingOrder != that.renderingOrder) {
return false;
}
if (this.columnRenderingOrder != that.columnRenderingOrder) {
return false;
}
if (this.rowRenderingOrder != that.rowRenderingOrder) {
return false;
}
if (this.domainGridlinesVisible != that.domainGridlinesVisible) {
return false;
}
if (this.domainGridlinePosition != that.domainGridlinePosition) {
return false;
}
if (!ObjectUtilities.equal(this.domainGridlineStroke,
that.domainGridlineStroke)) {
return false;
}
if (!PaintUtilities.equal(this.domainGridlinePaint,
that.domainGridlinePaint)) {
return false;
}
if (this.rangeGridlinesVisible != that.rangeGridlinesVisible) {
return false;
}
if (!ObjectUtilities.equal(this.rangeGridlineStroke,
that.rangeGridlineStroke)) {
return false;
}
if (!PaintUtilities.equal(this.rangeGridlinePaint,
that.rangeGridlinePaint)) {
return false;
}
if (this.anchorValue != that.anchorValue) {
return false;
}
if (this.rangeCrosshairVisible != that.rangeCrosshairVisible) {
return false;
}
if (this.rangeCrosshairValue != that.rangeCrosshairValue) {
return false;
}
if (!ObjectUtilities.equal(this.rangeCrosshairStroke,
that.rangeCrosshairStroke)) {
return false;
}
if (!PaintUtilities.equal(this.rangeCrosshairPaint,
that.rangeCrosshairPaint)) {
return false;
}
if (this.rangeCrosshairLockedOnData
!= that.rangeCrosshairLockedOnData) {
return false;
}
if (!ObjectUtilities.equal(this.foregroundDomainMarkers,
that.foregroundDomainMarkers)) {
return false;
}
if (!ObjectUtilities.equal(this.backgroundDomainMarkers,
that.backgroundDomainMarkers)) {
return false;
}
if (!ObjectUtilities.equal(this.foregroundRangeMarkers,
that.foregroundRangeMarkers)) {
return false;
}
if (!ObjectUtilities.equal(this.backgroundRangeMarkers,
that.backgroundRangeMarkers)) {
return false;
}
if (!ObjectUtilities.equal(this.annotations, that.annotations)) {
return false;
}
if (this.weight != that.weight) {
return false;
}
if (!ObjectUtilities.equal(this.fixedDomainAxisSpace,
that.fixedDomainAxisSpace)) {
return false;
}
if (!ObjectUtilities.equal(this.fixedRangeAxisSpace,
that.fixedRangeAxisSpace)) {
return false;
}
if (!ObjectUtilities.equal(this.fixedLegendItems,
that.fixedLegendItems)) {
return false;
}
return super.equals(obj);
}
Tests the plot for equality with an arbitrary object. |
public double getAnchorValue() {
return this.anchorValue;
}
Returns the anchor value. |
public List getAnnotations() {
return this.annotations;
}
Returns the list of annotations. |
public RectangleInsets getAxisOffset() {
return this.axisOffset;
}
|
public List getCategories() {
List result = null;
if (getDataset() != null) {
result = Collections.unmodifiableList(getDataset().getColumnKeys());
}
return result;
}
Returns a list of the categories in the plot's primary dataset. |
public List getCategoriesForAxis(CategoryAxis axis) {
List result = new ArrayList();
int axisIndex = this.domainAxes.indexOf(axis);
List datasets = datasetsMappedToDomainAxis(axisIndex);
Iterator iterator = datasets.iterator();
while (iterator.hasNext()) {
CategoryDataset dataset = (CategoryDataset) iterator.next();
// add the unique categories from this dataset
for (int i = 0; i < dataset.getColumnCount(); i++) {
Comparable category = dataset.getColumnKey(i);
if (!result.contains(category)) {
result.add(category);
}
}
}
return result;
}
Returns a list of the categories that should be displayed for the
specified axis. |
public SortOrder getColumnRenderingOrder() {
return this.columnRenderingOrder;
}
Returns the order in which the columns are rendered. The default value
is SortOrder.ASCENDING. |
public Range getDataRange(ValueAxis axis) {
Range result = null;
List mappedDatasets = new ArrayList();
int rangeIndex = this.rangeAxes.indexOf(axis);
if (rangeIndex >= 0) {
mappedDatasets.addAll(datasetsMappedToRangeAxis(rangeIndex));
}
else if (axis == getRangeAxis()) {
mappedDatasets.addAll(datasetsMappedToRangeAxis(0));
}
// iterate through the datasets that map to the axis and get the union
// of the ranges.
Iterator iterator = mappedDatasets.iterator();
while (iterator.hasNext()) {
CategoryDataset d = (CategoryDataset) iterator.next();
CategoryItemRenderer r = getRendererForDataset(d);
if (r != null) {
result = Range.combine(result, r.findRangeBounds(d));
}
}
return result;
}
Returns the range of data values that will be plotted against the range
axis. If the dataset is null, this method returns
null. |
public CategoryDataset getDataset() {
return getDataset(0);
}
Returns the primary dataset for the plot. |
public CategoryDataset getDataset(int index) {
CategoryDataset result = null;
if (this.datasets.size() > index) {
result = (CategoryDataset) this.datasets.get(index);
}
return result;
}
Returns the dataset at the given index. |
public int getDatasetCount() {
return this.datasets.size();
}
Returns the number of datasets. |
public DatasetRenderingOrder getDatasetRenderingOrder() {
return this.renderingOrder;
}
Returns the dataset rendering order. |
public CategoryAxis getDomainAxis() {
return getDomainAxis(0);
}
Returns the domain axis for the plot. If the domain axis for this plot
is null, then the method will return the parent plot's
domain axis (if there is a parent plot). |
public CategoryAxis getDomainAxis(int index) {
CategoryAxis result = null;
if (index < this.domainAxes.size()) {
result = (CategoryAxis) this.domainAxes.get(index);
}
if (result == null) {
Plot parent = getParent();
if (parent instanceof CategoryPlot) {
CategoryPlot cp = (CategoryPlot) parent;
result = cp.getDomainAxis(index);
}
}
return result;
}
|
public int getDomainAxisCount() {
return this.domainAxes.size();
}
Returns the number of domain axes. |
public RectangleEdge getDomainAxisEdge() {
return getDomainAxisEdge(0);
}
Returns the domain axis edge. This is derived from the axis location
and the plot orientation. |
public RectangleEdge getDomainAxisEdge(int index) {
RectangleEdge result = null;
AxisLocation location = getDomainAxisLocation(index);
if (location != null) {
result = Plot.resolveDomainAxisLocation(location, this.orientation);
}
else {
result = RectangleEdge.opposite(getDomainAxisEdge(0));
}
return result;
}
Returns the edge for a domain axis. |
public CategoryAxis getDomainAxisForDataset(int index) {
CategoryAxis result = getDomainAxis();
Integer axisIndex = (Integer) this.datasetToDomainAxisMap.get(index);
if (axisIndex != null) {
result = getDomainAxis(axisIndex.intValue());
}
return result;
}
|
public int getDomainAxisIndex(CategoryAxis axis) {
if (axis == null) {
throw new IllegalArgumentException("Null 'axis' argument.");
}
return this.domainAxes.indexOf(axis);
}
Returns the index of the specified axis, or -1 if the axis
is not assigned to the plot. |
public AxisLocation getDomainAxisLocation() {
return getDomainAxisLocation(0);
}
Returns the domain axis location for the primary domain axis. |
public AxisLocation getDomainAxisLocation(int index) {
AxisLocation result = null;
if (index < this.domainAxisLocations.size()) {
result = (AxisLocation) this.domainAxisLocations.get(index);
}
if (result == null) {
result = AxisLocation.getOpposite(getDomainAxisLocation(0));
}
return result;
}
Returns the location for a domain axis. |
public Paint getDomainGridlinePaint() {
return this.domainGridlinePaint;
}
Returns the paint used to draw grid-lines against the domain axis. |
public CategoryAnchor getDomainGridlinePosition() {
return this.domainGridlinePosition;
}
Returns the position used for the domain gridlines. |
public Stroke getDomainGridlineStroke() {
return this.domainGridlineStroke;
}
Returns the stroke used to draw grid-lines against the domain axis. |
public Collection getDomainMarkers(Layer layer) {
return getDomainMarkers(0, layer);
}
Returns the list of domain markers (read only) for the specified layer. |
public Collection getDomainMarkers(int index,
Layer layer) {
Collection result = null;
Integer key = new Integer(index);
if (layer == Layer.FOREGROUND) {
result = (Collection) this.foregroundDomainMarkers.get(key);
}
else if (layer == Layer.BACKGROUND) {
result = (Collection) this.backgroundDomainMarkers.get(key);
}
if (result != null) {
result = Collections.unmodifiableCollection(result);
}
return result;
}
Returns a collection of domain markers for a particular renderer and
layer. |
public boolean getDrawSharedDomainAxis() {
return this.drawSharedDomainAxis;
}
Returns the flag that controls whether or not the shared domain axis is
drawn for each subplot. |
public AxisSpace getFixedDomainAxisSpace() {
return this.fixedDomainAxisSpace;
}
Returns the fixed domain axis space. |
public LegendItemCollection getFixedLegendItems() {
return this.fixedLegendItems;
}
Returns the fixed legend items, if any. |
public AxisSpace getFixedRangeAxisSpace() {
return this.fixedRangeAxisSpace;
}
Returns the fixed range axis space. |
public int getIndexOf(CategoryItemRenderer renderer) {
return this.renderers.indexOf(renderer);
}
Returns the index of the specified renderer, or -1 if the
renderer is not assigned to this plot. |
public LegendItemCollection getLegendItems() {
LegendItemCollection result = this.fixedLegendItems;
if (result == null) {
result = new LegendItemCollection();
// get the legend items for the datasets...
int count = this.datasets.size();
for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
CategoryDataset dataset = getDataset(datasetIndex);
if (dataset != null) {
CategoryItemRenderer renderer = getRenderer(datasetIndex);
if (renderer != null) {
int seriesCount = dataset.getRowCount();
for (int i = 0; i < seriesCount; i++) {
LegendItem item = renderer.getLegendItem(
datasetIndex, i);
if (item != null) {
result.add(item);
}
}
}
}
}
}
return result;
}
Returns the legend items for the plot. By default, this method creates
a legend item for each series in each of the datasets. You can change
this behaviour by overriding this method. |
public PlotOrientation getOrientation() {
return this.orientation;
}
Returns the orientation of the plot. |
public String getPlotType() {
return localizationResources.getString("Category_Plot");
}
Returns a string describing the type of plot. |
public ValueAxis getRangeAxis() {
return getRangeAxis(0);
}
Returns the range axis for the plot. If the range axis for this plot is
null, then the method will return the parent plot's range axis (if there
is a parent plot). |
public ValueAxis getRangeAxis(int index) {
ValueAxis result = null;
if (index < this.rangeAxes.size()) {
result = (ValueAxis) this.rangeAxes.get(index);
}
if (result == null) {
Plot parent = getParent();
if (parent instanceof CategoryPlot) {
CategoryPlot cp = (CategoryPlot) parent;
result = cp.getRangeAxis(index);
}
}
return result;
}
|
public int getRangeAxisCount() {
return this.rangeAxes.size();
}
Returns the number of range axes. |
public RectangleEdge getRangeAxisEdge() {
return getRangeAxisEdge(0);
}
Returns the edge where the primary range axis is located. |
public RectangleEdge getRangeAxisEdge(int index) {
AxisLocation location = getRangeAxisLocation(index);
RectangleEdge result = Plot.resolveRangeAxisLocation(location,
this.orientation);
if (result == null) {
result = RectangleEdge.opposite(getRangeAxisEdge(0));
}
return result;
}
Returns the edge for a range axis. |
public ValueAxis getRangeAxisForDataset(int index) {
ValueAxis result = getRangeAxis();
Integer axisIndex = (Integer) this.datasetToRangeAxisMap.get(index);
if (axisIndex != null) {
result = getRangeAxis(axisIndex.intValue());
}
return result;
}
|
public int getRangeAxisIndex(ValueAxis axis) {
if (axis == null) {
throw new IllegalArgumentException("Null 'axis' argument.");
}
int result = this.rangeAxes.indexOf(axis);
if (result < 0) { // try the parent plot
Plot parent = getParent();
if (parent instanceof CategoryPlot) {
CategoryPlot p = (CategoryPlot) parent;
result = p.getRangeAxisIndex(axis);
}
}
return result;
}
Returns the index of the specified axis, or -1 if the axis
is not assigned to the plot. |
public AxisLocation getRangeAxisLocation() {
return getRangeAxisLocation(0);
}
Returns the range axis location. |
public AxisLocation getRangeAxisLocation(int index) {
AxisLocation result = null;
if (index < this.rangeAxisLocations.size()) {
result = (AxisLocation) this.rangeAxisLocations.get(index);
}
if (result == null) {
result = AxisLocation.getOpposite(getRangeAxisLocation(0));
}
return result;
}
Returns the location for a range axis. |
public Paint getRangeCrosshairPaint() {
return this.rangeCrosshairPaint;
}
Returns the paint used to draw the range crosshair. |
public Stroke getRangeCrosshairStroke() {
return this.rangeCrosshairStroke;
}
Returns the pen-style (Stroke) used to draw the crosshair
(if visible). |
public double getRangeCrosshairValue() {
return this.rangeCrosshairValue;
}
Returns the range crosshair value. |
public Paint getRangeGridlinePaint() {
return this.rangeGridlinePaint;
}
Returns the paint used to draw the grid-lines against the range axis. |
public Stroke getRangeGridlineStroke() {
return this.rangeGridlineStroke;
}
Returns the stroke used to draw the grid-lines against the range axis. |
public Collection getRangeMarkers(Layer layer) {
return getRangeMarkers(0, layer);
}
Returns the list of range markers (read only) for the specified layer. |
public Collection getRangeMarkers(int index,
Layer layer) {
Collection result = null;
Integer key = new Integer(index);
if (layer == Layer.FOREGROUND) {
result = (Collection) this.foregroundRangeMarkers.get(key);
}
else if (layer == Layer.BACKGROUND) {
result = (Collection) this.backgroundRangeMarkers.get(key);
}
if (result != null) {
result = Collections.unmodifiableCollection(result);
}
return result;
}
Returns a collection of range markers for a particular renderer and
layer. |
public CategoryItemRenderer getRenderer() {
return getRenderer(0);
}
Returns a reference to the renderer for the plot. |
public CategoryItemRenderer getRenderer(int index) {
CategoryItemRenderer result = null;
if (this.renderers.size() > index) {
result = (CategoryItemRenderer) this.renderers.get(index);
}
return result;
}
Returns the renderer at the given index. |
public CategoryItemRenderer getRendererForDataset(CategoryDataset dataset) {
CategoryItemRenderer result = null;
for (int i = 0; i < this.datasets.size(); i++) {
if (this.datasets.get(i) == dataset) {
result = (CategoryItemRenderer) this.renderers.get(i);
break;
}
}
return result;
}
Returns the renderer for the specified dataset. If the dataset doesn't
belong to the plot, this method will return null. |
public SortOrder getRowRenderingOrder() {
return this.rowRenderingOrder;
}
Returns the order in which the rows should be rendered. The default
value is SortOrder.ASCENDING. |
public int getWeight() {
return this.weight;
}
Returns the weight for this plot when it is used as a subplot within a
combined plot. |
public void handleClick(int x,
int y,
PlotRenderingInfo info) {
Rectangle2D dataArea = info.getDataArea();
if (dataArea.contains(x, y)) {
// set the anchor value for the range axis...
double java2D = 0.0;
if (this.orientation == PlotOrientation.HORIZONTAL) {
java2D = x;
}
else if (this.orientation == PlotOrientation.VERTICAL) {
java2D = y;
}
RectangleEdge edge = Plot.resolveRangeAxisLocation(
getRangeAxisLocation(), this.orientation);
double value = getRangeAxis().java2DToValue(
java2D, info.getDataArea(), edge);
setAnchorValue(value);
setRangeCrosshairValue(value);
}
}
Handles a 'click' on the plot by updating the anchor value. |
public boolean isDomainGridlinesVisible() {
return this.domainGridlinesVisible;
}
Returns the flag that controls whether the domain grid-lines are visible. |
public boolean isDomainZoomable() {
return false;
}
Returns false to indicate that the domain axes are not
zoomable. |
public boolean isRangeCrosshairLockedOnData() {
return this.rangeCrosshairLockedOnData;
}
Returns a flag indicating whether or not the crosshair should "lock-on"
to actual data values. |
public boolean isRangeCrosshairVisible() {
return this.rangeCrosshairVisible;
}
Returns a flag indicating whether or not the range crosshair is visible. |
public boolean isRangeGridlinesVisible() {
return this.rangeGridlinesVisible;
}
Returns the flag that controls whether the range grid-lines are visible. |
public boolean isRangeZoomable() {
return true;
}
Returns true to indicate that the range axes are zoomable. |
public void mapDatasetToDomainAxis(int index,
int axisIndex) {
this.datasetToDomainAxisMap.set(index, new Integer(axisIndex));
// fake a dataset change event to update axes...
datasetChanged(new DatasetChangeEvent(this, getDataset(index)));
}
Maps a dataset to a particular domain axis. |
public void mapDatasetToRangeAxis(int index,
int axisIndex) {
this.datasetToRangeAxisMap.set(index, new Integer(axisIndex));
// fake a dataset change event to update axes...
datasetChanged(new DatasetChangeEvent(this, getDataset(index)));
}
Maps a dataset to a particular range axis. |
public boolean removeAnnotation(CategoryAnnotation annotation) {
return removeAnnotation(annotation, true);
}
Removes an annotation from the plot and sends a PlotChangeEvent
to all registered listeners. |
public boolean removeAnnotation(CategoryAnnotation annotation,
boolean notify) {
if (annotation == null) {
throw new IllegalArgumentException("Null 'annotation' argument.");
}
boolean removed = this.annotations.remove(annotation);
if (removed && notify) {
fireChangeEvent();
}
return removed;
}
Removes an annotation from the plot and, if requested, sends a
PlotChangeEvent to all registered listeners. |
public boolean removeDomainMarker(Marker marker) {
return removeDomainMarker(marker, Layer.FOREGROUND);
}
Removes a marker for the domain axis and sends a PlotChangeEvent
to all registered listeners. |
public boolean removeDomainMarker(Marker marker,
Layer layer) {
return removeDomainMarker(0, marker, layer);
}
Removes a marker for the domain axis in the specified layer and sends a
PlotChangeEvent to all registered listeners. |
public boolean removeDomainMarker(int index,
|