📄 logarithmicaxis.html
字号:
<FONT color="green">542</FONT> upper = (upper + lower + minRange) / 2;<a name="line.542"></a><FONT color="green">543</FONT> lower = (upper + lower - minRange) / 2;<a name="line.543"></a><FONT color="green">544</FONT> //if autorange still below minimum then adjust by 1%<a name="line.544"></a><FONT color="green">545</FONT> // (can be needed when minRange is very small):<a name="line.545"></a><FONT color="green">546</FONT> if (upper - lower < minRange) {<a name="line.546"></a><FONT color="green">547</FONT> double absUpper = Math.abs(upper);<a name="line.547"></a><FONT color="green">548</FONT> //need to account for case where upper==0.0<a name="line.548"></a><FONT color="green">549</FONT> double adjVal = (absUpper > SMALL_LOG_VALUE) ? absUpper<a name="line.549"></a><FONT color="green">550</FONT> / 100.0 : 0.01;<a name="line.550"></a><FONT color="green">551</FONT> upper = (upper + lower + adjVal) / 2;<a name="line.551"></a><FONT color="green">552</FONT> lower = (upper + lower - adjVal) / 2;<a name="line.552"></a><FONT color="green">553</FONT> }<a name="line.553"></a><FONT color="green">554</FONT> }<a name="line.554"></a><FONT color="green">555</FONT> <a name="line.555"></a><FONT color="green">556</FONT> setRange(new Range(lower, upper), false, false);<a name="line.556"></a><FONT color="green">557</FONT> setupSmallLogFlag(); //setup flag based on bounds values<a name="line.557"></a><FONT color="green">558</FONT> }<a name="line.558"></a><FONT color="green">559</FONT> }<a name="line.559"></a><FONT color="green">560</FONT> <a name="line.560"></a><FONT color="green">561</FONT> /**<a name="line.561"></a><FONT color="green">562</FONT> * Converts a data value to a coordinate in Java2D space, assuming that<a name="line.562"></a><FONT color="green">563</FONT> * the axis runs along one edge of the specified plotArea.<a name="line.563"></a><FONT color="green">564</FONT> * Note that it is possible for the coordinate to fall outside the<a name="line.564"></a><FONT color="green">565</FONT> * plotArea.<a name="line.565"></a><FONT color="green">566</FONT> *<a name="line.566"></a><FONT color="green">567</FONT> * @param value the data value.<a name="line.567"></a><FONT color="green">568</FONT> * @param plotArea the area for plotting the data.<a name="line.568"></a><FONT color="green">569</FONT> * @param edge the axis location.<a name="line.569"></a><FONT color="green">570</FONT> *<a name="line.570"></a><FONT color="green">571</FONT> * @return The Java2D coordinate.<a name="line.571"></a><FONT color="green">572</FONT> */<a name="line.572"></a><FONT color="green">573</FONT> public double valueToJava2D(double value, Rectangle2D plotArea,<a name="line.573"></a><FONT color="green">574</FONT> RectangleEdge edge) {<a name="line.574"></a><FONT color="green">575</FONT> <a name="line.575"></a><FONT color="green">576</FONT> Range range = getRange();<a name="line.576"></a><FONT color="green">577</FONT> double axisMin = switchedLog10(range.getLowerBound());<a name="line.577"></a><FONT color="green">578</FONT> double axisMax = switchedLog10(range.getUpperBound());<a name="line.578"></a><FONT color="green">579</FONT> <a name="line.579"></a><FONT color="green">580</FONT> double min = 0.0;<a name="line.580"></a><FONT color="green">581</FONT> double max = 0.0;<a name="line.581"></a><FONT color="green">582</FONT> if (RectangleEdge.isTopOrBottom(edge)) {<a name="line.582"></a><FONT color="green">583</FONT> min = plotArea.getMinX();<a name="line.583"></a><FONT color="green">584</FONT> max = plotArea.getMaxX();<a name="line.584"></a><FONT color="green">585</FONT> }<a name="line.585"></a><FONT color="green">586</FONT> else if (RectangleEdge.isLeftOrRight(edge)) {<a name="line.586"></a><FONT color="green">587</FONT> min = plotArea.getMaxY();<a name="line.587"></a><FONT color="green">588</FONT> max = plotArea.getMinY();<a name="line.588"></a><FONT color="green">589</FONT> }<a name="line.589"></a><FONT color="green">590</FONT> <a name="line.590"></a><FONT color="green">591</FONT> value = switchedLog10(value);<a name="line.591"></a><FONT color="green">592</FONT> <a name="line.592"></a><FONT color="green">593</FONT> if (isInverted()) {<a name="line.593"></a><FONT color="green">594</FONT> return max<a name="line.594"></a><FONT color="green">595</FONT> - (((value - axisMin) / (axisMax - axisMin)) * (max - min));<a name="line.595"></a><FONT color="green">596</FONT> }<a name="line.596"></a><FONT color="green">597</FONT> else {<a name="line.597"></a><FONT color="green">598</FONT> return min<a name="line.598"></a><FONT color="green">599</FONT> + (((value - axisMin) / (axisMax - axisMin)) * (max - min));<a name="line.599"></a><FONT color="green">600</FONT> }<a name="line.600"></a><FONT color="green">601</FONT> <a name="line.601"></a><FONT color="green">602</FONT> }<a name="line.602"></a><FONT color="green">603</FONT> <a name="line.603"></a><FONT color="green">604</FONT> /**<a name="line.604"></a><FONT color="green">605</FONT> * Converts a coordinate in Java2D space to the corresponding data<a name="line.605"></a><FONT color="green">606</FONT> * value, assuming that the axis runs along one edge of the specified<a name="line.606"></a><FONT color="green">607</FONT> * plotArea.<a name="line.607"></a><FONT color="green">608</FONT> *<a name="line.608"></a><FONT color="green">609</FONT> * @param java2DValue the coordinate in Java2D space.<a name="line.609"></a><FONT color="green">610</FONT> * @param plotArea the area in which the data is plotted.<a name="line.610"></a><FONT color="green">611</FONT> * @param edge the axis location.<a name="line.611"></a><FONT color="green">612</FONT> *<a name="line.612"></a><FONT color="green">613</FONT> * @return The data value.<a name="line.613"></a><FONT color="green">614</FONT> */<a name="line.614"></a><FONT color="green">615</FONT> public double java2DToValue(double java2DValue, Rectangle2D plotArea,<a name="line.615"></a><FONT color="green">616</FONT> RectangleEdge edge) {<a name="line.616"></a><FONT color="green">617</FONT> <a name="line.617"></a><FONT color="green">618</FONT> Range range = getRange();<a name="line.618"></a><FONT color="green">619</FONT> double axisMin = switchedLog10(range.getLowerBound());<a name="line.619"></a><FONT color="green">620</FONT> double axisMax = switchedLog10(range.getUpperBound());<a name="line.620"></a><FONT color="green">621</FONT> <a name="line.621"></a><FONT color="green">622</FONT> double plotMin = 0.0;<a name="line.622"></a><FONT color="green">623</FONT> double plotMax = 0.0;<a name="line.623"></a><FONT color="green">624</FONT> if (RectangleEdge.isTopOrBottom(edge)) {<a name="line.624"></a><FONT color="green">625</FONT> plotMin = plotArea.getX();<a name="line.625"></a><FONT color="green">626</FONT> plotMax = plotArea.getMaxX();<a name="line.626"></a><FONT color="green">627</FONT> }<a name="line.627"></a><FONT color="green">628</FONT> else if (RectangleEdge.isLeftOrRight(edge)) {<a name="line.628"></a><FONT color="green">629</FONT> plotMin = plotArea.getMaxY();<a name="line.629"></a><FONT color="green">630</FONT> plotMax = plotArea.getMinY();<a name="line.630"></a><FONT color="green">631</FONT> }<a name="line.631"></a><FONT color="green">632</FONT> <a name="line.632"></a><FONT color="green">633</FONT> if (isInverted()) {<a name="line.633"></a><FONT color="green">634</FONT> return Math.pow(<a name="line.634"></a><FONT color="green">635</FONT> 10, axisMax - ((java2DValue - plotMin) / (plotMax - plotMin))<a name="line.635"></a><FONT color="green">636</FONT> * (axisMax - axisMin)<a name="line.636"></a><FONT color="green">637</FONT> );<a name="line.637"></a><FONT color="green">638</FONT> }<a name="line.638"></a><FONT color="green">639</FONT> else {<a name="line.639"></a><FONT color="green">640</FONT> return Math.pow(<a name="line.640"></a><FONT color="green">641</FONT> 10, axisMin + ((java2DValue - plotMin) / (plotMax - plotMin))<a name="line.641"></a><FONT color="green">642</FONT> * (axisMax - axisMin)<a name="line.642"></a><FONT color="green">643</FONT> );<a name="line.643"></a><FONT color="green">644</FONT> }<a name="line.644"></a><FONT color="green">645</FONT> }<a name="line.645"></a><FONT color="green">646</FONT> <a name="line.646"></a><FONT color="green">647</FONT> /**<a name="line.647"></a><FONT color="green">648</FONT> * Calculates the positions of the tick labels for the axis, storing the<a name="line.648"></a><FONT color="green">649</FONT> * results in the tick label list (ready for drawing).<a name="line.649"></a><FONT color="green">650</FONT> *<a name="line.650"></a><FONT color="green">651</FONT> * @param g2 the graphics device.<a name="line.651"></a><FONT color="green">652</FONT> * @param dataArea the area in which the plot should be drawn.<a name="line.652"></a><FONT color="green">653</FONT> * @param edge the location of the axis.<a name="line.653"></a><FONT color="green">654</FONT> *<a name="line.654"></a><FONT color="green">655</FONT> * @return A list of ticks.<a name="line.655"></a><FONT color="green">656</FONT> */<a name="line.656"></a><FONT color="green">657</FONT> protected List refreshTicksHorizontal(Graphics2D g2,<a name="line.657"></a><FONT color="green">658</FONT> Rectangle2D dataArea,<a name="line.658"></a><FONT color="green">659</FONT> RectangleEdge edge) {<a name="line.659"></a><FONT color="green">660</FONT> <a name="line.660"></a><FONT color="green">661</FONT> List ticks = new java.util.ArrayList();<a name="line.661"></a><FONT color="green">662</FONT> Range range = getRange();<a name="line.662"></a><FONT color="green">663</FONT> <a name="line.663"></a><FONT color="green">664</FONT> //get lower bound value:<a name="line.664"></a><FONT color="green">665</FONT> double lowerBoundVal = range.getLowerBound();<a name="line.665"></a><FONT color="green">666</FONT> //if small log values and lower bound value too small<a name="line.666"></a><FONT color="green">667</FONT> // then set to a small value (don't allow <= 0):<a name="line.667"></a><FONT color="green">668</FONT> if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {<a name="line.668"></a><FONT color="green">669</FONT> lowerBoundVal = SMALL_LOG_VALUE;<a name="line.669"></a><FONT color="green">670</FONT> }<a name="line.670"></a><FONT color="green">671</FONT> <a name="line.671"></a><FONT color="green">672</FONT> //get upper bound value<a name="line.672"></a><FONT color="green">673</FONT> double upperBoundVal = range.getUpperBound();<a name="line.673"></a><FONT color="green">674</FONT> <a name="line.674"></a><FONT color="green">675</FONT> //get log10 version of lower bound and round to integer:<a name="line.675"></a><FONT color="green">676</FONT> int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));<a name="line.676"></a><FONT color="green">677</FONT> //get log10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -