public class VisJsVisualizer extends Object implements GraphTraverseHandler
This class provides a possibility to create a html file, which visualizes a salt graph, created from an [SDocument](\ref org.corpus_tools.salt.common.SDocument) or from an org.eclipse.emf.common.util.URI of a salt file, using the vis.js library from visjs.org. Also it can be used to get both nodes and relations of a salt document in JSON format. Note, if no export filter used, all nodes and all relations but textual relations will be visualized.
A simple way to use this class for writing the html file is shown in the following example code.
String inputSaltFile = "path_to_your_salt_file";
String outputFolder = "path_to_your_output_folder";
URI uri = URI.createFileURI(inputSaltFile);
VisJsVisualizer visJsVisualizer = new VisJsVisualizer(uri);
try {
URI outputFileUri = URI.createFileURI(outputFolder);
visJsVisualizer.visualize(outputFileUri);
} catch (IOException | XMLStreamException e) {
e.printStackTrace();
}
The next listing shows how to get the nodes and the relations of an input
salt file in JSON format by use of this class. For simplicity, the created
JSON objects will be written to the standard output. URI uri = URI.createFileURI("path_to_the_input_salt_file");
OutputStream nodeStream = Sytem.out;
OutputStream edgeStream = System.out;
VisJsVisualizer VisJsVisualizer = new VisJsVisualizer(uri);
VisJsVisualizer.setNodeWriter(nodeStream);
VisJsVisualizer.setEdgeWriter(edgeStream);
VisJsVisualizer.buildJSON();
try {
nodeStream.write('\n'); nodeStream.flush();
edgeStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
| Modifier and Type | Field and Description |
|---|---|
static String |
CSS_FILE |
static String |
CSS_FOLDER_OUT |
BufferedWriter |
edgeWriter |
static String |
HTML_FILE |
static String |
IMG_FOLDER_OUT |
static String |
JQUERY_FILE |
static String |
JS_FILE |
static String |
JS_FOLDER_OUT |
BufferedWriter |
nodeWriter |
| Constructor and Description |
|---|
VisJsVisualizer(SDocument doc)
Creates a new VisJsVisualizer instance for specified salt document.
|
VisJsVisualizer(SDocument doc,
ExportFilter exportFilter,
StyleImporter styleImporter)
Creates a new VisJsVisualizer instance with specified export filter for
specified salt document.
|
VisJsVisualizer(org.eclipse.emf.common.util.URI inputFileUri)
Creates a new VisJsVisualizer instance for a salt file specified by the
uri.
|
VisJsVisualizer(org.eclipse.emf.common.util.URI inputFileUri,
ExportFilter exportFilter,
StyleImporter styleImporter)
Creates a new VisJsVisualizer instance with specified export filter for a
salt file specified by the uri.
|
| Modifier and Type | Method and Description |
|---|---|
void |
buildJSON()
By invoking of this method the graph of the salt document specified by
the constructor will be traversed.
|
boolean |
checkConstraint(SGraph.GRAPH_TRAVERSE_TYPE traversalType,
String traversalId,
SRelation relation,
SNode currNode,
long order)
Implements the checkConstraint method of the
GraphTraverseHandler interface. |
void |
nodeLeft(SGraph.GRAPH_TRAVERSE_TYPE traversalType,
String traversalId,
SNode currNode,
SRelation relation,
SNode fromNode,
long order)
Implements the nodeLeft method of the
GraphTraverseHandler interface. |
void |
nodeReached(SGraph.GRAPH_TRAVERSE_TYPE traversalType,
String traversalId,
SNode currNode,
SRelation relation,
SNode fromNode,
long order)
Implements the nodeReached method of the
GraphTraverseHandler interface. |
void |
setEdgeWriter(OutputStream os)
Creates a new buffered writer with specified output stream.
|
void |
setNodeWriter(OutputStream os)
Creates a new buffered writer with specified output stream.
|
void |
visualize(org.eclipse.emf.common.util.URI outputFolderUri)
This method writes the html document, which visualizes the Salt document,
specified by constructor.
|
public BufferedWriter nodeWriter
public BufferedWriter edgeWriter
public static final String CSS_FOLDER_OUT
public static final String IMG_FOLDER_OUT
public static final String JS_FOLDER_OUT
public static final String CSS_FILE
public static final String JS_FILE
public static final String JQUERY_FILE
public static final String HTML_FILE
public VisJsVisualizer(SDocument doc) throws IOException
doc - an [SDocument](\ref org.corpus_tools.salt.common.SDocument) to
be visualizedIOException - if creation of tmp file failed *SaltParameterException - if the doc is nullpublic VisJsVisualizer(SDocument doc, ExportFilter exportFilter, StyleImporter styleImporter) throws IOException
doc - an [SDocument](\ref org.corpus_tools.salt.common.SDocument) to
be visualizedexportFilter - an ExportFilter to include or exclude nodes and/or
relations explicitly. If null, all nodes and relations will be
visualized.styleImporter - a StyleImporter to highlight nodes. If null, no nodes
will be highlighted.IOException - if creation of tmp file failedSaltParameterException - if doc is nullpublic VisJsVisualizer(org.eclipse.emf.common.util.URI inputFileUri)
throws IOException
inputFileUri - a hierarchical
org.eclipse.emf.common.util.URI of a salt file to be
visualized. The constructor will create a new [SDocument](\ref
org.corpus_tools.salt.common.SDocument) of this.IOException - if creation of tmp file failedSaltParameterException - - if the inputFileUri is nullpublic VisJsVisualizer(org.eclipse.emf.common.util.URI inputFileUri,
ExportFilter exportFilter,
StyleImporter styleImporter)
throws IOException
inputFileUri - a hierarchical
org.eclipse.emf.common.util.URI of a salt file, which has
to be visualized. The constructor will create a new
[SDocument](\ref org.corpus_tools.salt.common.SDocument) of
this.exportFilter - an ExportFilter to include or exclude nodes and/or
relations explicitly. If null, all nodes and relations will be
visualized.styleImporter - a StyleImporter to highlight nodes. If null, no nodes
will be highlighted.IOException - if creation of tmp file failedSaltParameterException - if the inputFileUri is nullSaltResourceException - if a problem occurred while loading salt project from the
inputFileUripublic void visualize(org.eclipse.emf.common.util.URI outputFolderUri)
throws SaltParameterException,
SaltResourceException,
SaltException,
SaltResourceException,
IOException,
XMLStreamException
This method writes the html document, which visualizes the Salt document, specified by constructor. The output folder structure will be created, if not yet exists. The output html file as well as the auxiliary files will be written.
The whole output structure will look like following: outputFolderUri - a hierarchical
org.eclipse.emf.common.util.URI that specifies the output
folder path. Note, that the output folder have not necessarily
to be existing.SaltParameterException - if the outputFolderUri is nullSaltResourceException - if the output auxiliary files cannot have been createdSaltException - if the output folders cannot have been created or permission
deniedSaltResourceException - if a problem occurred while copying the auxiliary filesXMLStreamException - if a problem occurred while writing the output html fileIOException - if a problem occurred while writing the output filepublic void setNodeWriter(OutputStream os)
buildJSON() method.os - OutputStream associated to the node writer.public void setEdgeWriter(OutputStream os)
buildJSON() method.os - OutputStream associated to the edge writerpublic void buildJSON()
throws SaltException,
SaltParameterException
nodeWriter and the
edgeWriter write nodes and relations of this graph respective to
the associated output streams.SaltException - if a problem occurred while building JSON objectsSaltParameterException - if the node writer and/or the edge writer not setpublic void nodeReached(SGraph.GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order)
GraphTraverseHandler interface.nodeReached in interface GraphTraverseHandlertraversalType - the type of current traversaltraversalId - the id of current traversal, given by the invoking objectcurrNode - the current noderelation - the relation via which the current node was reachedfromNode - the parent nodeorder - the number of the relation in the parent nodepublic void nodeLeft(SGraph.GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order)
GraphTraverseHandler interface.nodeLeft in interface GraphTraverseHandlertraversalType - the type of current traversaltraversalId - the id of current traversal, given by the invoking objectcurrNode - the current noderelation - the relation via which the current node was reachedfromNode - the parent nodeorder - the number of the relation in the parent nodepublic boolean checkConstraint(SGraph.GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SRelation relation, SNode currNode, long order)
GraphTraverseHandler interface.checkConstraint in interface GraphTraverseHandlertraversalType - the type of current traversaltraversalId - the id of current traversal, given by the invoking objectrelation - the relation via which the current node was reachedcurrNode - the current nodeorder - the number of the relation in the parent nodeCopyright © 2009–2019 Humboldt-Universität zu Berlin, INRIA. All rights reserved.