Commit 17119bca authored by Nico Mack's avatar Nico Mack

Modified scaling strategy

parent f0c73390
...@@ -45,7 +45,7 @@ public class ShapeGraph extends ValueCorona { ...@@ -45,7 +45,7 @@ public class ShapeGraph extends ValueCorona {
protected ColorPair fillColour; protected ColorPair fillColour;
protected ColorPair strokeColour; protected ColorPair strokeColour;
protected int strokeWidth; protected int strokeWidth;
// protected Shape graphShape; protected Shape scaledShape;
protected Timeline blinkingTimeline; protected Timeline blinkingTimeline;
protected Timeline balisticTimeline; protected Timeline balisticTimeline;
...@@ -71,6 +71,7 @@ public class ShapeGraph extends ValueCorona { ...@@ -71,6 +71,7 @@ public class ShapeGraph extends ValueCorona {
this.strokeColour = builder.strokeColour; this.strokeColour = builder.strokeColour;
this.strokeWidth = builder.strokeWidth; this.strokeWidth = builder.strokeWidth;
this.shape = builder.graphShape; this.shape = builder.graphShape;
this.scaledShape = builder.shape;
borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null; borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null;
...@@ -95,6 +96,7 @@ public class ShapeGraph extends ValueCorona { ...@@ -95,6 +96,7 @@ public class ShapeGraph extends ValueCorona {
this.strokeColour = original.strokeColour; this.strokeColour = original.strokeColour;
this.strokeWidth = original.strokeWidth; this.strokeWidth = original.strokeWidth;
this.shape = original.shape; this.shape = original.shape;
this.scaledShape = original.shape;
borderStroke = (original.strokeWidth > 0) ? new BasicStroke(original.strokeWidth) : null; borderStroke = (original.strokeWidth > 0) ? new BasicStroke(original.strokeWidth) : null;
...@@ -135,7 +137,9 @@ public class ShapeGraph extends ValueCorona { ...@@ -135,7 +137,9 @@ public class ShapeGraph extends ValueCorona {
shownValue = value; shownValue = value;
if (variable != null) { if (variable != null) {
double size = lowerBound + (upperBound - lowerBound) * (shownValue - this.variable.getMinValue()) / (this.variable.getMaxValue() - this.variable.getMinValue()); // double size = lowerBound + (upperBound - lowerBound) * (shownValue - this.variable.getMinValue())
// / (this.variable.getMaxValue() - this.variable.getMinValue());
double size = lowerBound + ((upperBound - lowerBound) * this.variable.getNormalizedValue());
if (size == upperBound) if (size == upperBound)
this.startBlinking(); this.startBlinking();
...@@ -143,6 +147,9 @@ public class ShapeGraph extends ValueCorona { ...@@ -143,6 +147,9 @@ public class ShapeGraph extends ValueCorona {
this.stopBlinking(); this.stopBlinking();
scale = size / lowerBound; scale = size / lowerBound;
AffineTransform scaler = AffineTransform.getScaleInstance(scale, scale);
scaledShape = scaler.createTransformedShape(this.shape);
} }
} }
...@@ -150,9 +157,7 @@ public class ShapeGraph extends ValueCorona { ...@@ -150,9 +157,7 @@ public class ShapeGraph extends ValueCorona {
@Override @Override
public Shape getShape() { public Shape getShape() {
AffineTransform transform = this.getTransform(null); return this.scaledShape;
transform.scale(scale, scale);
return transform.createTransformedShape(super.getShape());
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -164,24 +169,7 @@ public class ShapeGraph extends ValueCorona { ...@@ -164,24 +169,7 @@ public class ShapeGraph extends ValueCorona {
Graphics2D localCanvas = (Graphics2D) canvas.create(); Graphics2D localCanvas = (Graphics2D) canvas.create();
// centre.toScreenCoordinates();
// if (initialTranslation != null)
// initialTranslation.toScreenCoordinates();
// Point drawAt = centre.add(initialTranslation);
//
// if (this.rotateWithHandle) {
// angle = (float) (drawAt.getAngle() % TWO_PI);
// }
//
// AffineTransform translation = new AffineTransform();
// translation.translate(drawAt.x, drawAt.y);
// translation.rotate(angle);
// translation.scale(scale, scale);
// localCanvas.setTransform(translation);
AffineTransform transform = this.getTransform(null); AffineTransform transform = this.getTransform(null);
transform.scale(scale, scale);
localCanvas.setTransform(transform); localCanvas.setTransform(transform);
if (this.opacity < 1.0f) if (this.opacity < 1.0f)
...@@ -190,14 +178,14 @@ public class ShapeGraph extends ValueCorona { ...@@ -190,14 +178,14 @@ public class ShapeGraph extends ValueCorona {
if (shape != null) { if (shape != null) {
if (fillColour != null) { if (fillColour != null) {
localCanvas.setPaint(fillColour.getColor()); localCanvas.setPaint(fillColour.getColor());
localCanvas.fill(shape); localCanvas.fill(scaledShape);
} }
if (strokeColour != null) { if (strokeColour != null) {
localCanvas.setPaint(strokeColour.getColor()); localCanvas.setPaint(strokeColour.getColor());
if (borderStroke != null) { if (borderStroke != null) {
localCanvas.setStroke(borderStroke); localCanvas.setStroke(borderStroke);
localCanvas.draw(shape); localCanvas.draw(scaledShape);
} }
} }
} }
......
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