1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 import java.util.*; 29 30 31 45 final class LBChartArea extends GraphChartArea { 46 47 48 private Rectangle maxBounds; 49 private Rectangle minBounds; 50 private Dimension prefSize; 51 private XAxisArea xAxis; 52 private YAxisArea yAxis; 53 private LegendArea legend; 54 private boolean needsUpdate; 55 56 57 60 LBChartArea() { 61 62 xAxis = getXAxis(); 63 yAxis = getYAxis(); 64 legend = getLegend(); 65 minBounds = new Rectangle(); 66 needsUpdate = true; 67 } 68 69 70 78 final Dimension getPrefSize (Graphics2D g2D) { 79 80 updateLBChartArea (g2D); 81 return prefSize; 82 } 83 84 85 89 final boolean getLBChartAreaNeedsUpdate() { 90 91 if (needsUpdate || getGraphChartAreaNeedsUpdate()) return true; 92 Vector graphVector = getGraphVector(); 93 for (int i = 0; i < graphVector.size(); ++i) { 94 if (((LBGraphArea)graphVector.get (i)).getLBGraphAreaNeedsUpdate()) 95 return true; 96 } 97 return false; 98 } 99 100 101 112 final void resetLBChartAreaModel (boolean reset) { 113 114 needsUpdate = true; 115 resetGraphChartAreaModel (reset); 116 Vector graphVector = this.getGraphVector(); 117 for (int i = 0; i < graphVector.size(); ++i) { 118 ((LBGraphArea)graphVector.get (i)).resetLBGraphAreaModel (reset); 119 } 120 } 121 122 123 127 final void updateLBChartArea (Graphics2D g2D) { 128 129 if (getLBChartAreaNeedsUpdate()) { 130 131 updateGraphChartArea (g2D); 132 update (g2D); 133 134 Vector graphVector = getGraphVector(); 135 for (int i = 0; i < graphVector.size(); ++i) { 136 ((LBGraphArea)graphVector.get (i)).updateLBGraphArea(); 137 } 138 139 Vector warningRegions = getWarningRegions(); 140 for (int i = 0; i < warningRegions.size(); ++i) { 141 ((WarningRegion)warningRegions.get (i)).updateWarningRegion(); 142 } 143 144 legend.updateLegendArea (g2D); 145 xAxis.updateXAxisArea (g2D); 146 yAxis.updateYAxisArea (g2D); 147 } 148 needsUpdate = false; 149 } 150 151 152 156 final void paintComponent (Graphics2D g2D) { 157 158 updateLBChartArea (g2D); 159 super.paintComponent (g2D); 160 161 Vector graphVector = getGraphVector(); 162 for (int i = graphVector.size() - 1; i >= 0; --i) { 163 ((LBGraphArea)graphVector.get (i)).paintComponent (g2D); 164 } 165 } 166 167 168 private void update (Graphics2D g2D) { 169 170 Vector graphVector = getGraphVector(); 171 Vector datasetVector = getDatasetVector(); 172 173 int colorOffset = 0; 174 for (int i = 0; i < graphVector.size(); ++i) { 175 176 int datasetsLength = ((Dataset)datasetVector.get (i)).getNumSets(); 177 Color[] graphColors = getDatasetColors (colorOffset, colorOffset + datasetsLength); 178 179 LBGraphArea thisGraph = (LBGraphArea)graphVector.get(i); 180 thisGraph.setBarColors (graphColors); 181 thisGraph.setDotColors (graphColors); 182 thisGraph.setLineColors (graphColors); 183 thisGraph.setWarningRegions (getWarningRegions()); 184 thisGraph.setComponentsColoringByCat (getGraphComponentsColoringByCat()); 185 thisGraph.setComponentsColorsByCat (getGraphComponentsColorsByCat()); 186 colorOffset += datasetsLength; 187 } 188 189 float widthRatio = getRatio (WIDTH); 190 float heightRatio = getRatio (HEIGHT); 191 xAxis.setCustomRatio (WIDTH, true, widthRatio); 192 xAxis.setCustomRatio (HEIGHT, true, heightRatio); 193 yAxis.setCustomRatio (WIDTH, true, widthRatio); 194 yAxis.setCustomRatio (HEIGHT, true, heightRatio); 195 legend.setCustomRatio (WIDTH, true, widthRatio); 196 legend.setCustomRatio (HEIGHT, true, heightRatio); 197 for (int i = 0; i < graphVector.size(); ++i) { 198 ((LBGraphArea)graphVector.get(i)).setCustomRatio (WIDTH, true, widthRatio); 199 ((LBGraphArea)graphVector.get(i)).setCustomRatio (HEIGHT, true, heightRatio); 200 ((LBGraphArea)graphVector.get(i)).setLabelsAxisTicksAlignment (xAxis.getTicksAlignment()); 201 } 202 203 maxBounds = getMaxEntitledSpaceBounds (g2D); 204 205 float xAxisToHeightRatio = getXAxisToHeightRatio(); 206 float yAxisToHeightRatio = getYAxisToHeightRatio(); 207 float graphToHeightRatio = getGraphToHeightRatio(); 208 float legendToHeightRatio = getLegendToHeightRatio(); 209 210 float xAxisToWidthRatio = getXAxisToWidthRatio(); 211 float yAxisToWidthRatio = getYAxisToWidthRatio(); 212 float graphToWidthRatio = getGraphToWidthRatio(); 213 float legendToWidthRatio = getLegendToWidthRatio(); 214 215 int betweenChartAndLegendGapThickness = 0; 216 int availableWidth = maxBounds.width; 217 if (getBetweenChartAndLegendGapExistence() && getLegendExistence()) { 218 betweenChartAndLegendGapThickness = 219 applyRatio (getBetweenChartAndLegendGapThicknessModel(), getRatio (WIDTH)); 220 betweenChartAndLegendGapThickness = 221 betweenChartAndLegendGapThickness <= availableWidth ? 222 betweenChartAndLegendGapThickness : availableWidth; 223 availableWidth -= betweenChartAndLegendGapThickness; 224 } 225 226 int width = 0, height = 0; 227 if (getLegendExistence()) { 228 height = (int)(legendToHeightRatio * maxBounds.height); 229 width = (int)(legendToWidthRatio * availableWidth); 230 } 231 legend.setSize (MAX, new Dimension (width, height)); 232 233 VerticalTextListArea yTextList = yAxis.getTextList(); 234 yTextList.setCustomSpaceMinHeight (false, 0); 235 height = (int)(yAxisToHeightRatio * maxBounds.height); 236 width = (int)(yAxisToWidthRatio * availableWidth); 237 yAxis.setSize (MAX, new Dimension (width, height)); 238 239 HorizontalTextListArea xTextList = xAxis.getTextList(); 240 xTextList.setCustomSpaceMinWidth (false, 0); 241 height = (int)(xAxisToHeightRatio * maxBounds.height); 242 width = (int)(xAxisToWidthRatio * availableWidth); 243 xAxis.setSize (MAX, new Dimension (width, height)); 244 245 height = (int)(graphToHeightRatio * maxBounds.height); 246 width = (int)(graphToWidthRatio * availableWidth); 247 for (int i = 0; i < graphVector.size(); ++i) { 248 ((LBGraphArea)graphVector.get(i)).setSize (MAX, new Dimension (width, height)); 249 } 250 251 xAxis.setNumTicks (xTextList.getNumBullets()); yAxis.setNumTicks (getNumPlotAxisLabels()); 254 float greatestValue = -9999999999999999f; 255 float leastValue = 9999999999999999f; 256 for (int i = 0; i < datasetVector.size(); ++i) { 257 greatestValue = 258 ((Dataset)datasetVector.get (i)).getGreatest() > greatestValue ? 259 ((Dataset)datasetVector.get (i)).getGreatest() : greatestValue; 260 leastValue = 261 ((Dataset)datasetVector.get (i)).getLeast() < leastValue ? 262 ((Dataset)datasetVector.get (i)).getLeast() : leastValue; 263 } 264 265 greatestValue = getCustomizeGreatestValue() && (getCustomGreatestValue() > greatestValue) 266 ? getCustomGreatestValue() : greatestValue; 267 leastValue = getCustomizeLeastValue() && (getCustomLeastValue() < leastValue) 268 ? getCustomLeastValue() : leastValue; 269 270 float maxValue = getGraphableToAvailableRatio() > 0 ? 271 (greatestValue - leastValue) / getGraphableToAvailableRatio() : 0f; 272 float emptyValue = maxValue - (greatestValue - leastValue); 273 274 int dataSign = GraphArea.NEG; 275 if (greatestValue > 0f && leastValue < 0f) { 276 greatestValue = greatestValue + (emptyValue / 2f); 277 leastValue = leastValue - (emptyValue / 2f); 278 float nomValue = Math.abs (greatestValue) > Math.abs (leastValue) ? 279 Math.abs (greatestValue) : Math.abs (leastValue); 280 greatestValue = nomValue; 281 leastValue = -nomValue; 282 dataSign = GraphArea.MIX; 283 } 284 else if (greatestValue >= 0f && leastValue >= 0f) { 285 greatestValue = greatestValue + emptyValue; 286 if (!getCustomizeLeastValue()) leastValue = 0f; 287 dataSign = GraphArea.POS; 288 } 289 else { 290 leastValue = leastValue - emptyValue; 291 if (!getCustomizeGreatestValue()) greatestValue = 0f; 292 } 293 294 int precisionNum = getLabelsPrecisionNum(); 295 greatestValue = getPrecisionCeil (greatestValue, precisionNum); 296 leastValue = getPrecisionFloor (leastValue, precisionNum); 297 maxValue = greatestValue - leastValue; 298 299 float difference = 0; 300 float label = 0; 301 if (getNumPlotAxisLabels() > 1) { 302 difference = maxValue / (getNumPlotAxisLabels() - 1); 303 label = leastValue; 304 } 305 else { 306 label = maxValue / 2f; 307 } 308 309 String [] labels = new String [getNumPlotAxisLabels()]; 310 String lastLabel = null; 311 for (int i = getNumPlotAxisLabels() - 1; i >= 0 ; --i) { 312 float sign = label > 0 ? 1f : -1f; 313 if (i == getNumPlotAxisLabels() - 1 || i == 0) { 314 labels[i] = getFloatToString ( 315 sign * getPrecisionRound (sign * label, precisionNum), precisionNum); 316 } 317 else { 318 labels[i] = getFloatToString (label, precisionNum); 319 } 320 label += difference; 321 if (labels[i].equals (lastLabel)) labels[i] = "^"; 322 else lastLabel = labels[i]; 323 } 324 yAxis.getTextList().setLabels (labels); 325 326 int graphPrefWidth = 0; 327 for (int i = 0; i < graphVector.size(); ++i) { 328 int numSets = ((Dataset)datasetVector.get (i)).getNumSets(); 329 int numCats = ((Dataset)datasetVector.get (i)).getNumCats(); 330 int numCompsPerCat = ((Dataset)datasetVector.get (i)).getNumItems(); 331 int tempWidth = 332 ((LBGraphArea)graphVector.get (i)).getPrefSpaceWidth (numSets, numCats, numCompsPerCat); 333 graphPrefWidth = tempWidth > graphPrefWidth ? tempWidth : graphPrefWidth; 334 ((LBGraphArea)graphVector.get(i)).setDataSign (dataSign); 335 } 336 337 xTextList.setCustomSpaceMinWidth (true, graphPrefWidth); 338 xAxis.updateXAxisArea (g2D); 339 int minSpaceWidth = xAxis.getSpaceSize (MIN).width; 340 341 yAxis.updateYAxisArea (g2D); 342 int minSpaceHeight = 0; 343 Rectangle[] yAxisTicks = yAxis.getTicks (g2D); 344 if (yAxisTicks.length > 0) { 345 minSpaceHeight = yAxisTicks[yAxisTicks.length - 1].y - yAxisTicks[0].y + yAxisTicks[0].height; 346 } 347 348 Dimension minGraphSpaceSize = new Dimension (minSpaceWidth, minSpaceHeight); 349 for (int i = 0; i < graphVector.size(); ++i) { 350 ((LBGraphArea)graphVector.get(i)).setSpaceSize (MIN, minGraphSpaceSize); 351 } 352 353 LBGraphArea graphFirst = (LBGraphArea)graphVector.get (graphVector.size() - 1); 354 int graphMinSizeWidth = 0; 355 int graphMinSizeHeight = 0; 356 if (graphVector.size() > 0) { 357 graphMinSizeWidth = graphFirst.getSize(MIN).width; 358 graphMinSizeHeight = graphFirst.getSize(MIN).height; 359 } 360 361 legend.updateLegendArea(g2D); 362 363 int width1 = yAxis.getSize(MIN).width + graphMinSizeWidth + 364 betweenChartAndLegendGapThickness + legend.getSize(MIN).width; 365 int width2 = yAxis.getSize(MIN).width + xAxis.getSize (MIN).width + 366 betweenChartAndLegendGapThickness + legend.getSize(MIN).width; 367 width = width1 > width2 ? width1 : width2; 368 369 int topTickY = yAxis.getTicks(g2D)[0].y; 370 int titleTopY = yAxis.getSizeLocation(MIN).y + 371 (int)((yAxis.getSize(MIN).height - 372 yAxis.getTitle().getSize(MIN).height) / 2f); 373 int labelTopY = yTextList.getLabels(g2D)[0].getSizeLocation(MIN).y; 374 int graphTopY = topTickY - graphFirst.getBorderThickness (TOP); 375 int topY = titleTopY < labelTopY ? titleTopY : labelTopY; 376 topY = topY < graphTopY ? topY : graphTopY; 377 378 int bottomTickY = yAxis.getTicks(g2D)[yAxis.getTicks(g2D).length-1].y; 379 int tickHeight = yAxis.getTicks(g2D)[0].height; 380 int graphBottomY = bottomTickY + tickHeight + graphFirst.getBorderThickness (BOTTOM); 382 int titleBottomY = titleTopY + yAxis.getTitle().getSize(MIN).height; TextArea yAxisLabelBottom = 384 yTextList.getLabels(g2D)[yTextList.getLabels(g2D).length-1]; 385 int labelBottomY = yAxisLabelBottom.getSizeLocation(MIN).y + yAxisLabelBottom.getSize(MIN).height; 387 int xAxisBottomY = graphBottomY + xAxis.getSize(MIN).height; int bottomY = titleBottomY > labelBottomY ? titleBottomY : labelBottomY; 389 bottomY = bottomY > xAxisBottomY ? bottomY : xAxisBottomY; 390 391 int height1 = legend.getSize(MIN).height; 392 int height2 = (bottomY - topY); 393 height = height1 > height2 ? height1 : height2; 394 int heightForDeficient = (labelBottomY > xAxisBottomY ? labelBottomY : xAxisBottomY) - 395 (labelTopY < graphTopY ? labelTopY : graphTopY); 396 397 if (getAutoSetLayoutRatios()) { 398 399 yAxisToWidthRatio = width > 0 ? yAxis.getSize (MIN).width / (float)width : 0f; 400 yAxisToWidthRatio = yAxisToWidthRatio < 1f ? yAxisToWidthRatio : 1f; 401 xAxisToWidthRatio = width > 0 ? xAxis.getSize (MIN).width / (float)width : 0f; 402 xAxisToWidthRatio = xAxisToWidthRatio < 1f ? xAxisToWidthRatio : 1f; 403 graphToWidthRatio = width > 0 ? graphMinSizeWidth / (float)width : 0f; 404 graphToWidthRatio = graphToWidthRatio < 1f ? graphToWidthRatio : 1f; 405 if (xAxisToWidthRatio > graphToWidthRatio) graphToWidthRatio = xAxisToWidthRatio; 406 else xAxisToWidthRatio = graphToWidthRatio; 407 408 yAxisToHeightRatio = height > 0 ? yAxis.getSize (MIN).height / (float)height : 0f; 409 yAxisToHeightRatio = yAxisToHeightRatio < 1f ? yAxisToHeightRatio : 1f; 410 xAxisToHeightRatio = height > 0 ? xAxis.getSize (MIN).height / (float)height : 0f; 411 xAxisToHeightRatio = xAxisToHeightRatio < 1f ? xAxisToHeightRatio : 1f; 412 graphToHeightRatio = height > 0 ? graphMinSizeHeight / (float)height : 0f; 413 graphToHeightRatio = graphToHeightRatio < 1f ? graphToHeightRatio : 1f; 414 if (yAxisToHeightRatio > graphToHeightRatio) graphToHeightRatio = yAxisToHeightRatio; 415 else yAxisToHeightRatio = graphToHeightRatio; 416 417 if (yAxisToWidthRatio <= 0f || yAxisToHeightRatio <= 0f) { 418 yAxisToWidthRatio = yAxisToHeightRatio = 0f; 419 } 420 if (xAxisToWidthRatio <= 0f || xAxisToHeightRatio <= 0f) { 421 xAxisToWidthRatio = xAxisToHeightRatio = 0f; 422 } 423 if (graphToWidthRatio <= 0f || graphToHeightRatio <= 0f) { 424 graphToWidthRatio = graphToHeightRatio = 0f; 425 } 426 legendToWidthRatio = 1f - yAxisToWidthRatio - graphToWidthRatio; 427 legendToHeightRatio = 1f; 428 if (legendToWidthRatio <= 0f || legendToHeightRatio <= 0f) { 429 legendToWidthRatio = legendToHeightRatio = 0f; 430 } 431 432 setYAxisToWidthRatio (yAxisToWidthRatio); 433 setXAxisToWidthRatio (xAxisToWidthRatio); 434 setGraphToWidthRatio (graphToWidthRatio); 435 setLegendToWidthRatio (legendToWidthRatio); 436 437 setYAxisToHeightRatio (yAxisToHeightRatio); 438 setXAxisToHeightRatio (xAxisToHeightRatio); 439 setGraphToHeightRatio (graphToHeightRatio); 440 setLegendToHeightRatio (legendToHeightRatio); 441 442 setAutoSetLayoutRatios (false); 443 } 444 445 Dimension titleSize = getTitleSize (MIN, g2D); 446 int widthForDeficient = width; 447 width = width > titleSize.width ? width : titleSize.width; 448 int prefWidth = width + (getSize (MIN).width - getSpaceSize (MIN).width); 449 int prefHeight = 450 height + (getSize (MIN).height - getSpaceSize (MIN).height) + 451 titleSize.height + getBetweenTitleAndSpaceGapThickness (g2D); 452 prefSize = new Dimension ((int)(1.3f * prefWidth), (int)(1.3f * prefHeight)); 453 454 int deficientHeight = 0; 455 int deficientWidth = 0; 456 if (getAutoSize (MIN)) { 457 deficientWidth = maxBounds.width - widthForDeficient; 458 deficientHeight = maxBounds.height - heightForDeficient; 459 } 460 else { 461 deficientWidth = width - widthForDeficient; 462 deficientHeight = height - heightForDeficient; 463 } 464 465 graphPrefWidth = minSpaceWidth + deficientWidth; 466 xTextList.setCustomSpaceMinWidth (true, graphPrefWidth); 467 xAxis.updateXAxisArea (g2D); 468 minSpaceWidth = xAxis.getSpaceSize (MIN).width; 469 470 deficientHeight += (deficientHeight / getNumPlotAxisLabels()); 471 int yAxisPrefHeight = yTextList.getSize(MIN).height + deficientHeight; 472 yTextList.setCustomSpaceMinHeight (true, yAxisPrefHeight); 473 474 yAxis.updateYAxisArea (g2D); 475 minSpaceHeight = 0; 476 yAxisTicks = yAxis.getTicks (g2D); 477 if (yAxisTicks.length > 0) { 478 minSpaceHeight = yAxisTicks[yAxisTicks.length - 1].y - 479 yAxisTicks[0].y + yAxisTicks[0].height; 480 } 481 482 minGraphSpaceSize = new Dimension (minSpaceWidth, minSpaceHeight); 483 for (int i = 0; i < graphVector.size(); ++i) { 484 ((LBGraphArea)graphVector.get(i)).setSpaceSize (MIN, minGraphSpaceSize); 485 } 486 487 graphMinSizeWidth = 0; 488 graphMinSizeHeight = 0; 489 if (graphVector.size() > 0) { 490 graphMinSizeWidth = graphFirst.getSize(MIN).width; 491 graphMinSizeHeight = graphFirst.getSize(MIN).height; 492 } 493 494 legend.updateLegendArea(g2D); 495 496 width1 = yAxis.getSize(MIN).width + graphMinSizeWidth + 497 betweenChartAndLegendGapThickness + legend.getSize(MIN).width; 498 width2 = yAxis.getSize(MIN).width + xAxis.getSize (MIN).width + 499 betweenChartAndLegendGapThickness + legend.getSize(MIN).width; 500 width = width1 > width2 ? width1 : width2; 501 width = width > titleSize.width ? width : titleSize.width; 502 503 topTickY = yAxis.getTicks(g2D)[0].y; 504 titleTopY = yAxis.getSizeLocation(MIN).y + 505 (int)((yAxis.getSize(MIN).height - 506 yAxis.getTitle().getSize(MIN).height) / 2f); 507 labelTopY = yTextList.getLabels(g2D)[0].getSizeLocation(MIN).y; 508 graphTopY = topTickY - graphFirst.getBorderThickness (TOP); 509 topY = titleTopY < labelTopY ? titleTopY : labelTopY; 510 topY = topY < graphTopY ? topY : graphTopY; 511 512 bottomTickY = yAxis.getTicks(g2D)[yAxis.getTicks(g2D).length-1].y; 513 tickHeight = yAxis.getTicks(g2D)[0].height; 514 graphBottomY = bottomTickY + tickHeight + 515 graphFirst.getBorderThickness (BOTTOM); 516 titleBottomY = titleTopY + yAxis.getTitle().getSize(MIN).height; 517 yAxisLabelBottom = 518 yTextList.getLabels(g2D)[yTextList.getLabels(g2D).length-1]; 519 labelBottomY = yAxisLabelBottom.getSizeLocation(MIN).y + 520 yAxisLabelBottom.getSize(MIN).height; 521 xAxisBottomY = graphBottomY + xAxis.getSize(MIN).height; 522 bottomY = titleBottomY > labelBottomY ? titleBottomY : labelBottomY; 523 bottomY = bottomY > xAxisBottomY ? bottomY : xAxisBottomY; 524 525 height1 = legend.getSize(MIN).height; 526 height2 = (bottomY - topY); 527 height = height1 > height2 ? height1 : height2; 528 529 float heightMultiplier = maxValue != 0 ? 530 (float)(minSpaceHeight) / maxValue : 0; 531 int graphLinesFillInteriorBaseValue = 0; 532 if (greatestValue > 0 & leastValue < 0) 533 graphLinesFillInteriorBaseValue = (int)Math.ceil (maxValue / 2f * heightMultiplier); 534 else if (greatestValue > 0) graphLinesFillInteriorBaseValue = 0; 535 else graphLinesFillInteriorBaseValue = (int)Math.ceil (maxValue * heightMultiplier); 536 537 for (int k = 0; k < graphVector.size(); ++k) { 538 float[][] thisDataSet = ((Dataset)datasetVector.get (k)).getOldGraphStruct(); 539 int numSets = thisDataSet.length; 540 int numHeights = numSets > 0 ? thisDataSet[0].length : 0; 541 int[][] heights = new int[numSets][numHeights]; 542 int[][] barLowHeights = new int[numSets][numHeights]; 543 for (int i = 0; i < numHeights; ++i) { 544 for (int j = 0; j < numSets; ++j) { 545 if (greatestValue > 0 && leastValue < 0) { 546 heights[j][i] = (int)((thisDataSet[j][i] + maxValue / 2f) * heightMultiplier); 547 barLowHeights[j][i] = (int)Math.ceil (maxValue / 2f * heightMultiplier); 548 } 549 else if (greatestValue > 0) { 550 heights[j][i] = (int)((thisDataSet[j][i] - leastValue) * heightMultiplier); 551 barLowHeights[j][i] = 0; 552 } 553 else { 554 heights[j][i] = 555 (int)((thisDataSet[j][i] + maxValue - greatestValue) * heightMultiplier); 556 barLowHeights[j][i] = (int)Math.ceil (maxValue * heightMultiplier); 557 } 558 } 559 } 560 ((LBGraphArea)graphVector.get(k)).setGraphValues (heights); 561 ((LBGraphArea)graphVector.get(k)).setBarLowValues (barLowHeights); 562 ((LBGraphArea)graphVector.get(k)).setLinesFillInteriorBaseValue ( 563 graphLinesFillInteriorBaseValue); 564 ((LBGraphArea)graphVector.get(k)).setXTicks (xAxis.getTicks (g2D)); 565 ((LBGraphArea)graphVector.get(k)).setYTicks (yAxis.getTicks (g2D)); 566 ((LBGraphArea)graphVector.get(k)).updateLBGraphArea(); 567 } 568 569 Vector warningRegions = getWarningRegions(); 570 for (int i = 0; i < warningRegions.size(); ++i) { 571 WarningRegion warningRegion = (WarningRegion)warningRegions.get(i); 572 if (greatestValue > 0 && leastValue < 0) { 573 574 warningRegion.setHighGraph ( 575 warningRegion.getHigh() == Float.POSITIVE_INFINITY ? minSpaceHeight : 576 (int)((warningRegion.getHigh() + maxValue / 2f) * heightMultiplier)); 577 warningRegion.setLowGraph ( 578 warningRegion.getLow() == Float.NEGATIVE_INFINITY ? 0f : 579 (int)((warningRegion.getLow() + maxValue / 2f) * heightMultiplier)); 580 } 581 else if (greatestValue >= 0) { 582 warningRegion.setHighGraph ( 583 warningRegion.getHigh() == Float.POSITIVE_INFINITY ? minSpaceHeight : 584 (int)((warningRegion.getHigh() - leastValue) * heightMultiplier)); 585 warningRegion.setLowGraph ( 586 warningRegion.getLow() == Float.NEGATIVE_INFINITY ? 0f : 587 (int)((warningRegion.getLow() - leastValue) * heightMultiplier)); 588 } 589 else { 590 warningRegion.setHighGraph ( 591 warningRegion.getHigh() == Float.POSITIVE_INFINITY ? minSpaceHeight : 592 (int)((warningRegion.getHigh() + maxValue - greatestValue) * heightMultiplier)); 593 warningRegion.setLowGraph ( 594 warningRegion.getLow() == Float.NEGATIVE_INFINITY ? 0f : 595 (int)((warningRegion.getLow() + maxValue - greatestValue) * heightMultiplier)); 596 } 597 if (warningRegion.getHighGraph() > minSpaceHeight) 598 warningRegion.setHighGraph (minSpaceHeight); 599 if (warningRegion.getLowGraph() < 0) warningRegion.setLowGraph (0); 600 if (warningRegion.getHighGraph() < warningRegion.getLowGraph()) 601 warningRegion.setHighGraph (warningRegion.getLowGraph()); 602 if (warningRegion.getLowGraph() > warningRegion.getHighGraph()) 603 warningRegion.setLowGraph (warningRegion.getHighGraph()); 604 if (heightMultiplier <= 0f) { 605 warningRegion.setHighGraph (0); 606 warningRegion.setLowGraph (0); 607 } 608 } 609 611 minBounds.setSize (width, height); 612 if (!getAutoSize(MIN)) { 613 int minWidth = titleSize.width > minBounds.width ? 614 titleSize.width : minBounds.width; 615 int minHeight; 616 if (titleSize.height > 0 && minBounds.height > 0) { 617 minHeight = titleSize.height + 618 getBetweenTitleAndSpaceGapThickness (g2D) + minBounds.height; 619 } 620 else minHeight = titleSize.height + minBounds.height; 621 setSpaceSize (MIN, new Dimension (minWidth, minHeight)); 622 } 623 624 int x = maxBounds.x + (maxBounds.width - minBounds.width) / 2; 625 int y = maxBounds.y + (maxBounds.height - minBounds.height) / 2; 626 minBounds.setLocation (x, y); 627 628 int graphBetweenWidth = graphFirst.getSpaceSizeLocation(MIN).x - 629 graphFirst.getSizeLocation(MIN).x; 630 int graphBetweenHeight = graphFirst.getSpaceSizeLocation(MIN).y - 631 graphFirst.getSizeLocation(MIN).y; 632 int legendBetweenWidth = 633 legend.getSpaceSizeLocation(MIN).x - legend.getSizeLocation(MIN).x; 634 635 int yAxisX, yAxisY, xAxisX, xAxisY, graphX, graphY, legendX, legendY; 636 637 yAxisX = minBounds.x; 638 graphX = yAxisX + yAxis.getSize(MIN).width + graphBetweenWidth; 639 xAxisX = graphX; 640 legendX = minBounds.x + minBounds.width - 641 legend.getSize(MIN).width + legendBetweenWidth; 642 int yAxisTopY = titleTopY < labelTopY ? titleTopY : labelTopY; 643 int yAxisOffsetY = yAxisTopY - topY; 644 yAxisY = minBounds.y + 645 yAxisOffsetY - (yAxisTopY - yAxis.getSpaceSizeLocation(MIN).y); 646 int graphOffsetY = graphTopY - topY; 647 graphY = minBounds.y + graphOffsetY + graphBetweenHeight; 648 xAxisY = graphY - graphBetweenHeight + graphFirst.getSize(MIN).height; 649 if (legend.getSize(MIN).height <= graphFirst.getSize(MIN).height) { 650 legendY = graphY + (graphFirst.getSpaceSize(MIN).height - 651 legend.getSpaceSize(MIN).height) / 2; 652 } 653 else { 654 if (legend.getSize(MIN).height <= 655 minBounds.y + minBounds.height - graphY) { 656 legendY = graphY; 657 } 658 else { 659 legendY = minBounds.y + 660 (minBounds.height - legend.getSpaceSize(MIN).height) / 2; 661 } 662 } 663 664 legend.setSpaceSizeLocation (MIN, new Point (legendX, legendY)); 665 legend.updateLegendArea (g2D); 666 xAxis.setSpaceSizeLocation (MIN, new Point (xAxisX, xAxisY)); 667 xAxis.updateXAxisArea (g2D); 668 yAxis.setSpaceSizeLocation (MIN, new Point (yAxisX, yAxisY)); 669 yAxis.updateYAxisArea (g2D); 670 671 for (int i = 0; i < graphVector.size(); ++i) { 672 673 ((LBGraphArea)graphVector.get(i)).setSpaceSizeLocation ( 674 MIN, new Point (graphX, graphY)); 675 ((LBGraphArea)graphVector.get(i)).setXTicks (xAxis.getTicks (g2D)); 676 ((LBGraphArea)graphVector.get(i)).setYTicks (yAxis.getTicks (g2D)); 677 ((LBGraphArea)graphVector.get(i)).updateLBGraphArea(); 678 } 679 680 for (int i = 0; i < warningRegions.size(); ++i) { 681 682 WarningRegion warningRegion = (WarningRegion)warningRegions.get (i); 683 warningRegion.setGraphSpaceX (graphFirst.getSpaceSizeLocation (MIN).x); 684 warningRegion.setGraphSpaceY (graphFirst.getSpaceSizeLocation (MIN).y); 685 warningRegion.setGraphSpaceWidth (graphFirst.getSpaceSize (MIN).width); 686 warningRegion.setGraphSpaceHeight (graphFirst.getSpaceSize (MIN).height); 687 } 688 689 if (getTitleSqueeze()) { 690 int titleX = minBounds.x + (minBounds.width - titleSize.width) / 2; 691 int titleY = minBounds.y - getBetweenTitleAndSpaceGapThickness (g2D) - 692 getTitle().getSize(MIN).height; 693 setTitleLocation (new Point (titleX, titleY)); 694 } 695 } 696 } | Popular Tags |