001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2020, by Object Refinery Limited and Contributors. 006 * 007 * Project Info: http://www.jfree.org/jfreechart/index.html 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * ------------------------- 028 * LineAndShapeRenderer.java 029 * ------------------------- 030 * (C) Copyright 2001-2016, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): Mark Watson (www.markwatson.com); 034 * Jeremy Bowman; 035 * Richard Atkinson; 036 * Christian W. Zuckschwerdt; 037 * Peter Kolb (patch 2497611); 038 * 039 * Changes 040 * ------- 041 * 23-Oct-2001 : Version 1 (DG); 042 * 15-Nov-2001 : Modified to allow for null data values (DG); 043 * 16-Jan-2002 : Renamed HorizontalCategoryItemRenderer.java 044 * --> CategoryItemRenderer.java (DG); 045 * 05-Feb-2002 : Changed return type of the drawCategoryItem method from void 046 * to Shape, as part of the tooltips implementation (DG); 047 * 11-May-2002 : Support for value label drawing (JB); 048 * 29-May-2002 : Now extends AbstractCategoryItemRenderer (DG); 049 * 25-Jun-2002 : Removed redundant import (DG); 050 * 05-Aug-2002 : Small modification to drawCategoryItem method to support URLs 051 * for HTML image maps (RA); 052 * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG); 053 * 11-Oct-2002 : Added new constructor to incorporate tool tip and URL 054 * generators (DG); 055 * 24-Oct-2002 : Amendments for changes in CategoryDataset interface and 056 * CategoryToolTipGenerator interface (DG); 057 * 05-Nov-2002 : Base dataset is now TableDataset not CategoryDataset (DG); 058 * 06-Nov-2002 : Renamed drawCategoryItem() --> drawItem() and now using axis 059 * for category spacing (DG); 060 * 17-Jan-2003 : Moved plot classes to a separate package (DG); 061 * 10-Apr-2003 : Changed CategoryDataset to KeyedValues2DDataset in drawItem() 062 * method (DG); 063 * 12-May-2003 : Modified to take into account the plot orientation (DG); 064 * 29-Jul-2003 : Amended code that doesn't compile with JDK 1.2.2 (DG); 065 * 30-Jul-2003 : Modified entity constructor (CZ); 066 * 22-Sep-2003 : Fixed cloning (DG); 067 * 10-Feb-2004 : Small change to drawItem() method to make cut-and-paste 068 * override easier (DG); 069 * 16-Jun-2004 : Fixed bug (id=972454) with label positioning on horizontal 070 * charts (DG); 071 * 15-Oct-2004 : Updated equals() method (DG); 072 * 05-Nov-2004 : Modified drawItem() signature (DG); 073 * 11-Nov-2004 : Now uses ShapeUtilities class to translate shapes (DG); 074 * 27-Jan-2005 : Changed attribute names, modified constructor and removed 075 * constants (DG); 076 * 01-Feb-2005 : Removed unnecessary constants (DG); 077 * 15-Mar-2005 : Fixed bug 1163897, concerning outlines for shapes (DG); 078 * 13-Apr-2005 : Check flags that control series visibility (DG); 079 * 20-Apr-2005 : Use generators for legend labels, tooltips and URLs (DG); 080 * 09-Jun-2005 : Use addItemEntity() method (DG); 081 * ------------- JFREECHART 1.0.x --------------------------------------------- 082 * 25-May-2006 : Added check to drawItem() to detect when both the line and 083 * the shape are not visible (DG); 084 * 20-Apr-2007 : Updated getLegendItem() for renderer change (DG); 085 * 17-May-2007 : Set datasetIndex and seriesIndex in getLegendItem() (DG); 086 * 18-May-2007 : Set dataset and seriesKey for LegendItem (DG); 087 * 24-Sep-2007 : Deprecated redundant fields/methods (DG); 088 * 27-Sep-2007 : Added option to offset series x-position within category (DG); 089 * 17-Jun-2008 : Apply legend shape, font and paint attributes (DG); 090 * 26-Jun-2008 : Added crosshair support (DG); 091 * 14-Jan-2009 : Added support for seriesVisible flags (PK); 092 * 093 */ 094 095package org.jfree.chart.renderer.category; 096 097import java.awt.Graphics2D; 098import java.awt.Paint; 099import java.awt.Shape; 100import java.awt.Stroke; 101import java.awt.geom.Line2D; 102import java.awt.geom.Rectangle2D; 103import java.io.Serializable; 104 105import org.jfree.chart.LegendItem; 106import org.jfree.chart.axis.CategoryAxis; 107import org.jfree.chart.axis.ValueAxis; 108import org.jfree.chart.entity.EntityCollection; 109import org.jfree.chart.event.RendererChangeEvent; 110import org.jfree.chart.plot.CategoryPlot; 111import org.jfree.chart.plot.PlotOrientation; 112import org.jfree.chart.util.BooleanList; 113import org.jfree.chart.util.ObjectUtils; 114import org.jfree.chart.util.PublicCloneable; 115import org.jfree.chart.util.ShapeUtils; 116import org.jfree.data.category.CategoryDataset; 117 118/** 119 * A renderer that draws shapes for each data item, and lines between data 120 * items (for use with the {@link CategoryPlot} class). 121 * The example shown here is generated by the {@code LineChartDemo1.java} 122 * program included in the JFreeChart Demo Collection: 123 * <br><br> 124 * <img src="../../../../../images/LineAndShapeRendererSample.png" 125 * alt="LineAndShapeRendererSample.png"> 126 */ 127public class LineAndShapeRenderer extends AbstractCategoryItemRenderer 128 implements Cloneable, PublicCloneable, Serializable { 129 130 /** For serialization. */ 131 private static final long serialVersionUID = -197749519869226398L; 132 133 /** 134 * A table of flags that control (per series) whether or not lines are 135 * visible. 136 */ 137 private BooleanList seriesLinesVisible; 138 139 /** 140 * A flag indicating whether or not lines are drawn between non-null 141 * points. 142 */ 143 private boolean defaultLinesVisible; 144 145 /** 146 * A table of flags that control (per series) whether or not shapes are 147 * visible. 148 */ 149 private BooleanList seriesShapesVisible; 150 151 /** The default value returned by the getShapeVisible() method. */ 152 private boolean defaultShapesVisible; 153 154 /** 155 * A table of flags that control (per series) whether or not shapes are 156 * filled. 157 */ 158 private BooleanList seriesShapesFilled; 159 160 /** The default value returned by the getShapeFilled() method. */ 161 private boolean defaultShapesFilled; 162 163 /** 164 * A flag that controls whether the fill paint is used for filling 165 * shapes. 166 */ 167 private boolean useFillPaint; 168 169 /** A flag that controls whether outlines are drawn for shapes. */ 170 private boolean drawOutlines; 171 172 /** 173 * A flag that controls whether the outline paint is used for drawing shape 174 * outlines - if not, the regular series paint is used. 175 */ 176 private boolean useOutlinePaint; 177 178 /** 179 * A flag that controls whether or not the x-position for each item is 180 * offset within the category according to the series. 181 * 182 * @since 1.0.7 183 */ 184 private boolean useSeriesOffset; 185 186 /** 187 * The item margin used for series offsetting - this allows the positioning 188 * to match the bar positions of the {@link BarRenderer} class. 189 * 190 * @since 1.0.7 191 */ 192 private double itemMargin; 193 194 /** 195 * Creates a renderer with both lines and shapes visible by default. 196 */ 197 public LineAndShapeRenderer() { 198 this(true, true); 199 } 200 201 /** 202 * Creates a new renderer with lines and/or shapes visible. 203 * 204 * @param lines draw lines? 205 * @param shapes draw shapes? 206 */ 207 public LineAndShapeRenderer(boolean lines, boolean shapes) { 208 super(); 209 this.seriesLinesVisible = new BooleanList(); 210 this.defaultLinesVisible = lines; 211 this.seriesShapesVisible = new BooleanList(); 212 this.defaultShapesVisible = shapes; 213 this.seriesShapesFilled = new BooleanList(); 214 this.defaultShapesFilled = true; 215 this.useFillPaint = false; 216 this.drawOutlines = true; 217 this.useOutlinePaint = false; 218 this.useSeriesOffset = false; // preserves old behaviour 219 this.itemMargin = 0.0; 220 } 221 222 // LINES VISIBLE 223 224 /** 225 * Returns the flag used to control whether or not the line for an item is 226 * visible. 227 * 228 * @param series the series index (zero-based). 229 * @param item the item index (zero-based). 230 * 231 * @return A boolean. 232 */ 233 public boolean getItemLineVisible(int series, int item) { 234 Boolean flag = getSeriesLinesVisible(series); 235 if (flag != null) { 236 return flag; 237 } 238 return this.defaultLinesVisible; 239 } 240 241 /** 242 * Returns the flag used to control whether or not the lines for a series 243 * are visible. 244 * 245 * @param series the series index (zero-based). 246 * 247 * @return The flag (possibly {@code null}). 248 * 249 * @see #setSeriesLinesVisible(int, Boolean) 250 */ 251 public Boolean getSeriesLinesVisible(int series) { 252 return this.seriesLinesVisible.getBoolean(series); 253 } 254 255 /** 256 * Sets the 'lines visible' flag for a series and sends a 257 * {@link RendererChangeEvent} to all registered listeners. 258 * 259 * @param series the series index (zero-based). 260 * @param flag the flag ({@code null} permitted). 261 * 262 * @see #getSeriesLinesVisible(int) 263 */ 264 public void setSeriesLinesVisible(int series, Boolean flag) { 265 this.seriesLinesVisible.setBoolean(series, flag); 266 fireChangeEvent(); 267 } 268 269 /** 270 * Sets the 'lines visible' flag for a series and sends a 271 * {@link RendererChangeEvent} to all registered listeners. 272 * 273 * @param series the series index (zero-based). 274 * @param visible the flag. 275 * 276 * @see #getSeriesLinesVisible(int) 277 */ 278 public void setSeriesLinesVisible(int series, boolean visible) { 279 setSeriesLinesVisible(series, Boolean.valueOf(visible)); 280 } 281 282 /** 283 * Returns the default 'lines visible' attribute. 284 * 285 * @return The default flag. 286 * 287 * @see #getDefaultLinesVisible() 288 */ 289 public boolean getDefaultLinesVisible() { 290 return this.defaultLinesVisible; 291 } 292 293 /** 294 * Sets the default 'lines visible' flag and sends a 295 * {@link RendererChangeEvent} to all registered listeners. 296 * 297 * @param flag the flag. 298 * 299 * @see #getDefaultLinesVisible() 300 */ 301 public void setDefaultLinesVisible(boolean flag) { 302 this.defaultLinesVisible = flag; 303 fireChangeEvent(); 304 } 305 306 // SHAPES VISIBLE 307 308 /** 309 * Returns the flag used to control whether or not the shape for an item is 310 * visible. 311 * 312 * @param series the series index (zero-based). 313 * @param item the item index (zero-based). 314 * 315 * @return A boolean. 316 */ 317 public boolean getItemShapeVisible(int series, int item) { 318 Boolean flag = getSeriesShapesVisible(series); 319 if (flag != null) { 320 return flag; 321 } 322 return this.defaultShapesVisible; 323 } 324 325 /** 326 * Returns the flag used to control whether or not the shapes for a series 327 * are visible. 328 * 329 * @param series the series index (zero-based). 330 * 331 * @return A boolean. 332 * 333 * @see #setSeriesShapesVisible(int, Boolean) 334 */ 335 public Boolean getSeriesShapesVisible(int series) { 336 return this.seriesShapesVisible.getBoolean(series); 337 } 338 339 /** 340 * Sets the 'shapes visible' flag for a series and sends a 341 * {@link RendererChangeEvent} to all registered listeners. 342 * 343 * @param series the series index (zero-based). 344 * @param visible the flag. 345 * 346 * @see #getSeriesShapesVisible(int) 347 */ 348 public void setSeriesShapesVisible(int series, boolean visible) { 349 setSeriesShapesVisible(series, Boolean.valueOf(visible)); 350 } 351 352 /** 353 * Sets the 'shapes visible' flag for a series and sends a 354 * {@link RendererChangeEvent} to all registered listeners. 355 * 356 * @param series the series index (zero-based). 357 * @param flag the flag. 358 * 359 * @see #getSeriesShapesVisible(int) 360 */ 361 public void setSeriesShapesVisible(int series, Boolean flag) { 362 this.seriesShapesVisible.setBoolean(series, flag); 363 fireChangeEvent(); 364 } 365 366 /** 367 * Returns the default 'shape visible' attribute. 368 * 369 * @return The base flag. 370 * 371 * @see #setDefaultShapesVisible(boolean) 372 */ 373 public boolean getDefaultShapesVisible() { 374 return this.defaultShapesVisible; 375 } 376 377 /** 378 * Sets the default 'shapes visible' flag and sends a 379 * {@link RendererChangeEvent} to all registered listeners. 380 * 381 * @param flag the flag. 382 * 383 * @see #getDefaultShapesVisible() 384 */ 385 public void setDefaultShapesVisible(boolean flag) { 386 this.defaultShapesVisible = flag; 387 fireChangeEvent(); 388 } 389 390 /** 391 * Returns {@code true} if outlines should be drawn for shapes, and 392 * {@code false} otherwise. 393 * 394 * @return A boolean. 395 * 396 * @see #setDrawOutlines(boolean) 397 */ 398 public boolean getDrawOutlines() { 399 return this.drawOutlines; 400 } 401 402 /** 403 * Sets the flag that controls whether outlines are drawn for 404 * shapes, and sends a {@link RendererChangeEvent} to all registered 405 * listeners. 406 * <P> 407 * In some cases, shapes look better if they do NOT have an outline, but 408 * this flag allows you to set your own preference. 409 * 410 * @param flag the flag. 411 * 412 * @see #getDrawOutlines() 413 */ 414 public void setDrawOutlines(boolean flag) { 415 this.drawOutlines = flag; 416 fireChangeEvent(); 417 } 418 419 /** 420 * Returns the flag that controls whether the outline paint is used for 421 * shape outlines. If not, the regular series paint is used. 422 * 423 * @return A boolean. 424 * 425 * @see #setUseOutlinePaint(boolean) 426 */ 427 public boolean getUseOutlinePaint() { 428 return this.useOutlinePaint; 429 } 430 431 /** 432 * Sets the flag that controls whether the outline paint is used for shape 433 * outlines, and sends a {@link RendererChangeEvent} to all registered 434 * listeners. 435 * 436 * @param use the flag. 437 * 438 * @see #getUseOutlinePaint() 439 */ 440 public void setUseOutlinePaint(boolean use) { 441 this.useOutlinePaint = use; 442 fireChangeEvent(); 443 } 444 445 // SHAPES FILLED 446 447 /** 448 * Returns the flag used to control whether or not the shape for an item 449 * is filled. The default implementation passes control to the 450 * {@code getSeriesShapesFilled} method. You can override this method 451 * if you require different behaviour. 452 * 453 * @param series the series index (zero-based). 454 * @param item the item index (zero-based). 455 * 456 * @return A boolean. 457 */ 458 public boolean getItemShapeFilled(int series, int item) { 459 return getSeriesShapesFilled(series); 460 } 461 462 /** 463 * Returns the flag used to control whether or not the shapes for a series 464 * are filled. 465 * 466 * @param series the series index (zero-based). 467 * 468 * @return A boolean. 469 */ 470 public boolean getSeriesShapesFilled(int series) { 471 Boolean flag = this.seriesShapesFilled.getBoolean(series); 472 if (flag != null) { 473 return flag; 474 } 475 return this.defaultShapesFilled; 476 } 477 478 /** 479 * Sets the 'shapes filled' flag for a series and sends a 480 * {@link RendererChangeEvent} to all registered listeners. 481 * 482 * @param series the series index (zero-based). 483 * @param filled the flag. 484 * 485 * @see #getSeriesShapesFilled(int) 486 */ 487 public void setSeriesShapesFilled(int series, Boolean filled) { 488 this.seriesShapesFilled.setBoolean(series, filled); 489 fireChangeEvent(); 490 } 491 492 /** 493 * Sets the 'shapes filled' flag for a series and sends a 494 * {@link RendererChangeEvent} to all registered listeners. 495 * 496 * @param series the series index (zero-based). 497 * @param filled the flag. 498 * 499 * @see #getSeriesShapesFilled(int) 500 */ 501 public void setSeriesShapesFilled(int series, boolean filled) { 502 // delegate 503 setSeriesShapesFilled(series, Boolean.valueOf(filled)); 504 } 505 506 /** 507 * Returns the default 'shape filled' attribute. 508 * 509 * @return The base flag. 510 * 511 * @see #setDefaultShapesFilled(boolean) 512 */ 513 public boolean getDefaultShapesFilled() { 514 return this.defaultShapesFilled; 515 } 516 517 /** 518 * Sets the default 'shapes filled' flag and sends a 519 * {@link RendererChangeEvent} to all registered listeners. 520 * 521 * @param flag the flag. 522 * 523 * @see #getDefaultShapesFilled() 524 */ 525 public void setDefaultShapesFilled(boolean flag) { 526 this.defaultShapesFilled = flag; 527 fireChangeEvent(); 528 } 529 530 /** 531 * Returns {@code true} if the renderer should use the fill paint 532 * setting to fill shapes, and {@code false} if it should just 533 * use the regular paint. 534 * 535 * @return A boolean. 536 * 537 * @see #setUseFillPaint(boolean) 538 */ 539 public boolean getUseFillPaint() { 540 return this.useFillPaint; 541 } 542 543 /** 544 * Sets the flag that controls whether the fill paint is used to fill 545 * shapes, and sends a {@link RendererChangeEvent} to all 546 * registered listeners. 547 * 548 * @param flag the flag. 549 * 550 * @see #getUseFillPaint() 551 */ 552 public void setUseFillPaint(boolean flag) { 553 this.useFillPaint = flag; 554 fireChangeEvent(); 555 } 556 557 /** 558 * Returns the flag that controls whether or not the x-position for each 559 * data item is offset within the category according to the series. 560 * 561 * @return A boolean. 562 * 563 * @see #setUseSeriesOffset(boolean) 564 * 565 * @since 1.0.7 566 */ 567 public boolean getUseSeriesOffset() { 568 return this.useSeriesOffset; 569 } 570 571 /** 572 * Sets the flag that controls whether or not the x-position for each 573 * data item is offset within its category according to the series, and 574 * sends a {@link RendererChangeEvent} to all registered listeners. 575 * 576 * @param offset the offset. 577 * 578 * @see #getUseSeriesOffset() 579 * 580 * @since 1.0.7 581 */ 582 public void setUseSeriesOffset(boolean offset) { 583 this.useSeriesOffset = offset; 584 fireChangeEvent(); 585 } 586 587 /** 588 * Returns the item margin, which is the gap between items within a 589 * category (expressed as a percentage of the overall category width). 590 * This can be used to match the offset alignment with the bars drawn by 591 * a {@link BarRenderer}). 592 * 593 * @return The item margin. 594 * 595 * @see #setItemMargin(double) 596 * @see #getUseSeriesOffset() 597 * 598 * @since 1.0.7 599 */ 600 public double getItemMargin() { 601 return this.itemMargin; 602 } 603 604 /** 605 * Sets the item margin, which is the gap between items within a category 606 * (expressed as a percentage of the overall category width), and sends 607 * a {@link RendererChangeEvent} to all registered listeners. 608 * 609 * @param margin the margin (0.0 <= margin < 1.0). 610 * 611 * @see #getItemMargin() 612 * @see #getUseSeriesOffset() 613 * 614 * @since 1.0.7 615 */ 616 public void setItemMargin(double margin) { 617 if (margin < 0.0 || margin >= 1.0) { 618 throw new IllegalArgumentException("Requires 0.0 <= margin < 1.0."); 619 } 620 this.itemMargin = margin; 621 fireChangeEvent(); 622 } 623 624 /** 625 * Returns a legend item for a series. 626 * 627 * @param datasetIndex the dataset index (zero-based). 628 * @param series the series index (zero-based). 629 * 630 * @return The legend item. 631 */ 632 @Override 633 public LegendItem getLegendItem(int datasetIndex, int series) { 634 635 CategoryPlot cp = getPlot(); 636 if (cp == null) { 637 return null; 638 } 639 640 if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) { 641 CategoryDataset dataset = cp.getDataset(datasetIndex); 642 String label = getLegendItemLabelGenerator().generateLabel( 643 dataset, series); 644 String description = label; 645 String toolTipText = null; 646 if (getLegendItemToolTipGenerator() != null) { 647 toolTipText = getLegendItemToolTipGenerator().generateLabel( 648 dataset, series); 649 } 650 String urlText = null; 651 if (getLegendItemURLGenerator() != null) { 652 urlText = getLegendItemURLGenerator().generateLabel( 653 dataset, series); 654 } 655 Shape shape = lookupLegendShape(series); 656 Paint paint = lookupSeriesPaint(series); 657 Paint fillPaint = (this.useFillPaint 658 ? getItemFillPaint(series, 0) : paint); 659 boolean shapeOutlineVisible = this.drawOutlines; 660 Paint outlinePaint = (this.useOutlinePaint 661 ? getItemOutlinePaint(series, 0) : paint); 662 Stroke outlineStroke = lookupSeriesOutlineStroke(series); 663 boolean lineVisible = getItemLineVisible(series, 0); 664 boolean shapeVisible = getItemShapeVisible(series, 0); 665 LegendItem result = new LegendItem(label, description, toolTipText, 666 urlText, shapeVisible, shape, getItemShapeFilled(series, 0), 667 fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, 668 lineVisible, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), 669 getItemStroke(series, 0), getItemPaint(series, 0)); 670 result.setLabelFont(lookupLegendTextFont(series)); 671 Paint labelPaint = lookupLegendTextPaint(series); 672 if (labelPaint != null) { 673 result.setLabelPaint(labelPaint); 674 } 675 result.setDataset(dataset); 676 result.setDatasetIndex(datasetIndex); 677 result.setSeriesKey(dataset.getRowKey(series)); 678 result.setSeriesIndex(series); 679 return result; 680 } 681 return null; 682 683 } 684 685 /** 686 * This renderer uses two passes to draw the data. 687 * 688 * @return The pass count ({@code 2} for this renderer). 689 */ 690 @Override 691 public int getPassCount() { 692 return 2; 693 } 694 695 /** 696 * Draw a single data item. 697 * 698 * @param g2 the graphics device. 699 * @param state the renderer state. 700 * @param dataArea the area in which the data is drawn. 701 * @param plot the plot. 702 * @param domainAxis the domain axis. 703 * @param rangeAxis the range axis. 704 * @param dataset the dataset. 705 * @param row the row index (zero-based). 706 * @param column the column index (zero-based). 707 * @param pass the pass index. 708 */ 709 @Override 710 public void drawItem(Graphics2D g2, CategoryItemRendererState state, 711 Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, 712 ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, 713 int pass) { 714 715 // do nothing if item is not visible 716 if (!getItemVisible(row, column)) { 717 return; 718 } 719 720 // do nothing if both the line and shape are not visible 721 if (!getItemLineVisible(row, column) 722 && !getItemShapeVisible(row, column)) { 723 return; 724 } 725 726 // nothing is drawn for null... 727 Number v = dataset.getValue(row, column); 728 if (v == null) { 729 return; 730 } 731 732 int visibleRow = state.getVisibleSeriesIndex(row); 733 if (visibleRow < 0) { 734 return; 735 } 736 int visibleRowCount = state.getVisibleSeriesCount(); 737 738 PlotOrientation orientation = plot.getOrientation(); 739 740 // current data point... 741 double x1; 742 if (this.useSeriesOffset) { 743 x1 = domainAxis.getCategorySeriesMiddle(column, 744 dataset.getColumnCount(), visibleRow, visibleRowCount, 745 this.itemMargin, dataArea, plot.getDomainAxisEdge()); 746 } 747 else { 748 x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), 749 dataArea, plot.getDomainAxisEdge()); 750 } 751 double value = v.doubleValue(); 752 double y1 = rangeAxis.valueToJava2D(value, dataArea, 753 plot.getRangeAxisEdge()); 754 755 if (pass == 0 && getItemLineVisible(row, column)) { 756 if (column != 0) { 757 Number previousValue = dataset.getValue(row, column - 1); 758 if (previousValue != null) { 759 // previous data point... 760 double previous = previousValue.doubleValue(); 761 double x0; 762 if (this.useSeriesOffset) { 763 x0 = domainAxis.getCategorySeriesMiddle( 764 column - 1, dataset.getColumnCount(), 765 visibleRow, visibleRowCount, 766 this.itemMargin, dataArea, 767 plot.getDomainAxisEdge()); 768 } 769 else { 770 x0 = domainAxis.getCategoryMiddle(column - 1, 771 getColumnCount(), dataArea, 772 plot.getDomainAxisEdge()); 773 } 774 double y0 = rangeAxis.valueToJava2D(previous, dataArea, 775 plot.getRangeAxisEdge()); 776 777 Line2D line = null; 778 if (orientation == PlotOrientation.HORIZONTAL) { 779 line = new Line2D.Double(y0, x0, y1, x1); 780 } 781 else if (orientation == PlotOrientation.VERTICAL) { 782 line = new Line2D.Double(x0, y0, x1, y1); 783 } 784 g2.setPaint(getItemPaint(row, column)); 785 g2.setStroke(getItemStroke(row, column)); 786 g2.draw(line); 787 } 788 } 789 } 790 791 if (pass == 1) { 792 Shape shape = getItemShape(row, column); 793 if (orientation == PlotOrientation.HORIZONTAL) { 794 shape = ShapeUtils.createTranslatedShape(shape, y1, x1); 795 } 796 else if (orientation == PlotOrientation.VERTICAL) { 797 shape = ShapeUtils.createTranslatedShape(shape, x1, y1); 798 } 799 800 if (getItemShapeVisible(row, column)) { 801 if (getItemShapeFilled(row, column)) { 802 if (this.useFillPaint) { 803 g2.setPaint(getItemFillPaint(row, column)); 804 } 805 else { 806 g2.setPaint(getItemPaint(row, column)); 807 } 808 g2.fill(shape); 809 } 810 if (this.drawOutlines) { 811 if (this.useOutlinePaint) { 812 g2.setPaint(getItemOutlinePaint(row, column)); 813 } 814 else { 815 g2.setPaint(getItemPaint(row, column)); 816 } 817 g2.setStroke(getItemOutlineStroke(row, column)); 818 g2.draw(shape); 819 } 820 } 821 822 // draw the item label if there is one... 823 if (isItemLabelVisible(row, column)) { 824 if (orientation == PlotOrientation.HORIZONTAL) { 825 drawItemLabel(g2, orientation, dataset, row, column, y1, 826 x1, (value < 0.0)); 827 } 828 else if (orientation == PlotOrientation.VERTICAL) { 829 drawItemLabel(g2, orientation, dataset, row, column, x1, 830 y1, (value < 0.0)); 831 } 832 } 833 834 // submit the current data point as a crosshair candidate 835 int datasetIndex = plot.indexOf(dataset); 836 updateCrosshairValues(state.getCrosshairState(), 837 dataset.getRowKey(row), dataset.getColumnKey(column), 838 value, datasetIndex, x1, y1, orientation); 839 840 // add an item entity, if this information is being collected 841 EntityCollection entities = state.getEntityCollection(); 842 if (entities != null) { 843 addItemEntity(entities, dataset, row, column, shape); 844 } 845 } 846 847 } 848 849 /** 850 * Tests this renderer for equality with an arbitrary object. 851 * 852 * @param obj the object ({@code null} permitted). 853 * 854 * @return A boolean. 855 */ 856 @Override 857 public boolean equals(Object obj) { 858 859 if (obj == this) { 860 return true; 861 } 862 if (!(obj instanceof LineAndShapeRenderer)) { 863 return false; 864 } 865 866 LineAndShapeRenderer that = (LineAndShapeRenderer) obj; 867 if (this.defaultLinesVisible != that.defaultLinesVisible) { 868 return false; 869 } 870 if (!ObjectUtils.equal(this.seriesLinesVisible, 871 that.seriesLinesVisible)) { 872 return false; 873 } 874 if (this.defaultShapesVisible != that.defaultShapesVisible) { 875 return false; 876 } 877 if (!ObjectUtils.equal(this.seriesShapesVisible, 878 that.seriesShapesVisible)) { 879 return false; 880 } 881 if (!ObjectUtils.equal(this.seriesShapesFilled, 882 that.seriesShapesFilled)) { 883 return false; 884 } 885 if (this.defaultShapesFilled != that.defaultShapesFilled) { 886 return false; 887 } 888 if (this.useOutlinePaint != that.useOutlinePaint) { 889 return false; 890 } 891 if (this.useSeriesOffset != that.useSeriesOffset) { 892 return false; 893 } 894 if (this.itemMargin != that.itemMargin) { 895 return false; 896 } 897 return super.equals(obj); 898 } 899 900 /** 901 * Returns an independent copy of the renderer. 902 * 903 * @return A clone. 904 * 905 * @throws CloneNotSupportedException should not happen. 906 */ 907 @Override 908 public Object clone() throws CloneNotSupportedException { 909 LineAndShapeRenderer clone = (LineAndShapeRenderer) super.clone(); 910 clone.seriesLinesVisible 911 = (BooleanList) this.seriesLinesVisible.clone(); 912 clone.seriesShapesVisible 913 = (BooleanList) this.seriesShapesVisible.clone(); 914 clone.seriesShapesFilled 915 = (BooleanList) this.seriesShapesFilled.clone(); 916 return clone; 917 } 918 919}