1818
1919import com .vaadin .ui .JavaScript ;
2020import com .vaadin .ui .JavaScriptFunction ;
21+ import de .symeda .sormas .api .campaign .diagram .DiagramType ;
2122import org .apache .commons .collections4 .CollectionUtils ;
2223import org .apache .commons .text .StringEscapeUtils ;
2324
@@ -46,6 +47,7 @@ public class CampaignDashboardDiagramComponent extends VerticalLayout {
4647 private final Map <CampaignDashboardTotalsReference , Double > totalValuesMap ;
4748 private boolean totalValuesWithoutStacks ;
4849 private boolean showPercentages ;
50+ private boolean showAsColumnChart ;
4951 private boolean showDataLabels = false ;
5052 private final HighChart campaignColumnChart ;
5153
@@ -63,6 +65,7 @@ public CampaignDashboardDiagramComponent(
6365 totalValuesWithoutStacks = true ;
6466 }
6567
68+ showAsColumnChart = DiagramType .values ().length > 0 && DiagramType .COLUMN == DiagramType .values ()[0 ];
6669 campaignColumnChart = new HighChart ();
6770
6871 setSizeFull ();
@@ -107,6 +110,12 @@ public CampaignDashboardDiagramComponent(
107110 buildDiagramChart (diagramDefinition .getDiagramCaption (), campaignJurisdictionLevelGroupBy );
108111 });
109112
113+ JavaScript .getCurrent ()
114+ .addFunction ("changeDiagramChartType_" + diagramDefinition .getDiagramId (), (JavaScriptFunction ) jsonArray -> {
115+ setShowAsColumnChart (!isShowAsColumnChart ());
116+ buildDiagramChart (diagramDefinition .getDiagramCaption (), campaignJurisdictionLevelGroupBy );
117+ });
118+
110119 buildDiagramChart (diagramDefinition .getDiagramCaption (), campaignJurisdictionLevelGroupBy );
111120 }
112121
@@ -116,7 +125,7 @@ public void buildDiagramChart(String title, CampaignJurisdictionLevel campaignJu
116125 //@formatter:off
117126 hcjs .append ("var options = {"
118127 + "chart:{ "
119- + " type: 'column', "
128+ + " type: '" + ( showAsColumnChart ? " column" : "bar" ) + " ', "
120129 + " backgroundColor: 'white', "
121130 + " borderRadius: '1', "
122131 + " borderWidth: '1', "
@@ -143,6 +152,15 @@ public void buildDiagramChart(String title, CampaignJurisdictionLevel campaignJu
143152 : I18nProperties .getCaption (Captions .dashboardShowPercentageValues ))
144153 + "' } " );
145154 }
155+
156+ hcjs .append (
157+ ", toggleChartType: { onclick: function() { window.changeDiagramChartType_" + diagramDefinition .getDiagramId ()
158+ + "(); }, text: '"
159+ + (showAsColumnChart
160+ ? I18nProperties .getCaption (Captions .dashboardViewAsBarChart )
161+ : I18nProperties .getCaption (Captions .dashboardViewAsColumnChart ))
162+ + "' } " );
163+
146164 hcjs .append (" }, " );
147165
148166 hcjs .append (" buttons:{ contextButton:{ theme:{ fill: 'transparent' }, " )
@@ -154,6 +172,7 @@ public void buildDiagramChart(String title, CampaignJurisdictionLevel campaignJu
154172 hcjs .append (", 'togglePercentages'" );
155173 }
156174
175+ hcjs .append (", 'toggleChartType'" );
157176 hcjs .append ("]" );
158177
159178 final Map <String , Long > stackMap = diagramDefinition .getCampaignDiagramSeries ()
@@ -336,4 +355,12 @@ public boolean isShowDataLabels() {
336355 public void setShowDataLabels (boolean showDataLabels ) {
337356 this .showDataLabels = showDataLabels ;
338357 }
358+
359+ public boolean isShowAsColumnChart () {
360+ return showAsColumnChart ;
361+ }
362+
363+ public void setShowAsColumnChart (boolean showAsColumnChart ) {
364+ this .showAsColumnChart = showAsColumnChart ;
365+ }
339366}
0 commit comments