Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.pdfjet.Chart Maven / Gradle / Ivy
/* */ package com.pdfjet;
/* */
/* */ import java.text.NumberFormat;
/* */ import java.util.List;
/* */
/* */ public class Chart
/* */ {
/* 21 */ private float w = 300.0F;
/* 22 */ private float h = 200.0F;
/* */ private float x1;
/* */ private float y1;
/* */ private float x2;
/* */ private float y2;
/* */ private float x3;
/* */ private float y3;
/* */ private float x4;
/* */ private float y4;
/* */ private float x5;
/* */ private float y5;
/* */ private float x6;
/* */ private float y6;
/* */ private float x7;
/* */ private float y7;
/* */ private float x8;
/* */ private float y8;
/* 48 */ private float x_max = 1.4E-45F;
/* 49 */ private float x_min = 3.4028235E+38F;
/* */
/* 51 */ private float y_max = 1.4E-45F;
/* 52 */ private float y_min = 3.4028235E+38F;
/* */
/* 54 */ private int x_axis_grid_lines = 0;
/* 55 */ private int y_axis_grid_lines = 0;
/* */
/* 57 */ private String title = "";
/* 58 */ private String x_axis_title = "";
/* 59 */ private String y_axis_title = "";
/* */
/* 61 */ private boolean drawXAxisLabels = true;
/* 62 */ private boolean drawYAxisLabels = true;
/* */ private float h_grid_line_width;
/* */ private float v_grid_line_width;
/* 67 */ private String h_grid_line_pattern = "[1 1] 0";
/* 68 */ private String v_grid_line_pattern = "[1 1] 0";
/* */
/* 70 */ private float chart_border_width = 0.3F;
/* 71 */ private float inner_border_width = 0.3F;
/* */
/* 73 */ private NumberFormat nf = null;
/* 74 */ private int minFractionDigits = 2;
/* 75 */ private int maxFractionDigits = 2;
/* */
/* 77 */ private Font f1 = null;
/* 78 */ private Font f2 = null;
/* */
/* 80 */ private List> chartData = null;
/* */
/* */ public Chart(Font paramFont1, Font paramFont2)
/* */ {
/* 90 */ this.f1 = paramFont1;
/* 91 */ this.f2 = paramFont2;
/* 92 */ this.nf = NumberFormat.getInstance();
/* */ }
/* */
/* */ public void setTitle(String paramString)
/* */ {
/* 102 */ this.title = paramString;
/* */ }
/* */
/* */ public void setXAxisTitle(String paramString)
/* */ {
/* 112 */ this.x_axis_title = paramString;
/* */ }
/* */
/* */ public void setYAxisTitle(String paramString)
/* */ {
/* 122 */ this.y_axis_title = paramString;
/* */ }
/* */
/* */ public void setData(List> paramList)
/* */ {
/* 132 */ this.chartData = paramList;
/* */ }
/* */
/* */ public List> getData()
/* */ {
/* 142 */ return this.chartData;
/* */ }
/* */
/* */ public void setPosition(double paramDouble1, double paramDouble2)
/* */ {
/* 153 */ setPosition((float)paramDouble1, (float)paramDouble2);
/* */ }
/* */
/* */ public void setPosition(float paramFloat1, float paramFloat2)
/* */ {
/* 164 */ setLocation(paramFloat1, paramFloat2);
/* */ }
/* */
/* */ public void setLocation(float paramFloat1, float paramFloat2)
/* */ {
/* 175 */ this.x1 = paramFloat1;
/* 176 */ this.y1 = paramFloat2;
/* */ }
/* */
/* */ public void setSize(double paramDouble1, double paramDouble2)
/* */ {
/* 187 */ setSize((float)paramDouble1, (float)paramDouble2);
/* */ }
/* */
/* */ public void setSize(float paramFloat1, float paramFloat2)
/* */ {
/* 198 */ this.w = paramFloat1;
/* 199 */ this.h = paramFloat2;
/* */ }
/* */
/* */ public void setMinimumFractionDigits(int paramInt)
/* */ {
/* 209 */ this.minFractionDigits = paramInt;
/* */ }
/* */
/* */ public void setMaximumFractionDigits(int paramInt)
/* */ {
/* 219 */ this.maxFractionDigits = paramInt;
/* */ }
/* */
/* */ public float slope(List paramList)
/* */ {
/* 231 */ return covar(paramList) / devsq(paramList) * (paramList.size() - 1);
/* */ }
/* */
/* */ public float intercept(List paramList, double paramDouble)
/* */ {
/* 243 */ return intercept(paramList, (float)paramDouble);
/* */ }
/* */
/* */ public float intercept(List paramList, float paramFloat)
/* */ {
/* 255 */ float[] arrayOfFloat = mean(paramList);
/* 256 */ return arrayOfFloat[1] - paramFloat * arrayOfFloat[0];
/* */ }
/* */
/* */ public void setDrawXAxisLabels(boolean paramBoolean)
/* */ {
/* 261 */ this.drawXAxisLabels = paramBoolean;
/* */ }
/* */
/* */ public void setDrawYAxisLabels(boolean paramBoolean)
/* */ {
/* 266 */ this.drawYAxisLabels = paramBoolean;
/* */ }
/* */
/* */ public void drawOn(Page paramPage)
/* */ throws Exception
/* */ {
/* 276 */ this.nf.setMinimumFractionDigits(this.minFractionDigits);
/* 277 */ this.nf.setMaximumFractionDigits(this.maxFractionDigits);
/* */
/* 279 */ this.x2 = (this.x1 + this.w);
/* 280 */ this.y2 = this.y1;
/* */
/* 282 */ this.x3 = this.x2;
/* 283 */ this.y3 = (this.y1 + this.h);
/* */
/* 285 */ this.x4 = this.x1;
/* 286 */ this.y4 = this.y3;
/* */
/* 288 */ setMinAndMaxChartValues();
/* 289 */ roundXAxisMinAndMaxValues();
/* 290 */ roundYAxisMinAndMaxValues();
/* */
/* 293 */ paramPage.drawString(this.f1, this.title, this.x1 + (this.w - this.f1.stringWidth(this.title)) / 2.0F, this.y1 + 1.5F * this.f1.body_height);
/* */
/* 299 */ float f3 = 2.5F * this.f1.body_height;
/* 300 */ float f4 = getLongestAxisYLabelWidth() + 2.0F * this.f2.body_height;
/* 301 */ float f5 = 2.0F * this.f2.body_height;
/* 302 */ float f6 = 2.5F * this.f2.body_height;
/* */
/* 304 */ this.x5 = (this.x1 + f4);
/* 305 */ this.y5 = (this.y1 + f3);
/* */
/* 307 */ this.x6 = (this.x2 - f5);
/* 308 */ this.y6 = this.y5;
/* */
/* 310 */ this.x7 = this.x6;
/* 311 */ this.y7 = (this.y3 - f6);
/* */
/* 313 */ this.x8 = this.x5;
/* 314 */ this.y8 = this.y7;
/* */
/* 316 */ drawChartBorder(paramPage);
/* 317 */ drawInnerBorder(paramPage);
/* */
/* 319 */ drawHorizontalGridLines(paramPage);
/* 320 */ drawVerticalGridLines(paramPage);
/* */
/* 322 */ if (this.drawXAxisLabels) {
/* 323 */ drawXAxisLabels(paramPage);
/* */ }
/* 325 */ if (this.drawYAxisLabels) {
/* 326 */ drawYAxisLabels(paramPage);
/* */ }
/* */
/* 330 */ for (int i = 0; i < this.chartData.size(); i++) {
/* 331 */ List localList = (List)this.chartData.get(i);
/* 332 */ for (int j = 0; j < localList.size(); j++) {
/* 333 */ Point localPoint = (Point)localList.get(j);
/* 334 */ localPoint.x = (this.x5 + (localPoint.x - this.x_min) * (this.x6 - this.x5) / (this.x_max - this.x_min));
/* */
/* 336 */ localPoint.y = (this.y8 - (localPoint.y - this.y_min) * (this.y8 - this.y5) / (this.y_max - this.y_min));
/* */
/* 338 */ if (localPoint.getURIAction() != null) {
/* 339 */ paramPage.addAnnotation(new Annotation(localPoint.getURIAction(), null, localPoint.x - localPoint.r, paramPage.height - (localPoint.y - localPoint.r), localPoint.x + localPoint.r, paramPage.height - (localPoint.y + localPoint.r), null, null, null));
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* 353 */ drawPathsAndPoints(paramPage, this.chartData);
/* */
/* 356 */ paramPage.setBrushColor(0);
/* 357 */ paramPage.setTextDirection(90);
/* 358 */ paramPage.drawString(this.f2, this.y_axis_title, this.x1 + this.f2.body_height, this.y8 - (this.y8 - this.y5 - this.f2.stringWidth(this.y_axis_title)) / 2.0F);
/* */
/* 365 */ paramPage.setTextDirection(0);
/* 366 */ paramPage.drawString(this.f2, this.x_axis_title, this.x5 + (this.x6 - this.x5 - this.f2.stringWidth(this.x_axis_title)) / 2.0F, this.y4 - this.f2.body_height / 2.0F);
/* */
/* 372 */ paramPage.setDefaultLineWidth();
/* 373 */ paramPage.setDefaultLinePattern();
/* 374 */ paramPage.setPenColor(0);
/* */ }
/* */
/* */ private float getLongestAxisYLabelWidth()
/* */ {
/* 379 */ float f3 = this.f2.stringWidth(this.nf.format(this.y_min) + "0");
/* */
/* 381 */ float f4 = this.f2.stringWidth(this.nf.format(this.y_max) + "0");
/* */
/* 383 */ if (f4 > f3) {
/* 384 */ return f4;
/* */ }
/* 386 */ return f3;
/* */ }
/* */
/* */ private void setMinAndMaxChartValues()
/* */ {
/* 391 */ for (int i = 0; i < this.chartData.size(); i++) {
/* 392 */ List localList = (List)this.chartData.get(i);
/* 393 */ for (int j = 0; j < localList.size(); j++) {
/* 394 */ Point localPoint = (Point)localList.get(j);
/* 395 */ if (localPoint.x < this.x_min) {
/* 396 */ this.x_min = localPoint.x;
/* */ }
/* 398 */ if (localPoint.x > this.x_max) {
/* 399 */ this.x_max = localPoint.x;
/* */ }
/* 401 */ if (localPoint.y < this.y_min) {
/* 402 */ this.y_min = localPoint.y;
/* */ }
/* 404 */ if (localPoint.y > this.y_max)
/* 405 */ this.y_max = localPoint.y;
/* */ }
/* */ }
/* */ }
/* */
/* */ private void roundXAxisMinAndMaxValues()
/* */ {
/* 413 */ Round localRound = roundMaxAndMinValues(this.x_max, this.x_min);
/* 414 */ this.x_max = localRound.max_value;
/* 415 */ this.x_min = localRound.min_value;
/* 416 */ this.x_axis_grid_lines = localRound.num_of_grid_lines;
/* */ }
/* */
/* */ private void roundYAxisMinAndMaxValues()
/* */ {
/* 421 */ Round localRound = roundMaxAndMinValues(this.y_max, this.y_min);
/* 422 */ this.y_max = localRound.max_value;
/* 423 */ this.y_min = localRound.min_value;
/* 424 */ this.y_axis_grid_lines = localRound.num_of_grid_lines;
/* */ }
/* */
/* */ private void drawChartBorder(Page paramPage) throws Exception
/* */ {
/* 429 */ paramPage.setPenWidth(this.chart_border_width);
/* 430 */ paramPage.setPenColor(0);
/* 431 */ paramPage.moveTo(this.x1, this.y1);
/* 432 */ paramPage.lineTo(this.x2, this.y2);
/* 433 */ paramPage.lineTo(this.x3, this.y3);
/* 434 */ paramPage.lineTo(this.x4, this.y4);
/* 435 */ paramPage.closePath();
/* 436 */ paramPage.strokePath();
/* */ }
/* */
/* */ private void drawInnerBorder(Page paramPage) throws Exception
/* */ {
/* 441 */ paramPage.setPenWidth(this.inner_border_width);
/* 442 */ paramPage.setPenColor(0);
/* 443 */ paramPage.moveTo(this.x5, this.y5);
/* 444 */ paramPage.lineTo(this.x6, this.y6);
/* 445 */ paramPage.lineTo(this.x7, this.y7);
/* 446 */ paramPage.lineTo(this.x8, this.y8);
/* 447 */ paramPage.closePath();
/* 448 */ paramPage.strokePath();
/* */ }
/* */
/* */ private void drawHorizontalGridLines(Page paramPage) throws Exception
/* */ {
/* 453 */ paramPage.setPenWidth(this.h_grid_line_width);
/* 454 */ paramPage.setPenColor(0);
/* 455 */ paramPage.setLinePattern(this.h_grid_line_pattern);
/* 456 */ float f3 = this.x8;
/* 457 */ float f4 = this.y8;
/* 458 */ float f5 = (this.y8 - this.y5) / this.y_axis_grid_lines;
/* 459 */ for (int i = 0; i < this.y_axis_grid_lines; i++) {
/* 460 */ paramPage.drawLine(f3, f4, this.x6, f4);
/* 461 */ f4 -= f5;
/* */ }
/* */ }
/* */
/* */ private void drawVerticalGridLines(Page paramPage) throws Exception
/* */ {
/* 467 */ paramPage.setPenWidth(this.v_grid_line_width);
/* 468 */ paramPage.setPenColor(0);
/* 469 */ paramPage.setLinePattern(this.v_grid_line_pattern);
/* 470 */ float f3 = this.x5;
/* 471 */ float f4 = this.y5;
/* 472 */ float f5 = (this.x6 - this.x5) / this.x_axis_grid_lines;
/* 473 */ for (int i = 0; i < this.x_axis_grid_lines; i++) {
/* 474 */ paramPage.drawLine(f3, f4, f3, this.y8);
/* 475 */ f3 += f5;
/* */ }
/* */ }
/* */
/* */ private void drawXAxisLabels(Page paramPage) throws Exception
/* */ {
/* 481 */ float f3 = this.x5;
/* 482 */ float f4 = this.y8 + this.f2.body_height;
/* 483 */ float f5 = (this.x6 - this.x5) / this.x_axis_grid_lines;
/* 484 */ paramPage.setBrushColor(0);
/* 485 */ for (int i = 0; i < this.x_axis_grid_lines + 1; i++) {
/* 486 */ String str = this.nf.format(this.x_min + (this.x_max - this.x_min) / this.x_axis_grid_lines * i);
/* */
/* 488 */ paramPage.drawString(this.f2, str, f3 - this.f2.stringWidth(str) / 2.0F, f4);
/* */
/* 490 */ f3 += f5;
/* */ }
/* */ }
/* */
/* */ private void drawYAxisLabels(Page paramPage) throws Exception
/* */ {
/* 496 */ float f3 = this.x5 - getLongestAxisYLabelWidth();
/* 497 */ float f4 = this.y8 + this.f2.ascent / 3.0F;
/* 498 */ float f5 = (this.y8 - this.y5) / this.y_axis_grid_lines;
/* 499 */ paramPage.setBrushColor(0);
/* 500 */ for (int i = 0; i < this.y_axis_grid_lines + 1; i++) {
/* 501 */ String str = this.nf.format(this.y_min + (this.y_max - this.y_min) / this.y_axis_grid_lines * i);
/* */
/* 503 */ paramPage.drawString(this.f2, str, f3, f4);
/* 504 */ f4 -= f5;
/* */ }
/* */ }
/* */
/* */ private void drawPathsAndPoints(Page paramPage, List> paramList)
/* */ throws Exception
/* */ {
/* 511 */ for (int i = 0; i < paramList.size(); i++) {
/* 512 */ List localList = (List)paramList.get(i);
/* 513 */ Point localPoint = (Point)localList.get(0);
/* 514 */ if (localPoint.isStartOfPath) {
/* 515 */ paramPage.setPenColor(localPoint.color);
/* 516 */ paramPage.setPenWidth(localPoint.lineWidth);
/* 517 */ paramPage.setLinePattern(localPoint.linePattern);
/* 518 */ paramPage.drawPath(localList, Operation.STROKE);
/* 519 */ if (localPoint.getText() != null) {
/* 520 */ paramPage.setBrushColor(localPoint.getTextColor());
/* 521 */ paramPage.setTextDirection(localPoint.getTextDirection());
/* 522 */ paramPage.drawString(this.f2, localPoint.getText(), localPoint.x, localPoint.y);
/* */ }
/* */ }
/* 525 */ for (int j = 0; j < localList.size(); j++) {
/* 526 */ localPoint = (Point)localList.get(j);
/* 527 */ if (localPoint.getShape() != -1) {
/* 528 */ paramPage.setPenWidth(localPoint.lineWidth);
/* 529 */ paramPage.setLinePattern(localPoint.linePattern);
/* 530 */ paramPage.setPenColor(localPoint.color);
/* 531 */ paramPage.setBrushColor(localPoint.color);
/* 532 */ paramPage.drawPoint(localPoint);
/* */ }
/* */ }
/* */ }
/* */ }
/* */
/* */ private Round roundMaxAndMinValues(float paramFloat1, float paramFloat2)
/* */ {
/* 541 */ int i = (int)Math.floor(Math.log(paramFloat1) / Math.log(10.0D));
/* 542 */ paramFloat1 *= (float)Math.pow(10.0D, -i);
/* */
/* 544 */ if (paramFloat1 > 9.0F) paramFloat1 = 10.0F;
/* 545 */ else if (paramFloat1 > 8.0F) paramFloat1 = 9.0F;
/* 546 */ else if (paramFloat1 > 7.0F) paramFloat1 = 8.0F;
/* 547 */ else if (paramFloat1 > 6.0F) paramFloat1 = 7.0F;
/* 548 */ else if (paramFloat1 > 5.0F) paramFloat1 = 6.0F;
/* 549 */ else if (paramFloat1 > 4.0F) paramFloat1 = 5.0F;
/* 550 */ else if (paramFloat1 > 3.5F) paramFloat1 = 4.0F;
/* 551 */ else if (paramFloat1 > 3.0F) paramFloat1 = 3.5F;
/* 552 */ else if (paramFloat1 > 2.5F) paramFloat1 = 3.0F;
/* 553 */ else if (paramFloat1 > 2.0F) paramFloat1 = 2.5F;
/* 554 */ else if (paramFloat1 > 1.75F) paramFloat1 = 2.0F;
/* 555 */ else if (paramFloat1 > 1.5F) paramFloat1 = 1.75F;
/* 556 */ else if (paramFloat1 > 1.25F) paramFloat1 = 1.5F;
/* 557 */ else if (paramFloat1 > 1.0F) paramFloat1 = 1.25F; else {
/* 558 */ paramFloat1 = 1.0F;
/* */ }
/* 560 */ Round localRound = new Round();
/* */
/* 562 */ if (paramFloat1 == 10.0F) localRound.num_of_grid_lines = 10;
/* 563 */ else if (paramFloat1 == 9.0F) localRound.num_of_grid_lines = 9;
/* 564 */ else if (paramFloat1 == 8.0F) localRound.num_of_grid_lines = 8;
/* 565 */ else if (paramFloat1 == 7.0F) localRound.num_of_grid_lines = 7;
/* 566 */ else if (paramFloat1 == 6.0F) localRound.num_of_grid_lines = 6;
/* 567 */ else if (paramFloat1 == 5.0F) localRound.num_of_grid_lines = 5;
/* 568 */ else if (paramFloat1 == 4.0F) localRound.num_of_grid_lines = 8;
/* 569 */ else if (paramFloat1 == 3.5F) localRound.num_of_grid_lines = 7;
/* 570 */ else if (paramFloat1 == 3.0F) localRound.num_of_grid_lines = 6;
/* 571 */ else if (paramFloat1 == 2.5F) localRound.num_of_grid_lines = 5;
/* 572 */ else if (paramFloat1 == 2.0F) localRound.num_of_grid_lines = 8;
/* 573 */ else if (paramFloat1 == 1.75F) localRound.num_of_grid_lines = 7;
/* 574 */ else if (paramFloat1 == 1.5F) localRound.num_of_grid_lines = 6;
/* 575 */ else if (paramFloat1 == 1.25F) localRound.num_of_grid_lines = 5;
/* 576 */ else if (paramFloat1 == 1.0F) localRound.num_of_grid_lines = 10;
/* */
/* 578 */ localRound.max_value = (paramFloat1 * (float)Math.pow(10.0D, i));
/* 579 */ float f3 = localRound.max_value / localRound.num_of_grid_lines;
/* 580 */ float f4 = localRound.max_value;
/* 581 */ localRound.num_of_grid_lines = 0;
/* */ do {
/* 583 */ localRound.num_of_grid_lines += 1;
/* 584 */ f4 -= f3;
/* 585 */ }while (f4 > paramFloat2);
/* 586 */ localRound.min_value = f4;
/* */
/* 591 */ return localRound;
/* */ }
/* */
/* */ private float[] mean(List paramList)
/* */ {
/* 596 */ float[] arrayOfFloat = new float[2];
/* 597 */ for (int i = 0; i < paramList.size(); i++) {
/* 598 */ Point localPoint = (Point)paramList.get(i);
/* 599 */ arrayOfFloat[0] += localPoint.x;
/* 600 */ arrayOfFloat[1] += localPoint.y;
/* */ }
/* 602 */ arrayOfFloat[0] /= (paramList.size() - 1);
/* 603 */ arrayOfFloat[1] /= (paramList.size() - 1);
/* 604 */ return arrayOfFloat;
/* */ }
/* */
/* */ private float covar(List paramList)
/* */ {
/* 609 */ float f = 0.0F;
/* 610 */ float[] arrayOfFloat = mean(paramList);
/* 611 */ for (int i = 0; i < paramList.size(); i++) {
/* 612 */ Point localPoint = (Point)paramList.get(i);
/* 613 */ f += (localPoint.x - arrayOfFloat[0]) * (localPoint.y - arrayOfFloat[1]);
/* */ }
/* 615 */ return f / (paramList.size() - 1);
/* */ }
/* */
/* */ private float devsq(List paramList)
/* */ {
/* 624 */ float f = 0.0F;
/* 625 */ float[] arrayOfFloat = mean(paramList);
/* 626 */ for (int i = 0; i < paramList.size(); i++) {
/* 627 */ Point localPoint = (Point)paramList.get(i);
/* 628 */ f = (float)(f + Math.pow(localPoint.x - arrayOfFloat[0], 2.0D));
/* */ }
/* 630 */ return f;
/* */ }
/* */ }
/* Location: E:\EGGWIFI\Customer\trunk\src\Workspace\Customer\Customer Maven Webapp\src\main\webapp\WEB-INF\lib\PDFjet.jar
* Qualified Name: com.pdfjet.Chart
* JD-Core Version: 0.6.2
*/