📄 barrenderer.html
字号:
<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> * Calculates the coordinates for the length of a single bar.<a name="line.560"></a><FONT color="green">561</FONT> * <a name="line.561"></a><FONT color="green">562</FONT> * @param value the value represented by the bar.<a name="line.562"></a><FONT color="green">563</FONT> * <a name="line.563"></a><FONT color="green">564</FONT> * @return The coordinates for each end of the bar (or <code>null</code> if <a name="line.564"></a><FONT color="green">565</FONT> * the bar is not visible for the current axis range).<a name="line.565"></a><FONT color="green">566</FONT> */<a name="line.566"></a><FONT color="green">567</FONT> protected double[] calculateBarL0L1(double value) {<a name="line.567"></a><FONT color="green">568</FONT> double lclip = getLowerClip();<a name="line.568"></a><FONT color="green">569</FONT> double uclip = getUpperClip();<a name="line.569"></a><FONT color="green">570</FONT> double barLow = Math.min(this.base, value);<a name="line.570"></a><FONT color="green">571</FONT> double barHigh = Math.max(this.base, value);<a name="line.571"></a><FONT color="green">572</FONT> if (barHigh < lclip) { // bar is not visible<a name="line.572"></a><FONT color="green">573</FONT> return null;<a name="line.573"></a><FONT color="green">574</FONT> }<a name="line.574"></a><FONT color="green">575</FONT> if (barLow > uclip) { // bar is not visible<a name="line.575"></a><FONT color="green">576</FONT> return null;<a name="line.576"></a><FONT color="green">577</FONT> }<a name="line.577"></a><FONT color="green">578</FONT> barLow = Math.max(barLow, lclip);<a name="line.578"></a><FONT color="green">579</FONT> barHigh = Math.min(barHigh, uclip);<a name="line.579"></a><FONT color="green">580</FONT> return new double[] {barLow, barHigh};<a name="line.580"></a><FONT color="green">581</FONT> }<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> * Returns the range of values the renderer requires to display all the <a name="line.584"></a><FONT color="green">585</FONT> * items from the specified dataset. This takes into account the range<a name="line.585"></a><FONT color="green">586</FONT> * of values in the dataset, plus the flag that determines whether or not<a name="line.586"></a><FONT color="green">587</FONT> * the base value for the bars should be included in the range.<a name="line.587"></a><FONT color="green">588</FONT> * <a name="line.588"></a><FONT color="green">589</FONT> * @param dataset the dataset (<code>null</code> permitted).<a name="line.589"></a><FONT color="green">590</FONT> * <a name="line.590"></a><FONT color="green">591</FONT> * @return The range (or <code>null</code> if the dataset is <a name="line.591"></a><FONT color="green">592</FONT> * <code>null</code> or empty).<a name="line.592"></a><FONT color="green">593</FONT> */<a name="line.593"></a><FONT color="green">594</FONT> public Range findRangeBounds(CategoryDataset dataset) {<a name="line.594"></a><FONT color="green">595</FONT> Range result = DatasetUtilities.findRangeBounds(dataset);<a name="line.595"></a><FONT color="green">596</FONT> if (result != null) {<a name="line.596"></a><FONT color="green">597</FONT> if (this.includeBaseInRange) {<a name="line.597"></a><FONT color="green">598</FONT> result = Range.expandToInclude(result, this.base);<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> return result;<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> * Returns a legend item for a series.<a name="line.605"></a><FONT color="green">606</FONT> *<a name="line.606"></a><FONT color="green">607</FONT> * @param datasetIndex the dataset index (zero-based).<a name="line.607"></a><FONT color="green">608</FONT> * @param series the series index (zero-based).<a name="line.608"></a><FONT color="green">609</FONT> *<a name="line.609"></a><FONT color="green">610</FONT> * @return The legend item.<a name="line.610"></a><FONT color="green">611</FONT> */<a name="line.611"></a><FONT color="green">612</FONT> public LegendItem getLegendItem(int datasetIndex, int series) {<a name="line.612"></a><FONT color="green">613</FONT> <a name="line.613"></a><FONT color="green">614</FONT> CategoryPlot cp = getPlot();<a name="line.614"></a><FONT color="green">615</FONT> if (cp == null) {<a name="line.615"></a><FONT color="green">616</FONT> return null;<a name="line.616"></a><FONT color="green">617</FONT> }<a name="line.617"></a><FONT color="green">618</FONT> <a name="line.618"></a><FONT color="green">619</FONT> CategoryDataset dataset;<a name="line.619"></a><FONT color="green">620</FONT> dataset = cp.getDataset(datasetIndex);<a name="line.620"></a><FONT color="green">621</FONT> String label = getLegendItemLabelGenerator().generateLabel(dataset, <a name="line.621"></a><FONT color="green">622</FONT> series);<a name="line.622"></a><FONT color="green">623</FONT> String description = label;<a name="line.623"></a><FONT color="green">624</FONT> String toolTipText = null; <a name="line.624"></a><FONT color="green">625</FONT> if (getLegendItemToolTipGenerator() != null) {<a name="line.625"></a><FONT color="green">626</FONT> toolTipText = getLegendItemToolTipGenerator().generateLabel(<a name="line.626"></a><FONT color="green">627</FONT> dataset, series); <a name="line.627"></a><FONT color="green">628</FONT> }<a name="line.628"></a><FONT color="green">629</FONT> String urlText = null;<a name="line.629"></a><FONT color="green">630</FONT> if (getLegendItemURLGenerator() != null) {<a name="line.630"></a><FONT color="green">631</FONT> urlText = getLegendItemURLGenerator().generateLabel(dataset, <a name="line.631"></a><FONT color="green">632</FONT> series); <a name="line.632"></a><FONT color="green">633</FONT> }<a name="line.633"></a><FONT color="green">634</FONT> Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);<a name="line.634"></a><FONT color="green">635</FONT> Paint paint = getSeriesPaint(series);<a name="line.635"></a><FONT color="green">636</FONT> Paint outlinePaint = getSeriesOutlinePaint(series);<a name="line.636"></a><FONT color="green">637</FONT> Stroke outlineStroke = getSeriesOutlineStroke(series);<a name="line.637"></a><FONT color="green">638</FONT> <a name="line.638"></a><FONT color="green">639</FONT> return new LegendItem(label, description, toolTipText, urlText,<a name="line.639"></a><FONT color="green">640</FONT> true, shape, true, paint, <a name="line.640"></a><FONT color="green">641</FONT> isDrawBarOutline(), outlinePaint, outlineStroke,<a name="line.641"></a><FONT color="green">642</FONT> false, new Line2D.Float(), new BasicStroke(1.0f), <a name="line.642"></a><FONT color="green">643</FONT> Color.black);<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> * Draws the bar for a single (series, category) data item.<a name="line.647"></a><FONT color="green">648</FONT> *<a name="line.648"></a><FONT color="green">649</FONT> * @param g2 the graphics device.<a name="line.649"></a><FONT color="green">650</FONT> * @param state the renderer state.<a name="line.650"></a><FONT color="green">651</FONT> * @param dataArea the data area.<a name="line.651"></a><FONT color="green">652</FONT> * @param plot the plot.<a name="line.652"></a><FONT color="green">653</FONT> * @param domainAxis the domain axis.<a name="line.653"></a><FONT color="green">654</FONT> * @param rangeAxis the range axis.<a name="line.654"></a><FONT color="green">655</FONT> * @param dataset the dataset.<a name="line.655"></a><FONT color="green">656</FONT> * @param row the row index (zero-based).<a name="line.656"></a><FONT color="green">657</FONT> * @param column the column index (zero-based).<a name="line.657"></a><FONT color="green">658</FONT> * @param pass the pass index.<a name="line.658"></a><FONT color="green">659</FONT> */<a name="line.659"></a><FONT color="green">660</FONT> public void drawItem(Graphics2D g2,<a name="line.660"></a><FONT color="green">661</FONT> CategoryItemRendererState state,<a name="line.661"></a><FONT color="green">662</FONT> Rectangle2D dataArea,<a name="line.662"></a><FONT color="green">663</FONT> CategoryPlot plot,<a name="line.663"></a><FONT color="green">664</FONT> CategoryAxis domainAxis,<a name="line.664"></a><FONT color="green">665</FONT> ValueAxis rangeAxis,<a name="line.665"></a><FONT color="green">666</FONT> CategoryDataset dataset,<a name="line.666"></a><FONT color="green">667</FONT> int row,<a name="line.667"></a><FONT color="green">668</FONT> int column,<a name="line.668"></a><FONT color="green">669</FONT> int pass) {<a name="line.669"></a><FONT color="green">670</FONT> <a name="line.670"></a><FONT color="green">671</FONT> // nothing is drawn for null values...<a name="line.671"></a><FONT color="green">672</FONT> Number dataValue = dataset.getValue(row, column);<a name="line.672"></a><FONT color="green">673</FONT> if (dataValue == null) {<a name="line.673"></a><FONT color="green">674</FONT> return;<a name="line.674"></a><FONT color="green">675</FONT> }<a name="line.675"></a><FONT color="green">676</FONT> <a name="line.676"></a><FONT color="green">677</FONT> double value = dataValue.doubleValue();<a name="line.677"></a><FONT color="green">678</FONT> <a name="line.678"></a><FONT color="green">679</FONT> PlotOrientation orientation = plot.getOrientation();<a name="line.679"></a><FONT color="green">680</FONT> double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, <a name="line.680"></a><FONT color="green">681</FONT> state, row, column);<a name="line.681"></a><FONT color="green">682</FONT> double[] barL0L1 = calculateBarL0L1(value);<a name="line.682"></a><FONT color="green">683</FONT> if (barL0L1 == null) {<a name="line.683"></a><FONT color="green">684</FONT> return; // the bar is not visible<a name="line.684"></a><FONT color="green">685</FONT> }<a name="line.685"></a><FONT color="green">686</FONT> <a name="line.686"></a><FONT color="green">687</FONT> RectangleEdge edge = plot.getRangeAxisEdge();<a name="line.687"></a><FONT color="green">688</FONT> double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge);<a name="line.688"></a><FONT color="green">689</FONT> double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge);<a name="line.689"></a><FONT color="green">690</FONT> double barL0 = Math.min(transL0, transL1);<a name="line.690"></a><FONT color="green">691</FONT> double barLength = Math.max(Math.abs(transL1 - transL0), <a name="line.691"></a><FONT color="green">692</FONT> getMinimumBarLength());<a name="line.692"></a><FONT color="green">693</FONT> <a name="line.693"></a><FONT color="green">694</FONT> // draw the bar...<a name="line.694"></a><FONT color="green">695</FONT> Rectangle2D bar
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -