HanSolo / medusa

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

Gauge.SkinType.DASHBOARD gets wobbly near max value #213

Closed jab27 closed 2 years ago

jab27 commented 2 years ago

Hi

I noticed that the bar gets bigger/higher near the max value and then falls back into place at max. Look for the middle/top part of the bar when value increases to 38, 39 in this example:

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.paint.Color;
import javafx.stage.Stage;

public class TestDashBoard extends Application {

    private Gauge          gauge5;
    private long           lastTimerCall;
    private AnimationTimer timer;
    private int value = 35;

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

    @Override
    public void start(Stage primaryStage) {
        gauge5 = GaugeBuilder.create()
                .skinType(Gauge.SkinType.DASHBOARD)
                .title("Dashboard")
                .maxValue(40)
                .minValue(0)
                .barColor(Color.CRIMSON)
                .build();

        Scene s = new Scene(gauge5, 800, 800);
        primaryStage.setScene(s);
        primaryStage.show();

        lastTimerCall = System.nanoTime();
        timer = new AnimationTimer() {
            @Override public void handle(long now) {
                if (now > lastTimerCall + 1_000_000_000l) {
                    gauge5.setValue(value);
                    if (++value > 40)
                        value = 35;
                    lastTimerCall = now;
                }
            }
        };
        timer.start();
    }
}

I think the issue might be that the start coordinate of the outer arch and end coordinate of the inner arch is a bit off. At lease it seems to go away if i make this change in DashboardSkin.java, Method private void setBar( final double VALUE ) line 314 - 319.

        } else {
            dataBarStart.setX(0.4);  // <- Change from dataBarStart.setX(0);
            dataBarStart.setY(smallHeight);
            dataBarOuterArc.setSweepFlag(true);
            dataBarInnerArc.setX(centerX + tinyHeight * -1);  // <- Change from dataBarInnerArc.setX(0.27778 * width);
            dataBarInnerArc.setY(smallHeight);
            dataBarInnerArc.setSweepFlag(false);
        }

        setBarColor(VALUE);

It probably also need to be changed in 285-288, 188-190

Regards, Jan

HanSolo commented 2 years ago

Fixed with commit 3d8fe103f00c3fd7933633bf19a649b509dfa08e in jdk16 branch

jab27 commented 2 years ago

Thanks - it works perfect!