Statistics:Posted by diddyxn — 28 May 2014 12:49
Statistics:Posted by hdean83@gmail.com — 09 Jul 2013 14:37
Statistics:Posted by eduramiba — 31 Mar 2012 17:41
CODE:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package org.ferretti.MultiColourNode;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Graphics2D;import java.awt.Stroke;import java.util.ArrayList;import java.util.Scanner;import org.gephi.graph.api.Node;import org.gephi.preview.api.*;import org.gephi.preview.plugin.items.NodeItem;import org.gephi.preview.spi.Renderer;import org.gephi.data.attributes.type.IntegerList;import org.gephi.preview.plugin.renderers.NodeRenderer;import org.openide.util.lookup.ServiceProvider;import org.w3c.dom.Element;import processing.core.PGraphicsJava2D;/** * * @author James */@ServiceProvider(service = Renderer.class, position = 1, supersedes={"org.gephi.preview.plugin.renderers.NodeRenderer"})public class MultiColourRenderer implements Renderer { @Override public void preProcess(PreviewModel previewModel) { } @Override public void render(Item item, RenderTarget target, PreviewProperties properties) { if (target instanceof ProcessingTarget) { renderProcessing(item, (ProcessingTarget) target, properties); } else if (target instanceof SVGTarget) { renderSVG(item, (SVGTarget) target, properties); } else if (target instanceof PDFTarget) { renderPDF(item, (PDFTarget) target, properties); } } @Override public PreviewProperty[] getProperties() { return new PreviewProperty[]{ PreviewProperty.createProperty(this, "MultiColourNode", Boolean.class, "Multi Colour Nodes", "Make a node be coloured more then one hue", PreviewProperty.CATEGORY_NODES).setValue(false) }; } @Override public boolean isRendererForitem(Item item, PreviewProperties properties) { return item.getType().equals(Item.NODE) && properties.getBooleanValue("MultiColourNode"); } private void renderProcessing(Item item, ProcessingTarget target, PreviewProperties properties) { //Params Float xF = item.getData(NodeItem.X); Float yF = item.getData(NodeItem.Y); //Float sizeF = item.getData(NodeItem.SIZE); int x = xF.intValue(); int y = yF.intValue(); Node n = (Node) item.getSource(); Integer size = (Integer) n.getNodeData().getAttributes().getValue("size"); Object colourList = n.getNodeData().getAttributes().getValue("colourList"); ArrayList<Color> colourArray = splitColourList(colourList); int radius = size; PGraphicsJava2D graphics = (PGraphicsJava2D) target.getGraphics(); Graphics2D g2 = graphics.g2; // draw colour indices as pie chart around point if (colourArray.size() > 0) { double arcAngle = 360.0 / colourArray.size(); // draw 'pieces of pie' for (int i = 0; i < colourArray.size(); i++) { //System.out.println(Integer.parseInt(n.getColour(i))); g2.setColor(colourArray.get(i)); g2.fillArc((x - radius), (y - radius), (radius * 2), (radius * 2), (int) (arcAngle * i), (int) arcAngle); } // draw 'spokes' between pieces if (colourArray.size() > 1) { Stroke oldStroke = g2.getStroke(); for (int i = 0; i < colourArray.size(); i++) { double spokeAngle = arcAngle * i / 180 * Math.PI; g2.setColor(Color.BLACK); g2.setStroke(new BasicStroke(0.5f)); g2.drawLine(x, y, (int) (x + radius * Math.cos(spokeAngle)), (int) (y - radius * Math.sin(spokeAngle))); } g2.setStroke(oldStroke); } } else { // draw filled white circle g2.setColor(Color.WHITE); g2.fillOval(x - radius, y - radius, radius * 2, radius * 2); } // draw black circle g2.setColor(Color.BLACK); g2.drawOval(x - radius, y - radius, radius * 2, radius * 2); //original //g2.setPaint(p); //g2.fillOval((int) (x.floatValue() - radius), (int) (y.floatValue() - radius), (int) (radius * 2), (int) (radius * 2)); } private void renderSVG(Item item, SVGTarget target, PreviewProperties properties) { //Params Float x = item.getData(NodeItem.X); Float y = item.getData(NodeItem.Y); Float size = item.getData(NodeItem.SIZE); Node n = (Node) item.getSource(); Object colourListObj = n.getNodeData().getAttributes().getValue("colourList"); ArrayList<Color> colourArray = splitColourList(colourListObj); Float radius = size - 3; //float borderSize = properties.getFloatValue(PreviewProperty.NODE_BORDER_WIDTH); float alpha = properties.getIntValue(PreviewProperty.NODE_OPACITY) / 100f; if (alpha > 1) { alpha = 1; } // draw colour indices as pie chart around point if (colourArray.size() > 0) { float arcAngle = (float) (360.0 / colourArray.size()); // draw 'pieces of pie' for (int i = 0; i < colourArray.size(); i++) { //Arc2D arca = new Arc2D.Float((x - radius), (y - radius), (radius * 2), (radius * 2), (arcAngle * i), (arcAngle), Arc2D.CHORD); float[] startXY = toCartesianCoordinate(x, y, radius, arcAngle * i); float[] endXY = toCartesianCoordinate(x, y, radius, (arcAngle * i) + arcAngle); Element nodeElem = target.createElement("path"); nodeElem.setAttribute("class", n.getNodeData().getId()); nodeElem.setAttribute("fill", target.toHexString(colourArray.get(i))); nodeElem.setAttribute("d", "M" + " " + startXY[0] + " " + startXY[1] + " " + "A" + " " + radius + " " + radius + " " + 0 + " " + 0 + " " + 0 + " " + endXY[0] + " " + endXY[1]); //PATH = M startXY[0] startXY[1] A radius radius 0 0 0 endXY[0] endXY[1] nodeElem.setAttribute("fill-opacity", "" + alpha); nodeElem.setAttribute("stroke", "black"); nodeElem.setAttribute("stroke-width", "2"); } } else { Element nodeElem = target.createElement("circle"); nodeElem.setAttribute("class", n.getNodeData().getId()); nodeElem.setAttribute("cx", x.toString()); nodeElem.setAttribute("cy", y.toString()); nodeElem.setAttribute("r", size.toString()); nodeElem.setAttribute("fill", target.toHexString(Color.WHITE)); nodeElem.setAttribute("fill-opacity", "" + alpha); } } private void renderPDF(Item item, PDFTarget pdfTarget, PreviewProperties properties) { //TODO } /** * turns a list of numbers into an ArrayList of Colours should be able to * deal with bot a string or a IntegerList item * * @param colorList String, list of colours taken from the column * "colourList" * @return An ArrayList of Colour objects, to be drawn on the node */ private ArrayList<Color> splitColourList(Object colourListObj) { ArrayList<Color> toReturn = new ArrayList<Color>(); if (colourListObj instanceof IntegerList) { IntegerList colourIntList = (IntegerList) colourListObj; if (colourIntList != null) { for (int i = 0; i < colourIntList.size(); i++) { Integer rgb = colourIntList.getItem(i); rgb = rgb/15; Color col = new Color(rgb); if (!toReturn.contains(col)) { toReturn.add(col); } } } } else if (colourListObj instanceof String) { //-1 denotes a default value where no colours were attributed to a node String colourList = (String) colourListObj; if (!colourList.equals("-1")) { Scanner scan = new Scanner(colourList); scan.useDelimiter(","); while (scan.hasNext()) { String str = scan.next(); Integer rgb = str.hashCode(); rgb = rgb/15; //Integer rgb = Integer.parseInt(str); Color col = new Color(rgb); if (!toReturn.contains(col)) { toReturn.add(col); } } } } return toReturn; } private float[] toCartesianCoordinate(float centerX, float centerY, float radius, float angleInDegrees) { float angleInRadians = (float) (angleInDegrees * Math.PI / 180.0); float x = (float) (centerX + radius * Math.cos(angleInRadians)); float y = (float) (centerY + radius * Math.sin(angleInRadians)); float[] arr = {x, y}; return arr; }}
Statistics:Posted by Ferretti — 31 Mar 2012 16:26
Statistics:Posted by eduramiba — 19 Feb 2012 15:32
CODE:
@ServiceProvider(service = Renderer.class, position = 1)
CODE:
@ServiceProvider(service = Renderer.class, supersedes={"NodeRenderer"})
CODE:
@ServiceProvider(service = Renderer.class, position = 1, supersedes={"NodeRenderer"})
Statistics:Posted by Ferretti — 18 Feb 2012 20:11
CODE:
@ServiceProvider(service = Renderer.class, position = 400)
Statistics:Posted by eduramiba — 14 Feb 2012 21:14
Surely when you click the check box the original renderer should be disabled and only mine used? it would possibly make more sense to have a drop-down menu to select renderer next to where the "presets" menu is. You could select renderer and also be presented with options specific to that renderer in the panel on the right.So the user should clearly notice on this and future plugins that he has to disable the normal nodes rendering and enable yours.
Statistics:Posted by Ferretti — 14 Feb 2012 18:19
CODE:
public boolean isRendererForitem(Item item, PreviewProperties properties) { return item.getType().equals(Item.NODE) && properties.getBooleanValue("MultiColourNode");}
Statistics:Posted by eduramiba — 13 Feb 2012 23:35
CODE:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package org.ferretti.MultiColourNode;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Graphics2D;import java.awt.Stroke;import java.awt.geom.Arc2D;import java.util.ArrayList;import java.util.Scanner;import org.gephi.graph.api.Node;import org.gephi.preview.api.*;import org.gephi.preview.plugin.items.NodeItem;import org.gephi.preview.spi.Renderer;import org.openide.util.lookup.ServiceProvider;import org.w3c.dom.Element;import processing.core.PGraphicsJava2D;/** * * @author James */@ServiceProvider(service = Renderer.class)public class MultiColourRenderer implements Renderer { @Override public void preProcess(PreviewModel previewModel) { } @Override public void render(Item item, RenderTarget target, PreviewProperties properties) { if (target instanceof ProcessingTarget) { renderProcessing(item, (ProcessingTarget) target, properties); } else if (target instanceof SVGTarget) { renderSVG(item, (SVGTarget) target, properties); } else if (target instanceof PDFTarget) { renderPDF(item, (PDFTarget) target, properties); } } @Override public PreviewProperty[] getProperties() { return new PreviewProperty[]{ PreviewProperty.createProperty(this, "MultiColourNode", Boolean.class, "Multi Colour Nodes", "Make a node be coloured more then one hue", PreviewProperty.CATEGORY_NODES).setValue(false) }; } @Override public boolean isRendererForitem(Item item, PreviewProperties properties) { return item.getType().equals(Item.NODE); } private void renderProcessing(Item item, ProcessingTarget target, PreviewProperties properties) { //Params Float xF = item.getData(NodeItem.X); Float yF = item.getData(NodeItem.Y); Float sizeF = item.getData(NodeItem.SIZE); int x = xF.intValue(); int y = yF.intValue(); int size = sizeF.intValue(); Node n = (Node) item.getSource(); String colourList = (String) n.getNodeData().getAttributes().getValue("colourList"); ArrayList<Color> colourArray = splitColourList(colourList); int radius = size - 4; PGraphicsJava2D graphics = (PGraphicsJava2D) target.getGraphics(); Graphics2D g2 = graphics.g2; // draw colour indices as pie chart around point if (colourArray.size() > 0) { double arcAngle = 360.0 / colourArray.size(); // draw 'pieces of pie' for (int i = 0; i < colourArray.size(); i++) { //System.out.println(Integer.parseInt(n.getColour(i))); g2.setColor(colourArray.get(i)); g2.fillArc((x - radius), (y - radius), (radius * 2), (radius * 2), (int) (arcAngle * i), (int) arcAngle); } // draw 'spokes' between pieces if (colourArray.size() > 1) { Stroke oldStroke = g2.getStroke(); for (int i = 0; i < colourArray.size(); i++) { double spokeAngle = arcAngle * i / 180 * Math.PI; g2.setColor(Color.BLACK); g2.setStroke(new BasicStroke(0.5f)); g2.drawLine(x, y, (int) (x + radius * Math.cos(spokeAngle)), (int) (y - radius * Math.sin(spokeAngle))); } g2.setStroke(oldStroke); } } else { // draw filled white circle g2.setColor(Color.WHITE); g2.fillOval(x - radius, y - radius, radius * 2, radius * 2); } // draw black circle g2.setColor(Color.BLACK); g2.drawOval(x - radius, y - radius, radius * 2, radius * 2); //original //g2.setPaint(p); //g2.fillOval((int) (x.floatValue() - radius), (int) (y.floatValue() - radius), (int) (radius * 2), (int) (radius * 2)); } private void renderSVG(Item item, SVGTarget target, PreviewProperties properties) { //Params Float x = item.getData(NodeItem.X); Float y = item.getData(NodeItem.Y); Float size = item.getData(NodeItem.SIZE); Node n = (Node) item.getSource(); String colourList = (String) n.getNodeData().getAttributes().getValue("colourList"); ArrayList<Color> colourArray = splitColourList(colourList); Float radius = size - 3; //float borderSize = properties.getFloatValue(PreviewProperty.NODE_BORDER_WIDTH); float alpha = properties.getIntValue(PreviewProperty.NODE_OPACITY) / 100f; if (alpha > 1) { alpha = 1; } // draw colour indices as pie chart around point if (colourArray.size() > 0) { float arcAngle = (float) (360.0 / colourArray.size()); // draw 'pieces of pie' for (int i = 0; i < colourArray.size(); i++) { //Arc2D arca = new Arc2D.Float((x - radius), (y - radius), (radius * 2), (radius * 2), (arcAngle * i), (arcAngle), Arc2D.CHORD); float[] startXY = toCartesianCoordinate(x, y, radius, arcAngle*i); float[] endXY = toCartesianCoordinate(x, y, radius, (arcAngle*i)+arcAngle); Element nodeElem = target.createElement("path"); nodeElem.setAttribute("class", n.getNodeData().getId()); nodeElem.setAttribute("fill", target.toHexString(colourArray.get(i))); nodeElem.setAttribute("d", "M" + " " + startXY[0] + " " + startXY[1] + " " + "A" + " " + radius + " " + radius + " " + 0 + " " + 0 + " " + 0 + " " + endXY[0] + " " + endXY[1]); //PATH = M startXY[0] startXY[1] A radius radius 0 0 0 endXY[0] endXY[1] nodeElem.setAttribute("fill-opacity", "" + alpha); nodeElem.setAttribute("stroke", "black"); nodeElem.setAttribute("stroke-width", "2"); } } else { Element nodeElem = target.createElement("circle"); nodeElem.setAttribute("class", n.getNodeData().getId()); nodeElem.setAttribute("cx", x.toString()); nodeElem.setAttribute("cy", y.toString()); nodeElem.setAttribute("r", size.toString()); nodeElem.setAttribute("fill", target.toHexString(Color.WHITE)); nodeElem.setAttribute("fill-opacity", "" + alpha); } } private void renderPDF(Item item, PDFTarget pdfTarget, PreviewProperties properties) { //TODO } /** * turns a list of numbers into an ArrayList of Colours * * @param colorList String, list of colours taken from the column * "colourList" * @return An ArrayList of Colour objects, to be drawn on the node */ private ArrayList<Color> splitColourList(String colourList) { ArrayList<Color> toReturn = new ArrayList<Color>(); //-1 denotes a default value where no colours were attributed to a node if (!colourList.equals("-1")) { Scanner scan = new Scanner(colourList); scan.useDelimiter(","); while (scan.hasNext()) { String str = scan.next(); Integer rgb = Integer.parseInt(str); Color col = new Color(rgb); toReturn.add(col); } } return toReturn; } private float[] toCartesianCoordinate(float centerX, float centerY, float radius, float angleInDegrees) { float angleInRadians = (float) (angleInDegrees * Math.PI / 180.0); float x = (float) (centerX + radius * Math.cos(angleInRadians)); float y = (float) (centerY + radius * Math.sin(angleInRadians)); float[] arr = {x, y}; return arr; }}
Statistics:Posted by Ferretti — 13 Feb 2012 18:12
What data type to you use? Because we have a list type in Gephi. It can be imported from a GEXF for example by setting 'listint' for an integer list, separated by one of the default separators (,|;). We don't support color lists but anyway it's better to import ints or doubles and assign colors later. Lists are not really integrated in Gephi at this point (no filtering capabilities or ranking). The column will be there, visible in the Data Laboratory and accessible like any other column.At the moment it requires a column labelled 'colourList', which isn't to most straightforward thing
Currently I have:Are you defining a new Node Renderer or inherit from the default?Also I have the problem that it will always use this renderer even if I disable the checkbox, presumably this is some error on my part?
CODE:
@ServiceProvider(service = Renderer.class)public class MultiColourRenderer implements Renderer {...}
So would this be something I could easily turn on or would it requre lots of changes? It's not the most important thing but it makes the graph more interactive and feel more 'alive'.It should be possible but we avoided doing that to maximize refresh rate in Preview. Our idea was to have speed and interactivity in Overview and customization and aesthetic in Preview.A personal request - I like the feature in the overview where moving over one node highlights its neighbours, is it possible to replicate this in preview mode?
Great, I will look more into this.
Statistics:Posted by Ferretti — 12 Feb 2012 16:28
What data type to you use? Because we have a list type in Gephi. It can be imported from a GEXF for example by setting 'listint' for an integer list, separated by one of the default separators (,|;). We don't support color lists but anyway it's better to import ints or doubles and assign colors later. Lists are not really integrated in Gephi at this point (no filtering capabilities or ranking). The column will be there, visible in the Data Laboratory and accessible like any other column.At the moment it requires a column labelled 'colourList', which isn't to most straightforward thing
Are you defining a new Node Renderer or inherit from the default?Also I have the problem that it will always use this renderer even if I disable the checkbox, presumably this is some error on my part?
It should be possible but we avoided doing that to maximize refresh rate in Preview. Our idea was to have speed and interactivity in Overview and customization and aesthetic in Preview.A personal request - I like the feature in the overview where moving over one node highlights its neighbours, is it possible to replicate this in preview mode?
Yes you can use the Gephi Toolkit. Here is an example of a standalone Preview component usage.Also is it possible to create a standalone interactive graph using Gephi as the basis but without having to actually load the gephi software?
Statistics:Posted by mbastian — 12 Feb 2012 07:26
Statistics:Posted by Ferretti — 11 Feb 2012 19:17
Statistics:Posted by eduramiba — 11 Feb 2012 00:47
Statistics:Posted by Ferretti — 10 Feb 2012 20:43
CODE:
String colourList = item.getData("colourList");
CODE:
Node n=(Node) item.getSource();n.getNodeData().getAttributes().getValue("colourList")
Statistics:Posted by eduramiba — 10 Feb 2012 19:38
CODE:
String colourList = item.getData("colourList");
Statistics:Posted by Ferretti — 10 Feb 2012 18:40
Statistics:Posted by mbastian — 09 Feb 2012 08:33