import java.awt.Color;
import java.util.Map;
-import org.simantics.Simantics;
import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.db.layer0.variable.Variables;
import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject;
import org.simantics.district.network.visualisations.model.DynamicColorContribution;
import org.simantics.district.network.visualisations.model.DynamicColorMap;
import org.simantics.district.network.visualisations.model.DynamicVisualisation;
import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
import org.simantics.scenegraph.profile.EvaluationContext;
import org.simantics.scenegraph.profile.common.ProfileVariables;
+import org.simantics.scl.runtime.SCLContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
DynamicVisualisation dv = graph.syncRequest(new RuntimeDynamicVisualisationsRequest(runtimeDiagram),
TransientCacheAsyncListener.instance());
- DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
// Prevent PendingVariableExceptions from coming through
boolean wasSynchronous = graph.setSynchronous(true);
try {
if (attribute != null) {
Double possibleValue = attribute.getPossibleValue(graph, Bindings.DOUBLE);
if (possibleValue != null) {
+
+ double minValue;
+ double maxValue;
+ if (dcc.isUseDefault()) {
+ DynamicColoringObject dynamicColoringObject = dv.getDefaultColorContributions().get(mappingName);
+
+ // This is required if ontology module needs to be compiled
+ Object currentGraph = SCLContext.getCurrent().get("graph");
+ try {
+ SCLContext.getCurrent().put("graph", graph);
+
+ DynamicColorContribution ddcc = dynamicColoringObject.getColorContributions().get(dcc.getLabel());
+ minValue = ddcc.getDefaultMin();
+ maxValue = ddcc.getDefaultMax();
+ } finally {
+ SCLContext.getCurrent().put("graph", currentGraph);
+ }
+ } else {
+ minValue = dcc.getDefaultMin();
+ maxValue = dcc.getDefaultMax();
+ }
// here we do the adjusting according to spec in #15038
double adjustedValue = possibleValue.doubleValue() * dcc.getVariableGain() + dcc.getVariableBias();
DynamicColorMap defaultColorMap = dcc.getDefaultColorMap();
- Color color = defaultColorMap.getColor(adjustedValue, dcc.getDefaultMin(), dcc.getDefaultMax());
+ Color color = defaultColorMap.getColor(adjustedValue, dv.getColorBarOptions().isUseGradients(), minValue, maxValue);
return color;
} else {
LOGGER.warn("No value for {}", attribute.getURI(graph));
}
}
}
-
- // the old implementation here
- if (ds.elementColoringFunction.isPresent()) {
- if (DEBUG)
- System.out.print("elementColoringFunction: " + ds.elementColoringFunction + "(" + groupItem + "): ");
- Double t = Simantics.applySCLRead(graph, ds.elementColoringFunction.get(), groupItem);
- if (DEBUG)
- System.out.print(t);
- if (t != null) {
- Color result = ds.coloringGradient.get(t);
- //System.out.println("color(" + t + "): " + result);
- return result;
- }
- }
}
finally {
graph.setSynchronous(wasSynchronous);