From 17119bca803dc69eb7e22960660c9eb4115e20b6 Mon Sep 17 00:00:00 2001 From: Nico Mack Date: Fri, 17 Nov 2017 12:36:24 +0100 Subject: [PATCH] Modified scaling strategy --- .../dkd/tui/widget/corona/ShapeGraph.java | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java index d86a8f2..aa00731 100644 --- a/CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java +++ b/CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java @@ -45,7 +45,7 @@ public class ShapeGraph extends ValueCorona { protected ColorPair fillColour; protected ColorPair strokeColour; protected int strokeWidth; - // protected Shape graphShape; + protected Shape scaledShape; protected Timeline blinkingTimeline; protected Timeline balisticTimeline; @@ -71,6 +71,7 @@ public class ShapeGraph extends ValueCorona { this.strokeColour = builder.strokeColour; this.strokeWidth = builder.strokeWidth; this.shape = builder.graphShape; + this.scaledShape = builder.shape; borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null; @@ -95,6 +96,7 @@ public class ShapeGraph extends ValueCorona { this.strokeColour = original.strokeColour; this.strokeWidth = original.strokeWidth; this.shape = original.shape; + this.scaledShape = original.shape; borderStroke = (original.strokeWidth > 0) ? new BasicStroke(original.strokeWidth) : null; @@ -135,7 +137,9 @@ public class ShapeGraph extends ValueCorona { shownValue = value; 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) this.startBlinking(); @@ -143,6 +147,9 @@ public class ShapeGraph extends ValueCorona { this.stopBlinking(); scale = size / lowerBound; + + AffineTransform scaler = AffineTransform.getScaleInstance(scale, scale); + scaledShape = scaler.createTransformedShape(this.shape); } } @@ -150,9 +157,7 @@ public class ShapeGraph extends ValueCorona { @Override public Shape getShape() { - AffineTransform transform = this.getTransform(null); - transform.scale(scale, scale); - return transform.createTransformedShape(super.getShape()); + return this.scaledShape; } // --------------------------------------------------------------------------- @@ -164,24 +169,7 @@ public class ShapeGraph extends ValueCorona { 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); - transform.scale(scale, scale); localCanvas.setTransform(transform); if (this.opacity < 1.0f) @@ -190,14 +178,14 @@ public class ShapeGraph extends ValueCorona { if (shape != null) { if (fillColour != null) { localCanvas.setPaint(fillColour.getColor()); - localCanvas.fill(shape); + localCanvas.fill(scaledShape); } if (strokeColour != null) { localCanvas.setPaint(strokeColour.getColor()); if (borderStroke != null) { localCanvas.setStroke(borderStroke); - localCanvas.draw(shape); + localCanvas.draw(scaledShape); } } } -- GitLab