📄 periodaxis.html
字号:
<FONT color="green">570</FONT> for (int i = 0; i < this.labelInfo.length; i++) {<a name="line.570"></a><FONT color="green">571</FONT> PeriodAxisLabelInfo info = this.labelInfo[i];<a name="line.571"></a><FONT color="green">572</FONT> FontMetrics fm = g2.getFontMetrics(info.getLabelFont());<a name="line.572"></a><FONT color="green">573</FONT> tickLabelBandsDimension <a name="line.573"></a><FONT color="green">574</FONT> += info.getPadding().extendHeight(fm.getHeight());<a name="line.574"></a><FONT color="green">575</FONT> }<a name="line.575"></a><FONT color="green">576</FONT> <a name="line.576"></a><FONT color="green">577</FONT> if (RectangleEdge.isTopOrBottom(edge)) {<a name="line.577"></a><FONT color="green">578</FONT> labelHeight = labelEnclosure.getHeight();<a name="line.578"></a><FONT color="green">579</FONT> space.add(labelHeight + tickLabelBandsDimension, edge);<a name="line.579"></a><FONT color="green">580</FONT> }<a name="line.580"></a><FONT color="green">581</FONT> else if (RectangleEdge.isLeftOrRight(edge)) {<a name="line.581"></a><FONT color="green">582</FONT> labelWidth = labelEnclosure.getWidth();<a name="line.582"></a><FONT color="green">583</FONT> space.add(labelWidth + tickLabelBandsDimension, edge);<a name="line.583"></a><FONT color="green">584</FONT> }<a name="line.584"></a><FONT color="green">585</FONT> <a name="line.585"></a><FONT color="green">586</FONT> // add space for the outer tick labels, if any...<a name="line.586"></a><FONT color="green">587</FONT> double tickMarkSpace = 0.0;<a name="line.587"></a><FONT color="green">588</FONT> if (isTickMarksVisible()) {<a name="line.588"></a><FONT color="green">589</FONT> tickMarkSpace = getTickMarkOutsideLength();<a name="line.589"></a><FONT color="green">590</FONT> }<a name="line.590"></a><FONT color="green">591</FONT> if (this.minorTickMarksVisible) {<a name="line.591"></a><FONT color="green">592</FONT> tickMarkSpace = Math.max(<a name="line.592"></a><FONT color="green">593</FONT> tickMarkSpace, this.minorTickMarkOutsideLength<a name="line.593"></a><FONT color="green">594</FONT> );<a name="line.594"></a><FONT color="green">595</FONT> }<a name="line.595"></a><FONT color="green">596</FONT> space.add(tickMarkSpace, edge);<a name="line.596"></a><FONT color="green">597</FONT> return space;<a name="line.597"></a><FONT color="green">598</FONT> }<a name="line.598"></a><FONT color="green">599</FONT> <a name="line.599"></a><FONT color="green">600</FONT> /**<a name="line.600"></a><FONT color="green">601</FONT> * Draws the axis on a Java 2D graphics device (such as the screen or a <a name="line.601"></a><FONT color="green">602</FONT> * printer).<a name="line.602"></a><FONT color="green">603</FONT> *<a name="line.603"></a><FONT color="green">604</FONT> * @param g2 the graphics device (<code>null</code> not permitted).<a name="line.604"></a><FONT color="green">605</FONT> * @param cursor the cursor location (determines where to draw the axis).<a name="line.605"></a><FONT color="green">606</FONT> * @param plotArea the area within which the axes and plot should be drawn.<a name="line.606"></a><FONT color="green">607</FONT> * @param dataArea the area within which the data should be drawn.<a name="line.607"></a><FONT color="green">608</FONT> * @param edge the axis location (<code>null</code> not permitted).<a name="line.608"></a><FONT color="green">609</FONT> * @param plotState collects information about the plot <a name="line.609"></a><FONT color="green">610</FONT> * (<code>null</code> permitted).<a name="line.610"></a><FONT color="green">611</FONT> * <a name="line.611"></a><FONT color="green">612</FONT> * @return The axis state (never <code>null</code>).<a name="line.612"></a><FONT color="green">613</FONT> */<a name="line.613"></a><FONT color="green">614</FONT> public AxisState draw(Graphics2D g2, <a name="line.614"></a><FONT color="green">615</FONT> double cursor,<a name="line.615"></a><FONT color="green">616</FONT> Rectangle2D plotArea, <a name="line.616"></a><FONT color="green">617</FONT> Rectangle2D dataArea,<a name="line.617"></a><FONT color="green">618</FONT> RectangleEdge edge,<a name="line.618"></a><FONT color="green">619</FONT> PlotRenderingInfo plotState) {<a name="line.619"></a><FONT color="green">620</FONT> <a name="line.620"></a><FONT color="green">621</FONT> AxisState axisState = new AxisState(cursor);<a name="line.621"></a><FONT color="green">622</FONT> if (isAxisLineVisible()) {<a name="line.622"></a><FONT color="green">623</FONT> drawAxisLine(g2, cursor, dataArea, edge);<a name="line.623"></a><FONT color="green">624</FONT> }<a name="line.624"></a><FONT color="green">625</FONT> drawTickMarks(g2, axisState, dataArea, edge);<a name="line.625"></a><FONT color="green">626</FONT> for (int band = 0; band < this.labelInfo.length; band++) {<a name="line.626"></a><FONT color="green">627</FONT> axisState = drawTickLabels(band, g2, axisState, dataArea, edge);<a name="line.627"></a><FONT color="green">628</FONT> }<a name="line.628"></a><FONT color="green">629</FONT> <a name="line.629"></a><FONT color="green">630</FONT> // draw the axis label (note that 'state' is passed in *and* <a name="line.630"></a><FONT color="green">631</FONT> // returned)...<a name="line.631"></a><FONT color="green">632</FONT> axisState = drawLabel(<a name="line.632"></a><FONT color="green">633</FONT> getLabel(), g2, plotArea, dataArea, edge, axisState<a name="line.633"></a><FONT color="green">634</FONT> );<a name="line.634"></a><FONT color="green">635</FONT> return axisState;<a name="line.635"></a><FONT color="green">636</FONT> <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> /**<a name="line.639"></a><FONT color="green">640</FONT> * Draws the tick marks for the axis.<a name="line.640"></a><FONT color="green">641</FONT> * <a name="line.641"></a><FONT color="green">642</FONT> * @param g2 the graphics device.<a name="line.642"></a><FONT color="green">643</FONT> * @param state the axis state.<a name="line.643"></a><FONT color="green">644</FONT> * @param dataArea the data area.<a name="line.644"></a><FONT color="green">645</FONT> * @param edge the edge.<a name="line.645"></a><FONT color="green">646</FONT> */<a name="line.646"></a><FONT color="green">647</FONT> protected void drawTickMarks(Graphics2D g2, AxisState state, <a name="line.647"></a><FONT color="green">648</FONT> Rectangle2D dataArea, <a name="line.648"></a><FONT color="green">649</FONT> RectangleEdge edge) {<a name="line.649"></a><FONT color="green">650</FONT> if (RectangleEdge.isTopOrBottom(edge)) {<a name="line.650"></a><FONT color="green">651</FONT> drawTickMarksHorizontal(g2, state, dataArea, edge);<a name="line.651"></a><FONT color="green">652</FONT> }<a name="line.652"></a><FONT color="green">653</FONT> else if (RectangleEdge.isLeftOrRight(edge)) {<a name="line.653"></a><FONT color="green">654</FONT> drawTickMarksVertical(g2, state, dataArea, edge);<a name="line.654"></a><FONT color="green">655</FONT> }<a name="line.655"></a><FONT color="green">656</FONT> }<a name="line.656"></a><FONT color="green">657</FONT> <a name="line.657"></a><FONT color="green">658</FONT> /**<a name="line.658"></a><FONT color="green">659</FONT> * Draws the major and minor tick marks for an axis that lies at the top or <a name="line.659"></a><FONT color="green">660</FONT> * bottom of the plot.<a name="line.660"></a><FONT color="green">661</FONT> * <a name="line.661"></a><FONT color="green">662</FONT> * @param g2 the graphics device.<a name="line.662"></a><FONT color="green">663</FONT> * @param state the axis state.<a name="line.663"></a><FONT color="green">664</FONT> * @param dataArea the data area.<a name="line.664"></a><FONT color="green">665</FONT> * @param edge the edge.<a name="line.665"></a><FONT color="green">666</FONT> */<a name="line.666"></a><FONT color="green">667</FONT> protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state, <a name="line.667"></a><FONT color="green">668</FONT> Rectangle2D dataArea, <a name="line.668"></a><FONT color="green">669</FONT> RectangleEdge edge) {<a name="line.669"></a><FONT color="green">670</FONT> List ticks = new ArrayList();<a name="line.670"></a><FONT color="green">671</FONT> double x0 = dataArea.getX();<a name="line.671"></a><FONT color="green">672</FONT> double y0 = state.getCursor();<a name="line.672"></a><FONT color="green">673</FONT> double insideLength = getTickMarkInsideLength();<a name="line.673"></a><FONT color="green">674</FONT> double outsideLength = getTickMarkOutsideLength();<a name="line.674"></a><FONT color="green">675</FONT> RegularTimePeriod t = RegularTimePeriod.createInstance(<a name="line.675"></a><FONT color="green">676</FONT> this.majorTickTimePeriodClass, this.first.getStart(), getTimeZone()<a name="line.676"></a><FONT color="green">677</FONT> );<a name="line.677"></a><FONT color="green">678</FONT> long t0 = t.getFirstMillisecond(getTimeZone());<a name="line.678"></a><FONT color="green">679</FONT> Line2D inside = null;<a name="line.679"></a><FONT color="green">680</FONT> Line2D outside = null;<a name="line.680"></a><FONT color="green">681</FONT> long firstOnAxis = getFirst().getFirstMillisecond(getTimeZone());<a name="line.681"></a><FONT color="green">682</FONT> long lastOnAxis = getLast().getLastMillisecond(getTimeZone());<a name="line.682"></a><FONT color="green">683</FONT> while (t0 <= lastOnAxis) {<a name="line.683"></a><FONT color="green">684</FONT> ticks.add(new NumberTick(new Double(t0), "", TextAnchor.CENTER, TextAnchor.CENTER, 0.0));<a name="line.684"></a><FONT color="green">685</FONT> x0 = valueToJava2D(t0, dataArea, edge);<a name="line.685"></a><FONT color="green">686</FONT> if (edge == RectangleEdge.TOP) {<a name="line.686"></a><FONT color="green">687</FONT> inside = new Line2D.Double(x0, y0, x0, y0 + insideLength); <a name="line.687"></a><FONT color="green">688</FONT> outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);<a name="line.688"></a><FONT color="green">689</FONT> }<a name="line.689"></a><FONT color="green">690</FONT> else if (edge == RectangleEdge.BOTTOM) {<a name="line.690"></a><FONT color="green">691</FONT> inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);<a name="line.691"></a><FONT color="green">692</FONT> outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);<a name="line.692"></a><FONT color="green">693</FONT> }<a name="line.693"></a><FONT color="green">694</FONT> if (t0 > firstOnAxis) {<a name="line.694"></a><FONT color="green">695</FONT> g2.setPaint(getTickMarkPaint());<a name="line.695"></a><FONT color="green">696</FONT> g2.setStroke(getTickMarkStroke());<a name="line.696"></a><FONT color="green">697</FONT> g2.draw(inside);<a name="line.697"></a><FONT color="green">698</FONT> g2.draw(outside);<a name="line.698"></a><FONT color="green">699</FONT> }<a name="line.699"></a><FONT color="green">700</FONT> // draw minor tick marks<a name="line.700"></a><FONT color="green">701</FONT> if (this.minorTickMarksVisible) {<a name="line.701"></a><FONT color="green">702</FONT> RegularTimePeriod tminor = RegularTimePeriod.createInstance(<a name="line.702"></a><FONT color="green">703</FONT> this.minorTickTimePeriodClass, new Date(t0), getTimeZone()<a name="line.703"></a><FONT color="green">704</FONT> );<a name="line.704"></a><FONT color="green">705</FONT> long tt0 = tminor.getFirstMillisecond(getTimeZone());<a name="line.705"></a><FONT color="green">706</FONT> while (tt0 < t.getLastMillisecond(getTimeZone()) <a name="line.706"></a><FONT color="green">707</FONT> && tt0 < lastOnAxis) {<a name="line.707"></a><FONT color="green">708</FONT> double xx0 = valueToJava2D(tt0, dataArea, edge);<a name="line.708"></a><FONT color="green">709</FONT> if (edge == RectangleEdge.TOP) {<a name="line.709"></a><FONT color="green">710</FON
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -