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)); }
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"); }
public int getColor(VisualItem item) { if (ENTROPY_COLOR) return entropyColor(item); // test // if (item.getBoolean("cut")){ // return new Color(222,13,107).getRGB(); // } // color is fixed, what changes as a function of the value is the transparency (alpha) int color = sca.getColor(item); // lemmas and senses in the pathToRoot if (item.isInGroup("pathToRoot") && ((item.getInt("type") == 1) || (item.getInt("type") == 4))) color = ColorScheme.pathToRootColor; // count off -- just return color if (NodeColorAction.this.docuBurstActionList.countType.equals(DocuBurstActionList.NOCOUNT)) return color; float total = (float) (item.getFloat( DocuBurstActionList.CACHECOUNT + NodeColorAction.this.docuBurstActionList.countType)); float maxTotal = NodeColorAction.this.docuBurstActionList.getMaxTotal( NodeColorAction.this.docuBurstActionList.countType); if (total < 0) color = ColorScheme.negativeColor; if (total == 0) { if (color != ColorScheme.pathToRootColor) // zero senses get grey, zero lemmas and words get clear return ColorLib.setAlpha(ColorScheme.zeroOccurrenceSenseColor, ColorScheme.zeroAlpha); else // modulate path to root color return ColorLib.setAlpha(color, ColorScheme.zeroAlpha); } // initial alpha for zero and one count int alpha = ColorScheme.zeroAlpha; alpha += (int) (((float) total / (float) maxTotal) * (float) (255 - alpha)); if (total < 0) System.err.println( "total: " + total + " node: " + item.getString("label") + " alpha: " + alpha); // this should not occur except for rounding errors if (alpha > 255) alpha = 255; return ColorLib.setAlpha(color, alpha); }
/** * 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")); }
public int entropyColor(VisualItem item) { // color is fixed, what changes as a function of the value is the transparency (alpha) int color = sca.getColor(item); // lemmas and senses in the pathToRoot if (item.isInGroup("pathToRoot") && ((item.getInt("type") == 1) || (item.getInt("type") == 4))) color = ColorScheme.pathToRootColor; // count off -- just return color if (NodeColorAction.this.docuBurstActionList.countType.equals(DocuBurstActionList.NOCOUNT)) return color; // float total = item.getFloat(DocuBurstActionList.CONDENTROPY); float total = item.getFloat(DocuBurstActionList.CONDENTROPY); float maxTotal = NodeColorAction.this.docuBurstActionList.getMaxTotal(DocuBurstActionList.CONDENTROPY); if (total < 0) color = ColorScheme.negativeColor; if (total == 0) { if (color != ColorScheme.pathToRootColor) // zero senses get grey, zero lemmas and words get clear return ColorLib.setAlpha(color, 255); else // modulate path to root color return ColorLib.setAlpha(color, ColorScheme.zeroAlpha); } // initial alpha for zero and one count int alpha = 10; float condEntropyMin = NodeColorAction.this.docuBurstActionList.getCondEntropyMinTotal(); // alpha += (int) ( (1 - Math.log(total/maxTotal)/Math.log(condEntropyMin)) * (float) (255 - // alpha)); alpha += (int) ((Math.log(total / maxTotal) / Math.log(condEntropyMin)) * (float) (255 - alpha)); if (total < 0) System.err.println( "total: " + total + " node: " + item.getString("label") + " alpha: " + alpha); // this should not occur except for rounding errors if (alpha > 255) alpha = 255; return ColorLib.setAlpha(color, alpha); }
@Override public int getColor(VisualItem item) { // highlight border of glyphs for which search is true // TODO: thicker borders? more outstanding highlighting? // do (inefficient) manual comparison (for now) Iterator itemsInGroup = m_vis.getGroup(Visualization.SEARCH_ITEMS).tuples(); while (itemsInGroup.hasNext()) { Tuple itemInGroup = (Tuple) itemsInGroup.next(); if (item.getString(DocumentGridTable.NODE_NAME) .equals(itemInGroup.getString(DocumentGridTable.NODE_NAME))) { // debug // System.out.println("debug: "+this.getClass().getName()+": item in // group! "+item.toString()); return ColorLib.rgb(191, 99, 130); } } if (item.isHover()) { return Color.LIGHT_GRAY.getRGB(); } // default border color // return ColorLib.gray(50); return Color.DARK_GRAY.getRGB(); }
/** @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem) */ @Override public void render(Graphics2D g, VisualItem item) { // render the edge line super.render(g, item); // render the edge arrow head, if appropriate if (m_curArrow != null) { g.setPaint(ColorLib.getColor(item.getFillColor())); g.fill(m_curArrow); } }
public ScatterPlot(Table t, String xfield, String yfield, String sfield) { super(new Visualization()); // -------------------------------------------------------------------- // STEP 1: setup the visualized data m_vis.addTable(group, t); DefaultRendererFactory rf = new DefaultRendererFactory(m_shapeR); m_vis.setRendererFactory(rf); // -------------------------------------------------------------------- // STEP 2: create actions to process the visual data // set up the actions AxisLayout x_axis = new AxisLayout(group, xfield, Constants.X_AXIS, VisiblePredicate.TRUE); m_vis.putAction("x", x_axis); AxisLayout y_axis = new AxisLayout(group, yfield, Constants.Y_AXIS, VisiblePredicate.TRUE); m_vis.putAction("y", y_axis); ColorAction color = new ColorAction(group, VisualItem.STROKECOLOR, ColorLib.rgb(100, 100, 255)); m_vis.putAction("color", color); DataShapeAction shape = new DataShapeAction(group, sfield); m_vis.putAction("shape", shape); ActionList draw = new ActionList(); draw.add(x_axis); draw.add(y_axis); if (sfield != null) draw.add(shape); draw.add(color); draw.add(new RepaintAction()); m_vis.putAction("draw", draw); // -------------------------------------------------------------------- // STEP 3: set up a display and ui components to show the visualization setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); setSize(700, 450); setHighQuality(true); ToolTipControl ttc = new ToolTipControl(new String[] {xfield, yfield}); addControlListener(ttc); // -------------------------------------------------------------------- // STEP 4: launching the visualization m_vis.run("draw"); }
/** @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem) */ @Override public void render(Graphics2D g, VisualItem item) { Shape s = getShape(item); GraphicsLib.paint(g, item, m_line, getStroke(item), getRenderType(item)); // check if we have a text label, if so, render it String str; if (item.canGetString(VisualItem.LABEL)) { str = (String) item.getString(VisualItem.LABEL); if (str != null && !str.equals("")) { float x = (float) m_box.getMinX(); float y = (float) m_box.getMinY() + m_ascent; // draw label background GraphicsLib.paint(g, item, s, null, RENDER_TYPE_FILL); AffineTransform origTransform = g.getTransform(); AffineTransform transform = this.getTransform(item); if (transform != null) { g.setTransform(transform); } g.setFont(item.getFont()); g.setColor(ColorLib.getColor(item.getTextColor())); if (!(str.length() > 5 && str.substring(str.length() - 5, str.length()).equals("_last"))) { g.setColor(Color.WHITE); // TODO properly hunt down source of null str! for now, triage if (str != null) { // bump y down by appropriate amount FontMetrics fm = g.getFontMetrics(item.getFont()); int strHeight = fm.getAscent(); // g.drawString(str, x, y); g.drawString(str, x, y + strHeight); } if (transform != null) { g.setTransform(origTransform); } } } } }
public void renderText(Graphics2D g, VisualItem item, Shape shape) { String s = getText(item); int textColor = item.getTextColor(); if (s != null) { Rectangle2D r = shape.getBounds2D(); g.setPaint(ColorLib.getColor(textColor)); g.setFont(m_font); FontMetrics fm = g.getFontMetrics(); double size = item.getSize(); double x = r.getX() + size * m_horizBorder; double y = r.getY() + size * m_vertBorder; g.drawString(s, (float) x, (float) y + fm.getAscent()); // if ( isHyperlink(item) ) { // int lx = (int)Math.round(x), ly = (int)Math.round(y); // g.drawLine(lx,ly,lx+fm.stringWidth(s),ly+fm.getHeight()-1); // } } }
/* (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"); }
public TextColorAction(String group) { super(group, VisualItem.TEXTCOLOR, ColorLib.gray(0)); add("_hover", ColorLib.rgb(255, 0, 0)); }
public NodeColorAction( DocuBurstActionList docuBurstActionList, String group, boolean trackSenseIndex) { super(group, VisualItem.FILLCOLOR, ColorLib.rgba(100, 100, 100, 0)); this.docuBurstActionList = docuBurstActionList; add("type = 1", new WordCountColorAction(group, VisualItem.FILLCOLOR)); }
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)); }
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 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"); } }); }
static { // EDGE_COLORS.put("refers_to", ColorLib.rgb(0, 0, 0)); QUERYSET_COLORS.put("start", ColorLib.rgb(0, 175, 0)); QUERYSET_COLORS.put("source", ColorLib.rgb(0, 175, 0)); QUERYSET_COLORS.put("end", ColorLib.rgb(220, 0, 0)); QUERYSET_COLORS.put("target", ColorLib.rgb(220, 0, 0)); QUERYSET_COLORS.put("start,end", ColorLib.rgb(220, 0, 220)); QUERYSET_COLORS.put("source,target", ColorLib.rgb(220, 0, 220)); QUERYSET_COLORS.put("rank", ColorLib.rgb(0, 175, 220)); NODE_COLORS.put("Node", ColorLib.rgb(240, 240, 240)); // Saturated greens NODE_COLORS.put("Sequence", ColorLib.rgb(211, 247, 163)); NODE_COLORS.put("Gene", ColorLib.rgb(211, 247, 163)); NODE_COLORS.put("Protein", ColorLib.rgb(199, 240, 178)); NODE_COLORS.put("Enzyme", ColorLib.rgb(193, 234, 174)); // NODE_COLORS.put("ProteinGroup", ColorLib.rgb(199, 240, 178)); NODE_COLORS.put("AllelicVariant", ColorLib.rgb(199, 240, 178)); // Beige NODE_COLORS.put("Article", ColorLib.rgb(250, 230, 160)); // Cyans (to do, make greener) NODE_COLORS.put("HomologGroup", ColorLib.rgb(187, 237, 215)); NODE_COLORS.put("OrthologGroup", ColorLib.rgb(194, 237, 218)); // Desaturated blues NODE_COLORS.put("GO", ColorLib.rgb(185, 218, 234)); NODE_COLORS.put("BiologicalProcess", ColorLib.rgb(185, 218, 234)); NODE_COLORS.put("MolecularFunction", ColorLib.rgb(189, 223, 239)); NODE_COLORS.put("CellularComponent", ColorLib.rgb(174, 214, 234)); // Light purples NODE_COLORS.put("Ligand", ColorLib.rgb(210, 203, 240)); NODE_COLORS.put("Substance", ColorLib.rgb(210, 203, 240)); NODE_COLORS.put("Compound", ColorLib.rgb(210, 203, 240)); NODE_COLORS.put("Drug", ColorLib.rgb(203, 196, 233)); NODE_COLORS.put("Glycan", ColorLib.rgb(198, 200, 242)); // Pink NODE_COLORS.put("GenomicContext", ColorLib.rgb(255, 215, 253)); // Blues NODE_COLORS.put("Locus", ColorLib.rgb(180, 196, 239)); // unused NODE_COLORS.put("Phenotype", ColorLib.rgb(193, 209, 255)); // NODE_COLORS.put("Locus/Phenotype, ColorLib.rgb(195, 199, 242)); // TMP MAPPING for illustration purposes BY LERONEN! Should never get to SVN! NODE_COLORS.put("Gene/Phenotype", ColorLib.rgb(211, 247, 163)); // NODE_COLORS.put("Gene/Phenotype", ColorLib.rgb(193, 223, 242)); // Greens NODE_COLORS.put("Family", ColorLib.rgb(179, 226, 192)); NODE_COLORS.put("Region", ColorLib.rgb(195, 229, 204)); NODE_COLORS.put("Domain", ColorLib.rgb(195, 229, 204)); NODE_COLORS.put("Repeat", ColorLib.rgb(195, 229, 204)); NODE_COLORS.put("Site", ColorLib.rgb(190, 229, 201)); NODE_COLORS.put("ActiveSite", ColorLib.rgb(190, 229, 201)); NODE_COLORS.put("BindingSite", ColorLib.rgb(190, 229, 201)); NODE_COLORS.put("PostTranslationalModification", ColorLib.rgb(190, 229, 201)); // Purple NODE_COLORS.put("Pathway", ColorLib.rgb(208, 185, 231)); // Browns NODE_COLORS.put("Tissue", ColorLib.rgb(229, 218, 189)); // NODE_COLORS.put("Organism", ColorLib.rgb(229, 215, 177)); NODE_COLORS.put("MeSHHeading", ColorLib.rgb(239, 231, 176)); NODE_COLORS.put("OMIM", ColorLib.rgb(239, 231, 176)); }
public ArrowColorAction(String group) { super(group, VisualItem.FILLCOLOR, ColorLib.rgb(0, 0, 0)); }
public static JComponent demo(Graph g, String label) { // create a new, empty visualization for our data final Visualization vis = new Visualization(); VisualGraph vg = vis.addGraph(graph, g); vis.setValue(edges, null, VisualItem.INTERACTIVE, Boolean.FALSE); int[] palette = new int[] { ColorLib.rgb(77, 175, 74), ColorLib.rgb(55, 126, 184), ColorLib.rgb(228, 26, 28), ColorLib.rgb(152, 78, 163), ColorLib.rgb(255, 127, 0) }; int[] shape_palette = new int[] {Constants.SHAPE_ELLIPSE, Constants.SHAPE_RECTANGLE, Constants.SHAPE_TRIANGLE_UP}; TupleSet focusGroup = vis.getGroup(Visualization.FOCUS_ITEMS); focusGroup.addTupleSetListener( new TupleSetListener() { public void tupleSetChanged(TupleSet ts, Tuple[] add, Tuple[] rem) { for (int i = 0; i < rem.length; ++i) ((VisualItem) rem[i]).setFixed(false); for (int i = 0; i < add.length; ++i) { ((VisualItem) add[i]).setFixed(false); ((VisualItem) add[i]).setFixed(true); } vis.run("draw"); } }); // set up the renderers /* ShapeRenderer s = new ShapeRenderer(); s.rectangle(0, 0, 30, 30); vis.setRendererFactory(new DefaultRendererFactory(s));*/ MyRenderer tr = new MyRenderer(label); // MyRenderer tr = new MyRenderer(label); DefaultRendererFactory d = new DefaultRendererFactory(tr); EdgeRenderer MyEdgeRenderer = new EdgeRenderer(); d.add(new InGroupPredicate(edges), MyEdgeRenderer); vis.setRendererFactory(d); // -- set up the actions ---------------------------------------------- int maxhops = 1024, hops = 1024; final GraphDistanceFilter filter = new GraphDistanceFilter(graph, hops); ActionList draw = new ActionList(); draw.add(filter); // draw.add(new ColorAction(nodes, VisualItem.FILLCOLOR, ColorLib.rgb(180,180,255))); 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(100))); draw.add(new ColorAction(edges, VisualItem.STROKECOLOR, ColorLib.gray(170))); draw.add(new DataShapeAction(nodes, "type", shape_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)); // create an action list containing all color assignments ActionList color = new ActionList(); color.add(fill); color.add(text); color.add(edges); // ColorAction fill = new ColorAction(nodes, // VisualItem.FILLCOLOR, ColorLib.rgb(200,200,255)); fill.add("_fixed", ColorLib.rgb(255, 100, 100)); fill.add("_highlight", ColorLib.rgb(255, 200, 125)); // Instead have to use GridLayout here - how do i create ForceDirectedLayout fdl = new ForceDirectedLayout(graph); // GridLayout fdl = new GridLayout(graph); ForceSimulator fsim = fdl.getForceSimulator(); fsim.getForces()[0].setParameter(0, -5f); ActionList animate = new ActionList(Activity.INFINITY); // ActionList animate = new ActionList(vis); animate.add(fdl); animate.add(fill); animate.add(new RepaintAction()); // finally, we register our ActionList with the Visualization. // we can later execute our Actions by invoking a method on our // Visualization, using the name we've chosen below. vis.putAction("draw", draw); vis.putAction("layout", animate); vis.runAfter("draw", "layout"); vis.putAction("color", color); // vis.putAction("layout", layout); // -------------------------------------------------------------------- // STEP 4: set up a display to show the visualization Display display = new Display(vis); display.setSize(2000, 2000); display.setForeground(Color.GRAY); display.setBackground(Color.WHITE); // main display controls display.addControlListener(new FocusControl(1)); display.addControlListener(new DragControl()); display.addControlListener(new PanControl()); display.addControlListener(new ZoomControl()); display.addControlListener(new WheelZoomControl()); display.addControlListener(new ZoomToFitControl()); display.addControlListener(new NeighborHighlightControl()); display.setForeground(Color.GRAY); display.setBackground(Color.WHITE); // -------------------------------------------------------------------- // STEP 5: launching the visualization // create a panel for editing force values final JForcePanel fpanel = new JForcePanel(fsim); final JValueSlider slider = new JValueSlider("Distance", 0, maxhops, hops); slider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { filter.setDistance(slider.getValue().intValue()); vis.run("draw"); } }); slider.setBackground(Color.WHITE); slider.setPreferredSize(new Dimension(300, 30)); slider.setMaximumSize(new Dimension(300, 30)); Box cf = new Box(BoxLayout.Y_AXIS); cf.add(slider); cf.setBorder(BorderFactory.createTitledBorder("Connectivity Filter")); fpanel.add(cf); fpanel.add(Box.createVerticalGlue()); // create a new JSplitPane to present the interface JSplitPane split = new JSplitPane(); split.setLeftComponent(display); split.setRightComponent(fpanel); split.setOneTouchExpandable(true); split.setContinuousLayout(false); split.setDividerLocation(530); split.setDividerLocation(800); // position and fix the default focus node NodeItem focus = (NodeItem) vg.getNode(0); PrefuseLib.setX(focus, null, 400); PrefuseLib.setY(focus, null, 250); focusGroup.setTuple(focus); // now we run our action list and return return split; }
public int getColor(VisualItem item) { if (m_vis.isInGroup(item, Visualization.SEARCH_ITEMS)) return ColorLib.rgb(255, 190, 190); else if (m_vis.isInGroup(item, Visualization.FOCUS_ITEMS)) return ColorLib.rgb(198, 229, 229); else if (item.getDOI() > -1) return ColorLib.rgb(164, 193, 193); else return ColorLib.rgba(255, 255, 255, 0); }
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 MPtrack(Table t) { super(new BorderLayout()); // -------------------------------------------------------------------- // STEP 1: setup the visualized data final Visualization vis = new Visualization(); m_vis = vis; final String group = "by_state"; VisualTable vt = vis.addTable(group, t); vis.setRendererFactory( new RendererFactory() { AbstractShapeRenderer sr = new ShapeRenderer(30); 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; } }); // -------------------------------------------------------------------- // set up the actions AxisLayout xaxis = new AxisLayout(group, "States", Constants.X_AXIS, VisiblePredicate.TRUE); AxisLayout yaxis = new AxisLayout(group, PARTY, Constants.Y_AXIS, VisiblePredicate.TRUE); // yaxis.setScale(Constants.LOG_SCALE); xaxis.setLayoutBounds(m_dataB); yaxis.setLayoutBounds(m_dataB); AxisLabelLayout ylabels = new AxisLabelLayout("ylab", yaxis, m_ylabB, 5); AxisLabelLayout xlabels = new AxisLabelLayout("xlab", xaxis, m_xlabB, 5); vis.putAction("xlabels", xlabels); int[] palette = new int[] {ColorLib.rgb(150, 150, 255)}; int[] palette2 = new int[200]; for (int i = 0; i < 200; i++) { palette2[i] = ColorLib.rgba(255, 0, 0, 2 * i); } /* DataColorAction color = new DataColorAction(group, "Party", Constants.ORDINAL, VisualItem.STROKECOLOR, palette); */ DataColorAction color2 = new DataColorAction(group, "Attendance", Constants.ORDINAL, VisualItem.FILLCOLOR, palette2); ActionList draw = new ActionList(); draw.add(color2); draw.add(xaxis); draw.add(yaxis); draw.add(ylabels); draw.add(new RepaintAction()); vis.putAction("draw", draw); ActionList update = new ActionList(); 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"); } }; // -------------------------------------------------------------------- // STEP 4: set up a display and ui components to show the visualization m_display = new Display(vis); 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); ToolTipControl ttc = new ToolTipControl("label"); Control hoverc = new ControlAdapter() { public void itemEntered(VisualItem item, MouseEvent evt) { if (item.isInGroup(group)) { 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)) { 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(Box.createHorizontalStrut(5)); // create dynamic queries Box radioBox = new Box(BoxLayout.X_AXIS); radioBox.add(Box.createHorizontalStrut(5)); radioBox.add(Box.createHorizontalGlue()); radioBox.add(Box.createHorizontalStrut(5)); radioBox.add(Box.createHorizontalStrut(16)); vis.run("draw"); vis.run("xlabels"); add(infoBox, BorderLayout.NORTH); add(m_display, BorderLayout.CENTER); add(radioBox, BorderLayout.SOUTH); UILib.setColor(this, ColorLib.getColor(255, 255, 255), Color.GRAY); UILib.setFont(radioBox, FontLib.getFont("Tahoma", 15)); m_details.setFont(FontLib.getFont("Tahoma", 18)); }
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"); }
/* * Constructor for the class * This is where all the important stuff happens */ public TabularDataVis(Table t) { super(new BorderLayout()); /* * Step 1: Setup the Visualization */ // create a new visualization object, and assign it to the global variable final Visualization vis = new Visualization(); g_vis = vis; // create a visual abstraction of the table data (loaded in the buildFrame method) // call our data "canUrban" VisualTable vt = vis.addTable("canUrban", t); // add a new column containing a label string showing // the Geographic name and population // note: uses the prefuse expression language vt.addColumn( "label", "CONCAT([Geographic name], ' (Population: ', FORMAT([2006 Population],0), ')')"); // add a new column that divides the provinces by their geographic location (derived values) // note: uses the prefuse expression language vt.addColumn( "geographic location", "IF ([Province]='BC') THEN 1 ELSE " + "(IF ([Province] = 'AB' OR [Province] = 'SK' OR [Province] = 'MB') THEN 2 ELSE " + "(IF ([Province] = 'ON' OR [Province] = 'QC') THEN 3 ELSE" + "(IF ([Province] = 'NS' OR [Province] = 'NB' OR [Province] = 'PE' OR [Province] = 'NL') THEN 4 ELSE 5)))"); // add a new column that converts the population data to ordinal data (derived values) // note: uses the prefuse expression language vt.addColumn( "population ordinal", "IF ([2006 Population] > 5000000) THEN 7 ELSE " + "(IF ([2006 Population] > 1000000) THEN 6 ELSE " + "(IF ([2006 Population] > 250000) THEN 5 ELSE " + "(IF ([2006 Population] > 100000) THEN 4 ELSE " + "(IF ([2006 Population] > 50000) THEN 3 ELSE " + "(IF ([2006 Population] > 20000) THEN 2 ELSE 1)))))"); // create a new renderer factory for drawing the visual items vis.setRendererFactory( new RendererFactory() { // specify the default shape renderer (the actions will decide how to actually render the // visual elements) AbstractShapeRenderer sr = new ShapeRenderer(); // renderers for the axes Renderer arY = new AxisRenderer(Constants.RIGHT, Constants.TOP); Renderer arX = new AxisRenderer(Constants.CENTER, Constants.FAR_BOTTOM); // return the appropriate renderer for a given visual item public Renderer getRenderer(VisualItem item) { return item.isInGroup("ylab") ? arY : item.isInGroup("xlab") ? arX : sr; } }); /* * Step 2: Add X-Axis */ // add the x-axis AxisLayout xaxis = new AxisLayout("canUrban", "Province", Constants.X_AXIS, VisiblePredicate.TRUE); // ensure the axis spans the width of the data container xaxis.setLayoutBounds(g_dataB); // add the labels to the x-axis AxisLabelLayout xlabels = new AxisLabelLayout("xlab", xaxis, g_xlabB, 15); /* * Step 3: Add the Y-Axis and its dynamic query feature */ // dynamic query based on population data RangeQueryBinding populationQ = new RangeQueryBinding(vt, "2006 Population"); AndPredicate filter = new AndPredicate(populationQ.getPredicate()); // add the y-axis AxisLayout yaxis = new AxisLayout("canUrban", "2006 Population", Constants.Y_AXIS, VisiblePredicate.TRUE); // set the range controls on the y-axis yaxis.setRangeModel(populationQ.getModel()); populationQ.getNumberModel().setValueRange(0, 6000000, 0, 6000000); // ensure the y-axis spans the height of the data container yaxis.setLayoutBounds(g_dataB); // add the labels to the y-axis AxisLabelLayout ylabels = new AxisLabelLayout("ylab", yaxis, g_ylabB); NumberFormat nf = NumberFormat.getIntegerInstance(); nf.setMaximumFractionDigits(0); ylabels.setNumberFormat(nf); /* * Step 4: Add the search box */ // dynamic query based on Geographic name data SearchQueryBinding searchQ = new SearchQueryBinding(vt, "Geographic name"); filter.add(searchQ.getPredicate()); // reuse the same filter as the population query /* * Step 5: Colours and Shapes */ // assign a set of five perceptually distinct colours to assign to the provinces // chosen from ColorBrewer (5-class qualitative Set1) int[] palette = new int[] { ColorLib.rgb(77, 175, 74), ColorLib.rgb(55, 126, 184), ColorLib.rgb(228, 26, 28), ColorLib.rgb(152, 78, 163), ColorLib.rgb(255, 127, 0) }; // specify the stroke (exterior line) based on the ordinal data DataColorAction color = new DataColorAction( "canUrban", "geographic location", Constants.ORDINAL, VisualItem.STROKECOLOR, palette); // specify the fill (interior) as a static colour (white) ColorAction fill = new ColorAction("canUrban", VisualItem.FILLCOLOR, 0); // represent all the data points with rectangles ShapeAction shape = new ShapeAction("canUrban", Constants.SHAPE_RECTANGLE); // assign the size of the visual element based on the population data (we // converted the 2006 Population data to ordinal values) DataSizeAction size = new DataSizeAction("canUrban", "population ordinal"); // setup a counter to keep track of which data points are currently being viewed Counter cntr = new Counter("canUrban"); /* * Step 6: Create the action list for drawing the visual elements */ ActionList draw = new ActionList(); draw.add(cntr); draw.add(color); draw.add(fill); draw.add(shape); draw.add(size); draw.add(xaxis); draw.add(yaxis); draw.add(ylabels); draw.add(new RepaintAction()); vis.putAction("draw", draw); vis.putAction("xlabels", xlabels); /* * create the action list for updating the visual elements * (during interactive operations and re-sizing of the window) */ ActionList update = new ActionList(); update.add(new VisibilityFilter("canUrban", filter)); // filter performs the size/name filtering update.add(cntr); update.add(xaxis); update.add(yaxis); update.add(ylabels); update.add(new RepaintAction()); vis.putAction("update", update); // create an update listener that will update the visualization when fired UpdateListener lstnr = new UpdateListener() { public void update(Object src) { vis.run("update"); } }; // add this update listener to the filter, so that when the filter changes (i.e., // the user adjusts the axis parameters, or enters a name for filtering), the // visualization is updated filter.addExpressionListener(lstnr); /* * Step 7: Setup the Display and the other Interface components * (scroll bar, query box, tool tips) */ // create the display g_display = new Display(vis); // set the display properties g_display.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); g_display.setSize(700, 450); g_display.setHighQuality(true); // call the function that sets the sizes of the containers that contain // the data and the axes displayLayout(); // whenever the window is re-sized, update the layout of the axes g_display.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent e) { displayLayout(); } }); // title label (top left) JFastLabel g_details = new JFastLabel("Canadian Urban Population"); g_details.setPreferredSize(new Dimension(350, 20)); g_details.setVerticalAlignment(SwingConstants.BOTTOM); // total label (top right) g_total.setPreferredSize(new Dimension(350, 20)); g_total.setHorizontalAlignment(SwingConstants.RIGHT); g_total.setVerticalAlignment(SwingConstants.BOTTOM); // tool tips ToolTipControl ttc = new ToolTipControl("label"); Control hoverc = new ControlAdapter() { public void itemEntered(VisualItem item, MouseEvent evt) { if (item.isInGroup("canUrban")) { g_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("canUrban")) { g_total.setText(g_totalStr); item.setFillColor(item.getEndFillColor()); item.setStrokeColor(item.getEndStrokeColor()); item.getVisualization().repaint(); } } }; g_display.addControlListener(ttc); g_display.addControlListener(hoverc); // vertical slider for adjusting the population filter JRangeSlider slider = populationQ.createVerticalRangeSlider(); slider.setThumbColor(null); slider.setToolTipText("drag the arrows to filter the data"); // smallest window: 200,000 slider.setMinExtent(200000); slider.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { g_display.setHighQuality(false); } public void mouseReleased(MouseEvent e) { g_display.setHighQuality(true); g_display.repaint(); } }); // search box JSearchPanel searcher = searchQ.createSearchPanel(); searcher.setLabelText("Urban Centre: "); searcher.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0)); /* * Step 8: Create Containers for the Interface Elements */ // add the listener to this component this.addComponentListener(lstnr); // container for elements at the top of the screen Box topContainer = new Box(BoxLayout.X_AXIS); topContainer.add(Box.createHorizontalStrut(5)); topContainer.add(g_details); topContainer.add(Box.createHorizontalGlue()); topContainer.add(Box.createHorizontalStrut(5)); topContainer.add(g_total); topContainer.add(Box.createHorizontalStrut(5)); // container for elements at the bottom of the screen Box bottomContainer = new Box(BoxLayout.X_AXIS); bottomContainer.add(Box.createHorizontalStrut(5)); bottomContainer.add(searcher); bottomContainer.add(Box.createHorizontalGlue()); bottomContainer.add(Box.createHorizontalStrut(5)); bottomContainer.add(Box.createHorizontalStrut(16)); // fonts, colours, etc. UILib.setColor(this, ColorLib.getColor(255, 255, 255), Color.GRAY); slider.setForeground(Color.LIGHT_GRAY); UILib.setFont(bottomContainer, FontLib.getFont("Tahoma", 15)); g_details.setFont(FontLib.getFont("Tahoma", 18)); g_total.setFont(FontLib.getFont("Tahoma", 16)); // add the containers to the JPanel add(topContainer, BorderLayout.NORTH); add(g_display, BorderLayout.CENTER); add(slider, BorderLayout.EAST); add(bottomContainer, BorderLayout.SOUTH); /* * Step 9: Start the Visualization */ vis.run("draw"); vis.run("xlabels"); }
/** * Color palette for the BMVis visualization. * * @author Kimmo Kulovesi */ public class ColorPalette { /** Predefined edge type stroke colors. */ public static final HashMap<String, Integer> EDGE_COLORS = new HashMap<String, Integer>(); /** Predefined node type colors. */ public static final HashMap<String, Integer> NODE_COLORS = new HashMap<String, Integer>(); /** Predefined queryset colors. */ public static final HashMap<String, Integer> QUERYSET_COLORS = new HashMap<String, Integer>(); static { // EDGE_COLORS.put("refers_to", ColorLib.rgb(0, 0, 0)); QUERYSET_COLORS.put("start", ColorLib.rgb(0, 175, 0)); QUERYSET_COLORS.put("source", ColorLib.rgb(0, 175, 0)); QUERYSET_COLORS.put("end", ColorLib.rgb(220, 0, 0)); QUERYSET_COLORS.put("target", ColorLib.rgb(220, 0, 0)); QUERYSET_COLORS.put("start,end", ColorLib.rgb(220, 0, 220)); QUERYSET_COLORS.put("source,target", ColorLib.rgb(220, 0, 220)); QUERYSET_COLORS.put("rank", ColorLib.rgb(0, 175, 220)); NODE_COLORS.put("Node", ColorLib.rgb(240, 240, 240)); // Saturated greens NODE_COLORS.put("Sequence", ColorLib.rgb(211, 247, 163)); NODE_COLORS.put("Gene", ColorLib.rgb(211, 247, 163)); NODE_COLORS.put("Protein", ColorLib.rgb(199, 240, 178)); NODE_COLORS.put("Enzyme", ColorLib.rgb(193, 234, 174)); // NODE_COLORS.put("ProteinGroup", ColorLib.rgb(199, 240, 178)); NODE_COLORS.put("AllelicVariant", ColorLib.rgb(199, 240, 178)); // Beige NODE_COLORS.put("Article", ColorLib.rgb(250, 230, 160)); // Cyans (to do, make greener) NODE_COLORS.put("HomologGroup", ColorLib.rgb(187, 237, 215)); NODE_COLORS.put("OrthologGroup", ColorLib.rgb(194, 237, 218)); // Desaturated blues NODE_COLORS.put("GO", ColorLib.rgb(185, 218, 234)); NODE_COLORS.put("BiologicalProcess", ColorLib.rgb(185, 218, 234)); NODE_COLORS.put("MolecularFunction", ColorLib.rgb(189, 223, 239)); NODE_COLORS.put("CellularComponent", ColorLib.rgb(174, 214, 234)); // Light purples NODE_COLORS.put("Ligand", ColorLib.rgb(210, 203, 240)); NODE_COLORS.put("Substance", ColorLib.rgb(210, 203, 240)); NODE_COLORS.put("Compound", ColorLib.rgb(210, 203, 240)); NODE_COLORS.put("Drug", ColorLib.rgb(203, 196, 233)); NODE_COLORS.put("Glycan", ColorLib.rgb(198, 200, 242)); // Pink NODE_COLORS.put("GenomicContext", ColorLib.rgb(255, 215, 253)); // Blues NODE_COLORS.put("Locus", ColorLib.rgb(180, 196, 239)); // unused NODE_COLORS.put("Phenotype", ColorLib.rgb(193, 209, 255)); // NODE_COLORS.put("Locus/Phenotype, ColorLib.rgb(195, 199, 242)); // TMP MAPPING for illustration purposes BY LERONEN! Should never get to SVN! NODE_COLORS.put("Gene/Phenotype", ColorLib.rgb(211, 247, 163)); // NODE_COLORS.put("Gene/Phenotype", ColorLib.rgb(193, 223, 242)); // Greens NODE_COLORS.put("Family", ColorLib.rgb(179, 226, 192)); NODE_COLORS.put("Region", ColorLib.rgb(195, 229, 204)); NODE_COLORS.put("Domain", ColorLib.rgb(195, 229, 204)); NODE_COLORS.put("Repeat", ColorLib.rgb(195, 229, 204)); NODE_COLORS.put("Site", ColorLib.rgb(190, 229, 201)); NODE_COLORS.put("ActiveSite", ColorLib.rgb(190, 229, 201)); NODE_COLORS.put("BindingSite", ColorLib.rgb(190, 229, 201)); NODE_COLORS.put("PostTranslationalModification", ColorLib.rgb(190, 229, 201)); // Purple NODE_COLORS.put("Pathway", ColorLib.rgb(208, 185, 231)); // Browns NODE_COLORS.put("Tissue", ColorLib.rgb(229, 218, 189)); // NODE_COLORS.put("Organism", ColorLib.rgb(229, 215, 177)); NODE_COLORS.put("MeSHHeading", ColorLib.rgb(239, 231, 176)); NODE_COLORS.put("OMIM", ColorLib.rgb(239, 231, 176)); } /** Node text color. */ public static final int NODE_TEXT = ColorLib.gray(0); /** Groupnode border stroke color. */ public static final int GROUPNODE_STROKE = ColorLib.gray(0); /** Edgenode fill color. */ public static final int EDGENODE_FILL = 0; /** * Default node fill color. This is generally unused, due to the use of type-specific colors set * in NODE_COLORS. */ public static final int DEFAULT_FILL = ColorLib.rgb(200, 215, 255); /** Selected node color. */ public static final int NODE_SELECT = ColorLib.rgb(255, 100, 100); /** Node hover highlight color. */ public static final int NODE_HOVER = ColorLib.rgb(255, 155, 140); /** Node hover neighbor highlight color. */ public static final int NEIGHBOR_HOVER = ColorLib.rgb(255, 175, 0); /** Selected node hover highlight color. */ public static final int SELECT_HOVER = ColorLib.rgb(255, 120, 120); /** Node hover neighbor highlight color for selected nodes. */ public static final int SELECT_NEIGHBOR = ColorLib.rgb(255, 100, 35); /** Default edge stroke color. */ public static final int DEFAULT_EDGE_STROKE = ColorLib.rgb(15, 15, 15); }
public void itemReleased(VisualItem item, MouseEvent evt) { item.setFillColor(ColorLib.rgb(255, 255, 255)); item.setStrokeColor(item.getEndStrokeColor()); item.getVisualization().repaint(); }
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 BorderColorAction(String group) { super(group, VisualItem.STROKECOLOR, ColorLib.rgba(0, 0, 255, 255)); add(isprocessfilter, ColorLib.rgba(176, 23, 31, 255)); }
@Override public void render(Graphics2D g, VisualItem item) { if (item.isVisible()) { item.setShape(Constants.SHAPE_RECTANGLE); RectangularShape shape = (RectangularShape) getShape(item); if (shape != null) { shape .getBounds2D() .setRect( (double) item.get(VisualItem.X), (double) item.get(VisualItem.Y), item.getSize(), item.getSize()); // draw basic glyph Color strokeColor = ColorLib.getColor(item.getStrokeColor()); Color fillColor = ColorLib.getColor(item.getFillColor()); // int size = (int)item.getSize(); int x = (int) item.getX() + bufferPx; int y = (int) item.getY() + bufferPx; int w = (int) item.getDouble(WIDTH) - 2 * bufferPx; int h = (int) item.getDouble(HEIGHT) - 2 * bufferPx; g.setPaint(fillColor); g.fillRect(x, y, w, h); // draw string on-top of glyph, filling the glyph's area // String s = "doc=" + item.getString(NODE_NAME) + "\n"; String s = ""; // set text: full document if no search term, else excerpts containing the search term String queryStr = searchQ.getSearchSet().getQuery(); String focusText = item.getString(DocumentGridTable.NODE_FOCUS_TEXT); if (queryStr != null && !queryStr.isEmpty() && focusText != null && !focusText.equals("null") && !focusText.equals("")) { // if search query and terms present in document, use term-containing spans s += focusText; } else if (queryStr != null && !queryStr.isEmpty() && focusText.equals(FOCUS_SENT_SPLITTER)) { // if search query but no terms present in document, use blank s += ""; } else if ((queryStr == null || queryStr.isEmpty()) && item.canGetInt(NODE_ID)) { // if no search query, build feature-oriented summary based on color attribute s = controller.getDocumentSummary(item.getInt(NODE_ID), colorAttrName); } // TODO : idea: set font size dynamically based on number of active nodes? based on size // of rect? int fontSize = 10; item.setFont(FontLib.getFont("Tahoma", Font.PLAIN, fontSize)); Font f = item.getFont(); // compute width, height for the given text // NOTE: this logic has been moved into drawStringMultiline // int[] textDims = getTextDims(g, f, s); // debug // System.out.println("debug: "+this.getClass().getName()+": // drawStringMultiline at x="+x1+", y="+y1+", w="+w+", h="+h); drawStringMultiline(g, f, s, x, y, w, h); } } }
public AggregateDemo() { // initialize display and data super(new Visualization()); initDataGroups(); // set up the renderers // draw the nodes as basic shapes Renderer nodeR = new ShapeRenderer(20); // draw aggregates as polygons with curved edges Renderer polyR = new PolygonRenderer(Constants.POLY_TYPE_CURVE); ((PolygonRenderer) polyR).setCurveSlack(0.15f); // modification to try drawing edges to aggregates Renderer edgeR = new EdgeRenderer() { @Override protected Shape getRawShape(VisualItem item) { EdgeItem edge = (EdgeItem) item; VisualItem item1 = edge.getSourceItem(); VisualItem item2 = edge.getTargetItem(); item2 = (AggregateItem) at.getAggregates(item2).next(); int type = m_edgeType; getAlignedPoint(m_tmpPoints[0], item1.getBounds(), m_xAlign1, m_yAlign1); getAlignedPoint(m_tmpPoints[1], item2.getBounds(), m_xAlign2, m_yAlign2); m_curWidth = (float) (m_width * getLineWidth(item)); // create the arrow head, if needed EdgeItem e = (EdgeItem) item; if (e.isDirected() && m_edgeArrow != Constants.EDGE_ARROW_NONE) { // get starting and ending edge endpoints boolean forward = (m_edgeArrow == Constants.EDGE_ARROW_FORWARD); Point2D start = null, end = null; start = m_tmpPoints[forward ? 0 : 1]; end = m_tmpPoints[forward ? 1 : 0]; // compute the intersection with the target bounding box VisualItem dest = forward ? e.getTargetItem() : e.getSourceItem(); int i = GraphicsLib.intersectLineRectangle(start, end, dest.getBounds(), m_isctPoints); if (i > 0) end = m_isctPoints[0]; // create the arrow head shape AffineTransform at = getArrowTrans(start, end, m_curWidth); m_curArrow = at.createTransformedShape(m_arrowHead); // update the endpoints for the edge shape // need to bias this by arrow head size Point2D lineEnd = m_tmpPoints[forward ? 1 : 0]; lineEnd.setLocation(0, -m_arrowHeight); at.transform(lineEnd, lineEnd); } else { m_curArrow = null; } // create the edge shape Shape shape = null; double n1x = m_tmpPoints[0].getX(); double n1y = m_tmpPoints[0].getY(); double n2x = m_tmpPoints[1].getX(); double n2y = m_tmpPoints[1].getY(); switch (type) { case Constants.EDGE_TYPE_LINE: m_line.setLine(n1x, n1y, n2x, n2y); shape = m_line; break; case Constants.EDGE_TYPE_CURVE: getCurveControlPoints(edge, m_ctrlPoints, n1x, n1y, n2x, n2y); m_cubic.setCurve( n1x, n1y, m_ctrlPoints[0].getX(), m_ctrlPoints[0].getY(), m_ctrlPoints[1].getX(), m_ctrlPoints[1].getY(), n2x, n2y); shape = m_cubic; break; default: throw new IllegalStateException("Unknown edge type"); } // return the edge shape return shape; } }; DefaultRendererFactory drf = new DefaultRendererFactory(nodeR, edgeR); drf.add("ingroup('aggregates')", polyR); m_vis.setRendererFactory(drf); // set up the visual operators // first set up all the color actions ColorAction nStroke = new ColorAction(NODES, VisualItem.STROKECOLOR); nStroke.setDefaultColor(ColorLib.gray(100)); nStroke.add("_hover", ColorLib.gray(50)); ColorAction nFill = new ColorAction(NODES, VisualItem.FILLCOLOR); nFill.setDefaultColor(ColorLib.gray(255)); nFill.add("_hover", ColorLib.gray(200)); ColorAction nEdges = new ColorAction(EDGES, VisualItem.STROKECOLOR); nEdges.setDefaultColor(ColorLib.gray(100)); ColorAction aStroke = new ColorAction(AGGR, VisualItem.STROKECOLOR); aStroke.setDefaultColor(ColorLib.gray(200)); aStroke.add("_hover", ColorLib.rgb(255, 100, 100)); int[] palette = new int[] { ColorLib.rgba(255, 200, 200, 255), ColorLib.rgba(200, 255, 200, 255), ColorLib.rgba(200, 200, 255, 255) }; ColorAction aFill = new DataColorAction(AGGR, "id", Constants.NOMINAL, VisualItem.FILLCOLOR, palette); // bundle the color actions ActionList colors = new ActionList(); colors.add(nStroke); colors.add(nFill); colors.add(nEdges); colors.add(aStroke); colors.add(aFill); // now create the main layout routine ActionList layout = new ActionList(Activity.INFINITY); layout.add(colors); layout.add(new ForceDirectedLayout(GRAPH, true)); layout.add(new AggregateLayout(AGGR)); layout.add(new RepaintAction()); m_vis.putAction("layout", layout); // set up the display setSize(500, 500); pan(250, 250); setHighQuality(true); addControlListener(new AggregateDragControl()); addControlListener(new ZoomControl()); addControlListener(new PanControl()); // set things running m_vis.run("layout"); }