embedded bar charts seem to work

This commit is contained in:
Axel Uhl committed 2011-09-20 17:35:03 +02:00
1 parent 17d0b3dea7
commit b86097af5c
8 files changed
+53 -25

No files matched your search

@@ -146,6 +146,7 @@ public abstract class ExpandableSortableColumn<C> extends SortableColumn<Leaderb
public void run() {
int insertIndex = table.getColumnIndex(ExpandableSortableColumn.this) + 1;
for (SortableColumn<LeaderboardRowDAO, ?> column : getAllVisibleChildren()) {
column.updateMinMax(getLeaderboardPanel().getLeaderboard());
getLeaderboardPanel().insertColumn(insertIndex++, column);
}
}
@@ -5,7 +5,6 @@ import com.google.gwt.cell.client.TextCell;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.client.Random;
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
public class FormattedDoubleLegDetailColumn extends LegDetailColumn<Double, String> {
@@ -45,7 +44,12 @@ public class FormattedDoubleLegDetailColumn extends LegDetailColumn<Double, Stri
}
private int getPercentage(LeaderboardRowDAO row) {
return Random.nextInt(100);
Double value = getField().get(row);
int percentage = 0;
if (value != null) {
percentage = (int) (100.*(value-getMinimum())/(getMaximum()-getMinimum()));
}
return percentage;
}
}
@@ -469,12 +469,19 @@ public class LeaderboardPanel extends FormPanel implements LegDetailSelectionPro
return namesOfExpandedRaces;
}
/**
* Also updates the min/max values on the columns
*/
private void updateLeaderboard(LeaderboardDAO leaderboard) {
setLeaderboard(leaderboard);
adjustColumnLayout(leaderboard);
getData().getList().clear();
if (leaderboard != null) {
getData().getList().addAll(leaderboard.rows.values());
for (int i=0; i<getLeaderboardTable().getColumnCount(); i++) {
SortableColumn<?, ?> c = (SortableColumn<?, ?>) getLeaderboardTable().getColumn(i);
c.updateMinMax(leaderboard);
}
Comparator<LeaderboardRowDAO> comparator = getComparatorForSelectedSorting();
if (comparator != null) {
Collections.sort(getData().getList(), comparator);
@@ -55,7 +55,7 @@
.cellTableEvenRow {
border-bottom: 1px solid #e5e5e5;
background-color: #FFFFFF;
background-color: #f2f2f2;
}
.cellTableEvenRowCell {
@@ -26,7 +26,7 @@ public class LegColumn extends ExpandableSortableColumn<String> {
private final StringConstants stringConstants;
private final LegDetailSelectionProvider legDetailSelectionProvider;
private abstract class AbstractLegDetailField<T> implements LegDetailField<T> {
private abstract class AbstractLegDetailField<T extends Comparable<?>> implements LegDetailField<T> {
public T get(LeaderboardRowDAO row) {
LegEntryDAO entry = getLegEntry(row);
if (entry == null) {
@@ -6,14 +6,17 @@ import com.google.gwt.cell.client.Cell;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Header;
import com.google.gwt.user.cellview.client.TextHeader;
import com.sap.sailing.gwt.ui.shared.LeaderboardDAO;
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
public abstract class LegDetailColumn<FieldType, RenderingType> extends SortableColumn<LeaderboardRowDAO, RenderingType> {
public abstract class LegDetailColumn<FieldType extends Comparable<?>, RenderingType> extends SortableColumn<LeaderboardRowDAO, RenderingType> {
private final String title;
private final LegDetailField<FieldType> field;
private final CellTable<LeaderboardRowDAO> leaderboardTable;
private FieldType minimum;
private FieldType maximum;
public interface LegDetailField<T> {
public interface LegDetailField<T extends Comparable<?>> {
T get(LeaderboardRowDAO row);
}
@@ -57,4 +60,33 @@ public abstract class LegDetailColumn<FieldType, RenderingType> extends Sortable
return new TextHeader(title);
}
public FieldType getMinimum() {
return minimum;
}
public FieldType getMaximum() {
return maximum;
}
@Override
protected void updateMinMax(LeaderboardDAO leaderboard) {
Comparator<LeaderboardRowDAO> comparator = getComparator();
LeaderboardRowDAO minimumRow = null;
LeaderboardRowDAO maximumRow = null;
for (LeaderboardRowDAO row : leaderboard.rows.values()) {
if (minimumRow == null || (comparator.compare(minimumRow, row) > 0 && getField().get(row) != null)) {
minimumRow = row;
}
if (maximumRow == null || (comparator.compare(maximumRow, row) < 0 && getField().get(row) != null)) {
maximumRow = row;
}
}
if (minimumRow != null) {
minimum = getField().get(minimumRow);
}
if (maximumRow != null) {
maximum = getField().get(maximumRow);
}
}
}
@@ -7,6 +7,7 @@ import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortList;
import com.google.gwt.user.cellview.client.Header;
import com.sap.sailing.gwt.ui.shared.LeaderboardDAO;
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
public abstract class SortableColumn<T, C> extends Column<T, C> {
@@ -15,6 +16,8 @@ public abstract class SortableColumn<T, C> extends Column<T, C> {
setSortable(true);
}
protected void updateMinMax(LeaderboardDAO leaderboard) {}
/**
* To enable sorting of <code>null</code> values to the end even in ascending order, the comparators provided
* by the subclasses will want to know whether the leaderboard table is currently sorted in ascending order
@@ -1,19 +0,0 @@
package com.sap.sailing.gwt.ui.client;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.user.cellview.client.CellTable;
import com.sap.sailing.gwt.ui.shared.LeaderboardRowDAO;
public class StringRenderingLegDetailColumn<FieldType> extends LegDetailColumn<FieldType, String> {
protected StringRenderingLegDetailColumn(String title,
com.sap.sailing.gwt.ui.client.LegDetailColumn.LegDetailField<FieldType> field, CellTable<LeaderboardRowDAO> leaderboardTable) {
super(title, field, new TextCell(), leaderboardTable);
}
@Override
public String getValue(LeaderboardRowDAO row) {
FieldType fieldValue = getField().get(row);
return fieldValue == null ? "" : fieldValue.toString();
}
}