//int pixelInterval;
double graphTop;
double value, valueSum;
boolean graphBreak;
SummaryData summary;
DataLabel label;
int labelWidth, labelHeight, labelPadding;
FragmentedColumn fragmentedColumn;
int centerX;
int centerY;
String textString;
panelWidth = getWidth();
panelHeight = getHeight();
if ( panelWidth != context.getPanelWidth() || panelHeight != context.getPanelHeight() ) {
logger.debug("Adjusting panel width to " + panelWidth + " and panel height to " + panelHeight);
context.setPanelWidth(panelWidth);
context.setPanelHeight(panelHeight);
context.generateSummaryData();
revalidate();
}
synchronized(context.getData()) {
//logger.debug("Painting TimeSeriesDataPanel: panelWidth=" + panelWidth + " panelHeight=" + panelHeight);
synchronized(context.getSummarySemaphore()) {
synchronized(game.getLandscape()) {
summary = context.getSummaryData();
if ( summary == null )
return;
graphTop = context.getGraphTop();
xOffset = panelWidth - summary.getNumberOfPoints();
g.clearRect(0, 0, panelWidth - 1, panelHeight - 1);
// Draw grid markings if behind
if ( context.horizontalGridLines() && ! context.linesInFront() ) {
drawHorizontalGridLines(g, panelWidth, panelHeight);
}
if ( context.verticalGridLines() && ! context.linesInFront() ) {
drawVerticalGridLines(g, summary, panelWidth, panelHeight);
}
if ( context.getSetsPositioning() == SetDisplay.Positioning.Grounded ) {
// not supported
} else if ( context.getSetsPositioning() == SetDisplay.Positioning.Stacked ) {
for ( point = 0 ; point < summary.getNumberOfPoints() ; point++ ) {
x = xOffset + point;
fragmentedColumn = game.getLandscape().getFragmentedColumnAt(x);
if ( fragmentedColumn == null || fragmentedColumn.size() == 0 ) {
valueSum = 0;
for ( set = 0 ; set < summary.getNumberOfSets() ; set++ ) {
g.setColor(context.getSetDisplayColor(set));
value = summary.getValue(set, point);
if ( ! Double.isNaN(value) ) {
oldy = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
valueSum += value;
y = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
if ( value > 0 )
g.drawLine(x, oldy, x, y);
}
}
}
// column is fragmented
else {
int fragmentNumber;
double fragmentTop;
Fragment fragment;
int startY;
int endY;
double partOfLine;
double initialOffset;
valueSum = 0;
fragmentNumber = 0;
fragment = fragmentedColumn.elementAt(fragmentNumber);
fragmentTop = fragment.getLength();
startY = 0;
initialOffset = 0;
for ( set = 0 ; set < summary.getNumberOfSets() ; set++ ) {
g.setColor(context.getSetDisplayColor(set));
value = summary.getValue(set, point);
partOfLine = value;
if ( ! Double.isNaN(value) ) {
while ( fragmentTop < initialOffset + partOfLine && fragmentNumber < fragmentedColumn.size() ) {
//startY = (int)(panelHeight - 1 - ( ( fragment.getPosition() + initialOffset ) * panelHeight / graphTop ) );
//endY = (int)(panelHeight - 1 - ( ( fragment.getPosition() + fragment.getLength() ) * panelHeight / graphTop) );
startY = context.getYPixelFromValue(fragment.getPosition() + initialOffset);
endY = context.getYPixelFromValue(fragment.getPosition() + fragment.getLength() );
g.drawLine(x, startY, x, endY);
partOfLine -= (fragment.getLength() - initialOffset);
initialOffset = 0;
fragmentNumber++;
// Fix: Next line sometimes throws an ArrayIndexOutOfBoundsException
if ( fragmentNumber < fragmentedColumn.size() ) {
fragment = fragmentedColumn.elementAt(fragmentNumber);
fragmentTop = fragment.getLength();
}
}
//startY = (int)(panelHeight - 1 - ( ( fragment.getPosition() + initialOffset ) * panelHeight / graphTop ) );
//endY = (int)(panelHeight - 1 - ( ( fragment.getPosition() + initialOffset + partOfLine ) * panelHeight / graphTop) );
startY = context.getYPixelFromValue(fragment.getPosition() + initialOffset);
endY = context.getYPixelFromValue(fragment.getPosition() + initialOffset + partOfLine);
g.drawLine(x, startY, x, endY);
initialOffset += partOfLine;
//oldy = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
//valueSum += value;
//y = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
//if ( value > 0 || set == 0 )
// g.drawLine(x, oldy, x, y);
}
}
}
}
}
if ( context.horizontalGridLines() && context.linesInFront() ) {
drawHorizontalGridLines(g, panelWidth, panelHeight);
}
if ( context.verticalGridLines() && context.linesInFront() ) {
drawVerticalGridLines(g, summary, panelWidth, panelHeight);
}
// Draw labels
if ( context.getShowLabels() ) {
g.setColor(Color.BLACK);
for ( int i = 0; i < context.getData().getLabels().getLabelCount() ; i++ ) {
label = context.getData().getLabels().getLabel(i);
x = context.getXPixelFromTime(label.getTime());
y = context.getYPixelFromValue(label.getValue());
if ( label.getTime() > summary.getOriginTime(panelWidth) && label.getTime() < summary.getLastTime() ) {
if ( label.getValue() < context.getGraphTop() ) {
labelWidth = g.getFontMetrics().stringWidth(label.getLabel());
//labelHeight = g.getFontMetrics().getAscent() + g.getFontMetrics().getDescent();
labelHeight = g.getFontMetrics().getAscent();
//labelPadding = g.getFontMetrics().getLeading();
//labelPadding = 4;
g.clearRect(x - labelWidth / 2 - LABEL_PADDING, y - labelHeight - LABEL_PADDING, labelWidth + LABEL_PADDING * 2, labelHeight + LABEL_PADDING * 2 );
g.drawRect(x - labelWidth / 2 - LABEL_PADDING, y - labelHeight - LABEL_PADDING, labelWidth + LABEL_PADDING * 2, labelHeight + LABEL_PADDING * 2 );
g.drawString(label.getLabel(), x - labelWidth / 2, y);
}
}
}
}
}