HanSolo / medusa

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

Needle position initially wrong when using scale direction counter-clockwise #129

Closed ianrenton closed 7 years ago

ianrenton commented 7 years ago

First of all, thanks for making a really useful library! I have found one minor issue. I am using the latest available version from the website (7.9).

When I configure a gauge to use the COUNTER_CLOCKWISE scale direction, the scale is correctly drawn the opposite side of the start angle. However, the initial position of the needle is still drawn the "clockwise" side, until the first value update comes through. The result is that until that update, you have the needle off the scale in the wrong direction.

The code below reproduces the problem. It creates two gauges, the left one being clockwise, the right one being identical except for it being counter-clockwise. You will see that on first run, the right-hand gauge needle is not properly lined up with the zero position, as shown in the picture:

capture

When a value update comes through (triggered by pressing the button), both gauges line up properly.

import eu.hansolo.medusa.Gauge;
import eu.hansolo.medusa.Gauge.ScaleDirection;
import eu.hansolo.medusa.GaugeBuilder;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class Test extends Application
{
  GridPane gridpane = new GridPane();

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

  @Override
  public void start(Stage stage)
  {
    stage.setScene(new Scene(gridpane));
    stage.show();
  }

  @Override
  public void init()
  {
    Gauge gauge1 = GaugeBuilder.create()
      .decimals(0).minValue(-100).maxValue(100)
      .startAngle(45).angleRange(90)
      .scaleDirection(ScaleDirection.CLOCKWISE).build();

    Gauge gauge2 = GaugeBuilder.create()
      .decimals(0).minValue(-100).maxValue(100)
      .startAngle(45).angleRange(90)
      .scaleDirection(ScaleDirection.COUNTER_CLOCKWISE).build();

    Button b = new Button("Update values");
    b.setOnAction((ActionEvent event) ->
    {
      gauge1.setValue(50);
      gauge2.setValue(50);
    });

    gridpane.add(gauge1, 0, 0);
    gridpane.add(gauge2, 1, 0);
    gridpane.add(b, 0, 1);
  }
}
HanSolo commented 7 years ago

Fixed with commit: 52f69d1bf5666b2a4cc2626517dd53377a4aae2f