/** * */ package visualizationElements; import java.awt.*; import java.util.Vector; /** * Represents a dot chart to visualize sort algorithms. * @author MSchaefer * */ public class DotChart extends VisualizationElement { private static final int DOT_DIAMETER = 5; private static final int START_X_POS = 20; private int startYPos; private int startXPos; private int height; private int width; private Vector values; /** * Creates a new dot chart. * @param values Vector with values the dot chart visualizes. * @param height Height of the dot chart. * @param width Width of the dot chart. */ public DotChart(Vector values, int height, int width) { super(); this.setValues(values); this.setHeight(height); this.setWidth(width); startYPos = height - 20; } /** * Creates a new dot chart. * @param values Array with values the dot chart visualizes. * @param height Height of the dot chart. * @param width Width of the dot chart. */ public DotChart(int[] values, int height, int width) { super(); this.setHeight(height); this.setWidth(width); startYPos = height - 20; Vector valueVector = new Vector(); for(int element : values){ valueVector.add(element); } this.setValues(valueVector); } @Override public void draw(Graphics g) { int xpos = START_X_POS; int section = (width)/values.size(); for(Integer value : values){ g.fillOval(xpos, startYPos - value * (height/values.size()) - DOT_DIAMETER, DOT_DIAMETER, DOT_DIAMETER); xpos = xpos + section; } // Ground g.drawLine(START_X_POS - 10, startYPos, xpos-10, startYPos); } /** * @param values the values to set */ public void setValues(Vector values) { this.values = values; } /** * @return Returns the values. */ public Vector getValues() { return values; } /** * @param startXPos the startXPos to set */ public void setStartXPos(int startXPos) { this.startXPos = startXPos; } /** * @return the startXPos */ public int getStartXPos() { return startXPos; } /** * @param height the height to set */ public void setHeight(int height) { this.height = height; } /** * @return the height */ public int getHeight() { return height; } /** * @param width the width to set */ public void setWidth(int width) { this.width = width; } /** * @return the width */ public int getWidth() { return width; } }