mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-24 14:38:45 +00:00
bug4134_2: Removed colors from VectorField and sublcasses and some code formatting.
This commit is contained in:
-18
@@ -89,11 +89,9 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
getCanvas().getElement().setId("swarm-display");
|
||||
createStreamletLegend(map);
|
||||
}
|
||||
|
||||
public double getAverageLatitudeDeg() {
|
||||
return latitudeCount > 0 ? latitudeSum/latitudeCount : 0;
|
||||
}
|
||||
|
||||
private void updateAverageLatitudeDeg(WindInfoForRaceDTO windInfoForRace) {
|
||||
for (Entry<WindSource, WindTrackInfoDTO> windSourceAndTrack : windInfoForRace.windTrackInfoByWindSource.entrySet()) {
|
||||
for (WindDTO wind : windSourceAndTrack.getValue().windFixes) {
|
||||
@@ -107,7 +105,6 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
windField.setAverageLatitudeDeg(latitudeSum/latitudeCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void createStreamletLegend(MapWidget map) {
|
||||
streamletLegend = Canvas.createIfSupported();
|
||||
streamletLegend.addStyleName("MapStreamletLegend");
|
||||
@@ -192,7 +189,6 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startStreamlets() {
|
||||
scheduleWindDataRefresh();
|
||||
if (swarm == null) {
|
||||
@@ -204,7 +200,6 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
this.swarm.start(animationIntervalMillis);
|
||||
this.swarm.getColorMapper().addListener(this);
|
||||
}
|
||||
|
||||
private void scheduleWindDataRefresh() {
|
||||
scheduler.scheduleFixedPeriod(new RepeatingCommand() {
|
||||
@Override
|
||||
@@ -223,14 +218,12 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
// Now run things once, first updating the wind sources, then grabbing the wind from those sources:
|
||||
updateWindSourcesToObserve(new Runnable() { @Override public void run() { updateWindField(); } });
|
||||
}
|
||||
|
||||
private void stopStreamlets() {
|
||||
if (this.swarm != null) {
|
||||
this.swarm.stop();
|
||||
this.swarm.getColorMapper().removeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check which wind sources are available for the race identified by {@link #raceIdentifier}. For any wind source
|
||||
* not yet observed (contained in the keys of {@link #windInfoForRace}'s
|
||||
@@ -244,7 +237,6 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
Notification.notify(stringMessages.errorFetchingWindStreamletData(caught.getMessage()),
|
||||
NotificationType.WARNING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WindInfoForRaceDTO result) {
|
||||
windInfoForRace.raceIsKnownToStartUpwind = result.raceIsKnownToStartUpwind;
|
||||
@@ -261,7 +253,6 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void updateWindField() {
|
||||
Date timeOfLastFixOfSource = null;
|
||||
Set<String> windSourceTypeNames = new HashSet<>();
|
||||
@@ -284,7 +275,6 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
Notification.notify(stringMessages.errorFetchingWindStreamletData(caught.getMessage()),
|
||||
NotificationType.WARNING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WindInfoForRaceDTO result) {
|
||||
updateAverageLatitudeDeg(result);
|
||||
@@ -311,12 +301,10 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return this.visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean isVisible) {
|
||||
if (getCanvas() != null) {
|
||||
@@ -335,7 +323,6 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setColors(boolean isColored) {
|
||||
this.colored = isColored;
|
||||
if ((isColored) && (firstColoring)) {
|
||||
@@ -345,26 +332,21 @@ public class WindStreamletsRaceboardOverlay extends MovingCanvasOverlay implemen
|
||||
if (swarm != null) {
|
||||
swarm.setColors(isColored);}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromMap() {
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawCenterChanged() {
|
||||
}
|
||||
|
||||
public void onBoundsChanged(boolean zoomChanged) {
|
||||
if (swarm != null) {
|
||||
int swarmPause = (zoomChanged ? 5 : 1);
|
||||
swarm.onBoundsChanged(zoomChanged, swarmPause);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorMappingChanged() {
|
||||
drawLegend();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-16
@@ -45,16 +45,12 @@ public class WindStreamletsCanvasOverlay extends FullCanvasOverlay implements Ti
|
||||
windFieldDTO = null;
|
||||
getCanvas().getElement().setId("swarm-display");
|
||||
}
|
||||
|
||||
public WindFieldDTO getWindFieldDTO() {
|
||||
return this.windFieldDTO;
|
||||
}
|
||||
|
||||
public WindFieldGenParamsDTO getWindParams() {
|
||||
return this.windParams;
|
||||
}
|
||||
|
||||
|
||||
public void startStreamlets() {
|
||||
if (swarm == null) {
|
||||
final SimulatorField field = new SimulatorField(getWindFieldDTO(), getWindParams(), streamletPars, coordinateSystem);
|
||||
@@ -63,27 +59,22 @@ public class WindStreamletsCanvasOverlay extends FullCanvasOverlay implements Ti
|
||||
}
|
||||
this.swarm.start(40);
|
||||
}
|
||||
|
||||
public void stopStreamlets() {
|
||||
if (swarm != null) {
|
||||
this.swarm.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public void setWindField(final WindFieldDTO windFieldDTO) {
|
||||
this.windFieldDTO = windFieldDTO;
|
||||
this.swarm = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return this.visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean isVisible) {
|
||||
if (getCanvas() != null) {
|
||||
@@ -99,14 +90,12 @@ public class WindStreamletsCanvasOverlay extends FullCanvasOverlay implements Ti
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToMap() {
|
||||
if (timer != null) {
|
||||
timer.addTimeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromMap() {
|
||||
if (timer != null) {
|
||||
@@ -114,11 +103,9 @@ public class WindStreamletsCanvasOverlay extends FullCanvasOverlay implements Ti
|
||||
}
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawCenterChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void draw() {
|
||||
super.draw();
|
||||
@@ -135,15 +122,12 @@ public class WindStreamletsCanvasOverlay extends FullCanvasOverlay implements Ti
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Swarm getSwarm() {
|
||||
return this.swarm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void timeChanged(final Date newDate, Date oldDate) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shallStop() {
|
||||
if (timer.getTime().getTime() >= this.endDate.getTime()) {
|
||||
|
||||
-22
@@ -29,13 +29,11 @@ public class RectField implements VectorField {
|
||||
|
||||
private final double maxLength;
|
||||
private final double particleFactor;
|
||||
private final String[] colorsForSpeeds;
|
||||
|
||||
private final CoordinateSystem coordinateSystem;
|
||||
|
||||
public RectField(Vector[][] field, double x0, double y0, double x1, double y1, StreamletParameters parameters, CoordinateSystem coordinateSystem) {
|
||||
this.coordinateSystem = coordinateSystem;
|
||||
colorsForSpeeds = createColorsForSpeeds();
|
||||
this.x0 = x0;
|
||||
this.x1 = x1;
|
||||
this.y0 = y0;
|
||||
@@ -147,26 +145,6 @@ public class RectField implements VectorField {
|
||||
public double getParticleWeight(LatLng p, Vector v) {
|
||||
return v == null ? 0 : (1.0 - v.length() / this.maxLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColor(double speed) {
|
||||
return colorsForSpeeds[getIntensity(speed)];
|
||||
}
|
||||
|
||||
private String[] createColorsForSpeeds() {
|
||||
String[] colors = new String[256];
|
||||
double alpha = 1.0;
|
||||
int greyValue = 255;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
colors[i] = "rgba(" + (greyValue) + "," + (greyValue) + "," + (greyValue) + "," + (alpha * i / 255.0) + ")";
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
private int getIntensity(double speed) {
|
||||
double s = speed / maxLength;
|
||||
return (int) Math.min(255, 90 + Math.round(350 * s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLineWidth(double speed) {
|
||||
|
||||
-34
@@ -49,7 +49,6 @@ public class SimulatorField implements VectorField {
|
||||
private final Position nvX;
|
||||
|
||||
private final double[][][] data;
|
||||
private final String[] colorsForSpeeds;
|
||||
private final Date startTime;
|
||||
private final Duration timeStep;
|
||||
private final CoordinateSystem coordinateSystem;
|
||||
@@ -58,7 +57,6 @@ public class SimulatorField implements VectorField {
|
||||
this.coordinateSystem = coordinateSystem;
|
||||
this.startTime = windParams.getStartTime();
|
||||
this.timeStep = windParams.getTimeStep();
|
||||
this.colorsForSpeeds = createColorsForSpeeds();
|
||||
this.rcStart = new DegreePosition(windData.windData.rcStart.getLatDeg(), windData.windData.rcStart.getLngDeg());
|
||||
this.rcEnd = new DegreePosition(windData.windData.rcEnd.getLatDeg(), windData.windData.rcEnd.getLngDeg());
|
||||
this.resX = windData.windData.resX;
|
||||
@@ -228,38 +226,6 @@ public class SimulatorField implements VectorField {
|
||||
return v == null ? 0 : (v.length() / this.maxLength + 0.1);
|
||||
}
|
||||
|
||||
private String[] createColorsForSpeeds() {
|
||||
String[] colors = new String[256];
|
||||
double alphaMin = 0.0;
|
||||
double alphaMax = 0.9;
|
||||
int greyValue = 255;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
colors[i] = "rgba(" + (greyValue) + "," + (greyValue) + "," + (greyValue) + ","
|
||||
+ (alphaMin + (alphaMax - alphaMin) * i / 255.0) + ")";
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColor(double speed) {
|
||||
return colorsForSpeeds[getIntensity(speed)];
|
||||
}
|
||||
|
||||
private int getIntensity(double speed) {
|
||||
/*
|
||||
* normalized intensity: speed == average wind speed => intensity 0.5 speed <= minimum wind speed => intensity
|
||||
* 0.0 speed between 0.0 and 1.0 double s; if (minLength == maxLength) { s = 0.5; } else if (speed <= minLength)
|
||||
* { s = 0.0; } else { s = (speed - minLength) / (maxLength - minLength); }
|
||||
*/
|
||||
|
||||
/*
|
||||
* absolute intensity speed == 12kn => intensity 0.7 speed == 20kn => intensity 1.0 speed == 0kn => intensity
|
||||
* 0.25
|
||||
*/
|
||||
double s = 0.7 + 0.0375 * (speed - 12.0);
|
||||
return (int) Math.max(0, Math.min(255, Math.round(255 * s)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLineWidth(double speed) {
|
||||
/*
|
||||
|
||||
+1
-13
@@ -63,6 +63,7 @@ public class Swarm implements TimeListener {
|
||||
|
||||
private HandlerRegistration handlerRegistration;
|
||||
|
||||
private boolean colored = false;
|
||||
private final ValueRangeBoundaries valueRange;
|
||||
private final ColorMapper colorMapper;
|
||||
|
||||
@@ -80,7 +81,6 @@ public class Swarm implements TimeListener {
|
||||
valueRange = new ValueRangeBoundaries(0.0, 120.0, /*percentage*/ 0.1);
|
||||
colorMapper = new ColorMapper(valueRange, !colored);
|
||||
}
|
||||
|
||||
public void start(final int animationIntervalMillis) {
|
||||
fullcanvas.setCanvasSettings();
|
||||
// if map is not yet loaded, wait for it
|
||||
@@ -96,7 +96,6 @@ public class Swarm implements TimeListener {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void startWithMap(int animationIntervalMillis) {
|
||||
projection = new Mercator(fullcanvas, map);
|
||||
projection.calibrate();
|
||||
@@ -105,11 +104,9 @@ public class Swarm implements TimeListener {
|
||||
swarmContinue = true;
|
||||
startLoop(animationIntervalMillis);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
swarmContinue = false;
|
||||
}
|
||||
|
||||
private Particle createParticle() {
|
||||
Particle particle = null;
|
||||
boolean done = false;
|
||||
@@ -140,7 +137,6 @@ public class Swarm implements TimeListener {
|
||||
}
|
||||
return particle;
|
||||
}
|
||||
|
||||
private LatLng getRandomPosition() {
|
||||
final LatLng result;
|
||||
double rndY = Math.random();
|
||||
@@ -157,7 +153,6 @@ public class Swarm implements TimeListener {
|
||||
}
|
||||
return newParticles;
|
||||
}
|
||||
|
||||
public void onBoundsChanged(boolean zoomChanged, int swarmPause) {
|
||||
this.zoomChanged |= zoomChanged;
|
||||
if (this.zoomChanged) {
|
||||
@@ -165,7 +160,6 @@ public class Swarm implements TimeListener {
|
||||
}
|
||||
this.swarmPause = swarmPause;
|
||||
}
|
||||
|
||||
private void updateBounds() {
|
||||
LatLngBounds fieldBounds = this.field.getFieldCorners();
|
||||
final LatLngBounds mapBounds = map.getBounds();
|
||||
@@ -179,11 +173,9 @@ public class Swarm implements TimeListener {
|
||||
cosineOfAverageLatitude = Math.cos((visibleBoundsOfField.getSouthWest().getLatitude()/180.*Math.PI+
|
||||
visibleBoundsOfField.getNorthEast().getLatitude()/180.*Math.PI)/2);
|
||||
};
|
||||
|
||||
//native void log(String message) /*-{
|
||||
// console.log( message );
|
||||
//}-*/;
|
||||
|
||||
private void startLoop(final int animationIntervalMillis) {
|
||||
// Create animation-loop based on timer timeout
|
||||
loopTimer = new com.google.gwt.user.client.Timer() {
|
||||
@@ -221,7 +213,6 @@ public class Swarm implements TimeListener {
|
||||
};
|
||||
loopTimer.schedule(animationIntervalMillis);
|
||||
}
|
||||
|
||||
private void drawSwarm() {
|
||||
Context2d ctxt = canvas.getContext2d();
|
||||
ctxt.setGlobalAlpha(0.08);
|
||||
@@ -245,8 +236,6 @@ public class Swarm implements TimeListener {
|
||||
ctxt.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean colored = false;
|
||||
public void setColors(boolean isColored) {
|
||||
this.colored = isColored;
|
||||
colorMapper.setGrey(!isColored);
|
||||
@@ -301,7 +290,6 @@ public class Swarm implements TimeListener {
|
||||
drawSwarm();
|
||||
return true;
|
||||
}
|
||||
|
||||
public ValueRangeBoundaries getValueRange() {
|
||||
return valueRange;
|
||||
}
|
||||
|
||||
-13
@@ -12,9 +12,6 @@ import com.sap.sailing.gwt.ui.client.shared.racemap.CoordinateSystem;
|
||||
* A field of vectors to display in a streamlet {@link Swarm}. The {@link Vector}s returned by {@link #getVector(Position, Date)}
|
||||
* are used to initialize {@link Particle}s. Their "speed" is the {@link Vector#length() length} of the vector.<p>
|
||||
*
|
||||
* This field provides color strings for each possible speed which are then used to style the particles as they fly through
|
||||
* the swarm.
|
||||
*
|
||||
* @author Christopher Ronnewinkel (D036654)
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
@@ -83,14 +80,4 @@ public interface VectorField {
|
||||
LatLngBounds getFieldCorners();
|
||||
|
||||
double getParticleFactor();
|
||||
|
||||
/**
|
||||
* Computes a color for a particle flying at a certain speed.
|
||||
*
|
||||
* @param speed
|
||||
* a speed as obtained by computing a {@link Vector}'s {@link Vector#length() length}.
|
||||
* @return an RGB color with optional transparency that is a legal color in CSS. Example:
|
||||
* <code>"rgba(1, 2, 3, 0.4)"</code>
|
||||
*/
|
||||
String getColor(double speed);
|
||||
}
|
||||
|
||||
-32
@@ -48,7 +48,6 @@ public class WindInfoForRaceVectorField implements VectorField, AverageLatitudeP
|
||||
private double averageLatitudeCosine;
|
||||
private double knotsInDegreePerFrame;
|
||||
private final CoordinateSystem coordinateSystem;
|
||||
private boolean colored = false;
|
||||
|
||||
private final Comparator<WindDTO> windByRequestTimePointComparator = new Comparator<WindDTO>() {
|
||||
@Override
|
||||
@@ -215,35 +214,4 @@ public class WindInfoForRaceVectorField implements VectorField, AverageLatitudeP
|
||||
public double getParticleFactor() {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
public void setColors(boolean isColored) {
|
||||
this.colored = isColored;
|
||||
}
|
||||
|
||||
public boolean getColors() {
|
||||
return this.colored;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link #MAX_WIND_SPEED_IN_KNOTS maximum wind speed} is fully opaque; zero speed is fully transparent
|
||||
*/
|
||||
@Override
|
||||
public String getColor(double speed) {
|
||||
if (this.colored) {
|
||||
double h;
|
||||
if (speed <= 4.0) {
|
||||
h = 240.0;
|
||||
} else if (speed <= 12.0) {
|
||||
h = 120.0 + (12.0 - speed) / (12.0 - 4.0) * (240.0 - 120.0);
|
||||
} else if (speed <= 20.0) {
|
||||
h = 0.0 + (20.0 - speed) / (20.0 - 12.0) * (120.0 - 0.0);
|
||||
} else {
|
||||
h = 0.0;
|
||||
}
|
||||
return "hsl(" + Math.round(h) + ", 100%, 50%)";
|
||||
} else {
|
||||
return "rgba(255,255,255," + Math.min(1.0, 0.5 + 0.6 * speed / MAX_WIND_SPEED_IN_KNOTS) + ")";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user