Skip to content

Commit

Permalink
Rebase 30/04
Browse files Browse the repository at this point in the history
  • Loading branch information
conker84 committed May 21, 2017
1 parent c3b7087 commit 6e74eb9
Show file tree
Hide file tree
Showing 28 changed files with 1,246 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/_includes/themes/zeppelin/_navigation.html
Expand Up @@ -88,6 +88,7 @@
<li><a href="{{BASE_PATH}}/displaysystem/basicdisplaysystem.html#text">Text</a></li>
<li><a href="{{BASE_PATH}}/displaysystem/basicdisplaysystem.html#html">Html</a></li>
<li><a href="{{BASE_PATH}}/displaysystem/basicdisplaysystem.html#table">Table</a></li>
<li><a href="{{BASE_PATH}}/displaysystem/basicdisplaysystem.html#network">Network</a></li>
<li role="separator" class="divider"></li>
<li class="title"><span><b>Angular API</b><span></li>
<li><a href="{{BASE_PATH}}/displaysystem/back-end-angular.html">Angular (backend API)</a></li>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions docs/displaysystem/basicdisplaysystem.md
Expand Up @@ -61,3 +61,56 @@ If table contents start with `%html`, it is interpreted as an HTML.
<img src="../assets/themes/zeppelin/img/screenshots/display_table_html.png" />

> **Note :** Display system is backend independent.
## Network

With the `%network` directive, Zeppelin treats your output as a graph. Zeppelin can leverage the Property Graph Model.

### What is the Labelled Property Graph Model?

A [Property Graph](https://github.com/tinkerpop/gremlin/wiki/Defining-a-Property-Graph) is a graph that has these elements:

* a set of vertices
* each vertex has a unique identifier.
* each vertex has a set of outgoing edges.
* each vertex has a set of incoming edges.
* each vertex has a collection of properties defined by a map from key to value
* a set of edges
* each edge has a unique identifier.
* each edge has an outgoing tail vertex.
* each edge has an incoming head vertex.
* each edge has a label that denotes the type of relationship between its two vertices.
* each edge has a collection of properties defined by a map from key to value.

<img src="https://github.com/tinkerpop/gremlin/raw/master/doc/images/graph-example-1.jpg" />

A [Labelled Property Graph](https://neo4j.com/developer/graph-database/#property-graph) is a Property Graph where the nodes can be tagged with **labels** representing their different roles in the graph model

<img src="http://s3.amazonaws.com/dev.assets.neo4j.com/wp-content/uploads/property_graph_model.png" />

### What are the APIs?

The new NETWORK visualization is based on json with the following params:

* "nodes" (mandatory): list of nodes of the graph every node can have the following params:
* "id" (mandatory): the id of the node (must be unique);
* "label": the main Label of the node;
* "labels": the list of the labels of the node;
* "data": the data attached to the node;
* "edges": list of the edges of the graph;
* "id" (mandatory): the id of the edge (must be unique);
* "source" (mandatory): the id of source node of the edge;
* "target" (mandatory): the id of target node of the edge;
* "label": the main type of the edge;
* "data": the data attached to the edge;
* "labels": a map (K, V) where K is the node label and V is the color of the node;
* "directed": (true/false, default false) wich tells if is directed graph or not;
* "types": a *distinct* list of the edge types of the graph

If you click on a node or edge on the bottom of the paragraph you find a list of entity properties

<img src="../assets/themes/zeppelin/img/screenshots/display_network.png" />

This kind of graph can be easily *flatten* in order to support other visualization formats provided by Zeppelin.

<img src="../assets/themes/zeppelin/img/screenshots/display_network_flatten.png" />
Expand Up @@ -50,7 +50,8 @@ public static enum Type {
TABLE,
IMG,
SVG,
NULL
NULL,
NETWORK
}

Code code;
Expand Down
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zeppelin.interpreter.graph;

import java.util.Map;

/**
* The base network entity
*
*/
public abstract class GraphEntity {

private long id;

/**
* The data of the entity
*
*/
private Map<String, Object> data;

/**
* The primary type of the entity
*/
private String label;

//private String color;

public GraphEntity() {}

public GraphEntity(long id, Map<String, Object> data, String label) {
super();
this.setId(id);
this.setData(data);
this.setLabel(label);
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public Map<String, Object> getData() {
return data;
}

public void setData(Map<String, Object> data) {
this.data = data;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

}
@@ -0,0 +1,120 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zeppelin.interpreter.graph;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import org.apache.zeppelin.interpreter.InterpreterResult;

import com.google.gson.Gson;

/**
* The intepreter result template for Networks
*
*/
public class GraphResult extends InterpreterResult {

/**
* The Graph structure parsed from the front-end
*
*/
public static class Graph {
private Collection<Node> nodes;

private Collection<Relationship> edges;

/**
* The node types in the whole graph, and the related colors
*
*/
private Map<String, String> labels;

/**
* The relationship types in the whole graph
*
*/
private Set<String> types;

/**
* Is a directed graph
*/
private boolean directed;

public Graph() {}

public Graph(Collection<Node> nodes, Collection<Relationship> edges,
Map<String, String> labels, Set<String> types, boolean directed) {
super();
this.setNodes(nodes);
this.setEdges(edges);
this.setLabels(labels);
this.setTypes(types);
this.setDirected(directed);
}

public Collection<Node> getNodes() {
return nodes;
}

public void setNodes(Collection<Node> nodes) {
this.nodes = nodes;
}

public Collection<Relationship> getEdges() {
return edges;
}

public void setEdges(Collection<Relationship> edges) {
this.edges = edges;
}

public Map<String, String> getLabels() {
return labels;
}

public void setLabels(Map<String, String> labels) {
this.labels = labels;
}

public Set<String> getTypes() {
return types;
}

public void setTypes(Set<String> types) {
this.types = types;
}

public boolean isDirected() {
return directed;
}

public void setDirected(boolean directed) {
this.directed = directed;
}

}

private static final Gson gson = new Gson();

public GraphResult(Code code, Graph graphObject) {
super(code, Type.NETWORK, gson.toJson(graphObject));
}

}
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zeppelin.interpreter.graph;

/**
* An utiliy class for networks
*
*/
public class GraphUtils {
private GraphUtils() {}

private static final String[] LETTERS = "0123456789ABCDEF".split("");

public static final String COLOR_GREY = "#D3D3D3";

public static String getRandomColor() {
char[] color = new char[7];
color[0] = '#';
for (int i = 1; i < color.length; i++) {
color[i] = LETTERS[(int) Math.floor(Math.random() * 16)].charAt(0);
}
return new String(color);
}

}
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zeppelin.interpreter.graph;

import java.util.Map;
import java.util.Set;

/**
* The Zeppelin Node Entity
*
*/
public class Node extends GraphEntity {

/**
* The labels (types) attached to a node
*/
private Set<String> labels;

public Node() {}


public Node(long id, Map<String, Object> data, Set<String> labels) {
super(id, data, labels.iterator().next());
}

public Set<String> getLabels() {
return labels;
}

public void setLabels(Set<String> labels) {
this.labels = labels;
}

}

0 comments on commit 6e74eb9

Please sign in to comment.