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

📄 linechart.java

📁 一个完整的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                    flag = true;

            return flag;
        } else
        {
            return false;
        }
    }

    public void setLegendImage(int i, String s)
    {
        if(i >= 0 && i < 1000)
        {
            super.setLegendImage(i, s);
            if(highlightImages == null)
                highlightImages = new String[i + 1];
            if(i >= highlightImages.length)
            {
                String as[] = new String[i + 1];
                System.arraycopy(highlightImages, 0, as, 0, highlightImages.length);
                highlightImages = as;
            }
            highlightImages[i] = s;
            super.hasChanged = true;
            autoRepaint();
        }
    }

    private String constructFloatingLabel(int i, int j, boolean flag)
    {
        if(i < 0 || i >= getSeriesCount() || j < 0 || j >= getSampleCount())
            return "";
        String s = "";
        if(flag)
        {
            String s1 = getSeriesLabel(i);
            if(s1 != null)
            {
                s += s1;
                if(!s1.endsWith("\n") && super.sampleLabelsOn && sampleLabelStyle == 2 && getSampleLabel(j) != null)
                    s += " : ";
            }
        }
        if(super.sampleLabelsOn && sampleLabelStyle == 2 && getSampleLabel(j) != null)
            s += getSampleLabel(j);
        if(isValueLabelsOn() && valueLabelStyle == 2)
        {
            String s2 = getLabel("valueLabelPrefix_" + i);
            if(s2 == null)
                s2 = getLabel("valueLabelPrefix");
            String s3 = getLabel("valueLabelPostfix_" + i);
            if(s3 == null)
                s3 = getLabel("valueLabelPostfix");
            if(s.length() > 0)
            {
                String s4 = formatNumber(getSampleValue(i, j), getSampleDecimalCount(i));
                s4 = s2 == null ? s4 : s2 + s4;
                s4 = s3 == null ? s4 : s4 + s3;
                if(s.endsWith("\n"))
                    s += s4;
                else
                    s = s + " : " + s4;
            } else
            {
                s = formatNumber(getSampleValue(i, j), getSampleDecimalCount(i));
                s = s2 == null ? s : s2 + s;
                s = s3 == null ? s : s + s3;
            }
        }
        return s;
    }

    private int calculateYPos(int i, int j, Rectangle rectangle)
    {
        double d = 0.0D;
        if(i >= 0 && stackedOn)
        {
            for(int k = 0; k <= i; k++)
                d += getSampleValue(k, j);

        } else
        if(i >= 0)
            d = getSampleValue(i, j);
        int l = getSeriesRange(i);
        double d1 = 0.0D;
        if(super.currentUpperRange[l] - super.currentLowerRange[l] != 0.0D)
            d1 = (d - super.currentLowerRange[l]) / (super.currentUpperRange[l] - super.currentLowerRange[l]);
        int i1 = (rectangle.y + rectangle.height) - (int)(d1 * (double)rectangle.height);
        boolean flag = is3DModeOn();
        if(flag && stackedOn)
            i1 -= super.depth3dPoint.y;
        else
        if(flag)
        {
            i1 -= super.depth3dPoint.y;
            double d2 = ((double)super.depth3dPoint.y / (double)getSeriesCount()) * (double)i;
            i1 += (int)Math.round(d2);
        }
        return i1;
    }

    private void paintValueLabels(Graphics g, Rectangle rectangle, Rectangle rectangle1, int i, boolean flag)
    {
        if(valueLabelStyle == 2)
            return;
        Font font = getFont("valueLabelFont");
        g.setFont(font);
        FontMetrics fontmetrics = g.getFontMetrics();
        int j = fontmetrics.getAscent();
        int k = getSampleDecimalCount(i);
        int l = getSampleCount();
        int i1 = getSeriesCount();
        int j1 = getLabelAngle("valueLabelAngle");
        getSize();
        double d = rectangle1.x;
        double d1 = rectangle1.width;
        if(l > 2)
            d1 = (double)rectangle1.width / (double)(l - 1);
        double d2 = super.depth3dPoint.x;
        boolean flag1 = is3DModeOn();
        if(flag1)
        {
            d -= super.depth3dPoint.x;
            double d3 = ((double)super.depth3dPoint.x / (double)i1) * (double)i;
            d += d3;
        }
        g.setColor(getChartForeground());
        String s = getLabel("valueLabelPrefix_" + i);
        if(s == null)
            s = getLabel("valueLabelPrefix");
        String s1 = getLabel("valueLabelPostfix_" + i);
        if(s1 == null)
            s1 = getLabel("valueLabelPostfix");
        ChartSample achartsample[] = getSamples(i);
        for(int k1 = 0; k1 < achartsample.length; k1++)
        {
            if(!flag && (achartsample[k1] == null || achartsample[k1].value == null || achartsample[k1].value.isNaN()))
            {
                d += d1;
                continue;
            }
            double d4 = 0.0D;
            if(flag)
            {
                boolean flag2 = false;
                for(int l1 = 0; l1 < i1; l1++)
                {
                    ChartSample chartsample = getSample(l1, k1);
                    if(chartsample != null && chartsample.value != null && !chartsample.value.isNaN())
                    {
                        d4 += chartsample.value.doubleValue();
                        flag2 = true;
                    }
                }

                if(!flag2)
                {
                    d += d1;
                    continue;
                }
            } else
            {
                d4 = achartsample[k1].getFloatValue();
            }
            String s2 = formatNumber(d4, k);
            s2 = s == null ? s2 : s + s2;
            s2 = s1 == null ? s2 : s2 + s1;
            Dimension dimension = getLabelSize(s2, font);
            Dimension dimension1 = getAngledLabelSize(dimension, j1);
            int i2 = (int)Math.round(d - (double)(dimension1.width / 2)) + 1;
            if(valueLabelStyle == 0)
            {
                if(flag1)
                    i2 = Math.max((rectangle1.x - super.depth3dPoint.x) + 2, i2);
                else
                    i2 = Math.max(rectangle1.x + 2, i2);
                i2 = Math.min(i2, (rectangle.x + rectangle.width) - dimension1.width - 1);
            }
            if(j1 % 360 > 90 && j1 % 360 < 180 || j1 % 360 > 270)
                i2 = (int)(d - (double)(fontmetrics.getAscent() / 2));
            int j2 = calculateYPos(i, k1, rectangle1) - 1;
            int k2 = j2;
            if(j1 % 180 != 0)
                k2 -= dimension1.height + 1;
            if(valueLabelStyle == 1)
            {
                if(j1 % 180 == 0)
                    k2 += j / 2;
                else
                    k2 = j2 - dimension1.height / 2;
            } else
            if(!stackedOn)
            {
                double d5 = k1 <= 0 || achartsample[k1 - 1] == null ? d4 : achartsample[k1 - 1].getFloatValue();
                double d7 = k1 >= achartsample.length - 1 || achartsample[k1 + 1] == null ? d4 : achartsample[k1 + 1].getFloatValue();
                double d9 = (d4 - d5) / d1;
                double d10 = (d7 - d4) / d1;
                if(d9 < d10)
                {
                    if(j1 % 180 == 0)
                        k2 += j;
                    else
                        k2 += dimension1.height + 4;
                    if(j1 % 360 > 90 && j1 % 360 < 180 || j1 % 360 > 270)
                        i2 = (int)((d - (double)dimension1.width) + (double)(fontmetrics.getAscent() / 2));
                } else
                if(flag1)
                {
                    double d11 = (double)super.depth3dPoint.x / (double)i1;
                    i2 = (int)((double)i2 + d11);
                    d11 = (double)super.depth3dPoint.y / (double)i1;
                    k2 = (int)((double)k2 + d11);
                }
                try
                {
                    boolean flag4 = sampleHighlightOn[i][k1];
                    int l2 = sampleHighlightSize[i];
                    if(flag4 && d9 < d10)
                        k2 += l2 / 2;
                    else
                    if(flag4)
                        k2 -= l2 / 2;
                }
                catch(IndexOutOfBoundsException indexoutofboundsexception)
                {
                    System.out.println("Internal error with value labels");
                    indexoutofboundsexception.printStackTrace();
                }
            }
            boolean flag3 = true;
            if(flag1)
            {
                if(j2 <= k2)
                {
                    flag3 = j2 >= rectangle.y - 2 && j2 <= (rectangle.y + rectangle.height + 2) - super.depth3dPoint.y && d >= (double)(rectangle.x - 2 - super.depth3dPoint.x) && d <= (double)(rectangle.x + rectangle.width + 2);
                } else
                {
                    double d6 = (double)super.depth3dPoint.x / (double)i1;
                    double d8 = (double)super.depth3dPoint.y / (double)i1;
                    flag3 = (double)j2 >= (double)rectangle.y - d8 - 2D && (double)j2 <= (double)((rectangle.y + rectangle.height) - super.depth3dPoint.y) - d8 && d >= (double)(rectangle.x - super.depth3dPoint.x) - d6 - 2D && d <= ((double)(rectangle.x + rectangle.width) - d6) + 2D;
                }
            } else
            {
                flag3 = j2 >= rectangle.y - 2 && j2 <= rectangle.y + rectangle.height + 2 && d >= (double)(rectangle.x - 4) && d <= (double)(rectangle.x + rectangle.width + 2);
            }
            if(flag3)
                paintLabel(g, s2, i2, k2, dimension, 0, j1);
            d += d1;
        }

    }

    public void render(Graphics g)
    {
        render(g, !isServletModeOn());
    }

    void render(Graphics g, boolean flag)
    {
        Dimension dimension = getSize();
        Rectangle rectangle = getGraphBounds();
        Rectangle rectangle1 = getDataBounds(rectangle);
        calculateChartData(rectangle, rectangle1);
        for(int i = 0; i < super.overlayCharts.size(); i++)
        {
            Chart chart = (Chart)super.overlayCharts.elementAt(i);
            if(chart != null)
            {
                Rectangle rectangle2 = new Rectangle(rectangle);
                Rectangle rectangle4 = new Rectangle(rectangle1);
                if(is3DModeOn())
                {
                    rectangle2.x -= super.depth3dPoint.x;
                    rectangle2.y -= super.depth3dPoint.y;
                    rectangle4.x -= super.depth3dPoint.x;
                    rectangle4.y -= super.depth3dPoint.y;
                }
                chart.calculateChartData(rectangle2, rectangle4);
            }
        }

        if(flag && super.offscreen == null)
        {
            super.offscreen = createImage(Math.max(1, dimension.width), Math.max(1, dimension.height));
            super.hasChanged = true;
        }
        if(!flag || super.hasChanged || super.offscreen == null)
        {
            if(!super.externalGraphicsOn && !flag)
                super.og = g;
            else
            if(flag || super.externalGraphicsOn)
            {
                if(!super.externalGraphicsOn && super.offscreen != null)
                    super.og = super.offscreen.getGraphics();
                super.og.setColor(getBackground());
                super.og.fillRect(0, 0, dimension.width, dimension.height);
            }
            paintGrid(super.og, rectangle);
            paintTitle(super.og, dimension);
            if(super.sampleLabelsOn && sampleLabelStyle != 2)
                paintSampleLabels(super.og, rectangle, rectangle1);
            if(isLegendOn())
                paintLegend(super.og, rectangle, getLegendLabels());
            renderData(super.og, rectangle, rectangle1);
            for(int j = 0; j < super.overlayCharts.size(); j++)
            {
                Chart chart1 = (Chart)super.overlayCharts.elementAt(j);
                if(chart1 != null && isOverlayChartOn(j))
                {
                    Rectangle rectangle3 = new Rectangle(rectangle);
                    Rectangle rectangle5 = new Rectangle(rectangle1);
                    rectangle3.x -= super.depth3dPoint.x;
                    rectangle3.y -= super.depth3dPoint.y;
                    rectangle5.x -= super.depth3dPoint.x;
                    rectangle5.y -= super.depth3dPoint.y;
                    if((chart1 instanceof LineChart) || (chart1 instanceof PieChart))
                        chart1.renderData(super.og, rectangle3, rectangle5);
                    else
                        chart1.renderData(super.og, rectangle, rectangle1);
                }
            }

            if(is3DModeOn())
            {
                for(int k = super.rangeOn.length - 1; k >= 0; k--)
                    paint3DZeroDivider(super.og, rectangle, k);

                if(isRangeOn(1))
                    paint3DEdges(super.og, rectangle);
            }
            if(!super.externalGraphicsOn && super.og != g)
                super.og.dispose();
            super.hasChanged = false;
        }
        if((flag || super.externalGraphicsOn) && super.offscreen != null)
            g.drawImage(super.offscreen, 0, 0, this);
        paintFloatingLabels(g, rectangle);
    }

    private void paintLines(Graphics g, Rectangle rectangle, Rectangle rectangle1)
    {
        int i = getSeriesCount();
        if(i > 0)
        {
            for(int j = i - 1; j >= 0; j--)
            {
                int i1 = getSeriesRange(j);
                if(super.currentUpperRange[i1] != super.currentLowerRange[i1])
                    paintLine(g, j, rectangle, rectangle1, getSampleColor(j), isSelected(j, -1));
            }

            if(!is3DModeOn() && lastSelectedLine >= 0)
            {
                int k = lastSelectedLine;
                paintLine(g, k, rectangle, rectangle1, getSampleColor(k), isSelected(k, -1));
            }
            if(stackedOn)
            {
                if(isValueLabelsOn(0))
                    paintValueLabels(g, rectangle, rectangle1, i - 1, true);
            } else
            {
                for(int l = i - 1; l >= 0; l--)
                    if(isValueLabelsOn(l))
                        paintValueLabels(g, rectangle, rectangle1, l, false);

            }
        }
    }

    public int getValuePosition(double d)
    {
        return getValuePosition(0, d, getGraphBounds());
    }

    public void setSeriesLabelsOn(boolean flag)
    {
        seriesLabelsOn = flag;
        super.hasChanged = true;
        autoRepaint();
    }

    public void setSampleHighlightOn(boolean flag)
    {
        for(int i = 0; i < sampleHighlightOn.length; i++)
        {
            for(int j = 0; j < sampleHighlightOn[i].length; j++)
                sampleHighlightOn[i][j] = flag;

        }

        super.hasChanged = true;
        autoRepaint();
    }

    public void setSampleHighlightOn(int i, boolean flag)
    {
        try
        {
            for(int j = 0; j < sampleHighlightOn[i].length; j++)
                sampleHighlightOn[i][j] = flag;

        }
        catch(IndexOutOfBoundsException _ex)
        {
            throw new IllegalArgumentException("Invalid series: " + i);
        }
        super.hasChanged = true;
        autoRepaint();
    }

⌨️ 快捷键说明

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