private void updateEdges(HierarchicalGraph graph) { Modeler edgeInit = engine.getModelClasses()[AbstractEngine.CLASS_EDGE].getCurrentModeler(); Modeler arrowInit = engine.getModelClasses()[AbstractEngine.CLASS_ARROW].getCurrentModeler(); EdgeIterable edgeIterable; edgeIterable = graph.getEdges(); float minWeight = Float.POSITIVE_INFINITY; float maxWeight = Float.NEGATIVE_INFINITY; TimeInterval timeInterval = DynamicUtilities.getVisibleInterval(dynamicModel); for (Edge edge : edgeIterable) { if (edge.getSource().getNodeData().getModel() == null || edge.getTarget().getNodeData().getModel() == null) { continue; } float weight = 1f; if (timeInterval == null) { weight = edge.getWeight(); } else { weight = edge.getWeight(timeInterval.getLow(), timeInterval.getHigh()); } minWeight = Math.min(minWeight, weight); maxWeight = Math.max(maxWeight, weight); Edge2dModel obj = (Edge2dModel) edge.getEdgeData().getModel(); if (obj == null) { // Model is null, ADD obj = (Edge2dModel) edgeInit.initModel(edge.getEdgeData()); engine.addObject(AbstractEngine.CLASS_EDGE, obj); if (!undirected && vizConfig.isShowArrows() && !edge.isSelfLoop()) { Arrow2dModel arrowObj = (Arrow2dModel) arrowInit.initModel(edge.getEdgeData()); engine.addObject(AbstractEngine.CLASS_ARROW, arrowObj); arrowObj.setCacheMarker(cacheMarker); arrowObj.setWeight(weight); obj.setArrow(arrowObj); } } else if (!obj.isValid()) { engine.addObject(AbstractEngine.CLASS_EDGE, obj); if (!undirected && vizConfig.isShowArrows() && !edge.isSelfLoop()) { Arrow2dModel arrowObj = obj.getArrow(); engine.addObject(AbstractEngine.CLASS_ARROW, arrowObj); arrowObj.setCacheMarker(cacheMarker); arrowObj.setWeight(weight); } } else { if (!undirected && vizConfig.isShowArrows() && !edge.isSelfLoop() && edge.isDirected()) { Arrow2dModel arrowObj = obj.getArrow(); arrowObj.setCacheMarker(cacheMarker); arrowObj.setWeight(weight); } } obj.setWeight(weight); obj.setCacheMarker(cacheMarker); } limits.setMinWeight(minWeight); limits.setMaxWeight(maxWeight); }
private String formatTime(double time) { if (dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATE)) { String t = DynamicUtilities.getXMLDateStringFromDouble(time); if (t.endsWith("T00:00:00.000")) { t = t.substring(0, t.length() - 13); } return t; } else { return Double.toString(time); } }
private void writeAttValues( XMLStreamWriter xmlWriter, AttributeRow row, TimeInterval visibleInterval) throws Exception { xmlWriter.writeStartElement(ATTVALUES); for (AttributeValue val : row.getValues()) { AttributeColumn col = val.getColumn(); if (!col.getOrigin().equals(AttributeOrigin.PROPERTY) || (exportDynamic && col.getOrigin().equals(AttributeOrigin.PROPERTY) && col.getIndex() == PropertiesColumn.EDGE_WEIGHT.getIndex())) { AttributeType type = col.getType(); if (type.isDynamicType()) { DynamicType dynamicValue = (DynamicType) val.getValue(); if (dynamicValue != null && visibleInterval != null && exportDynamic) { List<Interval<?>> intervals = dynamicValue.getIntervals(visibleInterval.getLow(), visibleInterval.getHigh()); for (Interval<?> interval : intervals) { Object value = interval.getValue(); if (value != null) { xmlWriter.writeStartElement(ATTVALUE); xmlWriter.writeAttribute(ATTVALUE_FOR, col.getId()); xmlWriter.writeAttribute(ATTVALUE_VALUE, value.toString()); if (!Double.isInfinite(interval.getLow())) { String intervalLow = formatTime(interval.getLow()); xmlWriter.writeAttribute( interval.isLowExcluded() ? START_OPEN : START, intervalLow); } if (!Double.isInfinite(interval.getHigh())) { String intervalHigh = formatTime(interval.getHigh()); xmlWriter.writeAttribute( interval.isHighExcluded() ? END_OPEN : END, intervalHigh); } xmlWriter.writeEndElement(); } } } else if (dynamicValue != null) { TimeInterval interval = visibleInterval; if (interval == null) { interval = new TimeInterval(); } Object value = DynamicUtilities.getDynamicValue( dynamicValue, interval.getLow(), interval.getHigh()); if (value != null) { xmlWriter.writeStartElement(ATTVALUE); xmlWriter.writeAttribute(ATTVALUE_FOR, val.getColumn().getId()); xmlWriter.writeAttribute(ATTVALUE_VALUE, value.toString()); xmlWriter.writeEndElement(); } } } else { if (val.getValue() != null) { xmlWriter.writeStartElement(ATTVALUE); xmlWriter.writeAttribute(ATTVALUE_FOR, col.getId()); xmlWriter.writeAttribute(ATTVALUE_VALUE, val.getValue().toString()); xmlWriter.writeEndElement(); } } } } xmlWriter.writeEndElement(); }