Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit ba0e3c1

Browse files
SORMAS-Foundation#2528 - Added percentage/total toggle (translation missing)
1 parent 06d8e14 commit ba0e3c1

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

sormas-ui/src/main/java/de/symeda/sormas/ui/dashboard/campaigns/CampaignDashboardDiagramComponent.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class CampaignDashboardDiagramComponent extends VerticalLayout {
2727
private final List<Object> axisKeys = new ArrayList<Object>();
2828
private final Map<Object, String> axisCaptions = new HashMap<Object, String>();
2929
private final Map<Object, Double> totalValues;
30+
private boolean showPercentage = true;
3031

3132
private final HighChart campaignColumnChart;
3233

@@ -67,7 +68,8 @@ public CampaignDashboardDiagramComponent(
6768
buildDiagramChart(diagramDefinition.getDiagramCaption());
6869
}
6970

70-
private void buildDiagramChart(String title) {
71+
public void buildDiagramChart(String title) {
72+
this.showPercentage = !showPercentage;
7173
final StringBuilder hcjs = new StringBuilder();
7274

7375
//@formatter:off
@@ -81,9 +83,24 @@ private void buildDiagramChart(String title) {
8183
+ "},"
8284
+ "credits:{ enabled: false },"
8385
+ "exporting:{ "
84-
+ " enabled: true,"
85-
+ " buttons:{ contextButton:{ theme:{ fill: 'transparent' } } }"
86-
+ "},"
86+
+ " enabled: true,");
87+
//@formatter:on
88+
89+
if (totalValues != null) {
90+
hcjs.append(
91+
" menuItemDefinitions: { togglePercentages: { onclick: function() { window.changeDiagramState_" + diagramDefinition.getDiagramId()
92+
+ "(); }, text: '" + (showPercentage ? "Show total values" : "Show percentages") + "' } }, ");
93+
}
94+
95+
hcjs.append(" buttons:{ contextButton:{ theme:{ fill: 'transparent' }");
96+
97+
if (totalValues != null) {
98+
hcjs.append(
99+
", menuItems: ['viewFullscreen', 'printChart', 'separator', 'downloadPNG', 'downloadJPEG', 'downloadPDF', 'downloadSVG', 'separator', 'downloadCSV', 'downloadXLS', 'viewData', 'separator', 'togglePercentages']");
100+
}
101+
102+
//@formatter:off
103+
hcjs.append("} } },"
87104
+ "legend: { backgroundColor: 'transparent', margin: 30 },"
88105
+ "colors: ['#4472C4', '#ED7D31', '#A5A5A5', '#FFC000', '#5B9BD5', '#70AD47', '#FF0000', '#6691C4','#ffba08','#519e8a','#ed254e','#39a0ed','#FF8C00','#344055','#D36135','#82d173'],"
89106
+ "title:{ text: '" + title + "', style: { fontSize: '15px' } },");
@@ -107,7 +124,7 @@ private void buildDiagramChart(String title) {
107124

108125
//@formatter:off
109126
hcjs.append("yAxis: { min: 0, title: { text: ''}");
110-
if (totalValues != null) {
127+
if (showPercentage && totalValues != null) {
111128
hcjs.append(", max: 100, ");
112129
}
113130
if (stackMap.size() > 1) {
@@ -119,13 +136,13 @@ private void buildDiagramChart(String title) {
119136

120137
// series
121138

122-
if (stackMap.size() > 0 || totalValues != null) {
139+
if (stackMap.size() > 0 || (showPercentage && totalValues != null)) {
123140
hcjs.append("plotOptions: {");
124141

125142
if (stackMap.size() > 0) {
126143
hcjs.append("column: { stacking: 'normal'}");
127144
}
128-
if (totalValues != null) {
145+
if (showPercentage && totalValues != null) {
129146
hcjs.append(stackMap.size() > 0 ? ", " : "").append("series: { dataLabels: { enabled: true, format: '{y} %'}}");
130147
}
131148

@@ -145,7 +162,7 @@ private void buildDiagramChart(String title) {
145162
hcjs.append("{ name:'").append(fieldName).append("', data: [");
146163
for (Object axisKey : axisKeys) {
147164
if (seriesData.containsKey(axisKey)) {
148-
if (totalValues != null) {
165+
if (showPercentage && totalValues != null) {
149166
double totalValue = totalValues.get(seriesData.get(axisKey).getGroupingKey());
150167
if (totalValue > 0) {
151168
hcjs.append(
@@ -174,4 +191,5 @@ private void buildDiagramChart(String title) {
174191

175192
campaignColumnChart.setHcjs(hcjs.toString());
176193
}
194+
177195
}

sormas-ui/src/main/java/de/symeda/sormas/ui/dashboard/campaigns/CampaignDashboardView.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.vaadin.server.Page;
55
import com.vaadin.shared.ui.MarginInfo;
66
import com.vaadin.ui.CssLayout;
7+
import com.vaadin.ui.JavaScript;
8+
import com.vaadin.ui.JavaScriptFunction;
79
import com.vaadin.ui.VerticalLayout;
810
import com.vaadin.ui.themes.ValoTheme;
911
import com.vaadin.v7.ui.OptionGroup;
@@ -142,6 +144,15 @@ public void refreshDashboard() {
142144
dataProvider.getCampaignFormTotalValues().get(campaignDashboardDiagramDto));
143145
styles.add(createDiagramStyle(diagramCssClass, diagramId));
144146
diagramComponent.setStyleName(diagramCssClass);
147+
148+
JavaScript.getCurrent()
149+
.addFunction("changeDiagramState_" + campaignDiagramDefinitionDto.getDiagramId(), (JavaScriptFunction) jsonArray -> {
150+
int index = diagramsLayout.getComponentIndex(diagramComponent);
151+
diagramsLayout.removeComponent(diagramComponent);
152+
diagramComponent.buildDiagramChart(campaignDiagramDefinitionDto.getDiagramCaption());
153+
diagramsLayout.addComponent(diagramComponent, index);
154+
});
155+
145156
diagramsLayout.addComponent(diagramComponent);
146157
});
147158
diagramsWrapper.addComponent(diagramsLayout);

0 commit comments

Comments
 (0)