Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8255891

[macos] LineChart is clipping the series stroke at min and max

XMLWordPrintable

    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      macos Catalina, Retina iMac (HiDPI)
      JavaFX 15.0.1, Java 15.0.1


      A DESCRIPTION OF THE PROBLEM :
      The series stroke in a LineChart, when it is at the min or max value on the y axis, is clipped and not shown at full width.

      I have a test program and some output images.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached program.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The series stroke should always be full width, even at min and max y.
      ACTUAL -
      The series stroke should always be full width.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.chart.LineChart;
      import javafx.scene.chart.NumberAxis;
      import javafx.stage.Stage;

      public class LineChartClipping extends Application {

        LineChart.Series<Number, Number> series;

        LineChart<Number, Number> makeChart() {
          NumberAxis xAxis = new NumberAxis();
          NumberAxis yAxis = new NumberAxis(0, 1, .1); // -0.05, 1.05, .1);
          var chart = new LineChart<>(xAxis, yAxis) {
            @Override // Remove output clutter. Has no effect on the issue.
            protected void dataItemAdded(Series<Number, Number> series, int i, Data<Number, Number> item) {}
          };
          xAxis.setLowerBound(0);
          chart.setHorizontalGridLinesVisible(true);
          // Remove output clutter. Has no effect on the issue.
          chart.setLegendVisible(false);
          xAxis.setTickLabelsVisible (false);
          xAxis.setTickMarkVisible (false);
          xAxis.setMinorTickVisible (false);
          chart.setVerticalGridLinesVisible(false);
          yAxis.setTickLabelsVisible (false);
          yAxis.setTickMarkVisible (false); // true
          series = new LineChart.Series<>();
          chart.getData().add(series);
          series.getNode().setStyle(String.format("-fx-stroke-width: %g;", 3.0));
          addSegments(0.5, 0.0, 1.0, 0.5, 0.1, 0.9, 0.5);
          // Ineffectual tweaks
       // chart.setBackground(new Background(new BackgroundFill(Color.color(0, 1, 1, .5), null, null)));
       // chart.setPadding(new Insets(5, 0, 5, 0)); // also tried negative
          return chart;
        }

        double x = 0;

        void addSegments(double... values) {
          for (var value : values) {
            addData(value); x += 2;
            addData(value);
          }
        }

        private void addData(double value) {
          series.getData().add(new LineChart.Data<>(x, value));
        }


        @Override
        public void start(Stage stage) {
          var chart = makeChart();
          final Scene scene = new Scene(chart, 100, 100);
          stage.setScene(scene);
          stage.show();
        }

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

      CUSTOMER SUBMITTED WORKAROUND :
      two possible workarounds have other problems. See screen shots. (Assuming I can attach them later.)

      FREQUENCY : always


            aghaisas Ajit Ghaisas
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: