1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 import java.util.*; 29 30 31 46 final class LLChartArea extends GraphChartArea { 47 48 49 private Rectangle maxBounds; 50 private Rectangle minBounds; 51 private Dimension prefSize; 52 private XAxisArea xAxis; 53 private YAxisArea yAxis; 54 private LegendArea legend; 55 private boolean needsUpdate; 56 57 58 61 LLChartArea() { 62 63 xAxis = getXAxis(); 64 yAxis = getYAxis(); 65 legend = getLegend(); 66 minBounds = new Rectangle(); 67 prefSize = new Dimension(); 68 69 xAxis.setType (LABELSLEFT); 70 yAxis.setType (LABELSLEFT); 71 } 72 73 74 82 final Dimension getPrefSize (Graphics2D g2D) { 83 84 updateLLChartArea (g2D); 85 return prefSize; 86 } 87 88 89 93 final boolean getLLChartAreaNeedsUpdate() { 94 95 if (needsUpdate || getGraphChartAreaNeedsUpdate()) return true; 96 Vector graphVector = getGraphVector(); 97 for (int i = 0; i < graphVector.size(); ++i) { 98 if (((LLGraphArea)graphVector.get (i)).getLLGraphAreaNeedsUpdate()) 99 return true; 100 } 101 return false; 102 } 103 104 105 116 final void resetLLChartAreaModel (boolean reset) { 117 118 needsUpdate = true; 119 resetGraphChartAreaModel (reset); 120 Vector graphVector = this.getGraphVector(); 121 for (int i = 0; i < graphVector.size(); ++i) { 122 ((LLGraphArea)graphVector.get (i)).resetLLGraphAreaModel (reset); 123 } 124 } 125 126 127 131 final void updateLLChartArea (Graphics2D g2D) { 132 133 if (getLLChartAreaNeedsUpdate()) { 134 updateGraphChartArea (g2D); 135 update (g2D); 136 Vector graphVector = getGraphVector(); 137 for (int i = 0; i < graphVector.size(); ++i) { 138 ((LLGraphArea)graphVector.get (i)).updateLLGraphArea(); 139 } 140 Vector warningRegions = getWarningRegions(); 141 for (int i = 0; i < warningRegions.size(); ++i) { 142 ((WarningRegion)warningRegions.get (i)).updateWarningRegion(); 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 updateLLChartArea (g2D); 159 super.paintComponent (g2D); 160 161 Vector graphVector = getGraphVector(); 162 for (int i = graphVector.size() - 1; i >= 0; --i) { 163 ((LLGraphArea)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 LLGraphArea thisGraph = (LLGraphArea)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 ((LLGraphArea)graphVector.get(i)).setCustomRatio (WIDTH, true, widthRatio); 199 ((LLGraphArea)graphVector.get(i)).setCustomRatio (HEIGHT, true, heightRatio); 200 ((LLGraphArea)graphVector.get(i)).setLabelsAxisTicksAlignment (yAxis.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 ((LLGraphArea)graphVector.get(i)).setSize (MAX, new Dimension (width, height)); 249 } 250 251 xAxis.setNumTicks (getNumPlotAxisLabels()); yAxis.setNumTicks (yTextList.getNumBullets()); 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 = 266 getCustomizeGreatestValue() && (getCustomGreatestValue() > greatestValue) 267 ? getCustomGreatestValue() : greatestValue; 268 leastValue = 269 getCustomizeLeastValue() && (getCustomLeastValue() < leastValue) 270 ? getCustomLeastValue() : leastValue; 271 272 float maxValue = getGraphableToAvailableRatio() > 0 ? 273 (greatestValue - leastValue) / getGraphableToAvailableRatio() : 0f; 274 float emptyValue = maxValue - (greatestValue - leastValue); 275 276 int dataSign = GraphArea.NEG; 277 if (greatestValue > 0f && leastValue < 0f) { 278 greatestValue = greatestValue + (emptyValue / 2f); 279 leastValue = leastValue - (emptyValue / 2f); 280 float nomValue = Math.abs (greatestValue) > Math.abs (leastValue) ? 281 Math.abs (greatestValue) : Math.abs (leastValue); 282 greatestValue = nomValue; 283 leastValue = -nomValue; 284 dataSign = GraphArea.MIX; 285 } 286 else if (greatestValue >= 0f && leastValue >= 0f) { 287 greatestValue = greatestValue + emptyValue; 288 if (!getCustomizeLeastValue()) leastValue = 0f; 289 dataSign = GraphArea.POS; 290 } 291 else { 292 leastValue = leastValue - emptyValue; 293 if (!getCustomizeGreatestValue()) greatestValue = 0f; 294 } 295 296 int precisionNum = getLabelsPrecisionNum(); 297 greatestValue = getPrecisionCeil (greatestValue, precisionNum); 298 leastValue = getPrecisionFloor (leastValue, precisionNum); 299 maxValue = greatestValue - leastValue; 300 301 float difference = 0; 302 float label = 0; 303 if (getNumPlotAxisLabels() > 1) { 304 difference = maxValue / (getNumPlotAxisLabels() - 1); 305 label = leastValue; 306 } 307 else { 308 label = maxValue / 2f; 309 } 310 311 String [] labels = new String [getNumPlotAxisLabels()]; 312 String lastLabel = null; 313 for (int i = 0; i < getNumPlotAxisLabels(); ++i) { 314 float sign = label > 0 ? 1f : -1f; 315 if (i == getNumPlotAxisLabels() - 1 || i == 0) { 316 labels[i] = getFloatToString ( 317 sign * getPrecisionRound (sign * label, precisionNum), precisionNum); 318 } 319 else { 320 labels[i] = getFloatToString (label, precisionNum); 321 } 322 label += difference; 323 if (labels[i].equals (lastLabel)) labels[i] = "^"; 324 else lastLabel = labels[i]; 325 } 326 xAxis.getTextList().setLabels (labels); 327 328 int graphPrefHeight = 0; 329 for (int i = 0; i < graphVector.size(); ++i) { 330 int numSets = ((Dataset)datasetVector.get (i)).getNumSets(); 331 int numCats = ((Dataset)datasetVector.get (i)).getNumCats(); 332 int numCompsPerCat = ((Dataset)datasetVector.get (i)).getNumItems(); 333 int tempHeight = 334 ((LLGraphArea)graphVector.get (i)).getPrefSpaceHeight (numSets, numCats, numCompsPerCat); 335 graphPrefHeight = tempHeight > graphPrefHeight ? tempHeight : graphPrefHeight; 336 ((LLGraphArea)graphVector.get(i)).setDataSign (dataSign); 337 } 338 339 yTextList.setCustomSpaceMinHeight (true, graphPrefHeight); 340 yAxis.updateYAxisArea (g2D); 341 int minSpaceHeight = yAxis.getSpaceSize (MIN).height; 342 343 xAxis.updateXAxisArea (g2D); 344 int minSpaceWidth = 0; 345 Rectangle[] xAxisTicks = xAxis.getTicks (g2D); 346 if (xAxisTicks.length > 0) { 347 minSpaceWidth = xAxisTicks[xAxisTicks.length - 1].x - xAxisTicks[0].x + xAxisTicks[0].width; 348 } 349 350 Dimension minGraphSpaceSize = new Dimension (minSpaceWidth, minSpaceHeight); 351 for (int i = 0; i < graphVector.size(); ++i) { 352 ((LLGraphArea)graphVector.get(i)).setSpaceSize (MIN, minGraphSpaceSize); 353 } 354 355 LLGraphArea graphFirst = (LLGraphArea)graphVector.get (graphVector.size() - 1); 356 int graphMinSizeWidth = 0; 357 int graphMinSizeHeight = 0; 358 if (graphVector.size() > 0) { 359 graphMinSizeWidth = graphFirst.getSize(MIN).width; 360 graphMinSizeHeight = graphFirst.getSize(MIN).height; 361 } 362 363 legend.updateLegendArea(g2D); 364 365 int height1 = xAxis.getSize(MIN).height + graphMinSizeHeight; 366 int height2 = xAxis.getSize(MIN).height + yAxis.getSize(MIN).height; 367 height = height1 > height2 ? height1 : height2; 368 int heightForDeficient = height; 369 370 int leftTickX = xAxis.getTicks(g2D)[0].x; 371 int titleLeftX = xAxis.getSizeLocation(MIN).x + 372 (int)((xAxis.getSize(MIN).width - 373 xAxis.getTitle().getSize(MIN).width) / 2f); 374 int labelLeftX = xTextList.getLabels(g2D)[0].getSizeLocation(MIN).x; 375 int yAxisLeftX = leftTickX - graphFirst.getBorderThickness (LEFT) - 376 yAxis.getSize(MIN).width; 377 int leftX = titleLeftX < labelLeftX ? titleLeftX : labelLeftX; 378 leftX = leftX < yAxisLeftX ? leftX : yAxisLeftX; 379 380 int rightTickX = xAxis.getTicks(g2D)[xAxis.getTicks(g2D).length-1].x; 381 int tickWidth = xAxis.getTicks(g2D)[0].width; 382 int graphRightX = rightTickX + tickWidth + 383 graphFirst.getBorderThickness (RIGHT); 384 int titleRightX = titleLeftX + xAxis.getTitle().getSize(MIN).width; 385 TextArea xAxisLabelRight = 386 xTextList.getLabels(g2D)[xTextList.getLabels(g2D).length-1]; 387 int labelRightX = xAxisLabelRight.getSizeLocation(MIN).x + 388 xAxisLabelRight.getSize(MIN).width; 389 int legendRightX = graphRightX + betweenChartAndLegendGapThickness + 390 legend.getSize(MIN).width ; 391 int rightX = titleRightX > labelRightX ? titleRightX : labelRightX; 392 rightX = rightX > legendRightX ? rightX : legendRightX; 393 394 width = (rightX - leftX); 395 396 if (getAutoSetLayoutRatios()) { 397 398 yAxisToWidthRatio = width > 0 ? yAxis.getSize (MIN).width / (float)width : 0f; 399 yAxisToWidthRatio = yAxisToWidthRatio < 1f ? yAxisToWidthRatio : 1f; 400 xAxisToWidthRatio = width > 0 ? xAxis.getSize (MIN).width / (float)width : 0f; 401 xAxisToWidthRatio = xAxisToWidthRatio < 1f ? xAxisToWidthRatio : 1f; 402 graphToWidthRatio = width > 0 ? graphMinSizeWidth / (float)width : 0f; 403 graphToWidthRatio = graphToWidthRatio < 1f ? graphToWidthRatio : 1f; 404 if (xAxisToWidthRatio > graphToWidthRatio) graphToWidthRatio = xAxisToWidthRatio; 405 else xAxisToWidthRatio = graphToWidthRatio; 406 407 yAxisToHeightRatio = height > 0 ? yAxis.getSize (MIN).height / (float)height : 0f; 408 yAxisToHeightRatio = yAxisToHeightRatio < 1f ? yAxisToHeightRatio : 1f; 409 xAxisToHeightRatio = height > 0 ? xAxis.getSize (MIN).height / (float)height : 0f; 410 xAxisToHeightRatio = xAxisToHeightRatio < 1f ? xAxisToHeightRatio : 1f; 411 graphToHeightRatio = height > 0 ? graphMinSizeHeight / (float)height : 0f; 412 graphToHeightRatio = graphToHeightRatio < 1f ? graphToHeightRatio : 1f; 413 if (yAxisToHeightRatio > graphToHeightRatio) graphToHeightRatio = yAxisToHeightRatio; 414 else yAxisToHeightRatio = graphToHeightRatio; 415 416 if (yAxisToWidthRatio <= 0f || yAxisToHeightRatio <= 0f) { 417 yAxisToWidthRatio = yAxisToHeightRatio = 0f; 418 } 419 if (xAxisToWidthRatio <= 0f || xAxisToHeightRatio <= 0f) { 420 xAxisToWidthRatio = xAxisToHeightRatio = 0f; 421 } 422 if (graphToWidthRatio <= 0f || graphToHeightRatio <= 0f) { 423 graphToWidthRatio = graphToHeightRatio = 0f; 424 } 425 legendToWidthRatio = 1f - yAxisToWidthRatio - graphToWidthRatio; 426 legendToHeightRatio = 1f; 427 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 = titleSize.width > width ? titleSize.width : 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.4f * prefWidth), (int)(1.3f * prefHeight)); 453 454 int deficientWidth = 0; 455 int deficientHeight = 0; 456 if (getAutoSize (MIN)) { 457 458 deficientHeight = maxBounds.height - heightForDeficient; 459 deficientWidth = maxBounds.width - widthForDeficient; 460 } 461 else { 462 deficientWidth = width - widthForDeficient; 463 deficientHeight = height - heightForDeficient; 464 } 465 466 graphPrefHeight = minSpaceHeight + deficientHeight; 467 yTextList.setCustomSpaceMinHeight (true, graphPrefHeight); 468 yAxis.updateYAxisArea (g2D); 469 minSpaceHeight = yAxis.getSize (MIN).height; 470 471 deficientWidth += (deficientWidth / getNumPlotAxisLabels()); 472 int xAxisPrefWidth = xAxis.getSize(MIN).width + deficientWidth; 473 xTextList.setCustomSpaceMinWidth (true, xAxisPrefWidth); 474 475 xAxis.updateXAxisArea (g2D); 476 minSpaceWidth = 0; 477 xAxisTicks = xAxis.getTicks (g2D); 478 if (xAxisTicks.length > 0) { 479 minSpaceWidth = xAxisTicks[xAxisTicks.length - 1].x - 480 xAxisTicks[0].x + xAxisTicks[0].width; 481 } 482 483 minGraphSpaceSize = new Dimension (minSpaceWidth, minSpaceHeight); 484 for (int i = 0; i < graphVector.size(); ++i) { 485 ((LLGraphArea)graphVector.get(i)).setSpaceSize (MIN, minGraphSpaceSize); 486 } 487 488 graphMinSizeWidth = 0; 489 graphMinSizeHeight = 0; 490 if (graphVector.size() > 0) { 491 graphMinSizeWidth = graphFirst.getSize(MIN).width; 492 graphMinSizeHeight = graphFirst.getSize(MIN).height; 493 } 494 495 legend.updateLegendArea (g2D); 496 497 leftTickX = xAxis.getTicks(g2D)[0].x; 498 titleLeftX = xAxis.getSizeLocation(MIN).x + 499 (int)((xAxis.getSize(MIN).width - 500 xAxis.getTitle().getSize(MIN).width) / 2f); 501 labelLeftX = xTextList.getLabels(g2D)[0].getSizeLocation(MIN).x; 502 yAxisLeftX = leftTickX - graphFirst.getBorderThickness (LEFT) - 503 yAxis.getSize(MIN).width; 504 leftX = titleLeftX < labelLeftX ? titleLeftX : labelLeftX; 505 leftX = leftX < yAxisLeftX ? leftX : yAxisLeftX; 506 507 rightTickX = xAxis.getTicks(g2D)[xAxis.getTicks(g2D).length-1].x; 508 tickWidth = xAxis.getTicks(g2D)[0].width; 509 graphRightX = rightTickX + tickWidth + 510 graphFirst.getBorderThickness (RIGHT); 511 titleRightX = titleLeftX + xAxis.getTitle().getSize(MIN).width; 512 xAxisLabelRight = 513 xTextList.getLabels(g2D)[xTextList.getLabels(g2D).length-1]; 514 labelRightX = xAxisLabelRight.getSizeLocation(MIN).x + 515 xAxisLabelRight.getSize(MIN).width; 516 legendRightX = graphRightX + betweenChartAndLegendGapThickness + 517 legend.getSize(MIN).width ; 518 rightX = titleRightX > labelRightX ? titleRightX : labelRightX; 519 rightX = rightX > legendRightX ? rightX : legendRightX; 520 521 width = (rightX - leftX); 522 width = titleSize.width > width ? titleSize.width : width; 523 524 height1 = xAxis.getSize(MIN).height + graphMinSizeHeight; 525 height2 = xAxis.getSize(MIN).height + yAxis.getSize(MIN).height; 526 height = height1 > height2 ? height1 : height2; 527 528 float widthMultiplier = maxValue != 0 ? 529 (float)(minSpaceWidth) / maxValue : 0; 530 int graphLinesFillInteriorBaseValue = 0; 531 if (greatestValue > 0 & leastValue < 0) 532 graphLinesFillInteriorBaseValue = 533 (int)Math.ceil (maxValue / 2f * widthMultiplier); 534 else if (greatestValue > 0) graphLinesFillInteriorBaseValue = 0; 535 else graphLinesFillInteriorBaseValue = 536 (int)Math.ceil (maxValue * widthMultiplier); 537 for (int k = 0; k < graphVector.size(); ++k) { 538 float[][] thisDataSet = ((Dataset)datasetVector.get (k)).getOldGraphStruct(); 539 int numSets = thisDataSet.length; 540 int numWidths = numSets > 0 ? thisDataSet[0].length : 0; 541 int[][] widths = new int[numSets][numWidths]; 542 int[][] barLowWidths = new int[numSets][numWidths]; 543 for (int i = 0; i < numWidths; ++i) { 544 for (int j = 0; j < numSets; ++j) { 545 if (greatestValue > 0 & leastValue < 0) { 546 widths[j][i] = 547 (int)((thisDataSet[j][i] + maxValue / 2f) * widthMultiplier); 548 barLowWidths[j][i] = 549 (int)Math.ceil (maxValue / 2f * widthMultiplier); 550 } 551 else if (greatestValue > 0) { 552 widths[j][i] = 553 (int)((thisDataSet[j][i] - leastValue) * widthMultiplier); 554 barLowWidths[j][i] = 0; 555 } 556 else { 557 widths[j][i] = (int)((thisDataSet[j][i] + 558 maxValue - greatestValue) * widthMultiplier); 559 barLowWidths[j][i] = (int)Math.ceil (maxValue * widthMultiplier); 560 } 561 } 562 } 563 ((LLGraphArea)graphVector.get(k)).setGraphValues (widths); 564 ((LLGraphArea)graphVector.get(k)).setBarLowValues (barLowWidths); 565 ((LLGraphArea)graphVector.get(k)).setLinesFillInteriorBaseValue ( 566 graphLinesFillInteriorBaseValue); 567 ((LLGraphArea)graphVector.get(k)).setXTicks (xAxis.getTicks (g2D)); 568 ((LLGraphArea)graphVector.get(k)).setYTicks (yAxis.getTicks (g2D)); 569 ((LLGraphArea)graphVector.get(k)).updateLLGraphArea(); 570 } 571 572 Vector warningRegions = getWarningRegions(); 573 for (int i = 0; i < warningRegions.size(); ++i) { 574 WarningRegion warningRegion = (WarningRegion)warningRegions.get(i); 575 if (greatestValue > 0 & leastValue < 0) { 576 warningRegion.setHighGraph ( 577 warningRegion.getHigh() == Float.POSITIVE_INFINITY ? minSpaceWidth : 578 (int)((warningRegion.getHigh() + maxValue / 2f) * widthMultiplier)); 579 warningRegion.setLowGraph ( 580 warningRegion.getLow() == Float.NEGATIVE_INFINITY ? 0f : 581 (int)((warningRegion.getLow() + maxValue / 2f) * widthMultiplier)); 582 } 583 else if (greatestValue >= 0) { 584 warningRegion.setHighGraph ( 585 warningRegion.getHigh() == Float.POSITIVE_INFINITY ? minSpaceWidth : 586 (int)((warningRegion.getHigh() - leastValue) * widthMultiplier)); 587 warningRegion.setLowGraph ( 588 warningRegion.getLow() == Float.NEGATIVE_INFINITY ? 0f : 589 (int)((warningRegion.getLow() - leastValue) * widthMultiplier)); 590 } 591 else { 592 warningRegion.setHighGraph ( 593 warningRegion.getHigh() == Float.POSITIVE_INFINITY ? minSpaceWidth : 594 (int)((warningRegion.getHigh() + maxValue - greatestValue) * widthMultiplier)); 595 warningRegion.setLowGraph ( 596 warningRegion.getLow() == Float.NEGATIVE_INFINITY ? 0f : 597 (int)((warningRegion.getLow() + maxValue - greatestValue) * widthMultiplier)); 598 } 599 if (warningRegion.getHighGraph() > minSpaceWidth) 600 warningRegion.setHighGraph (minSpaceWidth); 601 if (warningRegion.getLowGraph() < 0) warningRegion.setLowGraph (0); 602 if (warningRegion.getHighGraph() < warningRegion.getLowGraph()) 603 warningRegion.setHighGraph (warningRegion.getLowGraph()); 604 if (warningRegion.getLowGraph() > warningRegion.getHighGraph()) 605 warningRegion.setLowGraph (warningRegion.getHighGraph()); 606 if (widthMultiplier <= 0f) { 607 warningRegion.setHighGraph (0); 608 warningRegion.setLowGraph (0); 609 } 610 } 611 613 minBounds.setSize (width, height); 614 if (!getAutoSize(MIN)) { 615 int minWidth = titleSize.width > minBounds.width ? 616 titleSize.width : minBounds.width; 617 int minHeight; 618 if (titleSize.height > 0 && minBounds.height > 0) { 619 minHeight = titleSize.height + 620 getBetweenTitleAndSpaceGapThickness (g2D) + minBounds.height; 621 } 622 else minHeight = titleSize.height + minBounds.height; 623 setSpaceSize (MIN, new Dimension (minWidth, minHeight)); 624 } 625 626 int x = maxBounds.x + (maxBounds.width - minBounds.width) / 2; 627 int y = maxBounds.y + (maxBounds.height - minBounds.height) / 2; 628 minBounds.setLocation (x, y); 629 630 int graphBetweenWidth = graphFirst.getSpaceSizeLocation(MIN).x - 631 graphFirst.getSizeLocation(MIN).x; 632 int graphBetweenHeight = graphFirst.getSpaceSizeLocation(MIN).y - 633 graphFirst.getSizeLocation(MIN).y; 634 int legendBetweenWidth = 635 legend.getSpaceSizeLocation(MIN).x - legend.getSizeLocation(MIN).x; 636 637 int yAxisX, yAxisY, xAxisX, xAxisY, graphX, graphY, legendX, legendY; 638 639 int yAxisOffsetX = yAxisLeftX - leftX; 640 yAxisX = minBounds.x + yAxisOffsetX; 641 int xAxisLeftX = titleLeftX < labelLeftX ? titleLeftX : labelLeftX; 642 int xAxisOffsetX = xAxisLeftX - leftX; 643 xAxisX = minBounds.x + xAxisOffsetX - 644 (xAxisLeftX - xAxis.getSpaceSizeLocation(MIN).x); 645 graphX = yAxisX + yAxis.getSize(MIN).width + graphBetweenWidth; 646 legendX = minBounds.x + minBounds.width - 647 legend.getSize(MIN).width + legendBetweenWidth; 648 649 graphY = minBounds.y + graphBetweenHeight; 650 yAxisY = graphY; 651 xAxisY = minBounds.y + graphFirst.getSize(MIN).height; 652 legendY = graphY + (graphFirst.getSpaceSize(MIN).height - 653 legend.getSpaceSize(MIN).height) / 2; 654 655 yAxis.setSpaceSizeLocation (MIN, new Point (yAxisX, yAxisY)); 656 yAxis.updateYAxisArea (g2D); 657 xAxis.setSpaceSizeLocation (MIN, new Point (xAxisX, xAxisY)); 658 xAxis.updateXAxisArea(g2D); 659 legend.setSpaceSizeLocation (MIN, new Point (legendX, legendY)); 660 legend.updateLegendArea(g2D); 661 662 for (int i = 0; i < graphVector.size(); ++i) { 663 ((LLGraphArea)graphVector.get(i)).setSpaceSizeLocation ( 664 MIN, new Point (graphX, graphY)); 665 ((LLGraphArea)graphVector.get(i)).setXTicks (xAxis.getTicks (g2D)); 666 ((LLGraphArea)graphVector.get(i)).setYTicks (yAxis.getTicks (g2D)); 667 ((LLGraphArea)graphVector.get(i)).updateLLGraphArea(); 668 } 669 670 for (int i = 0; i < warningRegions.size(); ++i) { 671 WarningRegion warningRegion = (WarningRegion)warningRegions.get (i); 672 warningRegion.setGraphSpaceX (graphFirst.getSpaceSizeLocation (MIN).x); 673 warningRegion.setGraphSpaceY (graphFirst.getSpaceSizeLocation (MIN).y); 674 warningRegion.setGraphSpaceWidth (graphFirst.getSpaceSize (MIN).width); 675 warningRegion.setGraphSpaceHeight (graphFirst.getSpaceSize (MIN).height); 676 } 677 678 if (getTitleSqueeze()) { 679 int titleX = minBounds.x + (minBounds.width - titleSize.width) / 2; 680 int titleY = minBounds.y - getBetweenTitleAndSpaceGapThickness (g2D) - 681 getTitle().getSize(MIN).height; 682 setTitleLocation (new Point (titleX, titleY)); 683 } 684 } 685 } | Popular Tags |