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");
  }
예제 #2
0
  /**
   * To be called when the visibility filtering predicate changes.
   *
   * @param predStr string representation of the predicate on which to filter document visibility,
   *     or "" if no filtering should be applied
   */
  public void resetDocsVisiblePredicate(String predStr) {

    if (!predStr.equals("")) {
      docGlyphVisiblePredicate =
          new AndPredicate(new InGroupPredicate(DATA_GROUP), ExpressionParser.predicate(predStr));
    } else {
      docGlyphVisiblePredicate = new InGroupPredicate(DATA_GROUP);
    }

    if (docGlyphVisibleFilter != null) {
      docGlyphVisibleFilter.updatePredicate(docGlyphVisiblePredicate);
    }

    //        m_vis.run("repaint");
    m_vis.run("updateOnce");
  }
예제 #3
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;
  }
  public Congress(Table t) {
    super(new BorderLayout());

    // --------------------------------------------------------------------
    // STEP 1: setup the visualized data

    final Visualization vis = new Visualization();
    m_vis = vis;

    final String group = "by_state";

    // filter to show only candidates receiving more than $100,000
    Predicate p = (Predicate) ExpressionParser.parse("[" + TOTAL_RECEIPTS + "] >= 100000");
    VisualTable vt = vis.addTable(group, t, p);

    // add a new column containing a label string showing
    // candidate name, party, state, year, and total receipts
    vt.addColumn(
        "label",
        "CONCAT(CAP(Candidate), ' (', "
            + "CAP([Party Designation]), '-', [State Code], "
            + "') ', Year, ': $', FORMAT([Total Receipts],2))");

    // add calculation for senators
    vt.addColumn("Senate", "District <= 0");

    vis.setRendererFactory(
        new RendererFactory() {
          AbstractShapeRenderer sr = new ShapeRenderer();
          Renderer arY = new AxisRenderer(Constants.RIGHT, Constants.TOP);
          Renderer arX = new AxisRenderer(Constants.CENTER, Constants.FAR_BOTTOM);

          public Renderer getRenderer(VisualItem item) {
            return item.isInGroup("ylab") ? arY : item.isInGroup("xlab") ? arX : sr;
          }
        });

    // --------------------------------------------------------------------
    // STEP 2: create actions to process the visual data

    // set up dynamic queries, search set
    RangeQueryBinding receiptsQ = new RangeQueryBinding(vt, RECEIPTS);
    ListQueryBinding yearsQ = new ListQueryBinding(vt, "Year");
    SearchQueryBinding searchQ = new SearchQueryBinding(vt, "Candidate");

    // construct the filtering predicate
    AndPredicate filter = new AndPredicate(searchQ.getPredicate());
    filter.add(yearsQ.getPredicate());
    filter.add(receiptsQ.getPredicate());

    // set up the actions
    AxisLayout xaxis = new AxisLayout(group, "State Code", Constants.X_AXIS, VisiblePredicate.TRUE);
    AxisLayout yaxis = new AxisLayout(group, RECEIPTS, Constants.Y_AXIS, VisiblePredicate.TRUE);
    // yaxis.setScale(Constants.LOG_SCALE);
    yaxis.setRangeModel(receiptsQ.getModel());
    receiptsQ.getNumberModel().setValueRange(0, 65000000, 0, 65000000);

    xaxis.setLayoutBounds(m_dataB);
    yaxis.setLayoutBounds(m_dataB);

    AxisLabelLayout ylabels = new AxisLabelLayout("ylab", yaxis, m_ylabB);
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    nf.setMaximumFractionDigits(0);
    ylabels.setNumberFormat(nf);

    AxisLabelLayout xlabels = new AxisLabelLayout("xlab", xaxis, m_xlabB, 15);
    vis.putAction("xlabels", xlabels);

    // dems = blue, reps = red, other = gray
    int[] palette =
        new int[] {
          ColorLib.rgb(150, 150, 255), ColorLib.rgb(255, 150, 150), ColorLib.rgb(180, 180, 180)
        };
    DataColorAction color =
        new DataColorAction(group, "Party", Constants.ORDINAL, VisualItem.STROKECOLOR, palette);

    int[] shapes = new int[] {Constants.SHAPE_RECTANGLE, Constants.SHAPE_DIAMOND};
    DataShapeAction shape = new DataShapeAction(group, "Senate", shapes);

    Counter cntr = new Counter(group);

    ActionList draw = new ActionList();
    draw.add(cntr);
    draw.add(color);
    draw.add(shape);
    draw.add(xaxis);
    draw.add(yaxis);
    draw.add(ylabels);
    draw.add(new ColorAction(group, VisualItem.FILLCOLOR, 0));
    draw.add(new RepaintAction());
    vis.putAction("draw", draw);

    ActionList update = new ActionList();
    update.add(new VisibilityFilter(group, filter));
    update.add(cntr);
    update.add(xaxis);
    update.add(yaxis);
    update.add(ylabels);
    update.add(new RepaintAction());
    vis.putAction("update", update);

    UpdateListener lstnr =
        new UpdateListener() {
          public void update(Object src) {
            vis.run("update");
          }
        };
    filter.addExpressionListener(lstnr);

    // --------------------------------------------------------------------
    // STEP 4: set up a display and ui components to show the visualization

    m_display = new Display(vis);
    m_display.setItemSorter(
        new ItemSorter() {
          public int score(VisualItem item) {
            int score = super.score(item);
            if (item.isInGroup(group)) score += item.getInt(TOTAL_RECEIPTS);
            return score;
          }
        });
    m_display.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    m_display.setSize(700, 450);
    m_display.setHighQuality(true);
    m_display.addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            displayLayout();
          }
        });
    displayLayout();

    m_details = new JFastLabel(m_title);
    m_details.setPreferredSize(new Dimension(75, 20));
    m_details.setVerticalAlignment(SwingConstants.BOTTOM);

    m_total.setPreferredSize(new Dimension(500, 20));
    m_total.setHorizontalAlignment(SwingConstants.RIGHT);
    m_total.setVerticalAlignment(SwingConstants.BOTTOM);

    ToolTipControl ttc = new ToolTipControl("label");
    Control hoverc =
        new ControlAdapter() {
          public void itemEntered(VisualItem item, MouseEvent evt) {
            if (item.isInGroup(group)) {
              m_total.setText(item.getString("label"));
              item.setFillColor(item.getStrokeColor());
              item.setStrokeColor(ColorLib.rgb(0, 0, 0));
              item.getVisualization().repaint();
            }
          }

          public void itemExited(VisualItem item, MouseEvent evt) {
            if (item.isInGroup(group)) {
              m_total.setText(m_totalStr);
              item.setFillColor(item.getEndFillColor());
              item.setStrokeColor(item.getEndStrokeColor());
              item.getVisualization().repaint();
            }
          }
        };
    m_display.addControlListener(ttc);
    m_display.addControlListener(hoverc);

    // --------------------------------------------------------------------
    // STEP 5: launching the visualization

    this.addComponentListener(lstnr);

    // details
    Box infoBox = new Box(BoxLayout.X_AXIS);
    infoBox.add(Box.createHorizontalStrut(5));
    infoBox.add(m_details);
    infoBox.add(Box.createHorizontalGlue());
    infoBox.add(Box.createHorizontalStrut(5));
    infoBox.add(m_total);
    infoBox.add(Box.createHorizontalStrut(5));

    // set up search box
    JSearchPanel searcher = searchQ.createSearchPanel();
    searcher.setLabelText("Candidate: ");
    searcher.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));

    // create dynamic queries
    Box radioBox = new Box(BoxLayout.X_AXIS);
    radioBox.add(Box.createHorizontalStrut(5));
    radioBox.add(searcher);
    radioBox.add(Box.createHorizontalGlue());
    radioBox.add(Box.createHorizontalStrut(5));
    radioBox.add(yearsQ.createRadioGroup());
    radioBox.add(Box.createHorizontalStrut(16));

    JRangeSlider slider = receiptsQ.createVerticalRangeSlider();
    slider.setThumbColor(null);
    slider.setMinExtent(150000);
    slider.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            m_display.setHighQuality(false);
          }

          public void mouseReleased(MouseEvent e) {
            m_display.setHighQuality(true);
            m_display.repaint();
          }
        });

    vis.run("draw");
    vis.run("xlabels");

    add(infoBox, BorderLayout.NORTH);
    add(m_display, BorderLayout.CENTER);
    add(slider, BorderLayout.EAST);
    add(radioBox, BorderLayout.SOUTH);
    UILib.setColor(this, ColorLib.getColor(255, 255, 255), Color.GRAY);
    slider.setForeground(Color.LIGHT_GRAY);
    UILib.setFont(radioBox, FontLib.getFont("Tahoma", 15));
    m_details.setFont(FontLib.getFont("Tahoma", 18));
    m_total.setFont(FontLib.getFont("Tahoma", 16));
  }
예제 #5
0
 public void setHighlightPredicate(String attrName, String attrVal) {
   highlightPredicate = ExpressionParser.predicate("'" + attrName + "' == '" + attrVal + "'");
   highlightAttr = attrName;
   highlightVal = attrVal;
   m_vis.run("repaint");
 }
예제 #6
0
public class NetMonitor {

  public static String ACCELX = "accelX";
  public static String ACCELY = "accelY";
  public static String ACCELZ = "accelZ";
  public static String NODEID = "NodeID";
  public static String LABEL = "Label";
  public static String PARENT = "ParentID";
  public static String COLOR = "MyColor";
  public static String LEVEL = "Level";
  public static String DATATABLE = "Datatable";
  public static String TEMP = "Temperature";
  public static String CURRENT = "Current";

  public static String EDGETYPE = "EdgeType";

  public static String TREEEDGE = "TreeEdge";
  public static Predicate treeEdgePred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.TREEEDGE + "\")");
  public static String TREEEDGESTATE = "TreeEdgeState";
  public static Predicate treeEdgeStatePred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.TREEEDGESTATE + "\")");
  public static String TREEEDGEALARM = "TreeEdgeAlarm";
  public static Predicate treeEdgeAlarmPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.TREEEDGEALARM + "\")");
  public static String TREEEDGETEMP = "TreeEdgeTemp";
  public static Predicate treeEdgeTempPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.TREEEDGETEMP + "\")");
  public static String TREEEDGENEIGHBOR = "TreeEdgeNeighbor";
  public static Predicate treeEdgeNeighborPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND ("
                  + NetMonitor.EDGETYPE
                  + " = \""
                  + NetMonitor.TREEEDGENEIGHBOR
                  + "\")");

  public static String NEIGHBOREDGEBI = "NeighborEdgeBi";
  public static Predicate neighborEdgeBiPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND (" + NetMonitor.EDGETYPE + " = \"" + NetMonitor.NEIGHBOREDGEBI + "\")");
  public static String NEIGHBOREDGEUNI = "NeighborEdgeUni";
  public static Predicate neighborEdgeUniPred =
      (Predicate)
          ExpressionParser.parse(
              "ISEDGE() AND ("
                  + NetMonitor.EDGETYPE
                  + " = \""
                  + NetMonitor.NEIGHBOREDGEUNI
                  + "\")");

  public static String AGE = "Age";

  public static String PARENTNODE = "Parent_Node";
  public static String PARENTEDGE = "Parent_Edge";

  public static String EDGE_SOURCE = "Edge_Source";
  public static String EDGE_DESTINATION = "Edge_Destination";

  public static final String GRAPH = "graph";
  public static final String NODES = "graph.nodes";
  public static final String EDGES = "graph.edges";

  public static final String LIVEACTION = "readlineActionList";
  public static final String LAYOUTACTION = "layoutActionList";

  public static int MAXAGE = 50;
  public static int MAXDELETEAGE = 100;

  /** @param args */
  public static void main(String[] args) {
    HistoryManagement history = new HistoryManagement();

    Map nodeMap = new HashMap();

    DataFileReader fileReader = new DataFileReader(args[0], history);

    Window window = new Window(nodeMap, fileReader, history);

    fileReader.setGUI(window);
    fileReader.openDataFile();
    fileReader.setNodeMap(nodeMap);

    NodeData root = new NodeData(NodeData.ROOT, window, history);
    nodeMap.put(NodeData.ROOT, root);

    root.addTableRow(window.nodeTable);
    root.addValues(0, 0, 0, 0, 0);
    root.setLabel("root");
    root.addNode(0);

    window.graphDisplay.vis.run("color"); // assign the colors
    window.graphDisplay.vis.run(LAYOUTACTION); // start up the animated layout
    window.graphDisplay.vis.run("timesteps");

    window.graphDisplay.vis.run(LIVEACTION);
  }
}
예제 #7
0
/**
 * Demonstration of a node-link tree viewer
 *
 * @version 1.0
 * @author <a href="http://jheer.org">jeffrey heer</a>
 */
public class PhysioMapRadialGraphView extends Display {
  /** */
  private static final long serialVersionUID = 8464331927479988729L;

  SemGenSettings settings;

  public static final String DATA_FILE = "/socialnet.xml";
  private static final String tree = "tree";
  private static final String treeNodes = "tree.nodes";
  private static final String treeEdges = "tree.edges";
  private static final String linear = "linear";

  public SemSimModel semsimmodel;

  public static final Predicate isprocessfilter = ExpressionParser.predicate("process==true");

  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");
          }
        });
  }

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

  public JPanel demo() {
    return demo(DATA_FILE, "name");
  }

  public JPanel demo(String datafile, final String label) {
    Graph g = new Graph();
    g.addNodeRow();

    try {
      g = new GraphMLReader().readGraph(datafile);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
    return demo(g, label);
  }

  public JPanel demo(Graph g, final String label) {
    // create a new radial tree view
    final PhysioMapRadialGraphView gview =
        new PhysioMapRadialGraphView(settings, g, label, semsimmodel);
    Visualization vis = gview.getVisualization();

    // create a search panel for the tree map
    SearchQueryBinding sq =
        new SearchQueryBinding(
            (Table) vis.getGroup(treeNodes),
            label,
            (SearchTupleSet) vis.getGroup(Visualization.SEARCH_ITEMS));
    JSearchPanel search = sq.createSearchPanel();
    search.setShowResultCount(true);
    search.setBorder(BorderFactory.createEmptyBorder(5, 5, 4, 0));
    search.setFont(FontLib.getFont("Verdana", Font.PLAIN, 11));

    final JTextArea title = new JTextArea();
    title.setPreferredSize(new Dimension(450, 500));
    title.setMaximumSize(new Dimension(450, 500));
    title.setMinimumSize(new Dimension(450, 500));

    title.setAlignmentY(CENTER_ALIGNMENT);
    title.setLineWrap(true);
    title.setWrapStyleWord(true);
    title.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
    title.setFont(FontLib.getFont("Verdana", Font.PLAIN, 11));

    gview.addControlListener(
        new ControlAdapter() {
          public void itemEntered(VisualItem item, MouseEvent e) {}

          public void itemExited(VisualItem item, MouseEvent e) {
            title.setText(null);
          }
        });

    Box searchbox = new Box(BoxLayout.X_AXIS);
    searchbox.add(Box.createHorizontalStrut(10));
    searchbox.add(search);
    searchbox.add(Box.createHorizontalStrut(3));

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(searchbox, BorderLayout.NORTH);
    panel.add(gview, BorderLayout.CENTER);
    panel.add(Box.createGlue(), BorderLayout.SOUTH);

    Color BACKGROUND = Color.WHITE;
    Color FOREGROUND = Color.DARK_GRAY;
    UILib.setColor(panel, BACKGROUND, FOREGROUND);

    return panel;
  }

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

  /** Switch the root of the tree by requesting a new spanning tree at the desired root */
  public static class TreeRootAction extends GroupAction {
    public TreeRootAction(String graphGroup) {
      super(graphGroup);
    }

    public void run(double frac) {
      TupleSet focus = m_vis.getGroup(Visualization.FOCUS_ITEMS);
      if (focus == null || focus.getTupleCount() == 0) return;

      Graph g = (Graph) m_vis.getGroup(m_group);
      Node f = null;
      @SuppressWarnings("unchecked")
      Iterator<Node> tuples = focus.tuples();
      while (tuples.hasNext() && !g.containsTuple(f = tuples.next())) {
        f = null;
      }
      if (f == null) return;
      g.getSpanningTree(f);
    }
  }

  /** Set node fill colors */
  public static class NodeColorAction extends ColorAction {
    public NodeColorAction(String group) {
      super(group, VisualItem.FILLCOLOR, ColorLib.rgba(202, 225, 255, 250));
      add("_hover", ColorLib.gray(220, 230));
      add("ingroup('_search_')", ColorLib.rgb(255, 190, 190));
      add("ingroup('_focus_')", ColorLib.rgb(205, 197, 191));
      add(isprocessfilter, ColorLib.rgba(255, 193, 193, 255));
    }
  } // end of inner class NodeColorAction

  /** Set node text colors */
  public static class TextColorAction extends ColorAction {
    public TextColorAction(String group) {
      super(group, VisualItem.TEXTCOLOR, ColorLib.gray(0));
      add("_hover", ColorLib.rgb(255, 0, 0));
    }
  } // end of inner class TextColorAction

  public static class ArrowColorAction extends ColorAction {
    public ArrowColorAction(String group) {
      super(group, VisualItem.FILLCOLOR, ColorLib.rgb(0, 0, 0));
    }
  } // end of inner class ArrowColorAction

  public static class BorderColorAction extends ColorAction {
    public BorderColorAction(String group) {
      super(group, VisualItem.STROKECOLOR, ColorLib.rgba(0, 0, 255, 255));
      add(isprocessfilter, ColorLib.rgba(176, 23, 31, 255));
    }
  }
} // end of class RadialGraphView
예제 #8
0
 public void addInvisibility(String expr) {
   addInvisibility(ExpressionParser.predicate(expr));
 }