📄 piechart.java
字号:
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -