PieChart.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:40k
源码类别:
OA系统
开发平台:
Java
- // Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov Date: 2002-12-03 18:43:55
- // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
- // Decompiler options: packimports(3)
- // Source File Name: PieChart.java
- package cn.com.fcsoft.chart;
- import java.awt.*;
- import java.awt.event.MouseEvent;
- import java.util.Hashtable;
- import java.util.Vector;
- // Referenced classes of package com.objectplanet.chart:
- // Chart, ChartSample
- public class PieChart extends Chart
- {
- public int getSeriesLabelStyle()
- {
- return seriesLabelStyle;
- }
- private void paintPies(Graphics g, Rectangle rectangle)
- {
- int i = getSeriesCount();
- if(i == 1)
- {
- pieBounds[0] = rectangle;
- double ad[] = getSampleValues(0);
- paintPie(g, rectangle, ad, 0);
- } else
- {
- int j = getSampleCount();
- calculatePieBounds(rectangle, j);
- for(int k = 0; k < j; k++)
- {
- double ad1[] = new double[i];
- for(int l = 0; l < i; l++)
- ad1[l] = getSampleValue(l, k);
- paintPie(g, pieBounds[k], ad1, k);
- }
- }
- }
- public boolean isPercentLabelsOn()
- {
- return percentLabelsOn;
- }
- public boolean isSampleLabelsOn()
- {
- return sampleLabelsOn;
- }
- public boolean isPieLabelsOn()
- {
- return pieLabelsOn;
- }
- private void paintPieSegment(Graphics g, Color color, double d, double d1, int i,
- int j, int k, int l, boolean flag, double d2, int i1)
- {
- if(d2 > 0.0D && d1 < 360D)
- {
- double d3 = -d + d1 / 2D;
- double d5 = d3 * 0.017453292519943295D;
- k += (int)Math.round(Math.cos(d5) * ((double)i * (d2 / 2D)));
- l += (int)Math.round(Math.sin(d5) * ((double)j * (d2 / 2D)));
- }
- if(i1 == 1 || i1 == 2)
- {
- double d4 = d * 0.017453292519943295D;
- double d6 = (d - d1) * 0.017453292519943295D;
- int l1 = (int)Math.round((double)i * pieDepth * ((double)pieAngle / 90D));
- int i2 = i / 2;
- int j2 = j / 2;
- double d7 = Math.abs(d4 - d6) / 6.2831853071795862D;
- double d8 = 3.1415926535897931D * (double)Math.max(i, j);
- double d9 = d7 * d8;
- double d10 = Math.abs(d4 - d6) / d9;
- if(d10 > 0.0D)
- {
- double d11 = d4;
- double d12 = d4;
- g.setColor(color.darker().darker());
- while(d11 >= d6)
- {
- d11 -= d10;
- int k2 = (int)Math.round(Math.cos(d11) * (double)i2);
- int l2 = (int)Math.round(Math.sin(d11) * (double)j2);
- if(l2 < 0)
- g.drawLine(k + k2, l - l2, k + k2, (l - l2) + l1 + 1);
- else
- g.drawLine(k + k2, (l - l2) + 1, k + k2, (l - l2) + l1 + 2);
- double d13 = d11;
- }
- }
- }
- if(i1 == 0 || i1 == 2)
- {
- int j1 = k - i / 2;
- int k1 = l - j / 2;
- g.setColor(color);
- g.fillArc(j1, k1, i + 1, j + 1, (int)Math.round(d), (int)Math.round(-d1));
- g.setColor(color.darker());
- g.drawArc(j1, k1, i, j, (int)Math.round(d), (int)Math.round(-d1));
- }
- if(flag)
- paintSelectionMarker(g, color, (int)Math.round(-d), (int)Math.round(-d1), i, j, k, l, selectionStyle);
- }
- protected void processEvent(AWTEvent awtevent)
- {
- switch(awtevent.getID())
- {
- case 504:
- default:
- break;
- case 505:
- selectedSample = -1;
- selectedSeries = -1;
- repaint();
- break;
- case 503:
- case 506:
- MouseEvent mouseevent = (MouseEvent)awtevent;
- if(!seriesLabelsOn && !sampleLabelsOn && !isValueLabelsOn() && !percentLabelsOn)
- break;
- Point point = new Point(mouseevent.getX(), mouseevent.getY());
- ChartSample chartsample = checkSelection(point);
- boolean flag = false;
- if(chartsample != null)
- {
- flag = chartsample.getIndex() != selectedSample || chartsample.getSeries() != selectedSeries;
- selectedSample = chartsample.getIndex();
- selectedSeries = chartsample.getSeries();
- } else
- {
- flag = selectedSample != -1 || selectedSeries != -1;
- selectedSample = -1;
- selectedSeries = -1;
- }
- if(flag)
- repaint();
- break;
- }
- super.processEvent(awtevent);
- }
- public void setDepth(double d)
- {
- pieDepth = d;
- super.hasChanged = true;
- autoRepaint();
- }
- public float getDepth()
- {
- return (float)pieDepth;
- }
- public void setPercentLabelStyle(int i)
- {
- percentLabelStyle = 0;
- if(i == 1 || i == 2)
- percentLabelStyle = i;
- super.hasChanged = true;
- autoRepaint();
- }
- public int getPercentLabelStyle()
- {
- return percentLabelStyle;
- }
- public void setSampleLabelStyle(int i)
- {
- sampleLabelStyle = 0;
- if(i == 1 || i == 2)
- sampleLabelStyle = i;
- super.hasChanged = true;
- autoRepaint();
- }
- public int getSampleLabelStyle()
- {
- return sampleLabelStyle;
- }
- public void setDetachedDistance(double d)
- {
- detachedDistance = d;
- super.hasChanged = true;
- autoRepaint();
- }
- public double getDetachedDistance()
- {
- return detachedDistance;
- }
- public void setDetachedSlice(int i, int j, double d)
- {
- Double double1 = new Double(i * 0xf4240 + j);
- if(d != 0.0D)
- detachedSlices.put(double1, new Double(d));
- else
- detachedSlices.remove(double1);
- super.hasChanged = true;
- autoRepaint();
- }
- public double getDetachedSlice(int i, int j)
- {
- Double double1 = new Double(i * 0xf4240 + j);
- Double double2 = (Double)detachedSlices.get(double1);
- if(double2 != null)
- return double2.doubleValue();
- else
- return 0.0D;
- }
- public boolean isSliceSeperatorOn()
- {
- return sliceSeperatorOn;
- }
- protected void calculateChartData(Rectangle rectangle, Rectangle rectangle1)
- {
- }
- public double getPercentValue(int i, int j)
- {
- if(i < 0 || i >= getSeriesCount())
- throw new IllegalArgumentException("Invalid series index: " + i);
- if(j < 0 || j >= getSampleCount())
- throw new IllegalArgumentException("Invalid sample index: " + j);
- int k = getSeriesCount();
- if(k == 1)
- {
- int l = getSampleCount();
- double d1 = 0.0D;
- for(int j1 = 0; j1 < l; j1++)
- {
- double d5 = getSampleValue(0, j1);
- if(d5 > 0.0D)
- d1 += d5;
- }
- double d3 = getSampleValue(0, j);
- if(d3 >= 0.0D)
- return (d3 / d1) * 100D;
- } else
- {
- double d = 0.0D;
- for(int i1 = 0; i1 < k; i1++)
- {
- double d4 = getSampleValue(i1, j);
- if(d4 > 0.0D)
- d += d4;
- }
- double d2 = getSampleValue(i, j);
- if(d2 > 0.0D)
- return (d2 / d) * 100D;
- }
- return 0.0D;
- }
- private void paintFloatingLabels(Graphics g, int i, int j)
- {
- int k = getSeriesCount();
- int l = getSampleCount();
- if(g == null || i < 0 || i >= k || j < -1 || j >= l)
- return;
- Font font = getFont("floatingLabelFont");
- g.setFont(font);
- FontMetrics fontmetrics = g.getFontMetrics();
- boolean flag = isValueLabelsOn() && valueLabelStyle == 0;
- boolean flag1 = percentLabelsOn && percentLabelStyle == 0;
- boolean flag2 = sampleLabelsOn && sampleLabelStyle == 0;
- boolean flag3 = seriesLabelsOn && k > 1 && seriesLabelStyle == 0;
- if(j >= 0)
- {
- String s = constructLabel(i, j, flag3, flag2, flag, flag1);
- paintFloatingLabel(g, s, i, j, font, fontmetrics);
- } else
- if(isFloatingOnLegendOn())
- {
- for(int i1 = 0; i1 < l; i1++)
- {
- String s1 = constructLabel(i, i1, flag3, flag2, flag, flag1);
- paintFloatingLabel(g, s1, i, i1, font, fontmetrics);
- }
- }
- }
- private void paintSelectionMarker(Graphics g, Color color, double d, double d1, int i,
- int j, int k, int l, int i1)
- {
- if(i1 == 1)
- {
- double d2 = d - d1 / 2D;
- double d4 = d2 * 0.017453292519943295D;
- int j1 = k + (int)Math.round(Math.cos(d4) * ((double)i * 0.40000000000000002D));
- int l1 = l + (int)Math.round(Math.sin(d4) * ((double)j * 0.40000000000000002D));
- int j2 = Math.max(i / 16, 3);
- int l2 = Math.max(j / 16, 3);
- int j3 = j2 / 2;
- int k3 = l2 / 2;
- g.setColor(color.darker());
- g.fillOval(j1 - j3, l1 - k3, j2, l2);
- g.setColor(color.darker());
- g.drawArc(j1 - j3, l1 - k3, j2, l2, 45, 180);
- g.setColor(color.darker().darker());
- g.drawArc((j1 - j3) + 1, (l1 - k3) + 1, j2 - 2, l2 - 2, 45, 180);
- g.setColor(color);
- g.drawArc((j1 - j3) + 1, (l1 - k3) + 1, j2 - 2, l2 - 2, 45, -180);
- g.setColor(color.brighter());
- g.drawArc(j1 - j3, l1 - k3, j2, l2, 45, -180);
- } else
- if(i1 == 0)
- {
- double d3 = d - d1 / 2D;
- double d5 = d3 * 0.017453292519943295D;
- int k1 = (int)Math.round((double)i * 0.69999999999999996D);
- int i2 = (int)Math.round((double)j * 0.69999999999999996D);
- int k2 = k + (int)Math.round(Math.cos(d5) * ((double)i * 0.10000000000000001D));
- int i3 = l + (int)Math.round(Math.sin(d5) * ((double)j * 0.10000000000000001D));
- k2 -= (int)Math.round((double)k1 / 2D);
- i3 -= (int)Math.round((double)i2 / 2D);
- g.setColor(color.darker());
- g.fillArc(k2, i3, k1 + 1, i2 + 1, (int)(-Math.round(d)), (int)Math.round(d1));
- }
- }
- public void setPercentLabelsOn(boolean flag)
- {
- percentLabelsOn = flag;
- super.hasChanged = true;
- autoRepaint();
- }
- public void setSampleLabelsOn(boolean flag)
- {
- sampleLabelsOn = flag;
- super.hasChanged = true;
- autoRepaint();
- }
- public boolean isSeriesLabelsOn()
- {
- return seriesLabelsOn;
- }
- public void setPieLabelsOn(boolean flag)
- {
- pieLabelsOn = flag;
- super.hasChanged = true;
- autoRepaint();
- }
- private void paintPie(Graphics g, Rectangle rectangle, double ad[], int i)
- {
- if(rectangle == null || rectangle.width <= 0 || rectangle.height <= 0)
- return;
- int j = Math.min(rectangle.width, rectangle.height);
- int k = j;
- int l = k;
- int j1 = rectangle.x + rectangle.width / 2;
- int k1 = rectangle.y + rectangle.height / 2;
- Font font = getFont("pieLabelFont");
- if(font != null)
- g.setFont(font);
- else
- g.setFont(getFont());
- FontMetrics fontmetrics = g.getFontMetrics();
- boolean flag = is3DModeOn();
- if(flag)
- {
- int l1 = (int)Math.round((double)j * ((double)pieAngle / 90D));
- k -= l1;
- int i2 = (int)Math.round((double)j * pieDepth * ((double)pieAngle / 90D));
- int i1 = k + i2;
- k1 -= i2 / 2;
- double d1 = (double)rectangle.width / (double)j;
- int i3 = (int)Math.round((double)j * d1);
- int l3 = (int)Math.round((double)k * d1);
- i2 = (int)Math.round((double)i3 * pieDepth * ((double)pieAngle / 90D));
- i1 = l3 + i2;
- k1 = (rectangle.y + rectangle.height / 2) - i2 / 2;
- if(k1 - l3 / 2 < rectangle.y)
- {
- double d6 = (double)l3 / (double)i1;
- i1 = rectangle.height;
- l3 = (int)Math.round((double)i1 * d6);
- int j2 = rectangle.height - l3;
- double d2 = (double)j / (double)k;
- i3 = (int)Math.round((double)l3 * d2);
- k1 = (rectangle.y + rectangle.height / 2) - j2 / 2;
- }
- j = i3;
- k = l3;
- }
- if(pieLabelsOn)
- {
- Font font1 = getFont("pieLabelFont");
- String s = getSampleLabel(i);
- Dimension dimension = getLabelSize(s, font1);
- if(flag)
- {
- int l2 = (int)Math.round((double)j * pieDepth * ((double)pieAngle / 90D));
- int j3 = ((k1 + k / 2 + dimension.height) - fontmetrics.getDescent()) + 2;
- j3 += l2;
- if(j3 > rectangle.y + rectangle.height)
- {
- int i4 = j3 - (rectangle.y + rectangle.height);
- k -= i4;
- k1 -= i4 / 2;
- }
- } else
- {
- k -= dimension.height;
- j = k;
- k1 -= dimension.height / 2;
- }
- }
- pieCenter[i].x = j1;
- pieCenter[i].y = k1;
- pieWidth[i] = j;
- double d = 0.0D;
- for(int k2 = 0; k2 < ad.length; k2++)
- if(ad[k2] > 0.0D)
- d += ad[k2];
- double d3 = 90D;
- int k3 = getSeriesCount();
- for(int j4 = 0; j4 < ad.length; j4++)
- {
- double d7 = (ad[j4] / d) * 360D;
- if(k3 == 1)
- angles[0][j4] = d3;
- else
- angles[j4][i] = d3;
- d3 -= d7;
- }
- if(flag)
- {
- int k4 = k1;
- k1 += (int)Math.round((double)j * pieDepth * ((double)pieAngle / 90D));
- for(int j5 = 0; j5 < ad.length; j5++)
- {
- double d10 = -270D;
- double d15 = d10;
- if(k3 == 1)
- {
- if(j5 < angles[0].length - 1)
- d10 = angles[0][j5 + 1];
- d15 = angles[0][j5];
- } else
- {
- if(j5 < angles.length - 1)
- d10 = angles[j5 + 1][i];
- d15 = angles[j5][i];
- }
- if(d15 != d10)
- {
- boolean flag4 = false;
- if(k3 == 1)
- flag4 = isSelected(0, j5);
- else
- flag4 = isSelected(j5, i);
- double d19 = 0.0D;
- if(flag4 && selectionStyle == 2)
- d19 = detachedDistance;
- else
- if(k3 == 1)
- d19 = getDetachedSlice(0, j5);
- else
- d19 = getDetachedSlice(j5, i);
- flag4 = false;
- paintPieSegment(g, getSampleColor(j5).darker(), d15, d15 - d10, j, k, j1, k1, flag4, d19, 0);
- }
- }
- k1 = k4;
- }
- if(flag)
- {
- double d4 = -270D;
- double d11;
- for(int k5 = ad.length - 1; d4 < -90D && k5 >= 0; d4 = d11)
- {
- d11 = d4;
- if(k3 == 1)
- d11 = angles[0][k5];
- else
- d11 = angles[k5][i];
- boolean flag1 = false;
- if(k3 == 1)
- flag1 = isSelected(0, k5);
- else
- flag1 = isSelected(k5, i);
- double d16 = 0.0D;
- if(flag1 && selectionStyle == 2)
- d16 = detachedDistance;
- else
- if(k3 == 1)
- d16 = getDetachedSlice(0, k5);
- else
- d16 = getDetachedSlice(k5, i);
- paintPieSegment(g, getSampleColor(k5), d11, d11 - d4, j, k, j1, k1, flag1, d16, 1);
- k5--;
- }
- for(int l5 = 0; l5 < ad.length; l5++)
- {
- double d5 = -270D;
- double d12 = d5;
- if(k3 == 1)
- {
- if(l5 < angles[0].length - 1)
- d5 = angles[0][l5 + 1];
- d12 = angles[0][l5];
- } else
- {
- if(l5 < angles.length - 1)
- d5 = angles[l5 + 1][i];
- d12 = angles[l5][i];
- }
- if(d12 >= -90D)
- {
- boolean flag2 = false;
- if(k3 == 1)
- flag2 = isSelected(0, l5);
- else
- flag2 = isSelected(l5, i);
- double d17 = 0.0D;
- if(flag2 && selectionStyle == 2)
- d17 = detachedDistance;
- else
- if(k3 == 1)
- d17 = getDetachedSlice(0, l5);
- else
- d17 = getDetachedSlice(l5, i);
- paintPieSegment(g, getSampleColor(l5), d12, d12 - d5, j, k, j1, k1, flag2, d17, 1);
- }
- }
- }
- for(int l4 = 0; l4 < ad.length; l4++)
- {
- double d8 = -270D;
- double d13 = d8;
- if(k3 == 1)
- {
- if(l4 < angles[0].length - 1)
- d8 = angles[0][l4 + 1];
- d13 = angles[0][l4];
- } else
- {
- if(l4 < angles.length - 1)
- d8 = angles[l4 + 1][i];
- d13 = angles[l4][i];
- }
- if(d13 != d8)
- {
- boolean flag3 = false;
- if(k3 == 1)
- flag3 = isSelected(0, l4);
- else
- flag3 = isSelected(l4, i);
- double d18 = 0.0D;
- if(flag3 && selectionStyle == 2)
- d18 = detachedDistance;
- else
- if(k3 == 1)
- d18 = getDetachedSlice(0, l4);
- else
- d18 = getDetachedSlice(l4, i);
- paintPieSegment(g, getSampleColor(l4), d13, d13 - d8, j, k, j1, k1, flag3, d18, 0);
- }
- }
- if(sliceSeperatorOn)
- {
- for(int i5 = 0; i5 < ad.length; i5++)
- {
- double d9 = 0.0D;
- if(k3 == 1)
- d9 = angles[0][i5];
- else
- d9 = angles[i5][i];
- double d14 = -d9 * 0.017453292519943295D;
- int k6 = j1 + (int)Math.round(Math.cos(d14) * ((double)j * 0.5D));
- int l6 = k1 + (int)Math.round(Math.sin(d14) * ((double)k * 0.5D));
- if(sliceSeperatorColor != null)
- g.setColor(sliceSeperatorColor);
- else
- g.setColor(getSampleColor(i5).darker());
- g.drawLine(j1, k1, k6, l6);
- }
- }
- if(pieLabelsOn)
- {
- String s1 = k3 != 1 ? getSampleLabel(i) : getSeriesLabel(i);
- Font font2 = getFont("pieLabelFont");
- if(s1 != null && s1.trim().length() > 0)
- {
- Dimension dimension1 = getLabelSize(s1, font2);
- int i6 = j1 - dimension1.width / 2;
- int j6 = ((k1 + k / 2 + fontmetrics.getHeight()) - fontmetrics.getDescent()) + 2;
- if(flag)
- j6 += (int)Math.round((double)j * pieDepth * ((double)pieAngle / 90D));
- Color color = getSampleLabelColor(i);
- g.setColor(color == null ? getForeground() : color);
- paintLabel(g, s1, i6, j6, dimension1, 0, 0);
- }
- }
- }
- private String constructLabel(int i, int j, boolean flag, boolean flag1, boolean flag2, boolean flag3)
- {
- int k = getSeriesCount();
- int l = getSampleCount();
- if(i < 0 || i >= k || j < 0 || j >= l)
- return "";
- String s = getLabel("valueLabelPrefix_" + i);
- if(s == null)
- s = getLabel("valueLabelPrefix");
- String s1 = getLabel("valueLabelPostfix_" + i);
- if(s1 == null)
- s1 = getLabel("valueLabelPostfix");
- String s2 = flag ? getSeriesLabel(i) : null;
- String s3 = flag1 ? getSampleLabel(j) : null;
- String s4 = flag2 ? formatNumber(getSampleValue(i, j), getSampleDecimalCount(i)) : null;
- s4 = s == null || s4 == null ? s4 : s + s4;
- s4 = s1 == null || s4 == null ? s4 : s4 + s1;
- String s5 = flag3 ? formatNumber(getPercentValue(i, j), getPercentDecimalCount()) + "%" : null;
- StringBuffer stringbuffer = new StringBuffer();
- if(s2 != null)
- {
- stringbuffer.append(s2);
- if(!s2.endsWith("n") && (s3 != null || s4 != null || s5 != null))
- stringbuffer.append(" : ");
- }
- if(s3 != null)
- {
- stringbuffer.append(s3);
- if(!s3.endsWith("n") && (s4 != null || s5 != null))
- stringbuffer.append(" : ");
- }
- if(s4 != null)
- {
- stringbuffer.append(s4);
- if(!s4.endsWith("n") && s5 != null)
- stringbuffer.append(" : ");
- }
- if(s5 != null)
- stringbuffer.append(s5);
- return stringbuffer.toString();
- }
- private void paintStaticLabels(Graphics g)
- {
- if(g == null)
- return;
- int i = getSeriesCount();
- boolean flag = percentLabelsOn && percentLabelStyle != 0;
- flag |= isValueLabelsOn() && valueLabelStyle != 0;
- flag |= sampleLabelsOn && sampleLabelStyle != 0;
- flag |= seriesLabelsOn && i > 1 && seriesLabelStyle != 0;
- if(!flag)
- return;
- Font font = getFont("insideLabelFont");
- g.setFont(font);
- FontMetrics fontmetrics = g.getFontMetrics();
- int j = getSampleCount();
- boolean flag1 = percentLabelsOn && percentLabelStyle != 0;
- boolean flag2 = isValueLabelsOn() && valueLabelStyle != 0;
- boolean flag3 = seriesLabelsOn && i > 1 && seriesLabelStyle != 0;
- boolean flag4 = sampleLabelsOn && sampleLabelStyle != 0;
- for(int k = 0; k < i; k++)
- {
- for(int l = 0; l < j; l++)
- {
- String s = constructLabel(k, l, flag3, flag4, flag2, flag1);
- paintInsideLabel(g, s, k, l, font, fontmetrics);
- }
- }
- }
- public void setValueLabelStyle(int i)
- {
- valueLabelStyle = 0;
- if(i == 1 || i == 2)
- valueLabelStyle = i;
- super.hasChanged = true;
- autoRepaint();
- }
- public int getValueLabelStyle()
- {
- return valueLabelStyle;
- }
- public void setSliceSeperatorOn(boolean flag)
- {
- sliceSeperatorOn = flag;
- super.hasChanged = true;
- autoRepaint();
- }
- public ChartSample checkSelection(Point point)
- {
- ChartSample chartsample = super.checkSelection(point);
- if(chartsample == null)
- {
- int i = -1;
- Object obj = null;
- for(int j = 0; j < pieBounds.length; j++)
- {
- Rectangle rectangle = pieBounds[j];
- if(rectangle == null || !rectangle.contains(point))
- continue;
- i = j;
- break;
- }
- if(i >= 0)
- {
- point.x -= pieCenter[i].x;
- point.y -= pieCenter[i].y;
- if(is3DModeOn())
- {
- int k = pieWidth[i];
- int l = (int)Math.round((double)k * ((double)pieAngle / 90D));
- double d2 = (double)k / (double)(k - l);
- point.y = (int)Math.round((double)point.y * d2);
- }
- double d = Math.atan2(point.y, point.x);
- double d3 = -(d * 57.295779513082323D);
- if(d3 > 90D && d3 <= 180D)
- d3 = -360D + d3;
- int i1 = getSeriesCount();
- double d5 = 0.0D;
- double d6 = 0.0D;
- double d7 = 0.0D;
- if(i1 == 1)
- {
- int j1 = getSampleCount();
- for(int l1 = 0; l1 < j1; l1++)
- {
- if(l1 < j1 - 1)
- {
- d6 = Math.min(angles[0][l1], angles[0][l1 + 1]);
- d7 = Math.max(angles[0][l1], angles[0][l1 + 1]);
- } else
- {
- d6 = Math.min(angles[0][l1], -270D);
- d7 = Math.max(angles[0][l1], -270D);
- }
- if(d3 < d6 || d3 >= d7)
- continue;
- chartsample = getSample(0, l1);
- d5 = (d6 + d7) / 2D;
- break;
- }
- } else
- {
- for(int k1 = 0; k1 < i1; k1++)
- {
- if(k1 < i1 - 1)
- {
- d6 = Math.min(angles[k1][i], angles[k1 + 1][i]);
- d7 = Math.max(angles[k1][i], angles[k1 + 1][i]);
- } else
- {
- d6 = Math.min(angles[k1][i], -270D);
- d7 = Math.max(angles[k1][i], -270D);
- }
- if(d3 < d6 || d3 >= d7)
- continue;
- chartsample = getSample(k1, i);
- d5 = (d6 + d7) / 2D;
- break;
- }
- }
- if(chartsample != null && chartsample.isSelected() && selectionStyle == 2)
- {
- double d8 = d5 * 0.017453292519943295D;
- point.x -= Math.cos(d8) * (double)pieWidth[i] * 0.5D * detachedDistance;
- point.y += Math.sin(d8) * (double)pieWidth[i] * 0.5D * detachedDistance;
- double d1 = Math.atan2(point.y, point.x);
- double d4 = -(d1 * 57.295779513082323D);
- if(d4 > 90D && d4 <= 180D)
- d4 = -360D + d4;
- if(d4 < d6 || d4 >= d7)
- return null;
- }
- double d9 = Math.sqrt(point.x * point.x + point.y * point.y);
- if(d9 > (double)(pieWidth[i] / 2))
- return null;
- }
- }
- return chartsample;
- }
- protected void renderData(Graphics g, Rectangle rectangle, Rectangle rectangle1)
- {
- paintPies(g, rectangle);
- paintStaticLabels(g);
- }
- public void reset()
- {
- super.reset();
- pieAngle = 20;
- pieDepth = 0.40000000596046448D;
- sampleLabelsOn = false;
- percentLabelsOn = false;
- pieLabelsOn = false;
- percentDecimalCount = 0;
- selectionStyle = 0;
- sliceSeperatorOn = true;
- sliceSeperatorColor = null;
- detachedDistance = 0.10000000000000001D;
- if(detachedSlices != null)
- detachedSlices.clear();
- percentLabelStyle = 0;
- valueLabelStyle = 0;
- sampleLabelStyle = 0;
- seriesLabelStyle = 0;
- selectedSample = -1;
- selectedSeries = -1;
- }
- public PieChart()
- {
- this(1);
- }
- public PieChart(int i)
- {
- this(1, i);
- }
- public PieChart(int i, int j)
- {
- super(i, j);
- super.chartType = "pie";
- angles = new double[i][j];
- detachedSlices = new Hashtable();
- pieBounds = new Rectangle[i != 1 ? j : 1];
- pieCenter = new Point[pieBounds.length];
- pieWidth = new int[pieBounds.length];
- for(int k = 0; k < pieBounds.length; k++)
- {
- pieBounds[k] = new Rectangle();
- pieCenter[k] = new Point();
- }
- }
- public void setPercentDecimalCount(int i)
- {
- percentDecimalCount = i;
- super.hasChanged = true;
- autoRepaint();
- }
- public int getPercentDecimalCount()
- {
- return percentDecimalCount;
- }
- public void setSliceSeperatorColor(Color color)
- {
- sliceSeperatorColor = color;
- super.hasChanged = true;
- autoRepaint();
- }
- public Color getSliceSeperatorColor()
- {
- return sliceSeperatorColor;
- }
- public void setFont(String s, Font font)
- {
- super.setFont(s, font);
- }
- public void setAngle(int i)
- {
- pieAngle = i;
- super.hasChanged = true;
- autoRepaint();
- }
- public int getAngle()
- {
- return pieAngle;
- }
- public void setSelectionStyle(int i)
- {
- selectionStyle = i;
- super.hasChanged = true;
- autoRepaint();
- }
- public int getSelectionStyle()
- {
- return selectionStyle;
- }
- public void render(Graphics g)
- {
- render(g, !isServletModeOn());
- }
- public void setSeriesLabelsOn(boolean flag)
- {
- seriesLabelsOn = flag;
- super.hasChanged = true;
- autoRepaint();
- }
- protected void checkDataIntegrity()
- {
- super.checkDataIntegrity();
- int i = getSeriesCount();
- int j = getSampleCount();
- angles = new double[i][j];
- pieBounds = new Rectangle[i != 1 ? j : 1];
- pieCenter = new Point[pieBounds.length];
- pieWidth = new int[pieBounds.length];
- for(int k = 0; k < pieBounds.length; k++)
- {
- pieBounds[k] = new Rectangle();
- pieCenter[k] = new Point();
- }
- }
- void render(Graphics g, boolean flag)
- {
- Rectangle rectangle = getGraphBounds();
- for(int i = 0; i < super.overlayCharts.size(); i++)
- {
- Chart chart = (Chart)super.overlayCharts.elementAt(i);
- if(chart != null)
- chart.calculateChartData(rectangle, rectangle);
- }
- Dimension dimension = getSize();
- 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);
- }
- paintTitle(super.og, dimension);
- renderData(super.og, rectangle, rectangle);
- for(int j = 0; j < super.overlayCharts.size(); j++)
- {
- Chart chart1 = (Chart)super.overlayCharts.elementAt(j);
- if(chart1 != null)
- chart1.renderData(super.og, rectangle, rectangle);
- }
- if(isLegendOn())
- paintLegend(super.og, rectangle, getLegendLabels());
- 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);
- if(sampleLabelsOn && sampleLabelStyle == 0 || seriesLabelsOn && seriesLabelStyle == 0 || isValueLabelsOn() && valueLabelStyle == 0 || percentLabelsOn && percentLabelStyle == 0)
- paintFloatingLabels(g, selectedSeries, selectedSample);
- }
- public Rectangle getGraphBounds()
- {
- if(!super.hasChanged && super.currentBounds != null)
- return super.currentBounds;
- Rectangle rectangle = super.getGraphBounds(getLegendLabels());
- Insets insets = getGraphInsets();
- if(insets != null)
- {
- Dimension dimension = getSize();
- if(insets.top != -1)
- {
- int i = rectangle.y + rectangle.height;
- rectangle.y = insets.top;
- rectangle.height = i - rectangle.y;
- }
- if(insets.left != -1)
- {
- int j = rectangle.x + rectangle.width;
- rectangle.x = insets.left;
- rectangle.width = j - rectangle.x;
- }
- if(insets.bottom != -1)
- rectangle.height = dimension.height - insets.bottom - rectangle.y;
- if(insets.right != -1)
- rectangle.width = dimension.width - insets.right - rectangle.x;
- }
- super.currentBounds = rectangle;
- return rectangle;
- }
- private void calculatePieBounds(Rectangle rectangle, int i)
- {
- int j = 0;
- int k = i;
- int l = 1;
- for(int i1 = 1; i1 <= i; i1++)
- {
- for(int k1 = 1; k1 <= i; k1++)
- if(i1 * k1 >= i)
- {
- int i2 = Math.min(rectangle.width / i1, rectangle.height / k1);
- if(i2 > j)
- {
- j = i2;
- k = i1;
- l = k1;
- }
- }
- }
- int j1 = 0;
- for(int l1 = 0; l1 < l; l1++)
- {
- for(int j2 = 0; j2 < k; j2++)
- if(j1 < i)
- {
- Rectangle rectangle1 = pieBounds[j1];
- rectangle1.width = rectangle.width / k;
- rectangle1.height = rectangle.height / l;
- rectangle1.x = rectangle.x + rectangle1.width * j2;
- rectangle1.y = rectangle.y + rectangle1.height * l1;
- rectangle1.width -= 10;
- rectangle1.height -= 10;
- rectangle1.x += 5;
- rectangle1.y += 5;
- j1++;
- }
- }
- }
- private void paintFloatingLabel(Graphics g, String s, int i, int j, Font font, FontMetrics fontmetrics)
- {
- int k = getSeriesCount();
- Point point = pieCenter[k <= 1 ? 0 : j];
- if(point == null)
- return;
- double d = 0.0D;
- if(k == 1)
- {
- if(j < angles[0].length - 1)
- d = -((angles[0][j] + angles[0][j + 1]) / 2D);
- else
- d = -((angles[0][j] - 270D) / 2D);
- } else
- if(i < angles.length - 1)
- d = -((angles[i][j] + angles[i + 1][j]) / 2D);
- else
- d = -((angles[i][j] - 270D) / 2D);
- double d1 = 1.0D;
- int l = pieWidth[k != 1 ? j : 0];
- if(is3DModeOn())
- {
- int i1 = (int)Math.round((double)l * ((double)pieAngle / 90D));
- d1 = (double)(l - i1) / (double)l;
- }
- double d2 = d * 0.017453292519943295D;
- int j1 = point.x + (int)Math.round(Math.cos(d2) * (double)l * 0.29999999999999999D);
- int k1 = point.y + (int)Math.round(Math.sin(d2) * (double)l * 0.29999999999999999D * d1);
- Dimension dimension = getLabelSize(s, font);
- j1 -= dimension.width / 2;
- k1 -= dimension.height / 2 - fontmetrics.getAscent();
- Dimension dimension1 = getSize();
- j1 = Math.max(j1, 3);
- j1 = Math.min(j1, dimension1.width - dimension.width - 3);
- k1 = Math.max(k1, fontmetrics.getAscent());
- k1 = Math.min(k1, ((dimension1.height - dimension.height) + fontmetrics.getAscent()) - 1);
- int l1 = fontmetrics.getHeight();
- int i2 = fontmetrics.getDescent();
- g.setColor(new Color(255, 255, 231));
- g.fillRect(j1 - 2, ((k1 - l1) + i2 * 2) - 3, dimension.width + 5, dimension.height + 2);
- g.setColor(getSampleColor(getSeriesCount() != 1 ? i : j).darker());
- g.drawRect(j1 - 3, ((k1 - l1) + i2 * 2) - 4, dimension.width + 5, dimension.height + 3);
- g.setColor(Color.black);
- paintLabel(g, s, j1, k1, dimension, 0, 0);
- }
- private void paintInsideLabel(Graphics g, String s, int i, int j, Font font, FontMetrics fontmetrics)
- {
- int k = getSeriesCount();
- Point point = pieCenter[k <= 1 ? 0 : j];
- if(point == null)
- return;
- double d = 0.0D;
- double d1 = -270D;
- double d2 = d1;
- if(k == 1)
- {
- if(j < angles[0].length - 1)
- d1 = angles[0][j + 1];
- d2 = angles[0][j];
- } else
- {
- if(i < angles.length - 1)
- d1 = angles[i + 1][j];
- d2 = angles[i][j];
- }
- d = -((d2 + d1) / 2D);
- double d3 = 1.0D;
- int l = pieWidth[k != 1 ? j : 0];
- double d4 = 0.0D;
- if(isSelected(i, j) && d2 - d1 < 360D && selectionStyle == 2)
- d4 = ((double)l * detachedDistance) / 2D;
- if(is3DModeOn())
- {
- int i1 = (int)Math.round((double)l * ((double)pieAngle / 90D));
- d3 = (double)(l - i1) / (double)l;
- }
- double d5 = d * 0.017453292519943295D;
- int j1 = point.x + (int)Math.round(Math.cos(d5) * (double)l * 0.34999999999999998D + Math.cos(d5) * d4);
- int k1 = point.y + (int)Math.round((Math.sin(d5) * (double)l * 0.34999999999999998D + Math.sin(d5) * d4) * d3);
- Dimension dimension = getLabelSize(s, font);
- j1 -= dimension.width / 2;
- k1 -= dimension.height / 2 - fontmetrics.getAscent();
- Color color = getSampleColor(k != 1 ? i : j);
- if((color.getRed() + color.getGreen() + color.getBlue()) / 3 > 110)
- g.setColor(Color.black);
- else
- g.setColor(Color.white);
- paintLabel(g, s, j1, k1, dimension, 0, 0);
- }
- public void setSeriesLabelStyle(int i)
- {
- seriesLabelStyle = 0;
- if(i == 1 || i == 2)
- seriesLabelStyle = i;
- super.hasChanged = true;
- autoRepaint();
- }
- public static final int SELECTION_STYLE_TRIANGLE = 0;
- public static final int SELECTION_STYLE_CIRCLE = 1;
- public static final int SELECTION_STYLE_DETACHED = 2;
- public static final int FLOATING = 0;
- public static final int INSIDE = 1;
- public static final int OUTSIDE = 2;
- private int pieAngle;
- private double pieDepth;
- private boolean seriesLabelsOn;
- private boolean sampleLabelsOn;
- private boolean percentLabelsOn;
- private boolean pieLabelsOn;
- private int percentDecimalCount;
- private int selectionStyle;
- private boolean sliceSeperatorOn;
- private Color sliceSeperatorColor;
- private double detachedDistance;
- private Hashtable detachedSlices;
- private int percentLabelStyle;
- private int valueLabelStyle;
- private int seriesLabelStyle;
- private int sampleLabelStyle;
- private int selectedSample;
- private int selectedSeries;
- private double angles[][];
- private Rectangle pieBounds[];
- private Point pieCenter[];
- private int pieWidth[];
- private static final int PAINT_2D = 0;
- private static final int PAINT_3D = 1;
- private static final int PAINT_ALL = 2;
- }