public boolean getVisibilityFor(double value) { final VisualFlowMapModel model = visualFlowMap.getModel(); double weightFilterMin = model.getEdgeWeightFilterMin(); double weightFilterMax = model.getEdgeWeightFilterMax(); // double edgeLengthFilterMin = model.getEdgeLengthFilterMin(); // double edgeLengthFilterMax = model.getEdgeLengthFilterMax(); // double length = getEdgeLength(); double absValue = Math.abs(value); PBounds vb = getVisualFlowMap().getCamera().getViewBounds(); boolean visible = !Double.isNaN(value) && value != 0.0 && // model.getEdgeFilter().accepts(this) weightFilterMin <= absValue && absValue <= weightFilterMax && // edgeLengthFilterMin <= length && length <= edgeLengthFilterMax && (!isSelfLoop() || visualFlowMap.getModel().getShowSelfLoops()) && (vb.contains(getSourceNode().getPoint()) || vb.contains(getTargetNode().getPoint())); return visible; }
private double getSelfLoopSizeFor(double value) { double linewidth = Math.max(1, visualFlowMap.getModel().getMaxEdgeWidth()); double normAbsValue = Math.abs(normalizeForWidthScale(value)); if (Double.isNaN(normAbsValue)) { return 0; } double avgLen = visualFlowMap.getStats().getEdgeLengthStats().getAvg(); return avgLen / MAX_EDGE_WIDTH * linewidth * normAbsValue; }
public void setHighlighted( boolean value, boolean showDirection, boolean asOutgoing, boolean propagateEvent) { if (this.highlighted != value) { this.highlighted = value; PPath ppath = getEdgePPath(); if (ppath != null) { Paint paint; if (value) { Color color; if (showDirection) { if (asOutgoing) { color = visualFlowMap.getColor(ColorCodes.EDGE_STROKE_HIGHLIGHTED_OUTGOING_PAINT); } else { color = visualFlowMap.getColor(ColorCodes.EDGE_STROKE_HIGHLIGHTED_INCOMING_PAINT); } } else { color = visualFlowMap.getColor(ColorCodes.EDGE_STROKE_HIGHLIGHTED_PAINT); } paint = color; } else { paint = createPaintFor(normalizeForColorScale(getEdgeWeight())); } ppath.setStrokePaint(paint); } repaint(); if (propagateEvent) { if (logger.isDebugEnabled()) { logger.debug( (value ? "H" : "Unh") + "ighlight edge [" + getLabel() + " (" + visualFlowMap.getValueAttr() + " = " + getEdgeWeight() + ")]"); } getVisualFlowMap() .firePropertyChange( VisualFlowMap.PROPERTY_CODE_HIGHLIGHTED, VisualFlowMap.PROPERTY_HIGHLIGHTED, Pair.of(edge, !value), Pair.of(edge, value)); } } }
public void adjustBounds(double x, double y, double w, double h) { PBounds viewBounds = getCamera().getViewBounds(); getCamera().setBounds(x, y, w, h); pp.setBounds(x, y, w, h); visualFlowMap.updateFlowWeightAttrLabel(); if (!viewBounds.isEmpty()) { camera.setViewBounds(viewBounds); } }
private Paint createPaintFor(double normValue) { return visualFlowMap .getVisualEdgePaintFactory() .createPaint( normValue, getSourceX(), getSourceY(), getTargetX(), getTargetY(), edgeLength, isSelfLoop); }
public VisualEdge( VisualFlowMap visualFlowMap, Edge edge, VisualNode sourceNode, VisualNode targetNode) { this.edge = edge; this.sourceNode = sourceNode; this.targetNode = targetNode; this.visualFlowMap = visualFlowMap; this.isSelfLoop = visualFlowMap.getFlowMapGraph().isSelfLoop(edge); if (isSelfLoop) { this.edgeLength = 0; } else { this.edgeLength = getDistance(sourceNode, targetNode); } }
public VisualFlowMapLayer(VisualFlowMap visualFlowMap, PCamera camera) { this.visualFlowMap = visualFlowMap; this.camera = camera; this.camera.addLayer(this); // this.camera.addChild(visualFlowMap.getTooltipBox()); // border pp = new PPath(new PBounds(0, 0, 1, 1)); pp.setStroke(new PFixedWidthStroke(2)); pp.setStrokePaint(Color.gray); camera.addChild(pp); visualFlowMap.setFlowWeightAttrLabelVisibile(true); addChild(visualFlowMap); }
protected Stroke createStrokeFor(double normValue) { return visualFlowMap.getVisualEdgeStrokeFactory().createStroke(normValue); }
private double normalizeForColorScale(double value) { return visualFlowMap.getModel().normalizeForColorScale(value); }
public double getEdgeWeight() { return edge.getDouble(visualFlowMap.getValueAttr()); }
public FlowMapSmallMultipleView( VisualFlowMapModel model, final GeoMap areaMap, final MapProjections proj, final IFlowMapColorScheme cs, int numberOfColumns) { this.model = model; this.numberOfColumns = numberOfColumns; FlowMapGraph fmg = model.getFlowMapGraph(); VisualCanvas canvas = getVisualCanvas(); canvas.setInteractingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); canvas.setAnimatingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); final PTooltip tooltip = new PTooltip(); layers = Lists.newArrayList(); for (String attr : fmg.getEdgeWeightAttrs()) { final PCamera camera = new PCamera(); final VisualFlowMap vfm = new VisualFlowMap(this, model, true, proj, attr, cs) { @Override public PCamera getCamera() { return camera; } @Override protected PTooltip createTooltip() { return tooltip; } @Override public void showTooltip(PNode component, Point2D pos) { Point2D p = new Point2D.Double(pos.getX(), pos.getY()); getCamera().viewToLocal(p); super.showTooltip(component, p); } }; canvas.getCamera().addChild(tooltip); if (areaMap != null) { vfm.setAreaMap(new PGeoMap(vfm, areaMap, proj)); } VisualFlowMapLayer layer = new VisualFlowMapLayer(vfm, camera); layers.add(layer); vfm.addPropertyChangeListener( VisualFlowMap.PROPERTY_HIGHLIGHTED, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { for (VisualFlowMapLayer layer : layers) { if (layer.getVisualFlowMap() != vfm) { @SuppressWarnings("unchecked") Pair<Edge, Boolean> val = (Pair<Edge, Boolean>) evt.getNewValue(); layer.getVisualFlowMap().setEdgeHighlighted(val.first(), val.second()); } } } }); canvas.getLayer().addChild(layer.getCamera()); } final Legend legend; if (layers.size() > 0) { VisualFlowMapLayer layer1 = layers.get(0); final VisualFlowMap vfm = layer1.getVisualFlowMap(); final PCamera cam = layer1.getCamera(); legend = vfm.getVisualLegend(); cam.addChild(legend); cam.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName() == PCamera.PROPERTY_VIEW_TRANSFORM) { if (logger.isDebugEnabled()) { PBounds fb = vfm.getVisualNodesBounds(); PBounds b = cam.getViewBounds(); double areap = (b.width * b.height) / (fb.width * fb.height / 100); logger.debug( "View transform to " + b + " (" + FlowMapView.NUMBER_FORMAT.format(areap) + "% of visible area)"); } } } }); } else { legend = null; } final PButton diffButton = new PButton("DIFF", true, new Font("Dialog", Font.PLAIN, 11)); getCamera().addChild(diffButton); diffButton.addInputEventListener( new PBasicInputEventHandler() { @Override public void mouseClicked(PInputEvent event) { for (int i = 0; i < layers.size(); i++) { VisualFlowMap vfm = layers.get(i).getVisualFlowMap(); if (diffButton.isPressed()) { vfm.setValueType(ValueType.DIFF); } else { vfm.setValueType(ValueType.VALUE); } } } }); getVisualCanvas().getModeButtonsPanel().addChild(diffButton); canvas.setBackground(cs.get(ColorCodes.BACKGROUND)); canvas.setAutoFitOnBoundsChange(false); canvas.setPanEventHandler(createPanHandler()); canvas.setZoomHandler(createZoomHandler()); layoutChildren(); getCamera() .addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName() == PCamera.PROPERTY_BOUNDS) { layoutChildren(); // fitInView(); if (legend != null) { // PBounds b = getCamera().getBoundsReference(); PBounds lb = legend.getFullBoundsReference(); PBoxLayoutNode mp = getVisualCanvas().getModeButtonsPanel(); PBounds mpb = mp.getFullBoundsReference(); PNodes.setPosition(mp, lb.getMaxX() - mpb.width, lb.getMaxY() + 4); } } } }); fitInView(); }