Commit 99a6f7b7 authored by Nico Mack's avatar Nico Mack

Minor Bug fixes

parent 428a5aeb
......@@ -349,6 +349,8 @@ RADIAL_LAYOUT_NODE = radialLayout
RADIUS_NODE = radius
RADIUS_INCREMENT_NODE = radiusIncrement
RAMPING_TIME_NODE = rampingTime
RECEIVERS_NODE = receivers
......
......@@ -258,6 +258,7 @@ public class Externalization extends NLS {
// --- R ---
public static String RADIUS_NODE;
public static String RADIUS_INCREMENT_NODE;
public static String RADIAL_LAYOUT_NODE;
public static String RAMPING_TIME_NODE;
public static String RECEIVER_NODE;
......
......@@ -243,11 +243,9 @@ public class Sector extends SelectableCorona {
// extend.
Area pie = new Area(new Arc2D.Double(-outerRadius, -outerRadius, size, size, startAngle, arcSpan, Arc2D.PIE));
Area background = new Area(new Ellipse2D.Double(-outerRadius, -outerRadius, size, size));
Area hole = new Area(new Ellipse2D.Double(-innerRadius, -innerRadius, innerRadius * 2, innerRadius * 2));
pie.subtract(hole);
background.subtract(hole);
shape = pie;
borderStroke = (strokeWidth > 0) ? new BasicStroke(strokeWidth) : null;
......
......@@ -58,6 +58,7 @@ public class SegmentedArc extends FadingCorona implements Indexed {
protected double startAngle;
protected double arcSpan;
protected double gap;
protected double radiusIncrement;
protected Font textFont;
protected List<Shape> segments;
......@@ -85,6 +86,7 @@ public class SegmentedArc extends FadingCorona implements Indexed {
this.arcSpan = builder.arcSpan;
this.innerRadius = builder.innerRadius;
this.outerRadius = builder.outerRadius;
this.radiusIncrement = builder.radiusIncrement;
this.gap = builder.gap;
this.textFont = builder.textFont;
......@@ -109,6 +111,7 @@ public class SegmentedArc extends FadingCorona implements Indexed {
this.arcSpan = original.arcSpan;
this.innerRadius = original.innerRadius;
this.outerRadius = original.outerRadius;
this.radiusIncrement = original.radiusIncrement;
this.gap = original.gap;
this.textFont = original.textFont;
......@@ -134,20 +137,25 @@ public class SegmentedArc extends FadingCorona implements Indexed {
// extend.
correctedAngle = (int) AngleUtils.moduloThreeSixty(AngleUtils.THREE_SIXTY - startAngle);
double halfGap = (double) gap / 2;
double segmentSpan = (int) Math.round((double) arcSpan / segmentProperties.size()) - gap;
int segmentStartAngle = (int) Math.round(AngleUtils.moduloThreeSixty(correctedAngle - halfGap));
double halfGap = gap / 2;
double segmentSpan = Math.round(arcSpan / segmentProperties.size()) - gap;
double correctedRadius = outerRadius;
double segmentStartAngle = Math.round(AngleUtils.moduloThreeSixty(correctedAngle - halfGap));
for (SegmentedArcProperties property : segmentProperties) {
Area pie = new Area(new Arc2D.Double(-outerRadius, -outerRadius, size, size, segmentStartAngle, -segmentSpan, Arc2D.PIE));
Area background = new Area(new Ellipse2D.Double(-outerRadius, -outerRadius, size, size));
Area pie;
if (radiusIncrement == 0) {
pie = new Area(new Arc2D.Double(-outerRadius, -outerRadius, size, size, segmentStartAngle, -segmentSpan, Arc2D.PIE));
} else {
pie = new Area(ShapeFactory.buildEllipticArc(correctedRadius, (correctedRadius + radiusIncrement), segmentStartAngle, -segmentSpan));
correctedRadius += radiusIncrement;
}
Area hole = new Area(new Ellipse2D.Double(-innerRadius, -innerRadius, innerRadius * 2, innerRadius * 2));
pie.subtract(hole);
background.subtract(hole);
this.segments.add(pie);
segmentStartAngle -= (int) Math.round(AngleUtils.moduloThreeSixty(segmentSpan + halfGap));
segmentStartAngle -= Math.round(AngleUtils.moduloThreeSixty(segmentSpan + halfGap));
Shape label = (property.hasLabel()) ? this.renderLabel(segmentStartAngle, segmentSpan, property.getLabel()) : null;
this.labels.add(label);
......
......@@ -30,6 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
......@@ -82,8 +83,8 @@ public class ShapeFactory {
}
/**
* Method for building a circle and setting it for the shape field. The size will de defaulted to
* the calibration's default size.
* Method for building a circle and setting it for the shape field. The size will de defaulted
* to the calibration's default size.
*
* @return An instance of {@link java.awt.geom.Ellipse2D.Float}.
*/
......@@ -234,15 +235,15 @@ public class ShapeFactory {
}
/**
* Method for building an arc taking a ratio for the base bounding rectangle from the default square
* size given by the calibration and with a standard round form. The arc type can be specified to
* either give only an arc or build, for example, a pie.
* Method for building an arc taking a ratio for the base bounding rectangle from the default
* square size given by the calibration and with a standard round form. The arc type can be
* specified to either give only an arc or build, for example, a pie.
*
* @param radius
* The ratio of the bounding rectangle to draw the arc in.
* @param arcStart
* The angle at which the arc will commence. <b>Note</b>: The 0 angle is horizontal. See here
* http://kodejava.org/how-do-i-draw-an-arc-in-java-2d/.
* The angle at which the arc will commence. <b>Note</b>: The 0 angle is horizontal. See
* here http://kodejava.org/how-do-i-draw-an-arc-in-java-2d/.
* @param arcLength
* The length of the arc as given by degrees.
* @param arcType
......@@ -285,8 +286,25 @@ public class ShapeFactory {
LOGGER.error("Failed to parse path {}!", path, exception); //$NON-NLS-1$
}
return polygon;
}
/**
* @param radius1
* @param radius2
* @param startAngle
* @param arcSpan
* @return
*/
public static Shape buildEllipticArc(double radius1, double radius2, double startAngle, double arcSpan) {
double arcSpanInRadians = Math.toRadians(arcSpan);
double endX = radius2 * Math.cos(arcSpanInRadians);
double endY = radius2 * Math.sin(arcSpanInRadians);
double majorRadius = Math.sqrt((endY * endY) / (1 - ((endX * endX) / (radius1 * radius1))));
Rectangle2D.Double bounds = new Rectangle2D.Double(-radius1, -majorRadius, 2 * radius1, 2 * majorRadius);
Arc2D.Double ellipticArc = new Arc2D.Double(bounds, 0, arcSpan, Arc2D.PIE);
AffineTransform rotation = AffineTransform.getRotateInstance(-Math.toRadians(startAngle));
return rotation.createTransformedShape(ellipticArc);
}
}
\ No newline at end of file
......@@ -62,6 +62,8 @@ public abstract class BaseSegmentedArcBuilder<B extends BaseSegmentedArcBuilder<
*/
public int gap;
public double radiusIncrement;
/** Specifies the font to be used for rendering the title */
public Font textFont;
......@@ -126,6 +128,7 @@ public abstract class BaseSegmentedArcBuilder<B extends BaseSegmentedArcBuilder<
/** Optional fields */
radiusIncrement = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.RADIUS_INCREMENT_NODE, BootstrappingUtils.OPTIONAL, 0d, context);
gap = (int) BootstrappingUtils.getContentAsDegrees(rootElement, Externalization.GAP_NODE, BootstrappingUtils.OPTIONAL, 0d, context);
textFont = BootstrappingUtils.getContentAsFont(rootElement, Externalization.FONT_NODE, BootstrappingUtils.OPTIONAL, new Font("Monospaced", Font.BOLD, 14), context);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment