polarplot.java

来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,163 行 · 第 1/3 页

JAVA
1,163
字号
        // no renderer, no gridlines...        if (this.renderer == null) {            return;        }               // draw the domain grid lines, if any...        if (isAngleGridlinesVisible()) {            Stroke gridStroke = getAngleGridlineStroke();            Paint gridPaint = getAngleGridlinePaint();            if ((gridStroke != null) && (gridPaint != null)) {                this.renderer.drawAngularGridLines(                    g2, this, angularTicks, dataArea                );            }        }               // draw the radius grid lines, if any...        if (isRadiusGridlinesVisible()) {            Stroke gridStroke = getRadiusGridlineStroke();            Paint gridPaint = getRadiusGridlinePaint();            if ((gridStroke != null) && (gridPaint != null)) {                this.renderer.drawRadialGridLines(                    g2, this, this.axis, radialTicks, dataArea                );            }        }          }       /**     * Zooms the axis ranges by the specified percentage about the anchor point.     *     * @param percent  the amount of the zoom.     */    public void zoom(double percent) {        if (percent > 0.0) {            double radius = getMaxRadius();            double scaledRadius = radius * percent;            this.axis.setUpperBound(scaledRadius);            getAxis().setAutoRange(false);        }         else {            getAxis().setAutoRange(true);        }    }       /**     * Returns the range for the specified axis.     *     * @param axis  the axis.     *     * @return The range.     */    public Range getDataRange(ValueAxis axis) {        Range result = null;        result = Range.combine(            result, DatasetUtilities.findRangeBounds(this.dataset)        );        return result;    }       /**     * Receives notification of a change to the plot's m_Dataset.     * <P>     * The axis ranges are updated if necessary.     *     * @param event  information about the event (not used here).     */    public void datasetChanged(DatasetChangeEvent event) {        if (this.axis != null) {            this.axis.configure();        }               if (getParent() != null) {            getParent().datasetChanged(event);        }        else {            super.datasetChanged(event);        }    }       /**     * Notifies all registered listeners of a property change.     * <P>     * One source of property change events is the plot's m_Renderer.     *     * @param event  information about the property change.     */    public void rendererChanged(RendererChangeEvent event) {        notifyListeners(new PlotChangeEvent(this));    }       /**     * Returns the number of series in the dataset for this plot.  If the      * dataset is <code>null</code>, the method returns 0.     *     * @return The series count.     */    public int getSeriesCount() {        int result = 0;               if (this.dataset != null) {            result = this.dataset.getSeriesCount();        }        return result;    }       /**     * Returns the legend items for the plot.  Each legend item is generated by     * the plot's m_Renderer, since the m_Renderer is responsible for the visual     * representation of the data.     *     * @return The legend items.     */    public LegendItemCollection getLegendItems() {        LegendItemCollection result = new LegendItemCollection();               // get the legend items for the main m_Dataset...        if (this.dataset != null) {            if (this.renderer != null) {                int seriesCount = this.dataset.getSeriesCount();                for (int i = 0; i < seriesCount; i++) {                    LegendItem item = this.renderer.getLegendItem(i);                    result.add(item);                }            }        }              return result;    }       /**     * Tests this plot for equality with another object.     *     * @param obj  the object.     *     * @return <code>true</code> or <code>false</code>.     */    public boolean equals(Object obj) {               if (obj == this) {            return true;        }        if (!(obj instanceof PolarPlot)) {            return false;        }        if (!super.equals(obj)) {            return false;        }        PolarPlot that = (PolarPlot) obj;        if (!ObjectUtilities.equal(this.axis, that.axis)) {            return false;        }        if (!ObjectUtilities.equal(this.renderer, that.renderer)) {            return false;        }        if (this.angleGridlinesVisible != that.angleGridlinesVisible) {            return false;        }        if (!ObjectUtilities.equal(            this.angleGridlineStroke, that.angleGridlineStroke        )) {            return false;        }        if (!ObjectUtilities.equal(            this.angleGridlinePaint, that.angleGridlinePaint        )) {            return false;        }        if (this.radiusGridlinesVisible != that.radiusGridlinesVisible) {            return false;        }        if (!ObjectUtilities.equal(            this.radiusGridlineStroke, that.radiusGridlineStroke        )) {            return false;        }        if (!ObjectUtilities.equal(            this.radiusGridlinePaint, that.radiusGridlinePaint        )) {            return false;        }                 return true;    }       /**     * Returns a clone of the plot.     *     * @return A clone.     *     * @throws CloneNotSupportedException  this can occur if some component of      *         the plot cannot be cloned.     */    public Object clone() throws CloneNotSupportedException {              PolarPlot clone = (PolarPlot) super.clone();        if (this.axis != null) {            clone.axis = (ValueAxis) ObjectUtilities.clone(this.axis);            clone.axis.setPlot(clone);            clone.axis.addChangeListener(clone);        }              if (clone.dataset != null) {            clone.dataset.addChangeListener(clone);        }              if (this.renderer != null) {            clone.renderer                 = (PolarItemRenderer) ObjectUtilities.clone(this.renderer);        }               return clone;    }       /**     * Provides serialization support.     *     * @param stream  the output stream.     *     * @throws IOException  if there is an I/O error.     */    private void writeObject(ObjectOutputStream stream) throws IOException {        stream.defaultWriteObject();        SerialUtilities.writeStroke(this.angleGridlineStroke, stream);        SerialUtilities.writePaint(this.angleGridlinePaint, stream);        SerialUtilities.writeStroke(this.radiusGridlineStroke, stream);        SerialUtilities.writePaint(this.radiusGridlinePaint, stream);    }       /**     * Provides serialization support.     *     * @param stream  the input stream.     *     * @throws IOException  if there is an I/O error.     * @throws ClassNotFoundException  if there is a classpath problem.     */    private void readObject(ObjectInputStream stream)         throws IOException, ClassNotFoundException {              stream.defaultReadObject();        this.angleGridlineStroke = SerialUtilities.readStroke(stream);        this.angleGridlinePaint = SerialUtilities.readPaint(stream);        this.radiusGridlineStroke = SerialUtilities.readStroke(stream);        this.radiusGridlinePaint = SerialUtilities.readPaint(stream);              if (this.axis != null) {            this.axis.setPlot(this);            this.axis.addChangeListener(this);        }              if (this.dataset != null) {            this.dataset.addChangeListener(this);        }    }       // ---------------------------------------    // --- ValueAxisPlot Interface Methods ---    // ---------------------------------------       /**      * Multiplies the range on the domain axis/axes by the specified factor.     *     * @param x  the x-coordinate (in Java2D space).     * @param y  the y-coordinate (in Java2D space).     * @param factor  the zoom factor.     */    public void zoomDomainAxes(double x, double y, double factor) {        zoom(factor);    }       /**      * Zooms in on the domain axes.     *     * @param x  the x-coordinate (in Java2D space).     * @param y  the y-coordinate (in Java2D space).     * @param lowerPercent  the new lower bound.     * @param upperPercent  the new upper bound.     */    public void zoomDomainAxes(double x, double y, double lowerPercent,                                double upperPercent) {        zoom((upperPercent + lowerPercent) / 2.0);    }       /**      * Multiplies the range on the range axis/axes by the specified factor.     *     * @param x  the x-coordinate (in Java2D space).     * @param y  the y-coordinate (in Java2D space).     * @param factor  the zoom factor.     */    public void zoomRangeAxes(double x, double y, double factor) {        zoom(factor);    }       /**      * Zooms in on the range axes.     *     * @param x  the x-coordinate (in Java2D space).     * @param y  the y-coordinate (in Java2D space).     * @param lowerPercent  the new lower bound.     * @param upperPercent  the new upper bound.     */    public void zoomRangeAxes(double x, double y, double lowerPercent,                               double upperPercent) {        zoom((upperPercent + lowerPercent) / 2.0);    }       /**     * Returns <code>true</code>.     *      * @return A boolean.     */    public boolean isDomainZoomable() {        return true;    }        /**     * Returns <code>true</code>.     *      * @return A boolean.     */    public boolean isRangeZoomable() {        return true;    }    // ----------------------    // --- Public Methods ---    // ----------------------    /**     * Returns the upper bound of the radius axis.     *      * @return The upper bound.     */    public double getMaxRadius() {        return this.axis.getUpperBound();    }    /**     * Translates a (theta, radius) pair into Java2D coordinates.     *      * @param angleDegrees  the angle in degrees.     * @param radius  the radius.     * @param dataArea  the data area.     *      * @return A point in Java2D space.     */       public Point translateValueThetaRadiusToJava2D(double angleDegrees,                                                    double radius,                                                   Rectangle2D dataArea) {               double radians = Math.toRadians(angleDegrees - 90.0);              double minx = dataArea.getMinX() + MARGIN;        double maxx = dataArea.getMaxX() - MARGIN;        double miny = dataArea.getMinY() + MARGIN;        double maxy = dataArea.getMaxY() - MARGIN;              double lengthX = maxx - minx;        double lengthY = maxy - miny;        double length = Math.min(lengthX, lengthY);              double midX = minx + lengthX / 2.0;        double midY = miny + lengthY / 2.0;              double axisMin = this.axis.getLowerBound();        double axisMax =  getMaxRadius();        double xv = length / 2.0 * Math.cos(radians);        double yv = length / 2.0 * Math.sin(radians);        float x = (float) (midX + (xv * (radius - axisMin)                 / (axisMax - axisMin)));        float y = (float) (midY + (yv * (radius - axisMin)                 / (axisMax - axisMin)));              int ix = Math.round(x);        int iy = Math.round(y);              Point p = new Point(ix, iy);        return p;            }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?