mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-24 14:38:45 +00:00
bug4134_2: Changed behaviour of ValueRangeFlexibleBoundaries.
This commit is contained in:
+13
-5
@@ -5,20 +5,22 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class maps a given range of values to a full color spectrum. The color spectrum could also be a grey scale.
|
||||
* Therefore it needs the max and the min value to be mapped. It uses a {@link ValueRangeBoundaries} to get those.
|
||||
* The ColorMapper has listeners that will be notified if the colormapping has been changed.
|
||||
* Therefore it needs the max and the min value to be mapped. It uses a {@link ValueRangeFlexibleBoundaries} to get those. The
|
||||
* ColorMapper has listeners that will be notified if the colormapping has been changed. The ColorMapper accepts value
|
||||
* ranges that are negative, negative numbers will display as blue (hsl(240, 100%, 50%)) or fully transparent grey
|
||||
* (rgba(255,255,255,1.0)).
|
||||
*
|
||||
* @author D073259
|
||||
*
|
||||
*/
|
||||
public class ColorMapper implements ValueRangeBoundariesChangedListener {
|
||||
private final ValueRangeBoundaries valueRange;
|
||||
public class ColorMapper implements ValueRangeFlexibleBoundariesChangedListener {
|
||||
private final ValueRangeFlexibleBoundaries valueRange;
|
||||
private double minValue;
|
||||
private double maxValue;
|
||||
private boolean isGrey;
|
||||
private final Set<ColorMapperChangedListener> colorMapperChangedListeners;
|
||||
|
||||
public ColorMapper(ValueRangeBoundaries valueRange, boolean isGrey) {
|
||||
public ColorMapper(ValueRangeFlexibleBoundaries valueRange, boolean isGrey) {
|
||||
this.valueRange = valueRange;
|
||||
this.valueRange.addListener(this);
|
||||
minValue = this.valueRange.getMinLeft();
|
||||
@@ -34,8 +36,14 @@ public class ColorMapper implements ValueRangeBoundariesChangedListener {
|
||||
|
||||
public String getColor(double value) {
|
||||
if (isGrey) {
|
||||
if (value < 0) {
|
||||
return "rgba(255,255,255, 1.0)";
|
||||
}
|
||||
return "rgba(255,255,255," + Math.min(1.0, (value - minValue) / (maxValue - minValue)) + ")";
|
||||
} else {
|
||||
if (value < 0) {
|
||||
return "hsl(240, 100%, 50%)";
|
||||
}
|
||||
double h = (1 - (value - minValue) / (maxValue - minValue)) * 240;
|
||||
return "hsl(" + Math.round(h) + ", 100%, 50%)";
|
||||
}
|
||||
|
||||
+3
-3
@@ -64,7 +64,7 @@ public class Swarm implements TimeListener {
|
||||
private HandlerRegistration handlerRegistration;
|
||||
|
||||
private boolean colored = false;
|
||||
private final ValueRangeBoundaries valueRange;
|
||||
private final ValueRangeFlexibleBoundaries valueRange;
|
||||
private final ColorMapper colorMapper;
|
||||
|
||||
public Swarm(FullCanvasOverlay fullcanvas, MapWidget map, com.sap.sse.gwt.client.player.Timer timer,
|
||||
@@ -78,7 +78,7 @@ public class Swarm implements TimeListener {
|
||||
timePoint = timer.getTime();
|
||||
cosineOfAverageLatitude = 1.0; // default to equator
|
||||
diffPx = new Vector(0, 0);
|
||||
valueRange = new ValueRangeBoundaries(0.0, 120.0, /*percentage*/ 0.1);
|
||||
valueRange = new ValueRangeFlexibleBoundaries(0.0, 120.0, /*percentage*/ 0.15);
|
||||
colorMapper = new ColorMapper(valueRange, !colored);
|
||||
}
|
||||
public void start(final int animationIntervalMillis) {
|
||||
@@ -290,7 +290,7 @@ public class Swarm implements TimeListener {
|
||||
drawSwarm();
|
||||
return true;
|
||||
}
|
||||
public ValueRangeBoundaries getValueRange() {
|
||||
public ValueRangeFlexibleBoundaries getValueRange() {
|
||||
return valueRange;
|
||||
}
|
||||
public ColorMapper getColorMapper() {
|
||||
|
||||
+25
-32
@@ -4,9 +4,8 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class defines if a given value is within boundaries that are flexible by a given rangeWidth. The rangeWidth is
|
||||
* defined by a percentage of the minimum value, otherwise the adjustment of the boundaries will be biased and the max
|
||||
* boundaries are always much bigger then the minimum boundaries. It needs four types of boundaries:
|
||||
* This class defines if a given value is within boundaries that are flexible by a given halfBoundaryWidth. The halfBoundaryWidth is
|
||||
* defined by a percentage of the difference between max and min of a value range. It needs four types of boundaries:
|
||||
* a) minLeft
|
||||
* b) maxLeft
|
||||
* c) minRight
|
||||
@@ -15,54 +14,48 @@ import java.util.Set;
|
||||
* If a value is not within the left or the right boundaries the boundaries should be adjusted in a way that the value will fit in the
|
||||
* one or the other. Also there should be the possibility to add listeners that will notify on a boundary change.
|
||||
*
|
||||
* A ValueRangeBoundaries needs an initialMin, a initialMax and a percentage that indicates the width of the value range
|
||||
* A ValueRangeFlexibleBoundaries needs an initialMin, a initialMax and a percentage that indicates the width of the value range
|
||||
* surrounding initialMin and Max.
|
||||
*
|
||||
* @author D073259
|
||||
*
|
||||
*/
|
||||
public class ValueRangeBoundaries {
|
||||
public class ValueRangeFlexibleBoundaries {
|
||||
private double minLeft;
|
||||
private double maxLeft;
|
||||
private double minRight;
|
||||
private double maxRight;
|
||||
private double min;
|
||||
private double max;
|
||||
private final double percentage;
|
||||
private double halfRangeWidth;
|
||||
private final Set<ValueRangeBoundariesChangedListener> valueRangeChangedListeners;
|
||||
private double halfBoundaryWidth;
|
||||
private final Set<ValueRangeFlexibleBoundariesChangedListener> valueRangeChangedListeners;
|
||||
|
||||
public ValueRangeBoundaries(double initialMin, double initialMax, double percentage) {
|
||||
public ValueRangeFlexibleBoundaries(double initialMin, double initialMax, double percentage) {
|
||||
this.percentage = percentage;
|
||||
updateLeft(initialMin);
|
||||
updateRight(initialMax);
|
||||
valueRangeChangedListeners = new HashSet<>();
|
||||
this.halfRangeWidth = ((initialMin * (1 + percentage)) - (initialMin * (1 - percentage)))/2;
|
||||
min = initialMin;
|
||||
max = initialMax;
|
||||
update();
|
||||
}
|
||||
private void updateLeft(double value) {
|
||||
minLeft = value - halfRangeWidth;
|
||||
maxLeft = value + halfRangeWidth;
|
||||
}
|
||||
private void updateRight() {
|
||||
minRight =- halfRangeWidth;
|
||||
maxRight =+ halfRangeWidth;
|
||||
}
|
||||
private void updateRight(double value) {
|
||||
minRight = value - halfRangeWidth;
|
||||
maxRight = value + halfRangeWidth;
|
||||
}
|
||||
private void updateRangeWidth(double newMinValue) {
|
||||
halfRangeWidth = ((newMinValue * (1 + percentage)) - (newMinValue * (1 - percentage)))/2;
|
||||
private void update() {
|
||||
halfBoundaryWidth = (max - min) * (percentage);
|
||||
minLeft = min - halfBoundaryWidth;
|
||||
maxLeft = min + halfBoundaryWidth;
|
||||
minRight = max - halfBoundaryWidth;
|
||||
maxRight = max + halfBoundaryWidth;
|
||||
}
|
||||
public void checkIfValueIsInRightBoundaryRangeAndUpdateIfNecessary(double value) {
|
||||
if (!isValueInRightRange(value)) {
|
||||
updateRight(value);
|
||||
max = value;
|
||||
update();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
public void checkIfValueIsInLeftBoundaryRangeAndUpdateIfNecessary(double value) {
|
||||
if (!isValueInLeftRange(value)) {
|
||||
updateRangeWidth(value);
|
||||
updateRight();
|
||||
updateLeft(value);
|
||||
min = value;
|
||||
update();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -86,14 +79,14 @@ public class ValueRangeBoundaries {
|
||||
public double getMaxRight() {
|
||||
return maxRight;
|
||||
}
|
||||
public void addListener(ValueRangeBoundariesChangedListener listener) {
|
||||
public void addListener(ValueRangeFlexibleBoundariesChangedListener listener) {
|
||||
valueRangeChangedListeners.add(listener);
|
||||
}
|
||||
public void removeListener(ValueRangeBoundariesChangedListener listener) {
|
||||
public void removeListener(ValueRangeFlexibleBoundariesChangedListener listener) {
|
||||
valueRangeChangedListeners.remove(listener);
|
||||
}
|
||||
public void notifyListeners() {
|
||||
for (ValueRangeBoundariesChangedListener listener : valueRangeChangedListeners) {
|
||||
for (ValueRangeFlexibleBoundariesChangedListener listener : valueRangeChangedListeners) {
|
||||
listener.onValueRangeBoundariesChanged();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package com.sap.sailing.gwt.ui.simulator.streamlets;
|
||||
|
||||
public interface ValueRangeBoundariesChangedListener {
|
||||
public interface ValueRangeFlexibleBoundariesChangedListener {
|
||||
void onValueRangeBoundariesChanged();
|
||||
}
|
||||
Reference in New Issue
Block a user