📄 linechart.java
字号:
}
public void setSampleLabelsOn(boolean flag)
{
super.sampleLabelsOn = flag;
super.hasChanged = true;
autoRepaint();
}
public boolean isSeriesLabelsOn()
{
return seriesLabelsOn;
}
/**
* @deprecated Method setLineWidth is deprecated
*/
public void setLineWidth(int i)
{
setLineWidth(-1, i);
}
public void setLineWidth(int i, int j)
{
if(i >= 0 && i < lineWidth.length)
lineWidth[i] = j;
else
if(i < 0)
{
for(int k = 0; k < lineWidth.length; k++)
lineWidth[k] = j;
}
super.hasChanged = true;
autoRepaint();
}
/**
* @deprecated Method getLineWidth is deprecated
*/
public int getLineWidth()
{
return getLineWidth(0);
}
public int getLineWidth(int i)
{
if(i >= 0 && i < lineWidth.length)
return lineWidth[i];
else
return lineWidth[0];
}
public void setValueLabelStyle(int i)
{
valueLabelStyle = i;
super.hasChanged = true;
autoRepaint();
}
public int getValueLabelStyle()
{
return valueLabelStyle;
}
public boolean isSampleHighlightOn(int i, int j)
{
try
{
return sampleHighlightOn[i][j];
}
catch(IndexOutOfBoundsException _ex)
{
throw new IllegalArgumentException("Invalid series or index: " + i + ", " + j);
}
}
public ChartSample checkSelection(Point point)
{
if(point == null)
return null;
ChartSample chartsample = null;
getSeriesCount();
if(isLegendOn() && super.legendBounds != null)
{
for(int i = 0; i < super.legendBounds.length; i++)
{
if(super.legendBounds[i] == null || !super.legendBounds[i].contains(point))
continue;
chartsample = new ChartSample(-1);
chartsample.setSeries(i);
break;
}
}
if(chartsample == null && samplePosition != null)
{
byte byte0 = 3;
for(int j = 0; j < samplePosition.length; j++)
{
Point apoint[] = samplePosition[j];
if(apoint != null)
{
for(int k = 0; k < apoint.length; k++)
if(apoint[k] != null)
{
Point point1 = new Point(apoint[k]);
if(is3DModeOn())
{
point1.x -= super.depth3dPoint.x;
if(!stackedOn)
{
double d = (double)super.depth3dPoint.x / (double)getSeriesCount();
int l = (int)Math.round(d * (double)j);
point1.x += l;
}
}
boolean flag = point.x >= point1.x - byte0 && point.x <= point1.x + byte0;
flag &= point.y >= point1.y - byte0 && point.y <= point1.y + byte0;
if(flag)
return getSample(j, k);
}
}
}
}
return chartsample;
}
protected void renderData(Graphics g, Rectangle rectangle, Rectangle rectangle1)
{
paintLines(g, rectangle, rectangle1);
}
public void reset()
{
super.reset();
valueLabelStyle = 0;
autoLabelSpacingOn = false;
super.multiSeriesOn = true;
selectedSample = -1;
selectedSeries = -1;
super.hasChanged = true;
}
public void setSampleColors(Color acolor[])
{
super.setSampleColors(acolor);
if(acolor == null)
setSampleColor(2, new Color(132, 255, 198));
super.hasChanged = true;
autoRepaint();
}
public LineChart()
{
this(1, 5, 100D);
}
public LineChart(int i, int j, double d)
{
this(i, j, d, 0.0D);
}
public LineChart(int i, int j, double d, double d1)
{
super(j);
super.chartType = "line";
super.multiSeriesOn = true;
sampleHighlightOn = new boolean[i][j];
sampleHighlightStyle = new int[i];
sampleHighlightSize = new int[i];
seriesLinesOn = new boolean[i];
lineWidth = new int[i];
for(int k = 0; k < sampleHighlightSize.length; k++)
{
sampleHighlightSize[k] = 6;
seriesLinesOn[k] = true;
lineWidth[k] = 2;
}
connectedLinesOn = new boolean[i];
samplePosition = new Point[i][j];
for(int l = 0; l < samplePosition.length; l++)
{
for(int i1 = 0; i1 < samplePosition[l].length; i1++)
samplePosition[l][i1] = new Point();
}
mousePosition = new Point();
setAutomaticRepaintOn(false);
setSeriesCount(i);
setRange(0, d);
setLowerRange(0, d1);
setSampleColors(null);
setAutomaticRepaintOn(true);
selectedSample = -1;
selectedSeries = -1;
lastSelectedLine = -1;
}
private void paintLine(Graphics g, int i, Rectangle rectangle, Rectangle rectangle1, Color color, boolean flag)
{
int j = getSeriesCount();
if(i < 0 || i >= j)
throw new IllegalArgumentException("Invalid series: " + i);
if(flag)
lastSelectedLine = i;
ChartSample achartsample[] = getSamples(i);
if(achartsample == null || achartsample.length == 0)
return;
double d = rectangle1.width;
if(achartsample.length - 1 > 0)
d = (double)(rectangle1.width - 1) / (double)(achartsample.length - 1);
Color color1 = !stackedOn && !flag ? color : color.darker();
boolean flag1 = is3DModeOn();
Graphics g1 = g;
if(flag1)
g1.setClip((rectangle.x - super.depth3dPoint.x) + 1, rectangle.y + 1, (rectangle.width + super.depth3dPoint.x) - 1, rectangle.height - super.depth3dPoint.y - 1);
else
g1.setClip(rectangle.x + 1, rectangle.y, rectangle.width - 1, rectangle.height + 1);
double d1 = rectangle1.x + 1;
int ai[] = new int[4];
int ai1[] = new int[4];
boolean flag2 = false;
double d2 = d1;
double d3 = calculateYPos(i, 0, rectangle1);
for(int k = 0; k < achartsample.length - 1; k++)
{
boolean flag3 = achartsample[k] != null && achartsample[k].value != null && !achartsample[k].value.isNaN();
boolean flag4 = achartsample[k + 1] != null && achartsample[k + 1].value != null && !achartsample[k + 1].value.isNaN();
if(flag3)
{
d2 = d1;
d3 = calculateYPos(i, k, rectangle1);
flag2 = true;
}
boolean flag5 = flag3 && flag4;
flag5 |= flag4 && connectedLinesOn[i];
if(flag5 && flag2)
{
if(connectedLinesOn[i])
{
ai[0] = (int)d2;
ai1[0] = (int)d3;
} else
{
ai[0] = (int)d1;
ai1[0] = calculateYPos(i, k, rectangle1);
}
ai[1] = (int)(d1 + d);
ai1[1] = calculateYPos(i, k + 1, rectangle1);
if(flag1)
{
ai[0] -= super.depth3dPoint.x;
ai[1] -= super.depth3dPoint.x;
ai[2] -= super.depth3dPoint.x;
ai[3] -= super.depth3dPoint.x;
if(!stackedOn)
{
double d4 = (double)super.depth3dPoint.x / (double)j;
int i2 = (int)Math.round(d4 * (double)i);
ai[0] += i2;
ai[1] += i2;
ai[2] += i2;
ai[3] += i2;
}
}
if(stackedOn)
{
ai[2] = ai[1];
ai1[2] = calculateYPos(i - 1, k + 1, rectangle1);
ai[3] = ai[0];
ai1[3] = calculateYPos(i - 1, k, rectangle1);
}
boolean flag7 = false;
int l1 = rectangle.x - (flag1 ? super.depth3dPoint.x * 2 : 0);
int j2 = rectangle.x + rectangle.width;
flag7 |= ai[0] >= l1 && ai[0] <= j2;
flag7 |= ai[1] >= l1 && ai[1] <= j2;
flag7 |= ai[0] <= l1 && ai[1] >= j2;
if(flag7)
{
ai[0] = Math.max(ai[0], -10000);
ai[1] = Math.max(ai[1], -10000);
ai[0] = Math.min(ai[0], 11000);
ai[1] = Math.min(ai[1], 11000);
ai1[0] = Math.max(ai1[0], -10000);
ai1[1] = Math.max(ai1[1], -10000);
ai1[0] = Math.min(ai1[0], 11000);
ai1[1] = Math.min(ai1[1], 11000);
if(seriesLinesOn[i])
if(flag1 && stackedOn)
{
boolean flag8 = i == j - 1;
boolean flag9 = k == achartsample.length - 2;
if(k < achartsample.length - 2)
{
flag9 |= achartsample[k + 2] == null || achartsample[k + 2].value == null || achartsample[k + 2].value.isNaN();
flag9 &= !connectedLinesOn[i];
}
paint3DLine(g1, ai[0], ai1[0], ai[1], ai1[1], ai1[2], color1, flag8, flag9);
} else
if(flag1)
paint3DLine(g1, ai[0], ai1[0], ai[1], ai1[1], ai1[2], color1, true, false);
if(stackedOn && seriesLinesOn[i])
{
g1.setColor(flag ? color.darker() : color);
g1.fillPolygon(ai, ai1, 4);
g1.setColor(color.darker());
g1.drawLine(ai[1], ai1[1], ai[2], ai1[2]);
}
g1.setColor(color);
if(flag1 && stackedOn)
g1.setColor(color.darker().darker());
else
if(flag1 || stackedOn)
g1.setColor(color.darker());
if(seriesLinesOn[i] || flag)
{
g1.drawLine(ai[0], ai1[0], ai[1], ai1[1]);
if(!flag1 && !stackedOn && lineWidth[i] > 1 && (seriesLinesOn[i] || flag))
{
double d5 = 0.0D;
if(ai[1] - ai[0] != 0)
d5 = Math.abs((double)(ai1[1] - ai1[0]) / (double)(ai[1] - ai[0]));
int k2 = 1;
for(int i3 = 2; i3 <= lineWidth[i]; i3++)
{
int j3 = (i3 / 2) * k2;
if(d5 <= 1.0D)
g1.drawLine(ai[0], ai1[0] + j3, ai[1], ai1[1] + j3);
else
g1.drawLine(ai[0] - j3, ai1[0], ai[1] - j3, ai1[1]);
k2 = -k2;
}
}
}
if(flag && seriesLinesOn[i] && !flag1 && !stackedOn)
{
double d6 = 0.0D;
if(ai[1] - ai[0] != 0)
d6 = Math.abs((double)(ai1[1] - ai1[0]) / (double)(ai[1] - ai[0]));
int l2 = lineWidth[i] / 2 + 1;
g1.setColor(color.darker().darker());
if(d6 <= 1.0D)
g1.drawLine(ai[0], ai1[0] + l2, ai[1], ai1[1] + l2);
else
g1.drawLine(ai[0] - l2, ai1[0], ai[1] - l2, ai1[1]);
}
}
}
d1 += d;
}
if(!flag1)
{
d1 = rectangle1.x + 1;
for(int l = 0; l < achartsample.length; l++)
{
ChartSample chartsample = achartsample[l];
if(chartsample != null && chartsample.value != null && !chartsample.value.isNaN() && sampleHighlightOn[i][l])
{
int k1 = calculateYPos(i, l, rectangle1);
boolean flag6 = k1 >= rectangle.y && k1 <= rectangle.y + rectangle.height && d1 >= (double)rectangle.x && d1 <= (double)(rectangle.x + rectangle.width + 1);
if(flag6)
paintSampleHighlight(g, i, (int)Math.round(d1), k1, color);
}
d1 += d;
}
}
d1 = rectangle1.x + 1;
for(int i1 = 0; i1 < achartsample.length; i1++)
{
int j1 = calculateYPos(i, i1, rectangle1);
if(samplePosition != null && i < samplePosition.length && samplePosition[i] != null && i1 < samplePosition[i].length && samplePosition[i][i1] != null)
{
samplePosition[i][i1].x = (int)Math.round(d1);
samplePosition[i][i1].y = Math.round(j1);
}
d1 += d;
}
g.setClip(0, 0, 32767, 32767);
}
public boolean isAutoLabelSpacingOn()
{
return autoLabelSpacingOn;
}
public boolean isStackedOn()
{
return stackedOn;
}
public boolean isConnectedLinesOn(int i)
{
if(i >= 0 && i < connectedLinesOn.length)
return connectedLinesOn[i];
if(i == -1)
{
boolean flag = false;
for(int j = 0; j < connectedLinesOn.length; j++)
if(connectedLinesOn[j])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -