@Test public void testRepeatGroup() { Table t = new Table(); Graph g = new Graph(); try { m_vis.add("t", t); Assert.fail("Should not allow duplicate groups"); } catch (Exception e) { } try { m_vis.addFocusGroup(Visualization.FOCUS_ITEMS, t); Assert.fail("Should not allow duplicate groups"); } catch (Exception e) { } try { m_vis.add("g", g); Assert.fail("Should not allow duplicate groups"); } catch (Exception e) { } m_vis.removeGroup("t"); try { m_vis.add("t", t); } catch (Exception e) { Assert.fail("Should be able to re-use group name after removal"); } m_vis.removeGroup("g"); try { m_vis.add("g", t); } catch (Exception e) { Assert.fail("Should be able to re-use group name after removal"); } }
@Before public void setUp() { m_vis = new Visualization(); m_t = TableTest.getTestCaseTable(); m_g = GraphTest.getTestCaseGraph(); m_t0 = m_t.getTuple(0); m_n0 = m_g.getNode(0); VisualTable vt = (VisualTable) m_vis.add("t", m_t); VisualGraph vg = (VisualGraph) m_vis.add("g", m_g); m_vt0 = vt.getItem(0); m_vn0 = (NodeItem) vg.getNode(0); TupleSet ts = m_vis.getFocusGroup(Visualization.FOCUS_ITEMS); ts.addTuple(m_vt0); ts.addTuple(m_vn0); }
public Display getGraphDisplay( GraphLayoutType glType, final ExperimentPanel expPanel, String highlightName) { Display display = new Display(); int X = expPanel.getDetailWidth(); int Y = expPanel.getDetailHeight(); display.setSize(X, Y); // set display size // display.setHighQuality(true); // display.setPreferredSize(new Dimension(600,600)); display.addControlListener(new DragControl()); // drag items around display.addControlListener(new PanControl()); // pan with background left-drag display.addControlListener(new WheelZoomControl()); // zoom with vertical right-drag display.addControlListener( new ZoomToFitControl(Visualization.ALL_ITEMS, 50, 500, Control.MIDDLE_MOUSE_BUTTON)); display.addControlListener(new NeighborHighlightControl()); Visualization vis = new Visualization(); if (clusterGraph == null) { clusterGraph = this.toGraph(); } vis.add("graph", clusterGraph); LabelRenderer r = new LabelRenderer("name"); r.setHorizontalAlignment(Constants.CENTER); // r.setRoundedCorner(8, 8); // round the corners DefaultRendererFactory rf = new DefaultRendererFactory(r); rf.setDefaultEdgeRenderer(new EdgeRenderer(Constants.EDGE_TYPE_CURVE)); vis.setRendererFactory(rf); int[] palette = new int[] {ColorLib.rgb(255, 180, 180), ColorLib.rgb(190, 190, 255)}; DataColorAction fill = new DataColorAction( "graph.nodes", "type", Constants.NOMINAL, VisualItem.FILLCOLOR, palette); fill.add(VisualItem.FIXED, ColorLib.rgb(255, 100, 100)); fill.add(VisualItem.HIGHLIGHT, ColorLib.rgb(255, 200, 125)); int[] text_palette = new int[] {ColorLib.gray(0), ColorLib.gray(255)}; DataColorAction text = new DataColorAction( "graph.nodes", "indeterminate", Constants.NUMERICAL, VisualItem.TEXTCOLOR, text_palette); // ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0)); ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(200)); ActionList color = new ActionList(Activity.INFINITY); color.add(text); color.add(fill); color.add(edges); color.add(new RepaintAction()); if (highlightName != null) { String pred = "name='" + highlightName + "'"; Iterator iter = vis.items("graph.nodes", ExpressionParser.predicate(pred)); while (iter.hasNext()) { NodeItem ni = (NodeItem) iter.next(); highlightedItem = ni; ni.setFixed(true); Iterator iterEdge = ni.edges(); while (iterEdge.hasNext()) { EdgeItem eItem = (EdgeItem) iterEdge.next(); NodeItem nItem = eItem.getAdjacentItem(ni); if (eItem.isVisible()) { eItem.setHighlighted(true); nItem.setHighlighted(true); } } } } ActionList layout = new ActionList(); switch (glType) { case BALLOON_TREE: layout.add(new BalloonTreeLayout("graph")); break; case FORCE_DIRECTED: layout = new ActionList(Activity.INFINITY); layout.add(new ForceDirectedLayout("graph")); break; case NODE_LINK_TREE: layout.add(new NodeLinkTreeLayout("graph")); break; case RADIAL_TREE: layout.add(new RadialTreeLayout("graph")); break; } // layout.add(fill); layout.add(new RepaintAction()); vis.putAction("color", color); vis.putAction("layout", layout); display.setVisualization(vis); vis.run("color"); vis.run("layout"); // Rectangle2D bounds = vis.getBounds(Visualization.ALL_ITEMS); // GraphicsLib.expand(bounds, 50 + (int)(1/display.getScale())); // DisplayLib.fitViewToBounds(display,bounds,1); // vis.runAfter("layout",1000); Control shutoffHighlight = new HoverActionControl("color") { // public void itemEntered(VisualItem item, MouseEvent evt) { // } public void itemExited(VisualItem item, MouseEvent evt) { if (highlightedItem != null) { highlightedItem.setFixed(false); Iterator iterEdge = highlightedItem.edges(); while (iterEdge.hasNext()) { EdgeItem eItem = (EdgeItem) iterEdge.next(); NodeItem nItem = eItem.getAdjacentItem(highlightedItem); if (eItem.isVisible()) { eItem.setHighlighted(false); nItem.setHighlighted(false); } } highlightedItem = null; } } }; display.addControlListener(shutoffHighlight); Control selectItem = new FocusControl() { public void itemClicked(VisualItem item, MouseEvent evt) { if (item.isInGroup("graph.nodes")) { if (item.getString("type").equals("peptide")) { Peptide pep = minPeptides.get(item.getString("name")); expPanel.showPeptide(pep, true); } if (item.getString("type").equals("protein")) { Protein pro = minProteins.get(item.getString("name")); expPanel.showProtein(pro, true); } String pred = "name='" + item.getString("name") + "'"; Iterator iter = item.getVisualization().items("graph.nodes", ExpressionParser.predicate(pred)); while (iter.hasNext()) { NodeItem ni = (NodeItem) iter.next(); highlightedItem = ni; ni.setFixed(true); Iterator iterEdge = ni.edges(); while (iterEdge.hasNext()) { EdgeItem eItem = (EdgeItem) iterEdge.next(); NodeItem nItem = eItem.getAdjacentItem(ni); if (eItem.isVisible()) { eItem.setHighlighted(true); nItem.setHighlighted(true); } } } } } }; display.addControlListener(selectItem); final JPopupMenu menu = new JPopupMenu(); // Create and add a menu item // JMenuItem printItem = new JMenuItem("Print This"); // printItem.addActionListener(new java.awt.event.ActionListener() { // public void actionPerformed(java.awt.event.ActionEvent evt) { // PrintUtilities.printComponent(display); // } // }); // menu.add(printItem); // Set the component to show the popup menu display.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent evt) { if (evt.isPopupTrigger()) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } public void mouseReleased(MouseEvent evt) { if (evt.isPopupTrigger()) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }); display.pan(X / 2.0, Y / 2.0); return display; }
public static void main(String[] argv) { // -- 1. load the data ------------------------------------------------ // load the socialnet.xml file. it is assumed that the file can be // found at the root of the java classpath Graph graph = null; try { graph = new GraphMLReader().readGraph(System.in); } catch (DataIOException e) { e.printStackTrace(); System.err.println("Error loading graph. Exiting..."); System.exit(1); } // -- 2. the visualization -------------------------------------------- // add the graph to the visualization as the data group "graph" // nodes and edges are accessible as "graph.nodes" and "graph.edges" Visualization vis = new Visualization(); vis.add("graph", graph); vis.setInteractive("graph.edges", null, false); // -- 3. the renderers and renderer factory --------------------------- // draw the "name" label for NodeItems LabelRenderer r = new LabelRenderer("label"); r.setRoundedCorner(8, 8); // round the corners EdgeRenderer eRender = new EdgeRenderer(Constants.EDGE_TYPE_CURVE, Constants.EDGE_ARROW_FORWARD); // create a new default renderer factory // return our name label renderer as the default for all non-EdgeItems // includes straight line edges for EdgeItems by default vis.setRendererFactory(new DefaultRendererFactory(r, eRender)); // -- 4. the processing actions --------------------------------------- // create our nominal color palette // pink for females, baby blue for males int[] palette = new int[] { ColorLib.rgb(190, 190, 255), ColorLib.rgb(255, 180, 180), ColorLib.rgb(128, 128, 128), }; // map nominal data values to colors using our provided palette DataColorAction fill = new DataColorAction( "graph.nodes", "type", Constants.NOMINAL, VisualItem.FILLCOLOR, palette); // use black for node text ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0)); // use light grey for edges ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(200)); ColorAction arrows = new ColorAction("graph.edges", VisualItem.FILLCOLOR, ColorLib.gray(200)); // create an action list containing all color assignments ActionList color = new ActionList(); color.add(fill); color.add(text); color.add(edges); color.add(arrows); // Add a size action DataSizeAction size = new DataSizeAction("graph.nodes", "type", 2, Constants.LINEAR_SCALE); vis.putAction("size", size); // create an action list with an animated layout ActionList layout = new ActionList(Activity.INFINITY); layout.add(new ForceDirectedLayout("graph")); layout.add(new RepaintAction()); // add the actions to the visualization vis.putAction("color", color); vis.putAction("layout", layout); // -- 5. the display and interactive controls ------------------------- Display d = new Display(vis); d.setSize(720, 500); // set display size // drag individual items around d.addControlListener(new DragControl()); // pan with left-click drag on background d.addControlListener(new PanControl()); // zoom with right-click drag d.addControlListener(new ZoomControl()); // -- 6. launch the visualization ------------------------------------- // create a new window to hold the visualization JFrame frame = new JFrame("IFDS Visualization"); // ensure application exits when window is closed frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(d); frame.pack(); // layout components in window frame.setVisible(true); // show the window // assign the colors vis.run("color"); // start up the animated layout vis.run("layout"); }
/* (non-Javadoc) * @see org.lukep.javavis.visualisation.views.AbstractVisualisationView#visit(org.lukep.javavis.visualisation.visualisers.PrefuseVisualiser, org.lukep.javavis.ui.swing.WorkspaceContext, prefuse.Display) */ @Override public void visit(PrefuseVisualiser visualiser, WorkspaceContext wspContext, Display display) { display.reset(); // -- 1. load the data ------------------------------------------------ Graph graph = new Graph(); graph.addColumn("type", String.class); graph.addColumn("name", String.class); graph.addColumn("model", IGenericModelNode.class); graph.addColumn("metricMeasurement", double.class); // create package vertices ProjectModel modelStore = wspContext.getModelStore(); HashMap<IGenericModelNode, Node> parentNodeMap = new HashMap<IGenericModelNode, Node>(modelStore.getPackageMap().size() + 10); Node curNode; for (PackageModel pkg : modelStore.getPackageMap().values()) { // add the package node curNode = graph.addNode(); curNode.setString("type", pkg.getModelTypeName()); curNode.setString("name", pkg.getSimpleName()); curNode.set("model", pkg); // link to the parent with an edge IGenericModelNode parentPackage = pkg.getParent(); if (parentPackage != null && parentPackage instanceof PackageModel && parentNodeMap.containsKey(parentPackage)) { // link to the parent package with an edge graph.addEdge(parentNodeMap.get(parentPackage), curNode); } parentNodeMap.put(pkg, curNode); } // create class and method nodes Queue<IGenericModelNode> modelQueue = new LinkedList<IGenericModelNode>(modelStore.getClassMap().values()); IGenericModelNode model; while (modelQueue.peek() != null) { model = modelQueue.remove(); curNode = graph.addNode(); curNode.setString("type", model.getModelTypeName()); curNode.setString("name", model.getSimpleName()); curNode.set("model", model); // add children to iterModels if (model.getChildCount() > 0) { for (Relationship r : model.getChildren()) if (r.getRelationshipType() == RelationshipType.ENCLOSED_IN) modelQueue.add(r.getTarget()); parentNodeMap.put(model, curNode); } // link to the parent package if (parentNodeMap.containsKey(model.getParent())) { graph.addEdge(parentNodeMap.get(model.getParent()), curNode); } // grab metric measurement if applicable if (model instanceof IMeasurableNode && wspContext.getMetric().testAppliesTo(model.getModelTypeName())) { curNode.setDouble( "metricMeasurement", ((IMeasurableNode) (model)).getMetricMeasurement(wspContext.getMetric()).getResult()); } } // -- 2. the visualisation -------------------------------------------- // TODO implement a Visualization cache Visualization vis = new Visualization(); vis.add("graph", graph); vis.setInteractive("graph.edges", null, false); // -- 3. the renderers and renderer factory --------------------------- LabelRenderer r = new LabelRenderer("name"); r.setRoundedCorner(8, 8); vis.setRendererFactory(new DefaultRendererFactory(r)); // -- 4. the processing actions --------------------------------------- // create our nominal color palette // pink for classes, baby blue for packages int[] palette = ColorLib.getCoolPalette(); // create a metric palette int[] mPalette = ColorLib.getInterpolatedPalette(0xFF00AA6D, 0xFFFFAA6D); // TODO replace int[] mPalette2 = new int[mPalette.length + 1]; mPalette2[0] = Color.lightGray.getRGB(); for (int i = 1; i < mPalette.length; i++) mPalette2[i] = mPalette[i]; // map nominal data values to colors using our provided palette DataColorAction fill = new DataColorAction( "graph.nodes", "type", Constants.NOMINAL, VisualItem.FILLCOLOR, palette); DataColorAction fillMetrics = new DataColorAction( "graph.nodes", "metricMeasurement", Constants.NUMERICAL, VisualItem.FILLCOLOR, mPalette2); // use black for node text ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0)); // use light grey for edges ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(200)); // create an action list containing all color assignments ActionList colour = new ActionList(); colour.add(fillMetrics); colour.add(text); colour.add(edges); // create an action list with an animated layout ActionList layout = new ActionList(Activity.INFINITY); // layout.add(new ForceDirectedLayout("graph")); layout.add(new NodeLinkTreeLayout("graph")); layout.add(new RepaintAction()); // add the actions to the visualisation vis.putAction("colour", colour); vis.putAction("layout", layout); // -- 5. the display and interactive controls ------------------------- display.setVisualization(vis); // -- 6. launch the visualization ------------------------------------- vis.run("colour"); vis.run("layout"); }