⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plot.java

📁 Differential Evolution(JAVA)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Draw an error bar for the specified yLowEB and yHighEB values.      * If the specified point is below the y axis or outside the     * x range, do nothing.  If the <i>clip</i> argument is true,     * then do not draw above the y range.     */    protected void _drawErrorBar (Graphics graphics, int dataset,            long xpos, long yLowEBPos, long yHighEBPos,            boolean clip) {        if (_debug > 20) {            System.out.println("Plot: _drawErrorBar("+xpos+" "+                    yLowEBPos+" "+yHighEBPos+" "+clip+")");        }        _drawLine(graphics, dataset, xpos - _ERRORBAR_LEG_LENGTH, yHighEBPos,                xpos + _ERRORBAR_LEG_LENGTH, yHighEBPos, clip);        _drawLine(graphics, dataset, xpos, yLowEBPos, xpos, yHighEBPos, clip);        _drawLine(graphics, dataset, xpos - _ERRORBAR_LEG_LENGTH, yLowEBPos,                xpos + _ERRORBAR_LEG_LENGTH, yLowEBPos, clip);    }    /**     * Draw an impulse from the specified point to the y axis.     * If the specified point is below the y axis or outside the     * x range, do nothing.  If the <i>clip</i> argument is true,     * then do not draw above the y range.     */    protected void _drawImpulse (Graphics graphics,            long xpos, long ypos, boolean clip) {        if (_debug > 20) {            System.out.println("Plot: _drawImpulse("+xpos+" "+ypos+" "+                    clip+") ("+_ulx+" "+_uly+" "+_lrx+" "+_lry+")");        }        if (clip) {            if (ypos < _uly) {                ypos = _uly;            } if (ypos > _lry) {                ypos = _lry;            }        }        if (ypos <= _lry && xpos <= _lrx && xpos >= _ulx) {            // The y position of the zero line.            double zeroypos = _lry - (long) ((0-_yMin) * _yscale);            if (_lry < zeroypos) zeroypos = _lry;            if (_uly > zeroypos) zeroypos = _uly;            graphics.drawLine((int)xpos, (int)ypos, (int)xpos,                    (int)zeroypos);        }    }    /**     * Draw a line from the specified starting point to the specified     * ending point.  The current color is used.  If the <i>clip</i> argument     * is true, then draw only that portion of the line that lies within the     * plotting rectangle.     */    protected void _drawLine (Graphics graphics,            int dataset, long startx, long starty, long endx, long endy,            boolean clip) {        if (clip) {            // Rule out impossible cases.            if (_debug > 20) {                System.out.println("Plot: _drawLine: bounds: " + _ulx +", "+                        _uly +", "+ _lrx +", "+ _lry);                System.out.println("Plot: _drawLine:before: " + startx +", "+                        starty +", "+ endx +", "+ endy);            }            if (!((endx <= _ulx && startx <= _ulx) ||                    (endx >= _lrx && startx >= _lrx) ||                    (endy <= _uly && starty <= _uly) ||                    (endy >= _lry && starty >= _lry))) {                // If the end point is out of x range, adjust                // end point to boundary.                // The integer arithmetic has to be done with longs so as                // to not loose precision on extremely close zooms.                if (startx != endx) {                    if (endx < _ulx) {                        endy = (int)(endy + ((long)(starty - endy) *                                (_ulx - endx))/(startx - endx));                        endx = _ulx;                    } else if (endx > _lrx) {                        endy = (int)(endy + ((long)(starty - endy) *                                (_lrx - endx))/(startx - endx));                        endx = _lrx;                    }                }                                    // If end point is out of y range, adjust to boundary.                // Note that y increases downward                if (starty != endy) {                    if (endy < _uly) {                        endx = (int)(endx + ((long)(startx - endx) *                                (_uly - endy))/(starty - endy));                        endy = _uly;                    } else if (endy > _lry) {                        endx = (int)(endx + ((long)(startx - endx) *                                (_lry - endy))/(starty - endy));                        endy = _lry;                    }                }                                    // Adjust current point to lie on the boundary.                if (startx != endx) {                    if (startx < _ulx) {                        starty = (int)(starty + ((long)(endy - starty) *                                (_ulx - startx))/(endx - startx));                        startx = _ulx;                    } else if (startx > _lrx) {                        starty = (int)(starty + ((long)(endy - starty) *                                (_lrx - startx))/(endx - startx));                        startx = _lrx;                    }                }                if (starty != endy) {                    if (starty < _uly) {                        startx = (int)(startx + ((long)(endx - startx) *                                (_uly - starty))/(endy - starty));                        starty = _uly;                    } else if (starty > _lry) {                        startx = (int)(startx + ((long)(endx - startx) *                                (_lry - starty))/(endy - starty));                        starty = _lry;                    }                }            }                             // Are the new points in range?            if (endx >= _ulx && endx <= _lrx &&                    endy >= _uly && endy <= _lry &&                    startx >= _ulx && startx <= _lrx &&                    starty >= _uly && starty <= _lry) {                if (_debug > 20) {                    System.out.println("after: " + startx +", "+ starty +                            ", "+ endx +", "+ endy);                }                graphics.drawLine((int)startx, (int)starty,                        (int)endx, (int)endy);            }        } else {            // draw unconditionally.            graphics.drawLine((int)startx, (int)starty,                    (int)endx, (int)endy);        }    }    /**     * Put a mark corresponding to the specified dataset at the     * specified x and y position. The mark is drawn in the current     * color. What kind of mark is drawn depends on the _marks     * variable and the dataset argument. If the fourth argument is     * true, then check the range and plot only points that     * are in range.     */    protected void _drawPoint(Graphics graphics,            int dataset, long xpos, long ypos,            boolean clip) {        if (_debug > 20) {            System.out.println("Plot:_drawPoint "+dataset+" "+xpos+                    " "+ypos+" "+" "+clip);        }        // If the point is not out of range, draw it.        if (!clip || (ypos <= _lry && ypos >= _uly &&                xpos <= _lrx && xpos >= _ulx)) {            int xposi = (int)xpos;            int yposi = (int)ypos;            switch (_marks) {            case 0:                // If no mark style is given, draw a filled rectangle.                // This is used, for example, to draw the legend.                graphics.fillRect(xposi-6, yposi-6, 6, 6);                break;            case 1:                // points -- use 3-pixel ovals.                graphics.fillOval(xposi-1, yposi-1, 3, 3);                break;            case 2:                // dots                graphics.fillOval(xposi-_radius, yposi-_radius,                        _diameter, _diameter);                 break;            case 3:                // marks                int xpoints[], ypoints[];                // Points are only distinguished up to _MAX_MARKS data sets.                int mark = dataset % _MAX_MARKS;                switch (mark) {                case 0:                    // filled circle                    graphics.fillOval(xposi-_radius, yposi-_radius,                            _diameter, _diameter);                     break;                case 1:                    // cross                    graphics.drawLine(xposi-_radius, yposi-_radius,                            xposi+_radius, yposi+_radius);                     graphics.drawLine(xposi+_radius, yposi-_radius,                            xposi-_radius, yposi+_radius);                     break;                case 2:                    // square                    graphics.drawRect(xposi-_radius, yposi-_radius,                            _diameter, _diameter);                     break;                case 3:                    // filled triangle                    xpoints = new int[4];                    ypoints = new int[4];                    xpoints[0] = xposi; ypoints[0] = yposi-_radius;                    xpoints[1] = xposi+_radius; ypoints[1] = yposi+_radius;                    xpoints[2] = xposi-_radius; ypoints[2] = yposi+_radius;                    xpoints[3] = xposi; ypoints[3] = yposi-_radius;                    graphics.fillPolygon(xpoints, ypoints, 4);                    break;                case 4:                    // diamond                    xpoints = new int[5];                    ypoints = new int[5];                    xpoints[0] = xposi; ypoints[0] = yposi-_radius;                    xpoints[1] = xposi+_radius; ypoints[1] = yposi;                    xpoints[2] = xposi; ypoints[2] = yposi+_radius;                    xpoints[3] = xposi-_radius; ypoints[3] = yposi;                    xpoints[4] = xposi; ypoints[4] = yposi-_radius;                    graphics.drawPolygon(xpoints, ypoints, 5);                    break;                case 5:                    // circle                    graphics.drawOval(xposi-_radius, yposi-_radius,                            _diameter, _diameter);                     break;                case 6:                    // plus sign                    graphics.drawLine(xposi, yposi-_radius, xposi,                            yposi+_radius);                     graphics.drawLine(xposi-_radius, yposi, xposi+_radius,                            yposi);                     break;                case 7:                    // filled square                    graphics.fillRect(xposi-_radius, yposi-_radius,                            _diameter, _diameter);                     break;                case 8:                    // triangle                    xpoints = new int[4];                    ypoints = new int[4];                    xpoints[0] = xposi; ypoints[0] = yposi-_radius;                    xpoints[1] = xposi+_radius; ypoints[1] = yposi+_radius;                    xpoints[2] = xposi-_radius; ypoints[2] = yposi+_radius;                    xpoints[3] = xposi; ypoints[3] = yposi-_radius;                    graphics.drawPolygon(xpoints, ypoints, 4);                    break;                case 9:                    // filled diamond                    xpoints = new int[5];                    ypoints = new int[5];                    xpoints[0] = xposi; ypoints[0] = yposi-_radius;                    xpoints[1] = xposi+_radius; ypoints[1] = yposi;                    xpoints[2] = xposi; ypoints[2] = yposi+_radius;                    xpoints[3] = xposi-_radius; ypoints[3] = yposi;                    xpoints[4] = xposi; ypoints[4] = yposi-_radius;                    graphics.fillPolygon(xpoints, ypoints, 5);                    break;                }                break;            default:                // none            }        }    }    /** Hook for child classes to do any file preprocessing     */     protected void _newFile(){        _filecount++;        _firstinset = true;        _sawfirstdataset = false;    }       /**     * Read in a pxgraph format binary file.     * @exception PlotDataException if there is a serious data format problem.     * @exception java.io.IOException if an I/O error occurs.     */     protected void _parseBinaryStream(DataInputStream in) throws PlotDataException,  IOException {        // This method is similar to _parseLine() below, except it parses        // an entire file at a time.        int c;        float x = 0, y = 0, pointCount = 0;        boolean byteSwapped = false;        boolean connected = false;        byte input[] = new byte[4];        if (_connected) connected = true;        switch (_endian) {        case NATIVE_ENDIAN:            try {                if ( System.getProperty("os.arch").equals("x86")) {                    byteSwapped = true;                }            } catch (SecurityException e) {}            break;        case BIG_ENDIAN:            break;        case LITTLE_ENDIAN:            byteSwapped = true;            break;        default:            throw new PlotDataException("Internal Error: Don't know about '"+                    _endian + "' style of endian");        }

⌨️ 快捷键说明

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