Debian Codegraph @

src/dr/app/gui/chart/Axis.java

raw symbols SCIP
1 /*
2 * Axis.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.gui.chart;
27
28 import dr.util.NumberFormatter;
29
30 /**
31 * Axis.java
32 *
33 * Description: Provides an interface for axis
34 * @author Andrew Rambaut
35 * @version $Id: Axis.java,v 1.11 2005/05/24 20:25:59 rambaut Exp $
36 */
37
38 public interface Axis {
39
40 // These constants are used for automatic scaling to select exactly
41 // where the axis starts and stops.
42 int AT_MAJOR_TICK=0;
43 int AT_MAJOR_TICK_PLUS=1;
44 int AT_MINOR_TICK=2;
45 int AT_MINOR_TICK_PLUS=3;
46 int AT_DATA=4;
47 int AT_ZERO=5;
48 int AT_VALUE=6;
49 int AT_MAJOR_TICK_MINUS=7; // offset towards negatives, especially to raise 0 in y
50
51 /**
52 * Set axis flags
53 */
54 void setAxisFlags(int minAxisFlag, int maxAxisFlag);
55
56 /**
57 * Set preferred number of ticks
58 */
59 void setPrefNumTicks(int prefNumMajorTicks, int prefNumMinorTicks);
60
61 /**
62 * Set integer scale
63 */
64 void setIsDiscrete(boolean isDiscrete);
65
66 /**
67 * Set show label for first tick
68 */
69 void setLabelFirst(boolean labelFirst);
70
71 /**
72 * Set show label for last tick
73 */
74 void setLabelLast(boolean labelLast);
75
76 /**
77 *@return IsDiscrete
78 */
79 boolean getIsDiscrete();
80
81 /**
82 *@return show label for first tick
83 */
84 boolean getLabelFirst();
85
86 /**
87 *@return show label for last tick
88 */
89 boolean getLabelLast();
90
91 /**
92 * Manually set the axis range. Axis flags must be set to AT_VALUE for this to take effect.
93 */
94 void setManualRange(double minValue, double maxValue);
95
96 /**
97 * Manually set the axis range and ticks
98 */
99 void setManualAxis(double minTick, double maxTick, double majorTick, double minorTick);
100
101 /**
102 * Set the axis to automatic calibration
103 */
104 void setAutomatic();
105
106 /**
107 * Set the axis to automatic calibration
108 */
109 void setAutomatic(int minAxisFlag, int maxAxisFlag);
110
111 /**
112 * Set the range of the data
113 */
114 void setRange(double minValue, double maxValue);
115
116 /**
117 * Adds the range of the data
118 */
119 void addRange(double minValue, double maxValue);
120
121 /**
122 * Transform a value
123 */
124 double transform(double value);
125
126 /**
127 * Untransform a value
128 */
129 double untransform(double value);
130
131 /**
132 * @return a string that appropriately formats the value
133 */
134 String format(double value);
135
136 /**
137 * @return minimum range of the axis
138 */
139 double getMinAxis();
140
141 /**
142 * @return maximum range of the axis
143 */
144 double getMaxAxis();
145
146 /**
147 * @return minimum range of the data
148 */
149 double getMinData();
150
151 /**
152 * @return maximum range of the data
153 */
154 double getMaxData();
155
156 /**
157 * @return the number of major tick marks along the axis
158 */
159 int getMajorTickCount();
160
161 /**
162 * @return the number of minor tick marks within each major one
163 * By default all major ticks have the same number of minor ticks
164 * except the last which has none.
165 */
166 int getMinorTickCount(int majorTickIndex);
167
168 /**
169 * @return the value of the majorTickIndex'th major tick
170 */
171 double getMajorTickValue(int majorTickIndex);
172
173 /**
174 * @return the label of the majorTickIndex'th major tick
175 */
176 String getMajorTickLabel(int majorTickIndex);
177
178 /**
179 * @return the value of the minorTickIndex'th minor tick
180 */
181 double getMinorTickValue(int minorTickIndex, int majorTickIndex);
182
183 /**
184 * @return the spacing between major ticks
185 */
186 double getMajorTickSpacing();
187
188 /**
189 * @return the spacing between minor ticks
190 */
191 double getMinorTickSpacing();
192
193 /** class AbstractAxis
194 * This class provides a base class for all axis.
195 */
196
197 abstract class AbstractAxis implements Axis {
198
199 // The minimum and maximum values of the data
200 protected double minData=Double.POSITIVE_INFINITY, maxData=Double.NEGATIVE_INFINITY;
201
202 // The number of major ticks and minor ticks within them
203 protected int majorTickCount, minorTickCount; // calculated automatically
204
205 // The prefered minimum number of ticks
206 protected int prefMajorTickCount = 5, prefMinorTickCount = 2; // set manually
207
208 // Flags using the above constants
209 protected int minAxisFlag, maxAxisFlag;
210
211 // The distance between major ticks and minor Ticks
212 protected double majorTick, minorTick; // calculated automatically or set by user
213
214 // The value of the first and last major tick
215 protected double minTick, maxTick; // calculated automatically or set by user
216
217 // The value of the beginning and end of the axis
218 protected double minAxis, maxAxis;
219
220 // User defined axis range
221 protected double minValue, maxValue;
222
223 // Flags to give automatic scaling and integer division
224 protected boolean isAutomatic=true, isDiscrete=false;
225
226 // Flags to specify that the first tick and last tick should have labels.
227 // It is up to the AxisPanel to do something about this.
228 protected boolean labelFirst=false, labelLast=false;
229
230 protected boolean isCalibrated = false;
231
232 protected final NumberFormatter formatter = new NumberFormatter(8);
233 protected final NumberFormatter discreteFormatter = new NumberFormatter(0);
234
235 // Used internally
236 private double epsilon;
237 private int fraction;
238
239 /**
240 * The constructor for automatic calibration
241 */
242 public AbstractAxis() {
243 this(AT_MAJOR_TICK, AT_MAJOR_TICK, false);
244 }
245
246 /**
247 * The constructor for automatic calibration
248 */
249 public AbstractAxis(int minAxisFlag, int maxAxisFlag) {
250 this(minAxisFlag, maxAxisFlag, false);
251 }
252
253 /**
254 * The constructor for automatic calibration
255 */
256 public AbstractAxis(int minAxisFlag, int maxAxisFlag, boolean isDiscrete) {
257 this.minAxisFlag = minAxisFlag;
258 this.maxAxisFlag = maxAxisFlag;
259 this.isDiscrete = isDiscrete;
260 isAutomatic = true;
261 isCalibrated = false;
262 }
263
264 /**
265 * The constructor for manual calibration
266 */
267 public AbstractAxis(double minTick, double maxTick,
268 double majorTick, double minorTick) {
269 setManualAxis(minTick, maxTick, majorTick, minorTick);
270 }
271
272 /**
273 * Set axis flags
274 */
275 public void setAxisFlags(int minAxisFlag, int maxAxisFlag) {
276 this.minAxisFlag = minAxisFlag;
277 this.maxAxisFlag = maxAxisFlag;
278 isCalibrated = false;
279 }
280
281 /**
282 * Set preferred number of ticks
283 */
284 public void setPrefNumTicks(int prefMajorTickCount, int prefMinorTickCount) {
285 this.prefMajorTickCount = prefMajorTickCount;
286 this.prefMinorTickCount = prefMinorTickCount;
287 isCalibrated = false;
288 }
289
290 /**
291 * Set integer scale
292 */
293 public void setIsDiscrete(boolean isDiscrete) {
294 this.isDiscrete = isDiscrete;
295 isCalibrated = false;
296 }
297
298 /**
299 * Set show label for first tick flag
300 */
301 public void setLabelFirst(boolean labelFirst) {
302 this.labelFirst = labelFirst;
303 }
304
305 /**
306 * Set show label for last tick flag
307 */
308 public void setLabelLast(boolean labelLast) {
309 this.labelLast = labelLast;
310 }
311
312 /**
313 * Set the number of significant figures for the tick labels
314 */
315 public void setSignficantFigures(int sf) {
316 this.formatter.setSignificantFigures(sf);
317 }
318
319
320 /**
321 * Turn a double value into a formatted string
322 * @param value
323 * @return
324 */
325 public String format(double value) {
326 if (isDiscrete) {
327 return discreteFormatter.format(value);
328 }
329 return formatter.format(value);
330 }
331
332 /**
333 * return show label for first tick flag
334 */
335 public boolean getIsDiscrete() {
336 return this.isDiscrete;
337 }
338
339
340 /**
341 * return show label for first tick flag
342 */
343 public boolean getLabelFirst() {
344 return getMinorTickCount(-1) != 0 && labelFirst;
345 }
346
347 /**
348 * return show label for last tick flag
349 */
350 public boolean getLabelLast() {
351 return getMinorTickCount(majorTickCount - 1) != 0 && labelLast;
352 }
353
354 /**
355 * Manually set the axis range. Axis flags must be set to AT_VALUE for this to take effect.
356 */
357 public void setManualRange(double minValue, double maxValue) {
358 if (!Double.isInfinite(minValue) && !Double.isNaN(minValue)) {
359 this.minValue = minValue;
360 }
361 if (!Double.isInfinite(minValue) && !Double.isNaN(minValue)) {
362 this.maxValue = maxValue;
363 }
364 isCalibrated = false;
365 }
366
367 /**
368 * Manually set the axis ticks
369 */
370 public void setManualAxis(double minTick, double maxTick,
371 double majorTick, double minorTick) {
372 this.minTick = minTick;
373 this.maxTick = maxTick;
374
375 this.majorTick = majorTick;
376 this.minorTick = minorTick;
377
378 majorTickCount = (int)((maxTick-minTick)/majorTick)+1; // Add 1 to include the last tick
379 minorTickCount = (int)(majorTick/minorTick)-1; // Sub 1 to exclude the major tick
380 isAutomatic=false;
381 isCalibrated = false;
382 }
383
384 /**
385 * Set the axis to automatic calibration
386 */
387 public void setAutomatic() {
388 setAutomatic(AT_MAJOR_TICK, AT_MAJOR_TICK);
389 }
390
391 /**
392 * Set the axis to automatic calibration
393 */
394 public void setAutomatic(int minAxisFlag, int maxAxisFlag) {
395 setAxisFlags(minAxisFlag, maxAxisFlag);
396 isAutomatic = true;
397 isCalibrated = false;
398 }
399
400 /**
401 * Set the range of the data
402 */
403 public void setRange(double minValue, double maxValue) {
404 if (!Double.isNaN(minValue)) {
405 this.minData = minValue;
406 }
407 if (!Double.isNaN(maxValue)) {
408 this.maxData = maxValue;
409 }
410
411 isCalibrated = false;
412 }
413
414 /**
415 * Adds the range to the existing range, widening if neccessary
416 */
417 public void addRange(double minValue, double maxValue) {
418 if (!Double.isNaN(minValue) && maxValue > maxData) {
419 maxData = maxValue;
420 }
421 if (!Double.isNaN(maxValue) && minValue < minData) {
422 minData = minValue;
423 }
424
425 //System.err.println("addRange("+minValue +", "+maxValue+")");
426 //System.err.println("maxValue = "+maxData);
427 //System.err.println("maxData = "+maxData);
428
429 isCalibrated = false;
430 }
431
432 /**
433 * A static method that uses the natural log to obtain log to base10.
434 * This is required for the linear autoCalibrate but will also be
435 * used by a derived class giving a log transformed axis.
436 */
437 static public double log10(double inValue) {
438 return Math.log(inValue)/Math.log(10.0);
439 }
440
441 /** autoCalibrate
442 * Attempt to find the optimum axis range and ticks.
443 * This will attempt to use at least numMajorTick ticks on the axis.
444 */
445 static private final int UNIT=0;
446 static private final int HALFS=1;
447 static private final int QUARTERS=2;
448 static private final int FIFTHS=3;
449
450 public void calibrate() {
451
452 double minValue = minData;
453 double maxValue = maxData;
454
455 if( Double.isInfinite(minValue) || Double.isNaN(minValue) ||
456 Double.isInfinite(maxValue) || Double.isNaN(maxValue)) {
457 // I am not sure which exception is appropriate here.
458 throw new ChartRuntimeException("Illegal range values, can't calibrate");
459 }
460
461 if (minAxisFlag==AT_ZERO ) {
462 minValue = 0;
463 } else if (minAxisFlag == AT_VALUE) {
464 minValue = this.minValue;
465 }
466
467 if (maxAxisFlag==AT_ZERO) {
468 maxValue = 0;
469 } else if (maxAxisFlag == AT_VALUE) {
470 maxValue = this.maxValue;
471 }
472
473 double range = maxValue - minValue;
474 if (range < 0.0) {
475 range = 0.0;
476 }
477
478 epsilon = range * 1.0E-10;
479
480 if (isAutomatic) {
481 // We must find the optimum minMajorTick and maxMajorTick so
482 // that they contain the data range (minData to maxData) and
483 // are in the right order of magnitude
484
485 if (range < 1.0E-30) {
486 if (minData < 0.0) {
487 majorTick = Math.pow(10.0, Math.floor(log10(Math.abs(minData))));
488 minTick = Math.floor(minData / majorTick) * majorTick;
489 maxTick = 0.0;
490 } else if (minData > 0.0) {
491 majorTick = Math.pow(10.0, Math.floor(log10(Math.abs(minData))));
492 minTick = 0.0;
493 maxTick = Math.ceil(maxData / majorTick) * majorTick;
494 } else {
495 minTick = -1.0;
496 maxTick = 1.0;
497 majorTick = 1.0;
498 }
499
500 minorTick = majorTick;
501 majorTickCount = 1;
502 minorTickCount = 0;
503
504 } else {
505 // First find order of magnitude below the data range...
506 majorTick = Math.pow(10.0, Math.floor(log10(range)));
507
508 calcMinTick();
509 calcMaxTick();
510
511 calcMajorTick();
512 calcMinorTick();
513 }
514 }
515
516 minAxis = minTick;
517 maxAxis = maxTick;
518
519 handleAxisFlags();
520
521 isCalibrated=true;
522 }
523
524 /**
525 * Calculate the optimum minimum tick. Override to change default behaviour
526 */
527 public void calcMinTick() {
528 // Find the nearest multiple of majorTick below minData
529 if (minData == 0.0)
530 minTick = 0;
531 else
532 minTick = Math.floor(minData / majorTick) * majorTick;
533 }
534
535 /**
536 * Calculate the optimum maximum tick. Override to change default behaviour
537 */
538 public void calcMaxTick() {
539 // Find the nearest multiple of majorTick above maxData
540 if (maxData == 0) {
541 maxTick = 0;
542 } else if (maxData < 0.0) {
543 // Added so that negative values are handled correctly -- AJD
544 maxTick = -Math.floor(-maxData / majorTick) * majorTick;
545 } else {
546 maxTick = Math.ceil(maxData / majorTick) * majorTick;
547 }
548 }
549
550 /**
551 * Calculate the optimum major tick distance. Override to change default behaviour
552 */
553 public void calcMajorTick() {
554 fraction=UNIT;
555
556 // make sure that there are at least prefNumMajorTicks major ticks
557 // by dividing up into halves, quarters, fifths or tenths
558 double u=majorTick;
559 double r=maxTick-minTick;
560 majorTickCount=(int)(r/u);
561
562 if (r == 0) {
563 majorTickCount = 1;
564 return;
565 }
566
567 while (majorTickCount < prefMajorTickCount) {
568 u=majorTick/2; // Try using halves
569 if (!isDiscrete || u==Math.floor(u)) { // u is an integer
570 majorTickCount=(int)(r/u);
571 fraction=HALFS;
572 if (majorTickCount >= prefMajorTickCount)
573 break;
574 }
575
576 u=majorTick/4; // Try using quarters
577 if (!isDiscrete || u==Math.floor(u)) { // u is an integer
578 majorTickCount=(int)(r/u);
579 fraction=QUARTERS;
580 if (majorTickCount >= prefMajorTickCount)
581 break;
582 }
583
584 u=majorTick/5; // Try using fifths
585 if (!isDiscrete || u==Math.floor(u)) { // u is an integer
586 majorTickCount=(int)(r/u);
587 fraction=FIFTHS;
588 if (majorTickCount >= prefMajorTickCount)
589 break;
590 }
591
592 if (isDiscrete && (majorTick/10)!=Math.floor(majorTick/10)) {
593 // majorTick/10 is not an integer so no point in further subdivision
594 u=majorTick;
595 majorTickCount=(int)(r/u);
596 break;
597 }
598
599 majorTick/=10; // finally just divide by ten
600 u=majorTick; // and go back to whole units
601 majorTickCount=(int)(r/u);
602 fraction=UNIT;
603
604 }
605 majorTick=u;
606
607 if (isDiscrete && majorTick<1.0) {
608 majorTick=1.0;
609 majorTickCount=(int)(r/majorTick);
610 fraction=UNIT;
611 }
612
613 majorTickCount++; // Add 1 to give the final tick
614
615 // Trim down any excess major ticks either side of the data range
616 // Epsilon allows for any inprecision in the calculation
617 while ((minTick + majorTick - epsilon)<minData) {
618 minTick+=majorTick;
619 majorTickCount--;
620 }
621 while ((maxTick - majorTick + epsilon)>maxData) {
622 maxTick-=majorTick;
623 majorTickCount--;
624 }
625 }
626
627 /**
628 * Calculate the optimum minor tick distance. Override to change default behaviour
629 */
630 public void calcMinorTick() {
631 minorTick=majorTick; // start with minorTick the same as majorTick
632 double u=minorTick;
633 double r=majorTick;
634 minorTickCount=(int)(r/u);
635
636 while (minorTickCount < prefMinorTickCount) {
637 // if the majorTick was divided as quarters, then we can't
638 // divide the minor ticks into halves or quarters.
639 if (fraction!=QUARTERS) {
640 u=minorTick/2; // Try using halves
641 if (!isDiscrete || u==Math.floor(u)) { // u is an integer
642 minorTickCount=(int)(r/u);
643 if (minorTickCount>=prefMinorTickCount)
644 break;
645 }
646
647 u=minorTick/4; // Try using quarters
648 if (!isDiscrete || u==Math.floor(u)) { // u is an integer
649 minorTickCount=(int)(r/u);
650 if (minorTickCount>=prefMinorTickCount)
651 break;
652 }
653 }
654
655 u=minorTick/5; // Try using fifths
656 if (!isDiscrete || u==Math.floor(u)) { // u is an integer
657 minorTickCount=(int)(r/u);
658 if (minorTickCount>=prefMinorTickCount)
659 break;
660 }
661
662 if (isDiscrete && (minorTick/10)!=Math.floor(minorTick/10)) {
663 // minorTick/10 is not an integer so no point in further subdivision
664 u=minorTick;
665 minorTickCount=(int)(r/u);
666 break;
667 }
668
669 minorTick/=10; // finally just divide by ten
670 u=minorTick; // and go back to whole units
671 minorTickCount=(int)(r/u);
672 }
673 minorTick=u;
674
675 minorTickCount--;
676 }
677
678 /**
679 * Handles axis flags. Override to change default behaviour
680 */
681 public void handleAxisFlags() {
682 // Now we must honor the min/maxAxisFlag settings
683 if (minAxisFlag==AT_MAJOR_TICK_PLUS || minAxisFlag==AT_MINOR_TICK_PLUS) {
684 if (minAxis==minData) {
685 majorTickCount++;
686 // minTick-=majorTick;
687 minAxis=minTick;
688 }
689 }
690
691 if (minAxisFlag==AT_MAJOR_TICK_MINUS) {
692 if (minAxis==minData) {
693 majorTickCount++;
694 minTick-=majorTick;
695 minAxis=minTick;
696 }
697 }
698
699 if (minAxisFlag==AT_MINOR_TICK_PLUS) {
700 if ((minAxis+minorTick)<minData) {
701 majorTickCount--;
702 minTick+=majorTick;
703 while ((minAxis+minorTick)<minData) {
704 minAxis+=minorTick;
705 }
706 }
707 } else if (minAxisFlag==AT_MINOR_TICK) {
708 if ((minAxis+minorTick)<=minData) {
709 majorTickCount--;
710 minTick+=majorTick;
711 while ((minAxis+minorTick)<=minData) {
712 minAxis+=minorTick;
713 }
714 }
715 } else if (minAxisFlag==AT_DATA) {
716 if (minTick<minData) { // in case minTick==minData
717 majorTickCount--;
718 minTick+=majorTick;
719 }
720 minAxis=minData;
721 } else if (minAxisFlag==AT_VALUE) {
722 if (minTick<minValue) { // in case minTick==minValue
723 majorTickCount--;
724 minTick+=majorTick;
725 }
726 minAxis=minValue;
727 } else if (minAxisFlag==AT_ZERO) {
728 majorTickCount+=(int)(minTick/majorTick);
729 minTick=0;
730 minAxis=0;
731 }
732
733 if (maxAxisFlag==AT_MAJOR_TICK_PLUS || maxAxisFlag==AT_MINOR_TICK_PLUS) {
734 if (maxAxis==maxData) {
735 majorTickCount++;
736 maxTick+=majorTick;
737 maxAxis=maxTick;
738 }
739 }
740
741 if (maxAxisFlag==AT_MINOR_TICK_PLUS) {
742 if ((maxAxis-minorTick)>maxData) {
743 majorTickCount--;
744 maxTick-=majorTick;
745 while ((maxAxis-minorTick)>maxData) {
746 maxAxis-=minorTick;
747 }
748 }
749 } else if (maxAxisFlag==AT_MINOR_TICK) {
750 if ((maxAxis-minorTick)>=maxData) {
751 majorTickCount--;
752 maxTick-=majorTick;
753 while ((maxAxis-minorTick)>=maxData) {
754 maxAxis-=minorTick;
755 }
756 }
757 } else if (maxAxisFlag==AT_DATA) {
758 if (maxTick>maxData) { // in case maxTick==maxData
759 majorTickCount--;
760 maxTick-=majorTick;
761 }
762 maxAxis=maxData;
763 } else if (maxAxisFlag==AT_VALUE) {
764 if (maxTick>maxValue) { // in case maxTick==maxValue
765 majorTickCount--;
766 maxTick-=majorTick;
767 }
768 maxAxis=maxValue;
769 } else if (maxAxisFlag==AT_ZERO) {
770 majorTickCount+=(int)(-maxTick/majorTick);
771 maxTick=0;
772 maxTick=0;
773 }
774 }
775
776 /**
777 * Scale a value to between 0 and 1.
778 */
779 public double scaleValue(double value) {
780 if (!isCalibrated)
781 calibrate();
782
783 final double ta = transform(minAxis);
784 return (transform(value)- ta)/(transform(maxAxis)- ta);
785 }
786
787 /**
788 * @return minimum range of the axis
789 */
790 public double getMinAxis() {
791 if (!isCalibrated)
792 calibrate();
793
794 return minAxis;
795 }
796
797 /**
798 * @return maximum range of the axis
799 */
800 public double getMaxAxis() {
801 if (!isCalibrated)
802 calibrate();
803
804 return maxAxis;
805 }
806
807 /**
808 * @return minimum range of the data
809 */
810 public double getMinData() { return minData; }
811
812 /**
813 * @return maximum range of the data
814 */
815 public double getMaxData() { return maxData; }
816
817 /**
818 * Returns the number of major tick marks along the axis
819 */
820 public int getMajorTickCount() {
821 if (!isCalibrated)
822 calibrate();
823 return majorTickCount;
824 }
825
826 /**
827 * Returns the number of minor tick marks within each major one
828 * By default all major ticks have the same number of minor ticks
829 * except the last which has none.
830 */
831 public int getMinorTickCount(int majorTickIndex) {
832 if (!isCalibrated)
833 calibrate();
834
835 if (majorTickIndex == majorTickCount-1)
836 return (int)((maxAxis-maxTick)/minorTick);
837 else if (majorTickIndex==-1)
838 return (int)((minTick-minAxis)/minorTick);
839 else
840 return minorTickCount;
841 }
842
843 /**
844 * getMajorTickValue
845 * Returns the value of the majorTickIndex'th major tick
846 */
847 public double getMajorTickValue(int majorTickIndex) {
848 if (!isCalibrated)
849 calibrate();
850 return (majorTickIndex*majorTick)+minTick;
851 }
852
853 /**
854 * getMajorTickValue
855 * Returns the value of the majorTickIndex'th major tick
856 */
857 public String getMajorTickLabel(int majorTickIndex) {
858 return format(getMajorTickValue(majorTickIndex));
859 }
860
861 /** getMinorTick
862 * Returns the value of the minorTickIndex'th minor tick
863 */
864 public double getMinorTickValue(int minorTickIndex, int majorTickIndex) {
865 if (!isCalibrated)
866 calibrate();
867 // get minorTickIndex+1 to skip the major tick
868 if (majorTickIndex==-1)
869 return minTick-((minorTickIndex+1)*minorTick);
870 else
871 return ((minorTickIndex+1)*minorTick)+getMajorTickValue(majorTickIndex);
872 }
873
874 /**
875 * @return the spacing between major ticks
876 */
877 public double getMajorTickSpacing() {
878 if (!isCalibrated)
879 calibrate();
880 return majorTick;
881 }
882
883 /**
884 * @return the spacing between minor ticks
885 */
886 public double getMinorTickSpacing() {
887 if (!isCalibrated)
888 calibrate();
889 return minorTick;
890 }
891
892 }
893
894 }
895