001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030/** 031 * 032 */ 033package org.openimaj.vis.general; 034 035import org.openimaj.image.typography.Font; 036 037/** 038 * Configuration for an axis. 039 * 040 * @param <Q> The colour representation of an axis. 041 * 042 * @author David Dupplaw (dpd@ecs.soton.ac.uk) 043 * @created 8 Jul 2013 044 */ 045public class AxisConfig<Q> 046{ 047 /** n dimensional position */ 048 private double[] location = new double[] {0,0}; 049 050 /** Whether to auto scale to fit the view. If so, the location may be null */ 051 private boolean autoScale = true; 052 053 /** n dimensional orientation */ 054 private double[] orientation = new double[] {0}; 055 056 /** Name of the axis */ 057 private String name = "Axis"; 058 059 /** Maximum value */ 060 private double maxValue = 10; 061 062 /** Minimum value */ 063 private double minValue = 0; 064 065 /** The rendering configuration */ 066 private AxisRenderingConfig<Q> renderingConfig = new AxisRenderingConfig<Q>(); 067 068 /** 069 * 070 * @param <Q> 071 * 072 * @author David Dupplaw (dpd@ecs.soton.ac.uk) 073 * @created 8 Jul 2013 074 */ 075 public static class AxisRenderingConfig<Q> 076 { 077 /** Whether to render this axis at all */ 078 private boolean renderAxis = true; 079 080 /** Colour to draw the main axis */ 081 private Q colour; 082 083 /** The thickness of the axis line */ 084 private double thickness = 3; 085 086 /** Whether to draw the minor ticks */ 087 private boolean drawMinorTicks = true; 088 089 /** Whether to draw the major ticks */ 090 private boolean drawMajorTicks = true; 091 092 /** How often to draw the minor ticks */ 093 private double minorTickSpacing = 1; 094 095 /** How often to drawn the major ticks */ 096 private double majorTickSpacing = 1; 097 098 /** Length of the minor ticks */ 099 private double minorTickLength = 7; 100 101 /** Length of the major ticks */ 102 private double majorTickLength = 11; 103 104 /** The thickness of the major ticks */ 105 private double majorTickThickness = 3; 106 107 /** The thickness of the minor ticks */ 108 private double minorTickThickness = 1; 109 110 /** Colour of the minor ticks */ 111 private Q minorTickColour; 112 113 /** Colour of the major ticks */ 114 private Q majorTickColour; 115 116 /** Whether to draw the minor tick labels */ 117 private boolean drawMinorTickLabels = false; 118 119 /** How often to draw the ticks (should be integer multiple of tick spacing */ 120 private double minorTickLabelSpacing = 1; 121 122 /** Whether to draw the major tick labels */ 123 private boolean drawMajorTickLabels = false; 124 125 /** How often to draw the ticks (should be integer multiple of tick spacing */ 126 private double majorTickLabelSpacing = 1; 127 128 /** The font to use for major ticks */ 129 @SuppressWarnings( "rawtypes" ) 130 private Font majorTickLabelFont; 131 132 /** The font to use for minor ticks */ 133 @SuppressWarnings( "rawtypes" ) 134 private Font minorTickLabelFont; 135 136 /** Whether to fit labels in the spaces */ 137 private boolean autoSpaceLabels = true; 138 139 /** Whether to remove ticks if they get too close together */ 140 private boolean autoSpaceTicks = true; 141 142 /** Size of the axis name label */ 143 private double nameSize = 10; 144 145 /** Colour of the axis name label */ 146 private Q nameColour; 147 148 /** The label transformer to convert a unit to a label */ 149 private LabelTransformer labelTransformer; 150 151 /** Whether to draw the minor grid */ 152 private boolean drawMinorGrid = false; 153 154 /** Whether to draw the major grid */ 155 private boolean drawMajorGrid = false; 156 157 /** The colour of the minor grid */ 158 private Q minorGridColour; 159 160 /** The colour of the major grid */ 161 private Q majorGridColour; 162 163 /** The thickness of the lines of the major grid */ 164 private double majorGridThickness = 1; 165 166 /** The thickness of the lines on the minor grid */ 167 private double minorGridThickness = 1; 168 169 /** Set if the axis name should be oriented */ 170 private double[] nameOrientation = null; 171 172 /** The direction of the name */ 173 private int nameDirection = 1; 174 175 /** 176 * @return the colour 177 */ 178 public Q getColour() 179 { 180 return this.colour; 181 } 182 183 /** 184 * @param colour the colour to set 185 */ 186 public void setColour( final Q colour ) 187 { 188 this.colour = colour; 189 } 190 191 /** 192 * @return the thickness 193 */ 194 public double getThickness() 195 { 196 return this.thickness; 197 } 198 199 /** 200 * @param thickness the thickness to set 201 */ 202 public void setThickness( final double thickness ) 203 { 204 this.thickness = thickness; 205 } 206 207 /** 208 * @return the drawMinorTicks 209 */ 210 public boolean isDrawMinorTicks() 211 { 212 return this.drawMinorTicks; 213 } 214 215 /** 216 * @param drawMinorTicks the drawMinorTicks to set 217 */ 218 public void setDrawMinorTicks( final boolean drawMinorTicks ) 219 { 220 this.drawMinorTicks = drawMinorTicks; 221 } 222 223 /** 224 * @return the drawMajorTicks 225 */ 226 public boolean isDrawMajorTicks() 227 { 228 return this.drawMajorTicks; 229 } 230 231 /** 232 * @param drawMajorTicks the drawMajorTicks to set 233 */ 234 public void setDrawMajorTicks( final boolean drawMajorTicks ) 235 { 236 this.drawMajorTicks = drawMajorTicks; 237 } 238 239 /** 240 * @return the minorTickSpacing 241 */ 242 public double getMinorTickSpacing() 243 { 244 return this.minorTickSpacing; 245 } 246 247 /** 248 * @param minorTickSpacing the minorTickSpacing to set 249 */ 250 public void setMinorTickSpacing( final double minorTickSpacing ) 251 { 252 this.minorTickSpacing = minorTickSpacing; 253 } 254 255 /** 256 * @return the majorTickSpacing 257 */ 258 public double getMajorTickSpacing() 259 { 260 return this.majorTickSpacing; 261 } 262 263 /** 264 * @param majorTickSpacing the majorTickSpacing to set 265 */ 266 public void setMajorTickSpacing( final double majorTickSpacing ) 267 { 268 this.majorTickSpacing = majorTickSpacing; 269 } 270 271 /** 272 * @return the minorTickLength 273 */ 274 public double getMinorTickLength() 275 { 276 return this.minorTickLength; 277 } 278 279 /** 280 * @param minorTickLength the minorTickLength to set 281 */ 282 public void setMinorTickLength( final double minorTickLength ) 283 { 284 this.minorTickLength = minorTickLength; 285 } 286 287 /** 288 * @return the majorTickLength 289 */ 290 public double getMajorTickLength() 291 { 292 return this.majorTickLength; 293 } 294 295 /** 296 * @param majorTickLength the majorTickLength to set 297 */ 298 public void setMajorTickLength( final double majorTickLength ) 299 { 300 this.majorTickLength = majorTickLength; 301 } 302 303 /** 304 * @return the minorTickColour 305 */ 306 public Q getMinorTickColour() 307 { 308 return this.minorTickColour; 309 } 310 311 /** 312 * @param minorTickColour the minorTickColour to set 313 */ 314 public void setMinorTickColour( final Q minorTickColour ) 315 { 316 this.minorTickColour = minorTickColour; 317 } 318 319 /** 320 * @return the majorTickColour 321 */ 322 public Q getMajorTickColour() 323 { 324 return this.majorTickColour; 325 } 326 327 /** 328 * @param majorTickColour the majorTickColour to set 329 */ 330 public void setMajorTickColour( final Q majorTickColour ) 331 { 332 this.majorTickColour = majorTickColour; 333 } 334 335 /** 336 * @return the drawMinorTickLabels 337 */ 338 public boolean isDrawMinorTickLabels() 339 { 340 return this.drawMinorTickLabels; 341 } 342 343 /** 344 * @param drawMinorTickLabels the drawMinorTickLabels to set 345 */ 346 public void setDrawMinorTickLabels( final boolean drawMinorTickLabels ) 347 { 348 this.drawMinorTickLabels = drawMinorTickLabels; 349 } 350 351 /** 352 * @return the minorTickLabelSpacing 353 */ 354 public double getMinorTickLabelSpacing() 355 { 356 return this.minorTickLabelSpacing; 357 } 358 359 /** 360 * @param minorTickLabelSpacing the minorTickLabelSpacing to set 361 */ 362 public void setMinorTickLabelSpacing( final double minorTickLabelSpacing ) 363 { 364 this.minorTickLabelSpacing = minorTickLabelSpacing; 365 } 366 367 /** 368 * @return the drawMajorTickLabels 369 */ 370 public boolean isDrawMajorTickLabels() 371 { 372 return this.drawMajorTickLabels; 373 } 374 375 /** 376 * @param drawMajorTickLabels the drawMajorTickLabels to set 377 */ 378 public void setDrawMajorTickLabels( final boolean drawMajorTickLabels ) 379 { 380 this.drawMajorTickLabels = drawMajorTickLabels; 381 } 382 383 /** 384 * @return the majorTickLabelSpacing 385 */ 386 public double getMajorTickLabelSpacing() 387 { 388 return this.majorTickLabelSpacing; 389 } 390 391 /** 392 * @param majorTickLabelSpacing the majorTickLabelSpacing to set 393 */ 394 public void setMajorTickLabelSpacing( final double majorTickLabelSpacing ) 395 { 396 this.majorTickLabelSpacing = majorTickLabelSpacing; 397 } 398 399 /** 400 * @return the majorTickLabelFont 401 */ 402 @SuppressWarnings( "rawtypes" ) 403 public Font getMajorTickLabelFont() 404 { 405 return this.majorTickLabelFont; 406 } 407 408 /** 409 * @param majorTickLabelFont the majorTickLabelFont to set 410 */ 411 @SuppressWarnings( "rawtypes" ) 412 public void setMajorTickLabelFont( final Font majorTickLabelFont ) 413 { 414 this.majorTickLabelFont = majorTickLabelFont; 415 } 416 417 /** 418 * @return the minorTickLabelFont 419 */ 420 @SuppressWarnings( "rawtypes" ) 421 public Font getMinorTickLabelFont() 422 { 423 return this.minorTickLabelFont; 424 } 425 426 /** 427 * @param minorTickLabelFont the minorTickLabelFont to set 428 */ 429 @SuppressWarnings( "rawtypes" ) 430 public void setMinorTickLabelFont( final Font minorTickLabelFont ) 431 { 432 this.minorTickLabelFont = minorTickLabelFont; 433 } 434 435 /** 436 * @return the autoSpaceLabels 437 */ 438 public boolean isAutoSpaceLabels() 439 { 440 return this.autoSpaceLabels; 441 } 442 443 /** 444 * @param autoSpaceLabels the autoSpaceLabels to set 445 */ 446 public void setAutoSpaceLabels( final boolean autoSpaceLabels ) 447 { 448 this.autoSpaceLabels = autoSpaceLabels; 449 } 450 451 /** 452 * @return the autoSpaceTicks 453 */ 454 public boolean isAutoSpaceTicks() 455 { 456 return this.autoSpaceTicks; 457 } 458 459 /** 460 * @param autoSpaceTicks the autoSpaceTicks to set 461 */ 462 public void setAutoSpaceTicks( final boolean autoSpaceTicks ) 463 { 464 this.autoSpaceTicks = autoSpaceTicks; 465 } 466 467 /** 468 * @return the nameSize 469 */ 470 public double getNameSize() 471 { 472 return this.nameSize; 473 } 474 475 /** 476 * @param nameSize the nameSize to set 477 */ 478 public void setNameSize( final double nameSize ) 479 { 480 this.nameSize = nameSize; 481 } 482 483 /** 484 * @return the nameColour 485 */ 486 public Q getNameColour() 487 { 488 return this.nameColour; 489 } 490 491 /** 492 * @param nameColour the nameColour to set 493 */ 494 public void setNameColour( final Q nameColour ) 495 { 496 this.nameColour = nameColour; 497 } 498 499 /** 500 * @return the labelTransformer 501 */ 502 public LabelTransformer getLabelTransformer() 503 { 504 return this.labelTransformer; 505 } 506 507 /** 508 * @param labelTransformer the labelTransformer to set 509 */ 510 public void setLabelTransformer( final LabelTransformer labelTransformer ) 511 { 512 this.labelTransformer = labelTransformer; 513 } 514 515 /** 516 * @return the drawMinorGrid 517 */ 518 public boolean isDrawMinorGrid() 519 { 520 return this.drawMinorGrid; 521 } 522 523 /** 524 * @param drawMinorGrid the drawMinorGrid to set 525 */ 526 public void setDrawMinorGrid( final boolean drawMinorGrid ) 527 { 528 this.drawMinorGrid = drawMinorGrid; 529 } 530 531 /** 532 * @return the drawMajorGrid 533 */ 534 public boolean isDrawMajorGrid() 535 { 536 return this.drawMajorGrid; 537 } 538 539 /** 540 * @param drawMajorGrid the drawMajorGrid to set 541 */ 542 public void setDrawMajorGrid( final boolean drawMajorGrid ) 543 { 544 this.drawMajorGrid = drawMajorGrid; 545 } 546 547 /** 548 * @return the minorGridColour 549 */ 550 public Q getMinorGridColour() 551 { 552 return this.minorGridColour; 553 } 554 555 /** 556 * @param minorGridColour the minorGridColour to set 557 */ 558 public void setMinorGridColour( final Q minorGridColour ) 559 { 560 this.minorGridColour = minorGridColour; 561 } 562 563 /** 564 * @return the majorGridColour 565 */ 566 public Q getMajorGridColour() 567 { 568 return this.majorGridColour; 569 } 570 571 /** 572 * @param majorGridColour the majorGridColour to set 573 */ 574 public void setMajorGridColour( final Q majorGridColour ) 575 { 576 this.majorGridColour = majorGridColour; 577 } 578 579 /** 580 * @return the majorGridThickness 581 */ 582 public double getMajorGridThickness() 583 { 584 return this.majorGridThickness; 585 } 586 587 /** 588 * @param majorGridThickness the majorGridThickness to set 589 */ 590 public void setMajorGridThickness( final double majorGridThickness ) 591 { 592 this.majorGridThickness = majorGridThickness; 593 } 594 595 /** 596 * @return the minorGridThickness 597 */ 598 public double getMinorGridThickness() 599 { 600 return this.minorGridThickness; 601 } 602 603 /** 604 * @param minorGridThickness the minorGridThickness to set 605 */ 606 public void setMinorGridThickness( final double minorGridThickness ) 607 { 608 this.minorGridThickness = minorGridThickness; 609 } 610 611 /** 612 * Returns whether an axis should be rendered 613 * @return Whether the axis should be rendered 614 */ 615 public boolean isRenderAxis() 616 { 617 return this.renderAxis; 618 } 619 620 /** 621 * 622 * @param renderAxis 623 */ 624 public void setRenderAxis( final boolean renderAxis ) 625 { 626 this.renderAxis = renderAxis; 627 } 628 629 /** 630 * @return the majorTickThickness 631 */ 632 public double getMajorTickThickness() 633 { 634 return this.majorTickThickness; 635 } 636 637 /** 638 * @param majorTickThickness the majorTickThickness to set 639 */ 640 public void setMajorTickThickness( final double majorTickThickness ) 641 { 642 this.majorTickThickness = majorTickThickness; 643 } 644 645 /** 646 * @return the minorTickThickness 647 */ 648 public double getMinorTickThickness() 649 { 650 return this.minorTickThickness; 651 } 652 653 /** 654 * @param minorTickThickness the minorTickThickness to set 655 */ 656 public void setMinorTickThickness( final double minorTickThickness ) 657 { 658 this.minorTickThickness = minorTickThickness; 659 } 660 661 /** 662 * @return the nameOrientation 663 */ 664 public double[] getNameOrientation() 665 { 666 return this.nameOrientation; 667 } 668 669 /** 670 * @param nameOrientation the nameOrientation to set 671 */ 672 public void setNameOrientation( final double[] nameOrientation ) 673 { 674 this.nameOrientation = nameOrientation; 675 } 676 677 /** 678 * 679 * @param i 680 */ 681 public void setNameDirection( final int i ) 682 { 683 this.nameDirection = i; 684 } 685 686 /** 687 * @return the nameDirection 688 */ 689 public int getNameDirection() 690 { 691 return this.nameDirection; 692 } 693 } 694 695 696 /** 697 * @return the location 698 */ 699 public double[] getLocation() 700 { 701 return this.location; 702 } 703 704 705 /** 706 * @param location the location to set 707 */ 708 public void setLocation( final double[] location ) 709 { 710 this.location = location; 711 } 712 713 714 /** 715 * @return the orientation 716 */ 717 public double[] getOrientation() 718 { 719 return this.orientation; 720 } 721 722 723 /** 724 * @param orientation the orientation to set 725 */ 726 public void setOrientation( final double[] orientation ) 727 { 728 this.orientation = orientation; 729 } 730 731 732 /** 733 * @return the name 734 */ 735 public String getName() 736 { 737 return this.name; 738 } 739 740 741 /** 742 * @param name the name to set 743 */ 744 public void setName( final String name ) 745 { 746 this.name = name; 747 } 748 749 750 /** 751 * @return the maxValue 752 */ 753 public double getMaxValue() 754 { 755 return this.maxValue; 756 } 757 758 759 /** 760 * @param maxValue the maxValue to set 761 */ 762 public void setMaxValue( final double maxValue ) 763 { 764 this.maxValue = maxValue; 765 } 766 767 768 /** 769 * @return the minValue 770 */ 771 public double getMinValue() 772 { 773 return this.minValue; 774 } 775 776 777 /** 778 * @param minValue the minValue to set 779 */ 780 public void setMinValue( final double minValue ) 781 { 782 this.minValue = minValue; 783 } 784 785 786 /** 787 * @return the renderingConfig 788 */ 789 public AxisRenderingConfig<Q> getRenderingConfig() 790 { 791 return this.renderingConfig; 792 } 793 794 795 /** 796 * 797 * @param config The rendering config 798 */ 799 public void setRenderingConfig( final AxisRenderingConfig<Q> config ) 800 { 801 this.renderingConfig = config; 802 } 803 804 805 /** 806 * Whether the axis should attempt to auto scale to fit the view 807 * @return TRUE to auto scale 808 */ 809 public boolean isAutoScale() 810 { 811 return this.autoScale; 812 } 813 814 /** 815 * Set whether the axis should attempt to auto scale to fit the view 816 * @param autoScale Whether to auto scale 817 */ 818 public void setAutoScale( final boolean autoScale ) 819 { 820 this.autoScale = autoScale; 821 } 822}