Skip to content

Chart size increases after expanding by adding to dialog and reinserting into dashboard widget #9886

@mukherjeesudebi

Description

@mukherjeesudebi

Description

A chart added inside a dashboard widget when added to a dialog and then on close of dialog is added back to the dashboard widget, the chart size does not match the original size if setSizeFull() is added to the chart.

Issue recording:

ChartInDashboard_issue.mp4

Expected outcome

The chart size should be same after re inserting to dashboard widget

Minimal reproducible example

public class ChartInDashboardWidget extends Div{

	public ChartInDashboardWidget() {
		
		ColumnChartForDashboard columnChartForDashboard = new ColumnChartForDashboard();

		Dashboard dashboard = new Dashboard();
		dashboard.setMaximumColumnCount(2);
		dashboard.setMaxHeight("100%");
		dashboard.setSizeFull();
		dashboard.setDenseLayout(true);


		DashboardWidget dashboardWidgetChart3 = new DashboardWidget("Chart sample");
		dashboardWidgetChart3.setHeaderContent(new Div(new Button(VaadinIcon.EXPAND_FULL.create(), event -> {
			Dialog dialog = new Dialog();
			dialog.setHeight("100vh");
			dialog.setWidth("100vw");
			dialog.add(columnChartForDashboard);
			dialog.open();
			dialog.getHeader().add(new Button(VaadinIcon.CLOSE.create(), ev -> {
				dialog.close();
				dashboardWidgetChart3.setContent(columnChartForDashboard);
				columnChartForDashboard.setHeight("100%");
				columnChartForDashboard.setWidth("100%");
			}));
			
		})));
		dashboardWidgetChart3.setContent(columnChartForDashboard);
		dashboardWidgetChart3.setColspan(1);
		dashboardWidgetChart3.setRowspan(1);
		dashboard.add(dashboardWidgetChart3);

		DashboardWidget visitorsByCountry = new DashboardWidget("Visitors by country");
		visitorsByCountry.setContent(createWidgetContent());
		visitorsByCountry.setColspan(1);
		visitorsByCountry.setRowspan(1);
		visitorsByCountry.addClassNames(LumoUtility.Height.FULL, LumoUtility.Width.FULL);
		dashboard.add(visitorsByCountry);
		add(dashboard);

	}

	private Div createWidgetContent() {
		Div content = new Div();
		content.add(new TextField());
		return content;
	}
	
	class ColumnChartForDashboard extends Chart{


		protected ColumnChartForDashboard() {

	        Configuration configuration = this.getConfiguration();
	        configuration.setTitle("Monthly Average Rainfall");
	        configuration.setSubTitle("Source: WorldClimate.com");
	        this.getConfiguration().getChart().setType(ChartType.COLUMN);

	        configuration.addSeries(new ListSeries("Tokyo", 49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4));
	        configuration.addSeries(new ListSeries("New York", 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3));
	        configuration.addSeries(new ListSeries("London", 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2));
	        configuration.addSeries(new ListSeries("Berlin", 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1));

	        XAxis x = new XAxis();
	        x.setCrosshair(new Crosshair());
	        x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
	                "Sep", "Oct", "Nov", "Dec");
	        configuration.addxAxis(x);

	        YAxis y = new YAxis();
	        y.setMin(0);
	        y.setTitle("Rainfall (mm)");
	        configuration.addyAxis(y);

	        Tooltip tooltip = new Tooltip();
	        tooltip.setShared(true);
	        configuration.setTooltip(tooltip);
	        setSizeFull();
	    }
	}


}

Steps to reproduce

Steps to reproduce:

  1. Add the sample code to a vaadin application
  2. click on the expand button in the top right corner of the dashboard widget having the chart
  3. click on 'X' to close the dialog

Environment

Vaadin version(s): 24.8.5

Browsers

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions