sort tiles on the dashboard

This commit is contained in:
2018-04-28 19:03:07 +02:00
parent 913057c6df
commit 2da54432ff
7 changed files with 183 additions and 49 deletions

View File

@@ -9,8 +9,7 @@ import org.lucares.pdb.plot.api.AggregatedData;
import org.lucares.pdb.plot.api.Limit;
public interface DataSeries {
public static final Comparator<? super DataSeries> BY_NUMBER_OF_VALUES = (
a, b) -> {
public static final Comparator<? super DataSeries> BY_NUMBER_OF_VALUES = (a, b) -> {
return a.getValues() - b.getValues();
};
@@ -18,24 +17,27 @@ public interface DataSeries {
final long result = a.getMaxValue() - b.getMaxValue();
return result < 0 ? -1 : (result > 0 ? 1 : 0);
};
public static final Comparator<? super DataSeries> BY_NAME = (a,b) -> {
public static final Comparator<? super DataSeries> BY_NAME = (a, b) -> {
return a.getTitle().compareToIgnoreCase(b.getTitle());
};
public String getIdAsString();
public int getId();
public String getTitle();
public int getValues();
public long getMaxValue();
public void setStyle(String style);
public String getStyle();
public AggregatedData getAggregatedData();
public String getGnuplotPlotDefinition();
public static Map<String, Integer> toMap(final List<DataSeries> dataSeries) {
@@ -53,7 +55,7 @@ public interface DataSeries {
static Comparator<? super DataSeries> getDataSeriesComparator(final Limit limitBy) {
switch (limitBy) {
case MOST_VALUES:
case MOST_VALUES:
return DataSeries.BY_NUMBER_OF_VALUES.reversed();
case FEWEST_VALUES:
return DataSeries.BY_NUMBER_OF_VALUES;
@@ -64,13 +66,13 @@ public interface DataSeries {
case NO_LIMIT:
return DataSeries.BY_NAME;
}
throw new IllegalStateException("unhandled enum: "+ limitBy);
throw new IllegalStateException("unhandled enum: " + limitBy);
}
static void sortAndLimit(final List<DataSeries> dataSeries, final Limit limitBy, final int limit) {
dataSeries.sort(DataSeries.getDataSeriesComparator(limitBy));
switch (limitBy) {
case FEWEST_VALUES:
case MOST_VALUES:
@@ -84,30 +86,27 @@ public interface DataSeries {
}
}
static void setColors(List<DataSeries> dataSeries){
static void setColors(final List<DataSeries> dataSeries) {
int i = 0;
for (DataSeries dataSerie : dataSeries) {
for (final DataSeries dataSerie : dataSeries) {
final int numColors = GnuplotColorPalettes.DEFAULT.size();
final int numDashTypes = DashTypes.DEFAULT.size();
GnuplotColor color = GnuplotColorPalettes.DEFAULT.get(i % numColors);
if (dataSerie.getAggregatedData() != null){
// color = color.brighter();
final GnuplotColor color = GnuplotColorPalettes.DEFAULT.get(i % numColors);
if (dataSerie.getAggregatedData() != null) {
// color = color.brighter();
}
final String dashType = DashTypes.DEFAULT.get((i/numColors) % numDashTypes);
String style = String.format("lt %s dt %s ",//
color.getColor(),//
final String dashType = DashTypes.DEFAULT.get((i / numColors) % numDashTypes);
final String style = String.format("lt %s dt %s ", //
color.getColor(), //
dashType//
);
);
dataSerie.setStyle(style);
i++;
}
}
}