X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fvisualisations%2Fmodel%2FDynamicColorMap.java;h=4c4580979ef6f613c83c776d0f44819fbe4f2e16;hb=a2c485af95024784aa9de3378759ee94b8caea2e;hp=09cb57943f6865ae8dd6f251c737c04d88f44588;hpb=0249f20bb127e61c58db4432b8609ff0cb441480;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorMap.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorMap.java index 09cb5794..4c458097 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorMap.java +++ b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorMap.java @@ -1,15 +1,10 @@ package org.simantics.district.network.visualisations.model; import java.awt.Color; -import java.util.Arrays; import java.util.List; public class DynamicColorMap { - static List blues = Arrays.asList(new RGBIntensity(0, 0, 0.1), new RGBIntensity(0, 0, 0.5), new RGBIntensity(0, 0, 0.9)); - - public static final DynamicColorMap DEFAULT = new DynamicColorMap("default", blues); - private String label; private List intensities; @@ -51,20 +46,49 @@ public class DynamicColorMap { } } - public Color getColor(double value, double defaultMin, double defaultMax) { + public Color getColor(double value, boolean useGradient, double defaultMin, double defaultMax) { + List intensities = getIntensities(); double gap = defaultMax - defaultMin; - double singleGap = gap / getIntensities().size(); + double singleGap = gap / intensities.size(); + double threshold = defaultMin; int i = 0; - while (i < getIntensities().size() - 1) { - if (value <= defaultMin + (i * singleGap)) { + while (i < intensities.size() - 1) { + threshold = threshold + singleGap; + if (value <= threshold) { break; } i++; } - RGBIntensity intensity = getIntensities().get(i); - return new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue()); + RGBIntensity intensity = intensities.get(i); + if (useGradient) { + + RGBIntensity upperLimitIntensity; + if (i + 1 != intensities.size()) + upperLimitIntensity = intensities.get(i + 1); + else + upperLimitIntensity = intensity; + + double minRed = intensity.getRed(); + double minGreen = intensity.getGreen(); + double minBlue = intensity.getBlue(); + + double maxRed = upperLimitIntensity.getRed(); + double maxGreen = upperLimitIntensity.getGreen(); + double maxBlue = upperLimitIntensity.getBlue(); + + double delta = Math.max(value - (defaultMin + singleGap * i), 0); + + double d = delta / singleGap; + + double redDelta = (maxRed - minRed) * d; + double greenDelta = (maxGreen - minGreen) * d; + double blueDelta = (maxBlue - minBlue) * d; + return new Color((float)(minRed + redDelta), (float)(minGreen + greenDelta), (float)(minBlue + blueDelta)); + } else { + return new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue()); + } } }