Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void draw(Graphics g, PointSet pointSet)
- {
- switch (_type)
- {
- case horizontal:
- drawHorizontalAxis(g, pointSet);
- drawHorizontalAxisScale(g, pointSet);
- break;
- case vertical:
- drawVerticalAxis(g, pointSet);
- //drawVerticalAxisScale(g, pointSet);
- break;
- }
- }
- private void drawHorizontalAxis(Graphics g, PointSet pointSet)
- {
- Graphics2D g2 = (Graphics2D) g;
- int height = g.getClipBounds().height;
- int width = g.getClipBounds().width;
- int namePos = (width - _gap.getLeft() - _gap.getRight()) / 2 - _name.length() / 2;
- g2.setColor(_color);
- g2.setStroke(new BasicStroke(_width));
- g2.drawLine(_gap.getLeft(), height - _gap.getBelow(), width - _gap.getLeft() - _gap.getRight(), height - _gap.getBelow());
- g2.drawString(_name, namePos, height - _gap.getBelow() + 35);
- }
- private void drawHorizontalAxisScale(Graphics g, PointSet pointSet)
- {
- Graphics2D g2 = (Graphics2D) g;
- int[] scalePositions = computeHorizontalScalePositions(pointSet);
- OutlierRanking ranking = pointSet.getRanking();
- int value = 0;
- String out = "";
- for(int i = 0, idx = 0; ranking.hasNext(); ++i)
- {
- value = ranking.next().getRankingPosition() - 1;
- out = Integer.toString(value);
- if (i % 5 == 0)
- {
- drawHorizontalScaleObject(g2, scalePositions[idx], out);
- ++idx;
- }
- }
- ++value;
- out = Integer.toString(value);
- drawHorizontalScaleObject(g2, scalePositions[scalePositions.length - 1], out);
- }
- private int[] computeHorizontalScalePositions(PointSet pointSet)
- {
- int[] scalePositions = new int[pointSet.getSize() / 5 + 1];
- Iterator<Point> it = pointSet.iterator();
- Point p = it.next();
- scalePositions[0] = p.x();
- for(int i = 1, idx = 1; it.hasNext(); ++i, p = it.next())
- {
- Point prevP = p;
- if (i % 5 == 0)
- {
- scalePositions[idx] = prevP.x();
- ++idx;
- }
- }
- scalePositions[scalePositions.length - 1] = p.x();
- return scalePositions;
- }
- private void drawHorizontalScaleObject(Graphics2D g, int position, String value)
- {
- int height = g.getClipBounds().height;
- g.drawLine(position, height - _gap.getBelow(), position, height - _gap.getBelow() + 5);
- g.drawString(value, position - g.getFontMetrics().stringWidth(value) / 2, height - _gap.getBelow() + 20);
- }
Add Comment
Please, Sign In to add comment