Skip to content

Commit

Permalink
Fix: make axisRescaled null safe (#1938) (CP: 21.0) (#1954)
Browse files Browse the repository at this point in the history
* Fix: make axisRescaled null safe (#1938)

Axis#setExtremes can be called with null params to reset to previous configuration.

Fixes #1915

Co-authored-by: Guille <alvarezguille@users.noreply.github.com>
  • Loading branch information
vaadin-bot and alvarezguille authored Jul 30, 2021
1 parent debc0b4 commit 9df875c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.vaadin.flow.component.charts.demo.examples.dynamic;

import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.charts.Chart;
import com.vaadin.flow.component.charts.demo.AbstractChartExample;
import com.vaadin.flow.component.charts.model.AxisTitle;
Expand All @@ -16,7 +13,7 @@
import com.vaadin.flow.component.charts.model.PlotOptionsLine;
import com.vaadin.flow.component.charts.model.VerticalAlign;
import com.vaadin.flow.component.charts.model.YAxis;
import com.vaadin.flow.component.html.Input;
import com.vaadin.flow.component.html.NativeButton;

public class DynamicExtremes extends AbstractChartExample {

Expand Down Expand Up @@ -79,12 +76,8 @@ public void initDemo() {
4.8);
configuration.addSeries(ls);

Input toggleExtremesButton = new Input();
toggleExtremesButton.setValue("Toggle extremes");
toggleExtremesButton.setId("toggleExtremesButton");
toggleExtremesButton.setType("button");
ComponentUtil.addListener(toggleExtremesButton, ClickEvent.class,
(ComponentEventListener) e -> {
NativeButton toggleExtremesButton = new NativeButton("Toggle extremes",
e -> {
if (setExtremes) {
chart.getConfiguration().getyAxes().getAxis(0)
.setExtremes(10, 15);
Expand All @@ -93,6 +86,7 @@ public void initDemo() {
}
setExtremes = !setExtremes;
});
toggleExtremesButton.setId("toggleExtremesButton");

add(chart, toggleExtremesButton);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import com.vaadin.flow.component.charts.testbench.ChartElement;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertEquals;

public class DynamicExtremesIT extends AbstractTBTest {

Expand All @@ -30,9 +32,14 @@ protected Class<? extends AbstractChartExample> getView() {
@Test
public void axisFunction_toggleExtremesPoint_pointHidden() {
ChartElement chart = getChartElement();
WebElement toggleExtremesButton = findElement(
By.id("toggleExtremesButton"));
int initialVisiblePointsCount = chart.getVisiblePoints().size();
findElement(By.id("toggleExtremesButton")).click();
toggleExtremesButton.click();
assertNotEquals(initialVisiblePointsCount,
chart.getVisiblePoints().size());
toggleExtremesButton.click();
assertEquals(initialVisiblePointsCount,
chart.getVisiblePoints().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ public void seriesStateChanged(SeriesStateEvent event) {
public void axisRescaled(AxisRescaledEvent event) {
chart.getElement().callJsFunction("__callAxisFunction", "setExtremes",
event.getAxis(), event.getAxisIndex(),
event.getMinimum().doubleValue(),
event.getMaximum().doubleValue(), event.isRedrawingNeeded(),
event.isAnimated());
event.getMinimum() == null ? null
: event.getMinimum().doubleValue(),
event.getMaximum() == null ? null
: event.getMaximum().doubleValue(),
event.isRedrawingNeeded(), event.isAnimated());
}

@Override
Expand Down

0 comments on commit 9df875c

Please sign in to comment.