X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2Fnodes%2FRulerNode.java;h=daec9e55e2a80c1143426228c098572ad206f89f;hb=fd9e089735dcfd10e49329a4f521c551fd3a7a74;hp=f7e0d1e5c6b5cb05d280b9a5ae514758723b2370;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java index f7e0d1e5c..daec9e55e 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java @@ -109,7 +109,9 @@ public class RulerNode extends G2DNode { // Vertical ruler for(double x = offsetX%stepX-stepX; x < bounds.getMaxX(); x+=stepX) { if(x > 20) { - String str = formatValue((x-offsetX)/scaleX); + double val = (x-offsetX)/scaleX; + double modifiedValue = modifyHorizontalValue(val); + String str = formatValue(modifiedValue); FontMetrics fm = g.getFontMetrics(); Rectangle2D r = fm.getStringBounds(str, g); if((x-r.getWidth()/2) > previousText) { @@ -141,9 +143,8 @@ public class RulerNode extends G2DNode { for(double y = offsetY%stepY-stepY; y < bounds.getMaxY(); y+=stepY) { if(y > 20) { double val = (y-offsetY)/scaleY; - if (MAP_Y_SCALING) - val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val)))); - String str = formatValue(val); + double modifiedValue = modifyVerticalValue(val); + String str = formatValue(modifiedValue); FontMetrics fm = g.getFontMetrics(); Rectangle2D r = fm.getStringBounds(str, g); if(y-1+r.getHeight()/2 > previousText) { @@ -175,6 +176,26 @@ public class RulerNode extends G2DNode { g.setTransform(tr); } + /** + * A method for subclasses to alter the actual X-value of the ruler + * + * @param value + * @return possibly modified X-value + */ + protected double modifyHorizontalValue(double value) { + return value; + } + + /** + * A method for subclasses to alter the actual Y-value of the ruler + * + * @param value + * @return possibly modified Y-value + */ + protected double modifyVerticalValue(double value) { + return value; + } + private static final transient int MAX_DIGITS = 5; private static final transient double EPSILON = 0.01; private static final transient double TRIM_THRESHOLD_MAX_VALUE = Math.pow(10, 4);