HanSolo / medusa

A JavaFX library for Gauges
Apache License 2.0
688 stars 129 forks source link

Gauge angleStep doesn't get changed once initialized #142

Closed marinamyl closed 6 years ago

marinamyl commented 6 years ago

If max value is being set dynamically after gauge is already initialized and visible it is causing problem with tick size not changed at the marks area. Need to recalculate ticks property according to the new max value.

image

Source code for the screenshot `import eu.hansolo.medusa.Gauge; import eu.hansolo.medusa.GaugeBuilder; import javafx.animation.AnimationTimer; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.StackPane; import javafx.stage.Stage;

import java.util.Random;

public class TestGauge extends Application { private static final Random RND = new Random(); private Gauge gauge; private long lastTimerCall; private AnimationTimer timer;

public static void main(String[] args) {
    launch(args);
}

@Override
public void init() {
    gauge = GaugeBuilder.create()
            .prefSize(250, 250).build();
    lastTimerCall = System.nanoTime();
    timer = new AnimationTimer() {
        @Override public void handle(final long now) {
            if (now > lastTimerCall + 2_000_000_000L) {
                gauge.setValue(RND.nextDouble() * 100);
                gauge.setMaxValue(RND.nextDouble() * 1000);
                lastTimerCall = now;
            }
        }
    };
    timer.start();
}

@Override
public void start(Stage stage) {
    StackPane pane = new StackPane(gauge);

    Scene scene = new Scene(pane);

    stage.setTitle("Dynamic values Demo");
    stage.setScene(scene);
    stage.show();
}

@Override
public void stop() {
    System.exit(0);
}

} `

marinamyl commented 6 years ago

I figured it is possible to use calcAutoScale() method to automatically recalculate tick marks spaces