public GraphVisualisation(rndalg.Graph graphToShow, Vector<Vertex> cut) {
    super();

    Graph displayed = new Graph(false);
    displayed.addColumn("id", String.class);
    displayed.addColumn("isCut", Boolean.class);

    this.makeGraph(displayed, graphToShow, cut);
    this.addGraph("graph", displayed);

    LabelRenderer r = new LabelRenderer("id");
    r.setRoundedCorner(10, 10);
    r.setHorizontalPadding(5);
    r.setVerticalPadding(2);
    this.setRendererFactory(new DefaultRendererFactory(r));

    ActionList layoutActions = new ActionList(Activity.INFINITY);
    ForceDirectedLayout layout = new ForceDirectedLayout("graph");
    layoutActions.add(layout);
    layoutActions.add(new RepaintAction());

    // black text
    ColorAction textCA =
        new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0));
    // black edges
    // ColorAction edgeCA = new ColorAction("graph.edges", VisualItem.STROKECOLOR,
    // ColorLib.rgb(0,0,0));
    // edges
    ColorAction edgeCA =
        new ColorAction(
            "graph.edges",
            ExpressionParser.predicate("isCut = false"),
            VisualItem.STROKECOLOR,
            ColorLib.rgb(0, 0, 0));
    ColorAction edgeCutCA =
        new ColorAction(
            "graph.edges",
            ExpressionParser.predicate("isCut = true"),
            VisualItem.STROKECOLOR,
            ColorLib.rgb(255, 0, 0));

    // concatenate the color actions
    ActionList colorActions = new ActionList();
    colorActions.add(textCA);
    colorActions.add(edgeCA);
    colorActions.add(edgeCutCA);

    this.putAction("draw", colorActions);
    this.putAction("layout", layoutActions);
    this.runAfter("draw", "layout");

    this.run("draw");
  }
Esempio n. 2
0
  /**
   * Create a new, empty FisheyeMenu.
   *
   * @see #addMenuItem(String, javax.swing.Action)
   */
  public FisheyeMenu() {
    super(new Visualization());
    m_vis.addTable(ITEMS, m_items);

    // set up the renderer to use
    LabelRenderer renderer = new LabelRenderer(LABEL);
    renderer.setHorizontalPadding(0);
    renderer.setVerticalPadding(1);
    renderer.setHorizontalAlignment(Constants.LEFT);
    m_vis.setRendererFactory(new DefaultRendererFactory(renderer));

    // set up this display
    setSize(100, 470);
    setHighQuality(true);
    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 5));
    addControlListener(
        new ControlAdapter() {
          // dispatch an action event to the menu item
          public void itemClicked(VisualItem item, MouseEvent e) {
            ActionListener al = (ActionListener) item.get(ACTION);
            al.actionPerformed(
                new ActionEvent(item, e.getID(), "click", e.getWhen(), e.getModifiers()));
          }
        });

    // text color function
    // items with the mouse over printed in red, otherwise black
    ColorAction colors = new ColorAction(ITEMS, VisualItem.TEXTCOLOR);
    colors.setDefaultColor(ColorLib.gray(0));
    colors.add("hover()", ColorLib.rgb(255, 0, 0));

    // initial layout and coloring
    ActionList init = new ActionList();
    init.add(new VerticalLineLayout(m_maxHeight));
    init.add(colors);
    init.add(new RepaintAction());
    m_vis.putAction("init", init);

    // fisheye distortion based on the current anchor location
    ActionList distort = new ActionList();
    Distortion feye = new FisheyeDistortion(0, m_scale);
    distort.add(feye);
    distort.add(colors);
    distort.add(new RepaintAction());
    m_vis.putAction("distort", distort);

    // update the distortion anchor position to be the current
    // location of the mouse pointer
    addControlListener(new AnchorUpdateControl(feye, "distort"));
  }
 // set orientation of layout
 public void setOrientation(int orientation) {
   NodeLinkTreeLayout rtl = (NodeLinkTreeLayout) m_vis.getAction("treeLayout");
   CollapsedSubtreeLayout stl = (CollapsedSubtreeLayout) m_vis.getAction("subLayout");
   Point2D anchor;
   switch (orientation) {
     case Constants.ORIENT_LEFT_RIGHT:
       m_nodeRenderer.setHorizontalAlignment(Constants.LEFT);
       m_edgeRenderer.setHorizontalAlignment1(Constants.RIGHT);
       m_edgeRenderer.setHorizontalAlignment2(Constants.LEFT);
       m_edgeRenderer.setVerticalAlignment1(Constants.CENTER);
       m_edgeRenderer.setVerticalAlignment2(Constants.CENTER);
       anchor = new Point2D.Double(25, getHeight() / 2);
       break;
     case Constants.ORIENT_RIGHT_LEFT:
       m_nodeRenderer.setHorizontalAlignment(Constants.RIGHT);
       m_edgeRenderer.setHorizontalAlignment1(Constants.LEFT);
       m_edgeRenderer.setHorizontalAlignment2(Constants.RIGHT);
       m_edgeRenderer.setVerticalAlignment1(Constants.CENTER);
       m_edgeRenderer.setVerticalAlignment2(Constants.CENTER);
       anchor = new Point2D.Double(getWidth() - 25, getHeight() / 2);
       break;
     case Constants.ORIENT_TOP_BOTTOM:
       m_nodeRenderer.setHorizontalAlignment(Constants.CENTER);
       m_edgeRenderer.setHorizontalAlignment1(Constants.CENTER);
       m_edgeRenderer.setHorizontalAlignment2(Constants.CENTER);
       m_edgeRenderer.setVerticalAlignment1(Constants.BOTTOM);
       m_edgeRenderer.setVerticalAlignment2(Constants.TOP);
       anchor = new Point2D.Double(getWidth() / 2, 35);
       break;
     case Constants.ORIENT_BOTTOM_TOP:
       m_nodeRenderer.setHorizontalAlignment(Constants.CENTER);
       m_edgeRenderer.setHorizontalAlignment1(Constants.CENTER);
       m_edgeRenderer.setHorizontalAlignment2(Constants.CENTER);
       m_edgeRenderer.setVerticalAlignment1(Constants.TOP);
       m_edgeRenderer.setVerticalAlignment2(Constants.BOTTOM);
       anchor = new Point2D.Double(getWidth() / 2, getHeight() - 35);
       break;
     default:
       throw new IllegalArgumentException("Unrecognized orientation value: " + orientation);
   }
   m_orientation = orientation;
   rtl.setOrientation(orientation);
   rtl.setLayoutAnchor(anchor);
   stl.setOrientation(orientation);
 }
 public void setLabelField(String field) {
   if (field != null && field.equals(getTextField())) {
     return;
   }
   super.setTextField(field);
   if (table != null) {
     for (Iterator<DecoratorItem> itemIter = table.tuples(); itemIter.hasNext(); ) {
       itemIter.next().setValidated(false);
     }
   }
 }
Esempio n. 5
0
  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;
  }
Esempio n. 6
0
  public DataMountain(Table t) {
    super(new Visualization());
    m_vis.addTable("data", t);

    LabelRenderer nodeRenderer = new LabelRenderer(null, "image");
    nodeRenderer.setTextField(null);
    nodeRenderer.setVerticalAlignment(Constants.BOTTOM);
    nodeRenderer.setHorizontalPadding(0);
    nodeRenderer.setVerticalPadding(0);
    nodeRenderer.setMaxImageDimensions(100, 100);

    m_vis.setRendererFactory(new DefaultRendererFactory(nodeRenderer));

    ActionList init = new ActionList();
    init.add(new RandomLayout());
    init.add(new DataMountainSizeAction());
    m_vis.putAction("init", init);

    ActionList update = new ActionList();
    update.add(new DataMountainSizeAction());
    update.add(
        new ColorAction("data", VisualItem.STROKECOLOR) {
          public int getColor(VisualItem item) {
            return ColorLib.rgb((item.isHover() ? 255 : 0), 0, 0);
          }
        });
    update.add(new RepaintAction());
    m_vis.putAction("update", update);

    // we run this to make sure the forces are stabilized
    ActionList preforce = new ActionList(1000);
    preforce.add(new DataMountainForceLayout(true));
    m_vis.putAction("preforce", preforce);

    // this will cause docs to move out of the way when dragging
    final ForceDirectedLayout fl = new DataMountainForceLayout(false);
    ActivityListener fReset =
        new ActivityAdapter() {
          public void activityCancelled(Activity a) {
            fl.reset();
          }
        };
    ActionList forces = new ActionList(Activity.INFINITY);
    forces.add(fl);
    forces.add(update);
    forces.addActivityListener(fReset);
    m_vis.putAction("forces", forces);

    setSize(640, 450);
    setDamageRedraw(false); // disable due to Java2D image clipping errors
    setBorder(BorderFactory.createEmptyBorder(30, 20, 5, 20));
    setItemSorter(new DataMountainSorter());
    addControlListener(new DataMountainControl());

    // pre-load images, otherwise they will be loaded asynchronously
    nodeRenderer.getImageFactory().preloadImages(m_vis.items(), "image");

    // initialize and present the interface
    m_vis.run("init");
    m_vis.runAfter("preforce", "update");
    m_vis.run("preforce");
  }
Esempio n. 7
0
  public trial(int st, String n) {

    // setup a visualisation
    super(new Visualization());

    System.out.println(st + "  " + n);

    // generate a graph
    initGraph(n, st);

    //  standard labelRenderer for the given label
    LabelRenderer nodeRenderer = new LabelRenderer(LABEL);
    // rendererFactory for the visualization items
    DefaultRendererFactory rendererFactory = new DefaultRendererFactory();
    // set the labelRenderer
    rendererFactory.setDefaultRenderer(nodeRenderer);
    m_vis.setRendererFactory(rendererFactory);

    // Color Actions
    ColorAction nodeText = new ColorAction(NODES, VisualItem.TEXTCOLOR);
    nodeText.setDefaultColor(ColorLib.gray(0));
    ColorAction nodeStroke = new ColorAction(NODES, VisualItem.STROKECOLOR);
    nodeStroke.setDefaultColor(ColorLib.gray(100));
    ColorAction nodeFill = new ColorAction(NODES, VisualItem.FILLCOLOR);
    nodeFill.setDefaultColor(ColorLib.gray(255));
    ColorAction edgeStrokes = new ColorAction(EDGES, VisualItem.STROKECOLOR);
    edgeStrokes.setDefaultColor(ColorLib.gray(100));

    // ColorAction fill = new ColorAction(NODES, VisualItem.FILLCOLOR,
    ColorLib.rgb(200, 200, 255);
    // fill.add(VisualItem.FIXED, ColorLib.rgb(255,100,100));
    // fill.add(VisualItem.HIGHLIGHT, ColorLib.rgb(255,200,125));

    // bundle the color actions
    ActionList draw = new ActionList();
    //    draw.add(fill);
    draw.add(new ColorAction(NODES, VisualItem.STROKECOLOR, 0));
    draw.add(new ColorAction(NODES, VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0)));
    draw.add(new ColorAction(EDGES, VisualItem.FILLCOLOR, ColorLib.gray(200)));
    draw.add(new ColorAction(EDGES, VisualItem.STROKECOLOR, ColorLib.gray(200)));
    draw.add(nodeText);
    draw.add(nodeStroke);
    draw.add(nodeFill);
    draw.add(edgeStrokes);

    ActionList animate = new ActionList(Activity.INFINITY);
    //   animate.add(fill);
    animate.add(new RepaintAction());

    m_nodeRenderer = new LabelRenderer(m_label);

    m_nodeRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_FILL);
    m_nodeRenderer.setHorizontalAlignment(Constants.LEFT);
    m_nodeRenderer.setRoundedCorner(8, 8);
    m_edgeRenderer = new EdgeRenderer(Constants.EDGE_TYPE_CURVE);

    DefaultRendererFactory rf = new DefaultRendererFactory(m_nodeRenderer);
    m_vis.setRendererFactory(rf);

    // DataSizeAction
    DataSizeAction nodeDataSizeAction = new DataSizeAction(NODES, SIZE);
    draw.add(nodeDataSizeAction);
    m_vis.putAction("draw", draw);
    m_vis.putAction("layout", animate);

    m_vis.runAfter("draw", "layout");

    // create the layout action for the graph
    NodeLinkTreeLayout treeLayout = new NodeLinkTreeLayout(GRAPH, m_orientation, 80, 5, 10);
    treeLayout.setLayoutAnchor(new Point2D.Double(250, -150));
    m_vis.putAction("treeLayout", treeLayout);
    m_vis.addFocusGroup("selected");

    CollapsedSubtreeLayout subLayout = new CollapsedSubtreeLayout(GRAPH, m_orientation);
    m_vis.putAction("subLayout", subLayout);

    m_vis.run("treeLayout");
    m_vis.run("draw");

    pan(250, 250);
    setHighQuality(true);
    addControlListener(new ZoomControl());
    addControlListener(new PanControl());
    addControlListener(new DragControl(true));
    addControlListener(new NodeClicked());
    addControlListener(new FocusControl());

    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_LEFT_RIGHT),
        "left-to-right",
        KeyStroke.getKeyStroke("ctrl 1"),
        WHEN_FOCUSED);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_TOP_BOTTOM),
        "top-to-bottom",
        KeyStroke.getKeyStroke("ctrl 2"),
        WHEN_FOCUSED);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_RIGHT_LEFT),
        "right-to-left",
        KeyStroke.getKeyStroke("ctrl 3"),
        WHEN_FOCUSED);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_BOTTOM_TOP),
        "bottom-to-top",
        KeyStroke.getKeyStroke("ctrl 4"),
        WHEN_FOCUSED);
    TupleSet search = new PrefixSearchTupleSet();
    m_vis.addFocusGroup(Visualization.SEARCH_ITEMS, search);
    search.addTupleSetListener(
        new TupleSetListener() {
          public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
            m_vis.cancel("animatePaint");
            m_vis.run("fullPaint");
            m_vis.run("animatePaint");
          }
        });
  }
  public ConcordanceTree() {
    super(new Visualization());

    m_display_self = this;
    m_label = NAME;

    tree = new Tree();
    Table ntable = tree.getNodeTable();
    ntable.addColumn(NAME, String.class);
    ntable.addColumn(NODECOUNT, int.class);
    ntable.addColumn(ROWCOUNT, int.class);
    resetTree();

    m_vis.add(TREE, tree);
    // m_vis.add(TREE, t, new WordCountPredicate());

    m_nodeRenderer = new LabelRenderer(m_label);
    m_nodeRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_FILL);
    m_nodeRenderer.setHorizontalAlignment(Constants.LEFT);
    m_nodeRenderer.setRoundedCorner(8, 8);
    m_edgeRenderer = new EdgeRenderer(Constants.EDGE_TYPE_CURVE);

    DefaultRendererFactory rf = new DefaultRendererFactory(m_nodeRenderer);
    rf.add(new InGroupPredicate(TREEEDGES), m_edgeRenderer);
    m_vis.setRendererFactory(rf);

    // colors
    ItemAction nodeColor = new NodeColorAction(TREENODES);
    ItemAction textColor = new ColorAction(TREENODES, VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0));
    m_vis.putAction("textColor", textColor);

    ItemAction edgeColor =
        new ColorAction(TREEEDGES, VisualItem.STROKECOLOR, ColorLib.rgb(255, 155, 155));

    // quick repaint
    ActionList repaint = new ActionList();
    repaint.add(nodeColor);
    // WordSizeAction wsaction = new WordSizeAction(TREEEDGES);
    repaint.add(new RepaintAction());
    m_vis.putAction("repaint", repaint);

    // full paint
    ActionList fullPaint = new ActionList();
    fullPaint.add(nodeColor);
    m_vis.putAction("fullPaint", fullPaint);

    // animate paint change
    ActionList animatePaint = new ActionList(400);
    animatePaint.add(new ColorAnimator(TREENODES));
    animatePaint.add(new RepaintAction());
    m_vis.putAction("animatePaint", animatePaint);

    // create the tree layout action
    NodeLinkTreeLayout treeLayout = new NodeLinkTreeLayout(TREE, m_orientation, 10, 0, 0);

    Point2D anchor = new Point2D.Double(25, HEIGHT / 2);
    treeLayout.setLayoutAnchor(anchor);
    m_vis.putAction("treeLayout", treeLayout);

    CollapsedSubtreeLayout subLayout = new CollapsedSubtreeLayout(TREE, m_orientation);
    m_vis.putAction("subLayout", subLayout);

    AutoPanAction autoPan = new AutoPanAction();
    AutoCenterAction autocenter = new AutoCenterAction();
    AutoFitAction autofit = new AutoFitAction();

    ActionList positioning = new ActionList();
    positioning.add(autofit);
    m_vis.putAction("positioning", positioning);

    ActionList fna = new ActionList();
    fna.add(new WordFontAction(TREENODES, defaultTreeFont));
    //   fna.add(new EdgeWidthAction(TREEEDGES));
    // fna.add(new WordSizeAction(TREEEDGES));
    m_vis.putAction("fontnodeaction", fna);

    // create the filtering and layout
    ActionList filter = new ActionList();
    filter.add(fna);
    filter.add(fisheyetreefilter);
    // VisibilityFilter visibfilter = new VisibilityFilter(new WordCountPredicate());
    // filter.add(visibfilter);
    filter.add(treeLayout);
    filter.add(subLayout);
    filter.add(textColor);
    filter.add(nodeColor);
    filter.add(edgeColor);
    m_vis.putAction("filter", filter);

    // This doesn't quite work as expected; the layout is calculated
    // for the entire tree and low freq nodes are simply not shown,
    // leaving gaps in the layout
    //
    // setPredicate(new WordCountPredicate());

    // animated transition
    ActionList animate = new ActionList(1000);
    animate.setPacingFunction(new SlowInSlowOutPacer());
    // animate.add(autoPan);
    animate.add(new QualityControlAnimator());
    animate.add(new VisibilityAnimator(TREE));
    animate.add(new LocationAnimator(TREENODES));
    animate.add(new ColorAnimator(TREENODES));
    animate.add(new RepaintAction());
    m_vis.putAction("animate", animate);
    m_vis.alwaysRunAfter("filter", "animate");

    // create animator for orientation changes
    ActionList orient = new ActionList(2000);
    orient.setPacingFunction(new SlowInSlowOutPacer());
    // orient.add(autoPan);
    // orient.add(autocenter);
    orient.add(new QualityControlAnimator());
    orient.add(new LocationAnimator(TREENODES));
    orient.add(new RepaintAction());
    // orient.add(autofit);

    m_vis.putAction("orient", orient);

    // ------------------------------------------------

    // initialize the display
    setSize(WIDTH, HEIGHT);
    setItemSorter(new TreeDepthItemSorter());
    addControlListener(new ZoomToFitControl());
    addControlListener(new ZoomControl());
    addControlListener(new WheelZoomControl());
    addControlListener(new PanControl());
    addControlListener(new FocusControl(1, "filter"));
    addControlListener(new ToolTipControl(NODECOUNT));

    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_LEFT_RIGHT),
        "left-to-right",
        KeyStroke.getKeyStroke("ctrl 1"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_TOP_BOTTOM),
        "top-to-bottom",
        KeyStroke.getKeyStroke("ctrl 2"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_RIGHT_LEFT),
        "right-to-left",
        KeyStroke.getKeyStroke("ctrl 3"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new OrientAction(Constants.ORIENT_BOTTOM_TOP),
        "bottom-to-top",
        KeyStroke.getKeyStroke("ctrl 4"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new FisheyeExpandAction(-1),
        "collapse-one",
        KeyStroke.getKeyStroke("ctrl 5"),
        WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(
        new FisheyeExpandAction(+1),
        "expand-one",
        KeyStroke.getKeyStroke("ctrl 6"),
        WHEN_IN_FOCUSED_WINDOW);

    // ------------------------------------------------

    // filter graph and perform layout
    setOrientation(m_orientation);
    m_vis.run("filter");

    /*
    TupleSet search = new PrefixSearchTupleSet();
      m_vis.addFocusGroup(Visualization.SEARCH_ITEMS, search);
      search.addTupleSetListener(new TupleSetListener() {
          public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
            m_vis.cancel("animatePaint");
            m_vis.run("fullPaint");
            m_vis.run("animatePaint");
          }
        });
       */

  }
  public PhysioMapRadialGraphView(
      SemGenSettings sets, Graph g, String label, SemSimModel semsimmodel) {
    super(new Visualization());
    this.semsimmodel = semsimmodel;

    // -- set up visualization --
    m_vis.add(tree, g);
    m_vis.setInteractive(treeEdges, null, false);

    // -- set up renderers --
    LabelRenderer m_nodeRenderer = new LabelRenderer(label);
    m_nodeRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_DRAW_AND_FILL);
    m_nodeRenderer.setHorizontalAlignment(Constants.CENTER);
    m_nodeRenderer.setRoundedCorner(8, 8);
    EdgeRenderer m_edgeRenderer =
        new EdgeRenderer(Constants.EDGE_TYPE_LINE, prefuse.Constants.EDGE_ARROW_REVERSE);
    m_edgeRenderer.setArrowType(prefuse.Constants.EDGE_ARROW_REVERSE);
    m_edgeRenderer.setArrowHeadSize(8, 8);

    // MAYBE HERE?
    DefaultRendererFactory rf = new DefaultRendererFactory(m_nodeRenderer);
    rf.add(new InGroupPredicate(treeEdges), m_edgeRenderer);
    m_vis.setRendererFactory(rf);
    // m_vis.

    // -- set up processing actions --
    // colors
    ItemAction nodeColor = new NodeColorAction(treeNodes);
    ItemAction borderColor = new BorderColorAction(treeNodes);
    m_vis.putAction("borderColor", borderColor);
    ItemAction textColor = new TextColorAction(treeNodes);
    m_vis.putAction("textColor", textColor);
    ItemAction edgeColor =
        new ColorAction(treeEdges, VisualItem.STROKECOLOR, ColorLib.rgb(0, 0, 0));
    ItemAction arrowColor = new ArrowColorAction(treeEdges);
    m_vis.putAction("arrowColor", arrowColor);

    FontAction fonts = new FontAction(treeNodes, FontLib.getFont("Verdana", 12));
    fonts.add("ingroup('_focus_')", FontLib.getFont("Verdana", 12));

    // recolor
    // When recolor, do these actions
    ActionList recolor = new ActionList();
    recolor.add(nodeColor);
    recolor.add(borderColor);
    recolor.add(textColor);
    recolor.add(arrowColor);
    m_vis.putAction("recolor", recolor);

    // repaint
    ActionList repaint = new ActionList();
    repaint.add(recolor);
    repaint.add(new RepaintAction());
    m_vis.putAction("repaint", repaint);

    // animate paint change
    ActionList animatePaint = new ActionList(400);
    animatePaint.add(new ColorAnimator(treeNodes));
    animatePaint.add(new RepaintAction());
    m_vis.putAction("animatePaint", animatePaint);

    // create the tree layout action
    RadialTreeLayout treeLayout = new RadialTreeLayout(tree);
    treeLayout.setAutoScale(true);
    m_vis.putAction("treeLayout", treeLayout);

    CollapsedSubtreeLayout subLayout = new CollapsedSubtreeLayout(tree);
    m_vis.putAction("subLayout", subLayout);

    // create the filtering and layout
    ActionList filter = new ActionList();
    filter.add(new TreeRootAction(tree));
    filter.add(fonts);
    filter.add(treeLayout);
    filter.add(borderColor);
    filter.add(subLayout);
    filter.add(textColor);
    filter.add(nodeColor);
    filter.add(edgeColor);
    filter.add(arrowColor);
    m_vis.putAction("filter", filter);

    // animated transition
    ActionList animate = new ActionList(700);
    animate.setPacingFunction(new SlowInSlowOutPacer());
    animate.add(new QualityControlAnimator());
    animate.add(new VisibilityAnimator(tree));
    animate.add(new PolarLocationAnimator(treeNodes, linear));
    animate.add(new ColorAnimator(treeNodes));
    animate.add(new RepaintAction());
    m_vis.putAction("animate", animate);
    m_vis.alwaysRunAfter("filter", "animate");
    // ------------------------------------------------

    // initialize the display

    setSize(sets.getAppWidth() - ExtractorTab.leftpanewidth - 50, sets.getAppHeight() - 235);
    setItemSorter(new TreeDepthItemSorter());
    addControlListener(new DragControl());
    addControlListener(new ZoomToFitControl());
    addControlListener(new ZoomControl());
    addControlListener(new PanControl());
    addControlListener(new FocusControl(1, "filter"));
    addControlListener(new HoverActionControl("repaint"));

    // ------------------------------------------------

    // filter graph and perform layout
    m_vis.run("filter");

    // maintain a set of items that should be interpolated linearly
    // this isn't absolutely necessary, but makes the animations nicer
    // the PolarLocationAnimator should read this set and act accordingly
    m_vis.addFocusGroup(linear, new DefaultTupleSet());
    m_vis
        .getGroup(Visualization.FOCUS_ITEMS)
        .addTupleSetListener(
            new TupleSetListener() {
              public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
                TupleSet linearInterp = m_vis.getGroup(linear);
                if (add.length < 1) return;
                linearInterp.clear();
                for (Node n = (Node) add[0]; n != null; n = n.getParent()) linearInterp.addTuple(n);
              }
            });

    SearchTupleSet search = new PrefixSearchTupleSet();
    m_vis.addFocusGroup(Visualization.SEARCH_ITEMS, search);
    search.addTupleSetListener(
        new TupleSetListener() {
          public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
            m_vis.cancel("animatePaint");
            m_vis.run("recolor");
            m_vis.run("animatePaint");
          }
        });
  }
Esempio n. 10
0
  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");
  }