📄 dateaxis.html
字号:
<FONT color="green">574</FONT> <a name="line.574"></a><FONT color="green">575</FONT> /**<a name="line.575"></a><FONT color="green">576</FONT> * Returns the tick mark position (start, middle or end of the time period).<a name="line.576"></a><FONT color="green">577</FONT> *<a name="line.577"></a><FONT color="green">578</FONT> * @return The position (never <code>null</code>).<a name="line.578"></a><FONT color="green">579</FONT> */<a name="line.579"></a><FONT color="green">580</FONT> public DateTickMarkPosition getTickMarkPosition() {<a name="line.580"></a><FONT color="green">581</FONT> return this.tickMarkPosition;<a name="line.581"></a><FONT color="green">582</FONT> }<a name="line.582"></a><FONT color="green">583</FONT> <a name="line.583"></a><FONT color="green">584</FONT> /**<a name="line.584"></a><FONT color="green">585</FONT> * Sets the tick mark position (start, middle or end of the time period) <a name="line.585"></a><FONT color="green">586</FONT> * and sends an {@link AxisChangeEvent} to all registered listeners.<a name="line.586"></a><FONT color="green">587</FONT> *<a name="line.587"></a><FONT color="green">588</FONT> * @param position the position (<code>null</code> not permitted).<a name="line.588"></a><FONT color="green">589</FONT> */<a name="line.589"></a><FONT color="green">590</FONT> public void setTickMarkPosition(DateTickMarkPosition position) {<a name="line.590"></a><FONT color="green">591</FONT> if (position == null) {<a name="line.591"></a><FONT color="green">592</FONT> throw new IllegalArgumentException("Null 'position' argument.");<a name="line.592"></a><FONT color="green">593</FONT> }<a name="line.593"></a><FONT color="green">594</FONT> this.tickMarkPosition = position;<a name="line.594"></a><FONT color="green">595</FONT> notifyListeners(new AxisChangeEvent(this));<a name="line.595"></a><FONT color="green">596</FONT> }<a name="line.596"></a><FONT color="green">597</FONT> <a name="line.597"></a><FONT color="green">598</FONT> /**<a name="line.598"></a><FONT color="green">599</FONT> * Configures the axis to work with the specified plot. If the axis has<a name="line.599"></a><FONT color="green">600</FONT> * auto-scaling, then sets the maximum and minimum values.<a name="line.600"></a><FONT color="green">601</FONT> */<a name="line.601"></a><FONT color="green">602</FONT> public void configure() {<a name="line.602"></a><FONT color="green">603</FONT> if (isAutoRange()) {<a name="line.603"></a><FONT color="green">604</FONT> autoAdjustRange();<a name="line.604"></a><FONT color="green">605</FONT> }<a name="line.605"></a><FONT color="green">606</FONT> }<a name="line.606"></a><FONT color="green">607</FONT> <a name="line.607"></a><FONT color="green">608</FONT> /**<a name="line.608"></a><FONT color="green">609</FONT> * Returns <code>true</code> if the axis hides this value, and <a name="line.609"></a><FONT color="green">610</FONT> * <code>false</code> otherwise.<a name="line.610"></a><FONT color="green">611</FONT> *<a name="line.611"></a><FONT color="green">612</FONT> * @param millis the data value.<a name="line.612"></a><FONT color="green">613</FONT> *<a name="line.613"></a><FONT color="green">614</FONT> * @return A value.<a name="line.614"></a><FONT color="green">615</FONT> */<a name="line.615"></a><FONT color="green">616</FONT> public boolean isHiddenValue(long millis) {<a name="line.616"></a><FONT color="green">617</FONT> return (!this.timeline.containsDomainValue(new Date(millis)));<a name="line.617"></a><FONT color="green">618</FONT> }<a name="line.618"></a><FONT color="green">619</FONT> <a name="line.619"></a><FONT color="green">620</FONT> /**<a name="line.620"></a><FONT color="green">621</FONT> * Translates the data value to the display coordinates (Java 2D User Space)<a name="line.621"></a><FONT color="green">622</FONT> * of the chart.<a name="line.622"></a><FONT color="green">623</FONT> *<a name="line.623"></a><FONT color="green">624</FONT> * @param value the date to be plotted.<a name="line.624"></a><FONT color="green">625</FONT> * @param area the rectangle (in Java2D space) where the data is to be <a name="line.625"></a><FONT color="green">626</FONT> * plotted.<a name="line.626"></a><FONT color="green">627</FONT> * @param edge the axis location.<a name="line.627"></a><FONT color="green">628</FONT> *<a name="line.628"></a><FONT color="green">629</FONT> * @return The coordinate corresponding to the supplied data value.<a name="line.629"></a><FONT color="green">630</FONT> */<a name="line.630"></a><FONT color="green">631</FONT> public double valueToJava2D(double value, Rectangle2D area, <a name="line.631"></a><FONT color="green">632</FONT> RectangleEdge edge) {<a name="line.632"></a><FONT color="green">633</FONT> <a name="line.633"></a><FONT color="green">634</FONT> value = this.timeline.toTimelineValue((long) value);<a name="line.634"></a><FONT color="green">635</FONT> <a name="line.635"></a><FONT color="green">636</FONT> DateRange range = (DateRange) getRange();<a name="line.636"></a><FONT color="green">637</FONT> double axisMin = this.timeline.toTimelineValue(range.getLowerDate());<a name="line.637"></a><FONT color="green">638</FONT> double axisMax = this.timeline.toTimelineValue(range.getUpperDate());<a name="line.638"></a><FONT color="green">639</FONT> double result = 0.0;<a name="line.639"></a><FONT color="green">640</FONT> if (RectangleEdge.isTopOrBottom(edge)) {<a name="line.640"></a><FONT color="green">641</FONT> double minX = area.getX();<a name="line.641"></a><FONT color="green">642</FONT> double maxX = area.getMaxX();<a name="line.642"></a><FONT color="green">643</FONT> if (isInverted()) {<a name="line.643"></a><FONT color="green">644</FONT> result = maxX + ((value - axisMin) / (axisMax - axisMin)) <a name="line.644"></a><FONT color="green">645</FONT> * (minX - maxX);<a name="line.645"></a><FONT color="green">646</FONT> }<a name="line.646"></a><FONT color="green">647</FONT> else {<a name="line.647"></a><FONT color="green">648</FONT> result = minX + ((value - axisMin) / (axisMax - axisMin)) <a name="line.648"></a><FONT color="green">649</FONT> * (maxX - minX);<a name="line.649"></a><FONT color="green">650</FONT> }<a name="line.650"></a><FONT color="green">651</FONT> }<a name="line.651"></a><FONT color="green">652</FONT> else if (RectangleEdge.isLeftOrRight(edge)) {<a name="line.652"></a><FONT color="green">653</FONT> double minY = area.getMinY();<a name="line.653"></a><FONT color="green">654</FONT> double maxY = area.getMaxY();<a name="line.654"></a><FONT color="green">655</FONT> if (isInverted()) {<a name="line.655"></a><FONT color="green">656</FONT> result = minY + (((value - axisMin) / (axisMax - axisMin)) <a name="line.656"></a><FONT color="green">657</FONT> * (maxY - minY));<a name="line.657"></a><FONT color="green">658</FONT> }<a name="line.658"></a><FONT color="green">659</FONT> else {<a name="line.659"></a><FONT color="green">660</FONT> result = maxY - (((value - axisMin) / (axisMax - axisMin)) <a name="line.660"></a><FONT color="green">661</FONT> * (maxY - minY));<a name="line.661"></a><FONT color="green">662</FONT> }<a name="line.662"></a><FONT color="green">663</FONT> }<a name="line.663"></a><FONT color="green">664</FONT> return result;<a name="line.664"></a><FONT color="green">665</FONT> <a name="line.665"></a><FONT color="green">666</FONT> }<a name="line.666"></a><FONT color="green">667</FONT> <a name="line.667"></a><FONT color="green">668</FONT> /**<a name="line.668"></a><FONT color="green">669</FONT> * Translates a date to Java2D coordinates, based on the range displayed by<a name="line.669"></a><FONT color="green">670</FONT> * this axis for the specified data area.<a name="line.670"></a><FONT color="green">671</FONT> *<a name="line.671"></a><FONT color="green">672</FONT> * @param date the date.<a name="line.672"></a><FONT color="green">673</FONT> * @param area the rectangle (in Java2D space) where the data is to be<a name="line.673"></a><FONT color="green">674</FONT> * plotted.<a name="line.674"></a><FONT color="green">675</FONT> * @param edge the axis location.<a name="line.675"></a><FONT color="green">676</FONT> *<a name="line.676"></a><FONT color="green">677</FONT> * @return The coordinate corresponding to the supplied date.<a name="line.677"></a><FONT color="green">678</FONT> */<a name="line.678"></a><FONT color="green">679</FONT> public double dateToJava2D(Date date, Rectangle2D area, <a name="line.679"></a><FONT color="green">680</FONT> RectangleEdge edge) { <a name="line.680"></a><FONT color="green">681</FONT> double value = date.getTime();<a name="line.681"></a><FONT color="green">682</FONT> return valueToJava2D(value, area, edge);<a name="line.682"></a><FONT color="green">683</FONT> }<a name="line.683"></a><FONT color="green">684</FONT> <a name="line.684"></a><FONT color="green">685</FONT> /**<a name="line.685"></a><FONT color="green">686</FONT> * Translates a Java2D coordinate into the corresponding data value. To <a name="line.686"></a><FONT color="green">687</FONT> * perform this translation, you need to know the area used for plotting <a name="line.687"></a><FONT color="green">688</FONT> * data, and which edge the axis is located on.<a name="line.688"></a><FONT color="green">689</FONT> *<a name="line.689"></a><FONT color="green">690</FONT> * @param java2DValue the coordinate in Java2D space.<a name="line.690"></a><FONT color="green">691</FONT> * @param area the rectangle (in Java2D space) where the data is to be <a name="line.691"></a><FONT color="green">692</FONT> * plotted.<a name="line.692"></a><FONT color="green">693</FONT> * @param edge the axis location.<a name="line.693"></a><FONT color="green">694</FONT> *<a name="line.694"></a><FONT color="green">695</FONT> * @return A data value.<a name="line.695"></a><FONT color="green">696</FONT> */<a name="line.696"></a><FONT color="green">697</FONT> public double java2DToValue(double java2DValue, Rectangle2D area, <a name="line.697"></a><FONT color="green">698</FONT> RectangleEdge edge) {<a name="line.698"></a><FONT color="green">699</FONT> <a name="line.699"></a><FONT color="green">700</FONT> DateRange range = (DateRange) getRange();<a name="line.700"></a><FONT color="green">701</FONT> double axisMin = this.timeline.toTimelineValue(range.getLowerDate());<a name="line.701"></a><FONT color="green">702</FONT> double axisMax = this.timeline.toTimelineValue(range.getUpperDate());<a name="line.702"></a><FONT color="green">703</FONT> <a name="line.703"></a><FONT color="green">704</FONT> double min = 0.0;<a name="line.704"></a><FONT color="green">705</FONT> double max = 0.0;<a name="line.705"></a><FONT color="green">706</FONT> if (RectangleEdge.isTopOrBottom(edge)) {<a name="line.706"></a><FONT color="green">707</FONT> min = area.getX();<a name="line.707"></a><FONT color="green">708</FONT> max = area.getMaxX();<a name="line.708"></a><FONT color="green">709</FONT> }<a name="line.709"></a><FONT color="green">710</FONT> else if (RectangleEdge.isLeftOrRight(edge)) {<a name="line.710"></a><FONT color="green">711</FONT> min = area.getMaxY();<a name="line.711"></a><FONT color="green">712</FONT> max = area.getY();<a name="line.712"></a><FONT color="green">713</FON
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -