+
+ DynamicVisualisation dv = graph.syncRequest(new RuntimeDynamicVisualisationsRequest(runtimeDiagram),
+ TransientCacheAsyncListener.instance());
+
+ // Prevent PendingVariableExceptions from coming through
+ boolean wasSynchronous = graph.setSynchronous(true);
+ try {
+ if (dv != null) {
+ Layer0 L0 = Layer0.getInstance(graph);
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ Resource mapping = graph.getSingleObject(groupItem, DN.HasMapping);
+
+ Map<String, DynamicColorContribution> colorContributions = dv.getColorContributions();
+ String mappingName = graph.getRelatedValue(mapping, L0.HasName);
+ DynamicColorContribution dcc = colorContributions.get(mappingName);
+ if (dcc != null && dcc.isUsed()) {
+
+ Resource mappedComponent = graph.getPossibleObject(groupItem, DN.MappedComponent);
+ if (mappedComponent != null) {
+
+ Resource component = graph.getSingleObject(mappedComponent, MOD.ElementToComponent);
+ Variable variable = Variables.getVariable(graph, component);
+ Variable possibleActiveVariable = Variables.possibleActiveVariable(graph, variable);
+ if (possibleActiveVariable != null) {
+
+ Variable module = possibleActiveVariable.getPossibleChild(graph, dcc.getModuleName());
+ if (module != null) {
+ Variable attribute = module.getPossibleProperty(graph, dcc.getAttributeName());
+ 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, dv.getColorBarOptions().isUseGradients(), minValue, maxValue);
+ return color;
+ } else {
+ LOGGER.warn("No value for {}", attribute.getURI(graph));
+ }
+ } else {
+ LOGGER.warn("Wrong attribute name {} for {} !!", dcc.getAttributeName(), module.getURI(graph));
+ }
+ } else {
+ LOGGER.warn("Wrong modulename {} for {} !!", dcc.getModuleName(), possibleActiveVariable.getURI(graph));
+ }
+ } else {
+ LOGGER.debug("No active experiment for {}", variable.getURI(graph));
+ }
+ } else {
+ LOGGER.debug("No mapped component for {} to calculate dynamic color style", groupItem);
+ }
+ }
+ }
+ }
+ finally {
+ graph.setSynchronous(wasSynchronous);