All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.invation.code.toval.graphic.diagrams.panels.DotChartPanel Maven / Gradle / Ivy

Go to download

TOVAL comprises a set of java classes for common programming issues. It includes utils for arrays, lists, sets and collections for convenient handling and modification, but also support for mathematic definitions concerning logic (clauses + resolution) together with some algorithms for permutations, powersets and resolution. Additionally it contains a number of types for multisets, matrices with object keys and much more.

The newest version!
package de.invation.code.toval.graphic.diagrams.panels;


import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;

import de.invation.code.toval.graphic.diagrams.models.DotChartModel;
import de.invation.code.toval.graphic.diagrams.models.ChartModel.ValueDimension;
import de.invation.code.toval.graphic.util.GraphicUtils;

@SuppressWarnings("serial")
public class DotChartPanel extends ScatterChartPanel {
	
	private static final int maxPointDiameter = 100;
	
	public DotChartPanel(DotChartModel dotChart) {
		this(dotChart, true);
	}
	
	public DotChartPanel(DotChartModel dotChart, boolean zeroBased) {
		this(dotChart, zeroBased, false, false);
	}
	
	public DotChartPanel(DotChartModel dotChart, boolean zeroBased, boolean onlyIntegerTicksX, boolean onlyIntegerTicksY) {
		super(dotChart, zeroBased, onlyIntegerTicksX, onlyIntegerTicksY, true, false);
	}
	
	@Override
	public Dimension getPreferredSize() {
		return new Dimension(getRequiredPoints(ValueDimension.X) + spacing.left + spacing.right, 
							 getPointDiameterFor(diagram.getValues(ValueDimension.Y).max().doubleValue()) + spacing.top + spacing.bottom);
	}
	
	protected int getPointDiameterFor(Number value) {
		return  (int) Math.round((maxPointDiameter/diagram.getValues(ValueDimension.Y).max().doubleValue())*value.doubleValue());
	}
	
	@Override
	protected void paintValues(Graphics g, boolean paintLines) {
		Point valueLocation;
		for (int i = 0; i < getValueCount(); i++) {
			valueLocation = getPointFor(i);
			int diameter = getPointDiameterFor(diagram.getValues(ValueDimension.Y).get(i));
			GraphicUtils.drawCircle(g, valueLocation, diameter);
//			g.drawLine(valueLocation.x, getPaintingRegion().getBottomLeft().y, valueLocation.x, (int) (valueLocation.y+Math.ceil(diameter/2.0)));
		}
	}
	
	@Override
	protected Integer getYFor(Number value) {
		return getPaintingRegion().getCenter().y-spacing.bottom/2;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy