mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-03 01:29:33 +00:00
Simple datamining results can now be sorted, but the chart resizing
doesn't work anymore
This commit is contained in:
1 parent
8e09e0f413
commit
db0e7b4ed3
5 files changed
+159
-32
No files matched your search
+5
@@ -1160,4 +1160,9 @@ public interface StringMessages extends com.sap.sse.gwt.client.StringMessages, c
|
|||||||
String showCompetitorFullNameColumn();
|
String showCompetitorFullNameColumn();
|
||||||
String loadingDimensionValues();
|
String loadingDimensionValues();
|
||||||
String runningQuery();
|
String runningQuery();
|
||||||
|
String results();
|
||||||
|
String group();
|
||||||
|
String valueAscending();
|
||||||
|
String valueDescending();
|
||||||
|
String sortBy();
|
||||||
}
|
}
|
||||||
+6
-1
@@ -1139,4 +1139,9 @@ fileUploadResult=File upload: {0} {1}.\nIn case of error please check that your
|
|||||||
showCompetitorSailIdColumn=Show Competitor Sail Id
|
showCompetitorSailIdColumn=Show Competitor Sail Id
|
||||||
showCompetitorFullNameColumn=Show Competitor Full Name
|
showCompetitorFullNameColumn=Show Competitor Full Name
|
||||||
loadingDimensionValues=Loading dimension values
|
loadingDimensionValues=Loading dimension values
|
||||||
runningQuery=Running Query
|
runningQuery=Running Query
|
||||||
|
results=Results
|
||||||
|
group=Group
|
||||||
|
valueAscending=Value (Ascending)
|
||||||
|
valueDescending=Value (Descending)
|
||||||
|
sortBy=Sort by
|
||||||
+6
-1
@@ -1129,4 +1129,9 @@ fileUploadResult=Ergebnis des Hochladens: {0} {1}\nIm Fehlerfall bitte die Konfi
|
|||||||
showCompetitorSailIdColumn=Sail Id anzeigen
|
showCompetitorSailIdColumn=Sail Id anzeigen
|
||||||
showCompetitorFullNameColumn=Vollen Namen anzeigen
|
showCompetitorFullNameColumn=Vollen Namen anzeigen
|
||||||
loadingDimensionValues=Lade Dimensionswerte
|
loadingDimensionValues=Lade Dimensionswerte
|
||||||
runningQuery=Datenabfrage läuft
|
runningQuery=Datenabfrage läuft
|
||||||
|
results=Ergebnisse
|
||||||
|
group=Gruppe
|
||||||
|
valueAscending=Wert (Aufsteigend)
|
||||||
|
valueDescending=Wert (Absteigend)
|
||||||
|
sortBy=Sortiert nach
|
||||||
+6
-1
@@ -1078,4 +1078,9 @@ fileUploadResult=File upload: {0} {1}.\nIn case of error please check that your
|
|||||||
showCompetitorSailIdColumn=Show Competitor Sail Id
|
showCompetitorSailIdColumn=Show Competitor Sail Id
|
||||||
showCompetitorFullNameColumn=Show Competitor Full Name
|
showCompetitorFullNameColumn=Show Competitor Full Name
|
||||||
loadingDimensionValues=Loading dimension values
|
loadingDimensionValues=Loading dimension values
|
||||||
runningQuery=Running Query
|
runningQuery=Running Query
|
||||||
|
results=Results
|
||||||
|
group=Group
|
||||||
|
valueAscending=Value (Ascending)
|
||||||
|
valueDescending=Value (Descending)
|
||||||
|
sortBy=Sort by
|
||||||
+136
-29
@@ -3,6 +3,7 @@ package com.sap.sailing.gwt.ui.datamining.presentation;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,10 +22,17 @@ import org.moxieapps.gwt.highcharts.client.labels.AxisLabelsData;
|
|||||||
import org.moxieapps.gwt.highcharts.client.labels.AxisLabelsFormatter;
|
import org.moxieapps.gwt.highcharts.client.labels.AxisLabelsFormatter;
|
||||||
import org.moxieapps.gwt.highcharts.client.labels.YAxisLabels;
|
import org.moxieapps.gwt.highcharts.client.labels.YAxisLabels;
|
||||||
|
|
||||||
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||||
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||||
|
import com.google.gwt.text.shared.AbstractRenderer;
|
||||||
|
import com.google.gwt.user.client.ui.FlowPanel;
|
||||||
import com.google.gwt.user.client.ui.HTML;
|
import com.google.gwt.user.client.ui.HTML;
|
||||||
import com.google.gwt.user.client.ui.SimplePanel;
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||||
|
import com.google.gwt.user.client.ui.Label;
|
||||||
|
import com.google.gwt.user.client.ui.ValueListBox;
|
||||||
import com.google.gwt.user.client.ui.Widget;
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||||
|
import com.sap.sailing.gwt.ui.client.shared.panels.ResizingFlowPanel;
|
||||||
import com.sap.sailing.gwt.ui.client.shared.panels.ResizingSimplePanel;
|
import com.sap.sailing.gwt.ui.client.shared.panels.ResizingSimplePanel;
|
||||||
import com.sap.sailing.gwt.ui.datamining.ResultsPresenter;
|
import com.sap.sailing.gwt.ui.datamining.ResultsPresenter;
|
||||||
import com.sap.sse.datamining.shared.GroupKey;
|
import com.sap.sse.datamining.shared.GroupKey;
|
||||||
@@ -32,33 +40,100 @@ import com.sap.sse.datamining.shared.QueryResult;
|
|||||||
import com.sap.sse.datamining.shared.impl.GenericGroupKey;
|
import com.sap.sse.datamining.shared.impl.GenericGroupKey;
|
||||||
|
|
||||||
public class ResultsChart implements ResultsPresenter<Number> {
|
public class ResultsChart implements ResultsPresenter<Number> {
|
||||||
|
|
||||||
private static final GroupKey SIMPLE_RESULT_SERIES_KEY = new GenericGroupKey<String>("Results");
|
private final Comparator<GroupKey> standardKeyComparator = new Comparator<GroupKey>() {
|
||||||
|
@Override
|
||||||
|
public int compare(GroupKey key1, GroupKey key2) {
|
||||||
|
return key1.compareTo(key2);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return stringMessages.group();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
private final Comparator<GroupKey> ascendingByValueKeyComparator = new Comparator<GroupKey>() {
|
||||||
|
@Override
|
||||||
|
public int compare(GroupKey key1, GroupKey key2) {
|
||||||
|
Map<GroupKey, ? extends Number> resultData = currentResult.getResults();
|
||||||
|
double doubleValue1 = resultData.get(key1).doubleValue();
|
||||||
|
double doubleValue2 = resultData.get(key2).doubleValue();
|
||||||
|
return Double.compare(doubleValue1, doubleValue2);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return stringMessages.valueAscending();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
private final Comparator<GroupKey> descendingByValueKeyComparator = new Comparator<GroupKey>() {
|
||||||
|
@Override
|
||||||
|
public int compare(GroupKey key1, GroupKey key2) {
|
||||||
|
return -1 * ascendingByValueKeyComparator.compare(key1, key2);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return stringMessages.valueDescending();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
private final StringMessages stringMessages;
|
private final StringMessages stringMessages;
|
||||||
private final SimplePanel mainPanel;
|
private final FlowPanel mainPanel;
|
||||||
|
|
||||||
|
private final HorizontalPanel sortByPanel;
|
||||||
|
private final ValueListBox<Comparator<GroupKey>> keyComparatorListBox;
|
||||||
|
|
||||||
|
private final ResizingSimplePanel presentationPanel;
|
||||||
private final Chart chart;
|
private final Chart chart;
|
||||||
private Map<GroupKey, Series> seriesMappedByGroupKey;
|
|
||||||
|
|
||||||
private final HTML errorLabel;
|
private final HTML errorLabel;
|
||||||
private final HTML labeledBusyIndicator;
|
private final HTML labeledBusyIndicator;
|
||||||
|
|
||||||
|
private Map<GroupKey, Series> seriesMappedByGroupKey;
|
||||||
|
private final GroupKey simpleResultSeriesKey;
|
||||||
private QueryResult<? extends Number> currentResult;
|
private QueryResult<? extends Number> currentResult;
|
||||||
private Map<GroupKey, Integer> mainKeyToXValueMap;
|
private Map<GroupKey, Integer> mainKeyToXValueMap;
|
||||||
|
|
||||||
public ResultsChart(StringMessages stringMessages) {
|
public ResultsChart(StringMessages stringMessages) {
|
||||||
super();
|
super();
|
||||||
this.stringMessages = stringMessages;
|
this.stringMessages = stringMessages;
|
||||||
mainPanel = new ResizingSimplePanel() {
|
|
||||||
|
mainPanel = new ResizingFlowPanel() {
|
||||||
|
@Override
|
||||||
|
public void onResize() {
|
||||||
|
presentationPanel.onResize();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
sortByPanel = new HorizontalPanel();
|
||||||
|
sortByPanel.setSpacing(5);
|
||||||
|
sortByPanel.setVisible(false);
|
||||||
|
mainPanel.add(sortByPanel);
|
||||||
|
sortByPanel.add(new Label(stringMessages.sortBy()));
|
||||||
|
keyComparatorListBox = new ValueListBox<>(new AbstractRenderer<Comparator<?>>() {
|
||||||
|
@Override
|
||||||
|
public String render(Comparator<?> object) {
|
||||||
|
return object.toString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
keyComparatorListBox.addValueChangeHandler(new ValueChangeHandler<Comparator<GroupKey>>() {
|
||||||
|
@Override
|
||||||
|
public void onValueChange(ValueChangeEvent<Comparator<GroupKey>> event) {
|
||||||
|
resetChartSeries();
|
||||||
|
showResultData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
sortByPanel.add(keyComparatorListBox);
|
||||||
|
|
||||||
|
presentationPanel = new ResizingSimplePanel() {
|
||||||
@Override
|
@Override
|
||||||
public void onResize() {
|
public void onResize() {
|
||||||
chart.setSizeToMatchContainer();
|
chart.setSizeToMatchContainer();
|
||||||
chart.redraw();
|
chart.redraw();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
mainPanel.add(presentationPanel);
|
||||||
|
|
||||||
chart = createChart();
|
chart = createChart();
|
||||||
seriesMappedByGroupKey = new HashMap<GroupKey, Series>();
|
seriesMappedByGroupKey = new HashMap<GroupKey, Series>();
|
||||||
|
simpleResultSeriesKey = new GenericGroupKey<String>(stringMessages.results());
|
||||||
|
|
||||||
errorLabel = new HTML();
|
errorLabel = new HTML();
|
||||||
errorLabel.setStyleName("chart-importantMessage");
|
errorLabel.setStyleName("chart-importantMessage");
|
||||||
@@ -72,9 +147,8 @@ public class ResultsChart implements ResultsPresenter<Number> {
|
|||||||
@Override
|
@Override
|
||||||
public void showError(String error) {
|
public void showError(String error) {
|
||||||
currentResult = null;
|
currentResult = null;
|
||||||
|
|
||||||
errorLabel.setHTML(error);
|
errorLabel.setHTML(error);
|
||||||
mainPanel.setWidget(errorLabel);
|
presentationPanel.setWidget(errorLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,35 +164,49 @@ public class ResultsChart implements ResultsPresenter<Number> {
|
|||||||
@Override
|
@Override
|
||||||
public void showBusyIndicator() {
|
public void showBusyIndicator() {
|
||||||
currentResult = null;
|
currentResult = null;
|
||||||
|
presentationPanel.setWidget(labeledBusyIndicator);
|
||||||
mainPanel.setWidget(labeledBusyIndicator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showResult(QueryResult<Number> result) {
|
public void showResult(QueryResult<Number> result) {
|
||||||
if (result != null && !result.isEmpty()) {
|
if (result != null && !result.isEmpty()) {
|
||||||
currentResult = result;
|
currentResult = result;
|
||||||
resetChart();
|
updateKeyComparatorListBox();
|
||||||
|
resetChartSeries();
|
||||||
updateYAxisLabels();
|
updateYAxisLabels();
|
||||||
updateChartSubtitleAndSetChartAsWidget();
|
updateChartSubtitleAndSetChartAsWidget();
|
||||||
buildMainKeyMapAndSetXAxisCategories();
|
showResultData();
|
||||||
createAndAddSeriesToChart();
|
|
||||||
|
|
||||||
for (Entry<GroupKey, ? extends Number> resultEntry : currentResult.getResults().entrySet()) {
|
|
||||||
GroupKey mainKey = resultEntry.getKey().getMainKey();
|
|
||||||
Point point = new Point(mainKeyToXValueMap.get(mainKey), resultEntry.getValue());
|
|
||||||
point.setName(mainKey.asString());
|
|
||||||
seriesMappedByGroupKey.get(groupKeyToSeriesKey(resultEntry.getKey()))
|
|
||||||
.addPoint(point, false, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
chart.redraw();
|
|
||||||
} else {
|
} else {
|
||||||
showError(stringMessages.noDataFound() + ".");
|
showError(stringMessages.noDataFound() + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetChart() {
|
private void updateKeyComparatorListBox() {
|
||||||
|
boolean visible = false;
|
||||||
|
Comparator<GroupKey> valueToBeSelected = standardKeyComparator;
|
||||||
|
Collection<Comparator<GroupKey>> acceptableValues = new ArrayList<>();
|
||||||
|
acceptableValues.add(valueToBeSelected);
|
||||||
|
if (currentResult != null && isCurrentResultSimple()) {
|
||||||
|
valueToBeSelected = getKeyComparator() != null ? getKeyComparator() : valueToBeSelected;
|
||||||
|
acceptableValues.add(ascendingByValueKeyComparator);
|
||||||
|
acceptableValues.add(descendingByValueKeyComparator);
|
||||||
|
visible = true;
|
||||||
|
}
|
||||||
|
keyComparatorListBox.setValue(valueToBeSelected);
|
||||||
|
keyComparatorListBox.setAcceptableValues(acceptableValues);
|
||||||
|
sortByPanel.setVisible(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCurrentResultSimple() {
|
||||||
|
for (GroupKey groupKey : currentResult.getResults().keySet()) {
|
||||||
|
if (groupKey.hasSubKey()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetChartSeries() {
|
||||||
chart.removeAllSeries(false);
|
chart.removeAllSeries(false);
|
||||||
seriesMappedByGroupKey = new HashMap<GroupKey, Series>();
|
seriesMappedByGroupKey = new HashMap<GroupKey, Series>();
|
||||||
}
|
}
|
||||||
@@ -133,8 +221,23 @@ public class ResultsChart implements ResultsPresenter<Number> {
|
|||||||
chart.setChartSubtitle(new ChartSubtitle().setText(stringMessages.queryResultsChartSubtitle(
|
chart.setChartSubtitle(new ChartSubtitle().setText(stringMessages.queryResultsChartSubtitle(
|
||||||
currentResult.getRetrievedDataAmount(), currentResult.getCalculationTimeInSeconds())));
|
currentResult.getRetrievedDataAmount(), currentResult.getCalculationTimeInSeconds())));
|
||||||
// This is needed, so that the subtitle is updated. Otherwise the text would stay empty
|
// This is needed, so that the subtitle is updated. Otherwise the text would stay empty
|
||||||
mainPanel.setWidget(null);
|
presentationPanel.setWidget(null);
|
||||||
mainPanel.setWidget(chart);
|
presentationPanel.setWidget(chart);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showResultData() {
|
||||||
|
buildMainKeyMapAndSetXAxisCategories();
|
||||||
|
createAndAddSeriesToChart();
|
||||||
|
|
||||||
|
for (Entry<GroupKey, ? extends Number> resultEntry : currentResult.getResults().entrySet()) {
|
||||||
|
GroupKey mainKey = resultEntry.getKey().getMainKey();
|
||||||
|
Point point = new Point(mainKeyToXValueMap.get(mainKey), resultEntry.getValue());
|
||||||
|
point.setName(mainKey.asString());
|
||||||
|
seriesMappedByGroupKey.get(groupKeyToSeriesKey(resultEntry.getKey()))
|
||||||
|
.addPoint(point, false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
chart.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildMainKeyMapAndSetXAxisCategories() {
|
private void buildMainKeyMapAndSetXAxisCategories() {
|
||||||
@@ -155,10 +258,14 @@ public class ResultsChart implements ResultsPresenter<Number> {
|
|||||||
mainKeySet.add(groupKey.getMainKey());
|
mainKeySet.add(groupKey.getMainKey());
|
||||||
}
|
}
|
||||||
List<GroupKey> sortedKeys = new ArrayList<>(mainKeySet);
|
List<GroupKey> sortedKeys = new ArrayList<>(mainKeySet);
|
||||||
Collections.sort(sortedKeys);
|
Collections.sort(sortedKeys, getKeyComparator());
|
||||||
return sortedKeys;
|
return sortedKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Comparator<GroupKey> getKeyComparator() {
|
||||||
|
return keyComparatorListBox.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
private void createAndAddSeriesToChart() {
|
private void createAndAddSeriesToChart() {
|
||||||
for (GroupKey groupKey : currentResult.getResults().keySet()) {
|
for (GroupKey groupKey : currentResult.getResults().keySet()) {
|
||||||
GroupKey seriesKey = groupKeyToSeriesKey(groupKey);
|
GroupKey seriesKey = groupKeyToSeriesKey(groupKey);
|
||||||
@@ -174,7 +281,7 @@ public class ResultsChart implements ResultsPresenter<Number> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GroupKey groupKeyToSeriesKey(GroupKey groupKey) {
|
private GroupKey groupKeyToSeriesKey(GroupKey groupKey) {
|
||||||
return groupKey.hasSubKey() ? groupKey.getSubKey() : SIMPLE_RESULT_SERIES_KEY;
|
return groupKey.hasSubKey() ? groupKey.getSubKey() : simpleResultSeriesKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Chart createChart() {
|
private Chart createChart() {
|
||||||
|
|||||||
Reference in new issue
Block a user