Guest User

Untitled

a guest
Jul 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. public void draw(Graphics g, PointSet pointSet)
  2. {
  3. switch (_type)
  4. {
  5. case horizontal:
  6. drawHorizontalAxis(g, pointSet);
  7. drawHorizontalAxisScale(g, pointSet);
  8. break;
  9. case vertical:
  10. drawVerticalAxis(g, pointSet);
  11. //drawVerticalAxisScale(g, pointSet);
  12. break;
  13. }
  14. }
  15.  
  16. private void drawHorizontalAxis(Graphics g, PointSet pointSet)
  17. {
  18. Graphics2D g2 = (Graphics2D) g;
  19.  
  20. int height = g.getClipBounds().height;
  21. int width = g.getClipBounds().width;
  22.  
  23. int namePos = (width - _gap.getLeft() - _gap.getRight()) / 2 - _name.length() / 2;
  24.  
  25. g2.setColor(_color);
  26. g2.setStroke(new BasicStroke(_width));
  27.  
  28. g2.drawLine(_gap.getLeft(), height - _gap.getBelow(), width - _gap.getLeft() - _gap.getRight(), height - _gap.getBelow());
  29. g2.drawString(_name, namePos, height - _gap.getBelow() + 35);
  30. }
  31.  
  32. private void drawHorizontalAxisScale(Graphics g, PointSet pointSet)
  33. {
  34. Graphics2D g2 = (Graphics2D) g;
  35.  
  36. int[] scalePositions = computeHorizontalScalePositions(pointSet);
  37.  
  38. OutlierRanking ranking = pointSet.getRanking();
  39. int value = 0;
  40. String out = "";
  41.  
  42. for(int i = 0, idx = 0; ranking.hasNext(); ++i)
  43. {
  44. value = ranking.next().getRankingPosition() - 1;
  45. out = Integer.toString(value);
  46.  
  47. if (i % 5 == 0)
  48. {
  49. drawHorizontalScaleObject(g2, scalePositions[idx], out);
  50.  
  51. ++idx;
  52. }
  53. }
  54.  
  55. ++value;
  56. out = Integer.toString(value);
  57.  
  58. drawHorizontalScaleObject(g2, scalePositions[scalePositions.length - 1], out);
  59. }
  60.  
  61. private int[] computeHorizontalScalePositions(PointSet pointSet)
  62. {
  63. int[] scalePositions = new int[pointSet.getSize() / 5 + 1];
  64.  
  65. Iterator<Point> it = pointSet.iterator();
  66. Point p = it.next();
  67.  
  68. scalePositions[0] = p.x();
  69.  
  70. for(int i = 1, idx = 1; it.hasNext(); ++i, p = it.next())
  71. {
  72. Point prevP = p;
  73.  
  74. if (i % 5 == 0)
  75. {
  76. scalePositions[idx] = prevP.x();
  77.  
  78. ++idx;
  79. }
  80. }
  81.  
  82. scalePositions[scalePositions.length - 1] = p.x();
  83.  
  84. return scalePositions;
  85. }
  86.  
  87. private void drawHorizontalScaleObject(Graphics2D g, int position, String value)
  88. {
  89. int height = g.getClipBounds().height;
  90.  
  91. g.drawLine(position, height - _gap.getBelow(), position, height - _gap.getBelow() + 5);
  92. g.drawString(value, position - g.getFontMetrics().stringWidth(value) / 2, height - _gap.getBelow() + 20);
  93. }
Add Comment
Please, Sign In to add comment